VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware2/VBoxPkg/VBoxFsDxe/fsw_iso9660.c@ 29921

Last change on this file since 29921 was 29125, checked in by vboxsync, 15 years ago

export more EFI files to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.8 KB
Line 
1/* $Id: fsw_iso9660.c 29125 2010-05-06 09:43:05Z vboxsync $ */
2/** @file
3 * fsw_iso9660.c - ISO9660 file system driver code.
4 *
5 * Current limitations:
6 * - Files must be in one extent (i.e. Level 2)
7 * - No Joliet or Rock Ridge extensions
8 * - No interleaving
9 * - inode number generation strategy fails on volumes > 2 GB
10 * - No blocksizes != 2048
11 * - No High Sierra or anything else != 'CD001'
12 * - No volume sets with directories pointing at other volumes
13 * - No extended attribute records
14 */
15
16/*
17 * Copyright (C) 2010 Oracle Corporation
18 *
19 * This file is part of VirtualBox Open Source Edition (OSE), as
20 * available from http://www.virtualbox.org. This file is free software;
21 * you can redistribute it and/or modify it under the terms of the GNU
22 * General Public License (GPL) as published by the Free Software
23 * Foundation, in version 2 as it comes in the "COPYING" file of the
24 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
25 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
26 */
27
28/*-
29 * This code is based on:
30 *
31 * Copyright (c) 2006 Christoph Pfisterer
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions are
35 * met:
36 *
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 *
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the
43 * distribution.
44 *
45 * * Neither the name of Christoph Pfisterer nor the names of the
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 */
61
62#include "fsw_iso9660.h"
63
64
65// functions
66
67static fsw_status_t fsw_iso9660_volume_mount(struct fsw_iso9660_volume *vol);
68static void fsw_iso9660_volume_free(struct fsw_iso9660_volume *vol);
69static fsw_status_t fsw_iso9660_volume_stat(struct fsw_iso9660_volume *vol, struct fsw_volume_stat *sb);
70
71static fsw_status_t fsw_iso9660_dnode_fill(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno);
72static void fsw_iso9660_dnode_free(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno);
73static fsw_status_t fsw_iso9660_dnode_stat(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
74 struct fsw_dnode_stat *sb);
75static fsw_status_t fsw_iso9660_get_extent(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
76 struct fsw_extent *extent);
77
78static fsw_status_t fsw_iso9660_dir_lookup(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
79 struct fsw_string *lookup_name, struct fsw_iso9660_dnode **child_dno);
80static fsw_status_t fsw_iso9660_dir_read(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
81 struct fsw_shandle *shand, struct fsw_iso9660_dnode **child_dno);
82static fsw_status_t fsw_iso9660_read_dirrec(struct fsw_iso9660_volume *vol, struct fsw_shandle *shand, struct iso9660_dirrec_buffer *dirrec_buffer);
83
84static fsw_status_t fsw_iso9660_readlink(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
85 struct fsw_string *link);
86
87static fsw_status_t rr_find_sp(struct iso9660_dirrec *dirrec, struct fsw_rock_ridge_susp_sp **psp);
88static fsw_status_t rr_find_nm(struct fsw_iso9660_volume *vol, struct iso9660_dirrec *dirrec, int off, struct fsw_string *str);
89static fsw_status_t rr_read_ce(struct fsw_iso9660_volume *vol, union fsw_rock_ridge_susp_ce *ce, fsw_u8 *begin);
90static void dump_dirrec(struct iso9660_dirrec *dirrec);
91//
92// Dispatch Table
93//
94
95struct fsw_fstype_table FSW_FSTYPE_TABLE_NAME(iso9660) = {
96 { FSW_STRING_TYPE_ISO88591, 4, 4, "iso9660" },
97 sizeof(struct fsw_iso9660_volume),
98 sizeof(struct fsw_iso9660_dnode),
99
100 fsw_iso9660_volume_mount,
101 fsw_iso9660_volume_free,
102 fsw_iso9660_volume_stat,
103 fsw_iso9660_dnode_fill,
104 fsw_iso9660_dnode_free,
105 fsw_iso9660_dnode_stat,
106 fsw_iso9660_get_extent,
107 fsw_iso9660_dir_lookup,
108 fsw_iso9660_dir_read,
109 fsw_iso9660_readlink,
110};
111
112static fsw_status_t rr_find_sp(struct iso9660_dirrec *dirrec, struct fsw_rock_ridge_susp_sp **psp)
113{
114 fsw_u8 *r;
115 int off = 0;
116 struct fsw_rock_ridge_susp_sp *sp;
117 r = (fsw_u8 *)((fsw_u8 *)dirrec + sizeof(*dirrec) + dirrec->file_identifier_length);
118 off = (int)(r - (fsw_u8 *)dirrec);
119 while(off < dirrec->dirrec_length)
120 {
121 if (*r == 'S')
122 {
123 sp = (struct fsw_rock_ridge_susp_sp *)r;
124 if( sp->e.sig[0] == 'S'
125 && sp->e.sig[1] == 'P'
126 && sp->magic[0] == 0xbe
127 && sp->magic[1] == 0xef)
128 {
129 *psp = sp;
130 return FSW_SUCCESS;
131 }
132 }
133 r++;
134 off = (int)(r - (fsw_u8 *)dirrec);
135 }
136 *psp = NULL;
137 return FSW_NOT_FOUND;
138}
139
140static fsw_status_t rr_find_nm(struct fsw_iso9660_volume *vol, struct iso9660_dirrec *dirrec, int off, struct fsw_string *str)
141{
142 fsw_u8 *r, *begin;
143 int fCe = 0;
144 struct fsw_rock_ridge_susp_nm *nm;
145 int limit = dirrec->dirrec_length;
146 begin = (fsw_u8 *)dirrec;
147 r = (fsw_u8 *)dirrec + off;
148 str->data = NULL;
149 str->len = 0;
150 str->size = 0;
151 str->type = 0;
152 while(off < limit)
153 {
154 if (r[0] == 'C' && r[1] == 'E' && r[2] == 28)
155 {
156 int rc;
157 int ce_off;
158 union fsw_rock_ridge_susp_ce *ce;
159 if (fCe == 0)
160 fsw_alloc_zero(ISO9660_BLOCKSIZE, (void *)&begin);
161 fCe = 1;
162 DEBUG((DEBUG_WARN, "%a:%d we found CE before NM or its continuation\n", __FILE__, __LINE__));
163 ce = (union fsw_rock_ridge_susp_ce *)r;
164 limit = ISOINT(ce->X.len);
165 ce_off = ISOINT(ce->X.offset);
166 rc = rr_read_ce(vol, ce, begin);
167 if (rc != FSW_SUCCESS)
168 {
169 fsw_free(begin);
170 return rc;
171 }
172 begin += ce_off;
173 r = begin;
174 }
175 if (r[0] == 'N' && r[1] == 'M')
176 {
177 nm = (struct fsw_rock_ridge_susp_nm *)r;
178 if( nm->e.sig[0] == 'N'
179 && nm->e.sig[1] == 'M')
180 {
181 int len = 0;
182 fsw_u8 *tmp = NULL;
183 if (nm->flags & RR_NM_CURR)
184 {
185 fsw_memdup(str->data, ".", 1);
186 str->len = 1;
187 goto done;
188 }
189 if (nm->flags & RR_NM_PARE)
190 {
191 fsw_memdup(str->data, "..", 2);
192 str->len = 2;
193 goto done;
194 }
195 len = nm->e.len - sizeof(struct fsw_rock_ridge_susp_nm) + 1;
196 fsw_alloc_zero(str->len + len, (void **)&tmp);
197 if (str->data != NULL)
198 {
199 fsw_memcpy(tmp, str->data, str->len);
200 fsw_free(str->data);
201 }
202 DEBUG((DEBUG_INFO, "dst:%p src:%p len:%d\n", tmp + str->len, &nm->name[0], len));
203 fsw_memcpy(tmp + str->len, &nm->name[0], len);
204 str->data = tmp;
205 str->len += len;
206
207 if ((nm->flags & RR_NM_CONT) == 0);
208 goto done;
209 }
210 }
211 r++;
212 off = (int)(r - (fsw_u8 *)begin);
213 }
214 if(fCe == 1)
215 fsw_free(begin);
216 return FSW_NOT_FOUND;
217done:
218 str->type = FSW_STRING_TYPE_ISO88591;
219 str->size = str->len;
220 if(fCe == 1)
221 fsw_free(begin);
222 return FSW_SUCCESS;
223}
224
225static fsw_status_t rr_read_ce(struct fsw_iso9660_volume *vol, union fsw_rock_ridge_susp_ce *ce, fsw_u8 *begin)
226{
227 int rc;
228 int i;
229 fsw_u8 *r = begin + ISOINT(ce->X.offset);
230 int len = ISOINT(ce->X.len);
231 rc = vol->g.host_table->read_block(&vol->g, ISOINT(ce->X.block_loc), begin);
232 if (rc != FSW_SUCCESS)
233 return rc;
234 for (i = 0; i < len; ++i)
235 {
236 DEBUG((DEBUG_INFO, "%d: (%d:%x)%c ", i, r[i], r[i], r[i]));
237 }
238 return FSW_SUCCESS;
239}
240static void dump_dirrec(struct iso9660_dirrec *dirrec)
241{
242 int i;
243 fsw_u8 *r = (fsw_u8 *)dirrec + dirrec->file_identifier_length;
244 int len = dirrec->dirrec_length;
245 for (i = dirrec->file_identifier_length; i < len; ++i)
246 {
247 DEBUG((DEBUG_INFO, "%d: (%d:%x)%c ", i, r[i], r[i], r[i]));
248 }
249}
250/**
251 * Mount an ISO9660 volume. Reads the superblock and constructs the
252 * root directory dnode.
253 */
254
255static fsw_status_t fsw_iso9660_volume_mount(struct fsw_iso9660_volume *vol)
256{
257 fsw_status_t status;
258 void *buffer;
259 fsw_u32 blockno;
260 struct iso9660_volume_descriptor *voldesc;
261 struct iso9660_primary_volume_descriptor *pvoldesc;
262 fsw_u32 voldesc_type;
263 int i;
264 struct fsw_string s;
265 struct iso9660_dirrec rootdir;
266 int sua_pos;
267 char *sig;
268 int skip;
269 struct fsw_rock_ridge_susp_entry *entry;
270
271 // read through the Volume Descriptor Set
272 fsw_set_blocksize(vol, ISO9660_BLOCKSIZE, ISO9660_BLOCKSIZE);
273 blockno = ISO9660_SUPERBLOCK_BLOCKNO;
274
275 do {
276 status = fsw_block_get(vol, blockno, 0, &buffer);
277 if (status)
278 return status;
279
280 voldesc = (struct iso9660_volume_descriptor *)buffer;
281 voldesc_type = voldesc->volume_descriptor_type;
282 if (fsw_memeq(voldesc->standard_identifier, "CD001", 5)) {
283 // descriptor follows ISO 9660 standard
284 if (voldesc_type == 1 && voldesc->volume_descriptor_version == 1) {
285 // suitable Primary Volume Descriptor found
286 if (vol->primary_voldesc) {
287 fsw_free(vol->primary_voldesc);
288 vol->primary_voldesc = NULL;
289 }
290 status = fsw_memdup((void **)&vol->primary_voldesc, voldesc, ISO9660_BLOCKSIZE);
291 }
292 } else if (!fsw_memeq(voldesc->standard_identifier, "CD", 2)) {
293 // completely alien standard identifier, stop reading
294 voldesc_type = 255;
295 }
296
297 fsw_block_release(vol, blockno, buffer);
298 blockno++;
299 } while (!status && voldesc_type != 255);
300 if (status)
301 return status;
302
303 // get information from Primary Volume Descriptor
304 if (vol->primary_voldesc == NULL)
305 return FSW_UNSUPPORTED;
306 pvoldesc = vol->primary_voldesc;
307 if (ISOINT(pvoldesc->logical_block_size) != 2048)
308 return FSW_UNSUPPORTED;
309
310 // get volume name
311 for (i = 32; i > 0; i--)
312 if (pvoldesc->volume_identifier[i-1] != ' ')
313 break;
314 s.type = FSW_STRING_TYPE_ISO88591;
315 s.size = s.len = i;
316 s.data = pvoldesc->volume_identifier;
317 status = fsw_strdup_coerce(&vol->g.label, vol->g.host_string_type, &s);
318 if (status)
319 return status;
320
321 // setup the root dnode
322 status = fsw_dnode_create_root(vol, ISO9660_SUPERBLOCK_BLOCKNO << ISO9660_BLOCKSIZE_BITS, &vol->g.root);
323 if (status)
324 return status;
325 fsw_memcpy(&vol->g.root->dirrec, &pvoldesc->root_directory, sizeof(struct iso9660_dirrec));
326
327 if ( pvoldesc->escape[0] == 0x25
328 && pvoldesc->escape[1] == 0x2f
329 && ( pvoldesc->escape[2] == 0x40
330 || pvoldesc->escape[2] == 0x43
331 || pvoldesc->escape[2] == 0x45))
332 {
333 FSW_MSG_DEBUG((FSW_MSGSTR("fsw_iso9660_volume_mount: success (joliet!!!)\n")));
334 vol->fJoliet = 1;
335 }
336
337
338 rootdir = pvoldesc->root_directory;
339 sua_pos = (sizeof(struct iso9660_dirrec)) + rootdir.file_identifier_length + (rootdir.file_identifier_length % 2) - 2;
340 //int sua_size = rootdir.dirrec_length - rootdir.file_identifier_length;
341 //FSW_MSG_DEBUG((FSW_MSGSTR("fsw_iso9660_volume_mount: success (SUA(pos:%x, sz:%d)!!!)\n"), sua_pos, sua_size));
342
343#if 1
344 status = fsw_block_get(vol, ISOINT(rootdir.extent_location), 0, &buffer);
345 sig = (char *)buffer + sua_pos;
346 skip = 0;
347 entry = (struct fsw_rock_ridge_susp_entry *)sig;
348 if ( entry->sig[0] == 'S'
349 && entry->sig[1] == 'P')
350 {
351 struct fsw_rock_ridge_susp_sp *sp = (struct fsw_rock_ridge_susp_sp *)entry;
352 if (sp->magic[0] == 0xbe && sp->magic[1] == 0xef)
353 {
354 vol->fRockRidge = 1;
355 } else {
356 FSW_MSG_DEBUG((FSW_MSGSTR("fsw_iso9660_volume_mount: SP magic isn't valid\n")));
357 }
358 skip = sp->skip;
359 }
360#endif
361 // release volume descriptors
362 fsw_free(vol->primary_voldesc);
363 vol->primary_voldesc = NULL;
364
365
366 FSW_MSG_DEBUG((FSW_MSGSTR("fsw_iso9660_volume_mount: success\n")));
367
368 return FSW_SUCCESS;
369}
370
371/**
372 * Free the volume data structure. Called by the core after an unmount or after
373 * an unsuccessful mount to release the memory used by the file system type specific
374 * part of the volume structure.
375 */
376
377static void fsw_iso9660_volume_free(struct fsw_iso9660_volume *vol)
378{
379 if (vol->primary_voldesc)
380 fsw_free(vol->primary_voldesc);
381}
382
383/**
384 * Get in-depth information on a volume.
385 */
386
387static fsw_status_t fsw_iso9660_volume_stat(struct fsw_iso9660_volume *vol, struct fsw_volume_stat *sb)
388{
389 sb->total_bytes = 0; //(fsw_u64)vol->sb->s_blocks_count * vol->g.log_blocksize;
390 sb->free_bytes = 0;
391 return FSW_SUCCESS;
392}
393
394/**
395 * Get full information on a dnode from disk. This function is called by the core
396 * whenever it needs to access fields in the dnode structure that may not
397 * be filled immediately upon creation of the dnode. In the case of iso9660, we
398 * delay fetching of the inode structure until dnode_fill is called. The size and
399 * type fields are invalid until this function has been called.
400 */
401
402static fsw_status_t fsw_iso9660_dnode_fill(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno)
403{
404 // get info from the directory record
405 dno->g.size = ISOINT(dno->dirrec.data_length);
406 if (dno->dirrec.file_flags & 0x02)
407 dno->g.type = FSW_DNODE_TYPE_DIR;
408 else
409 dno->g.type = FSW_DNODE_TYPE_FILE;
410
411 return FSW_SUCCESS;
412}
413
414/**
415 * Free the dnode data structure. Called by the core when deallocating a dnode
416 * structure to release the memory used by the file system type specific part
417 * of the dnode structure.
418 */
419
420static void fsw_iso9660_dnode_free(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno)
421{
422}
423
424/**
425 * Get in-depth information on a dnode. The core makes sure that fsw_iso9660_dnode_fill
426 * has been called on the dnode before this function is called. Note that some
427 * data is not directly stored into the structure, but passed to a host-specific
428 * callback that converts it to the host-specific format.
429 */
430
431static fsw_status_t fsw_iso9660_dnode_stat(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
432 struct fsw_dnode_stat *sb)
433{
434 sb->used_bytes = (dno->g.size + (ISO9660_BLOCKSIZE-1)) & ~(ISO9660_BLOCKSIZE-1);
435 /*
436 sb->store_time_posix(sb, FSW_DNODE_STAT_CTIME, dno->raw->i_ctime);
437 sb->store_time_posix(sb, FSW_DNODE_STAT_ATIME, dno->raw->i_atime);
438 sb->store_time_posix(sb, FSW_DNODE_STAT_MTIME, dno->raw->i_mtime);
439 sb->store_attr_posix(sb, dno->raw->i_mode);
440 */
441
442 return FSW_SUCCESS;
443}
444
445/**
446 * Retrieve file data mapping information. This function is called by the core when
447 * fsw_shandle_read needs to know where on the disk the required piece of the file's
448 * data can be found. The core makes sure that fsw_iso9660_dnode_fill has been called
449 * on the dnode before. Our task here is to get the physical disk block number for
450 * the requested logical block number.
451 */
452
453static fsw_status_t fsw_iso9660_get_extent(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
454 struct fsw_extent *extent)
455{
456 // Preconditions: The caller has checked that the requested logical block
457 // is within the file's size. The dnode has complete information, i.e.
458 // fsw_iso9660_dnode_read_info was called successfully on it.
459
460 extent->type = FSW_EXTENT_TYPE_PHYSBLOCK;
461 extent->phys_start = ISOINT(dno->dirrec.extent_location);
462 extent->log_start = 0;
463 extent->log_count = (ISOINT(dno->dirrec.data_length) + (ISO9660_BLOCKSIZE-1)) >> ISO9660_BLOCKSIZE_BITS;
464 return FSW_SUCCESS;
465}
466
467/**
468 * Lookup a directory's child dnode by name. This function is called on a directory
469 * to retrieve the directory entry with the given name. A dnode is constructed for
470 * this entry and returned. The core makes sure that fsw_iso9660_dnode_fill has been called
471 * and the dnode is actually a directory.
472 */
473
474static fsw_status_t fsw_iso9660_dir_lookup(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
475 struct fsw_string *lookup_name, struct fsw_iso9660_dnode **child_dno_out)
476{
477 fsw_status_t status;
478 struct fsw_shandle shand;
479 struct iso9660_dirrec_buffer dirrec_buffer;
480 struct iso9660_dirrec *dirrec = &dirrec_buffer.dirrec;
481
482 // Preconditions: The caller has checked that dno is a directory node.
483
484 // setup handle to read the directory
485 status = fsw_shandle_open(dno, &shand);
486 if (status)
487 return status;
488
489 // scan the directory for the file
490 while (1) {
491 // read next entry
492 status = fsw_iso9660_read_dirrec(vol, &shand, &dirrec_buffer);
493 if (status)
494 goto errorexit;
495 if (dirrec->dirrec_length == 0) {
496 // end of directory reached
497 status = FSW_NOT_FOUND;
498 goto errorexit;
499 }
500
501 // skip . and ..
502 if (dirrec->file_identifier_length == 1 &&
503 (dirrec->file_identifier[0] == 0 || dirrec->file_identifier[0] == 1))
504 continue;
505
506 // compare name
507 if (fsw_streq(lookup_name, &dirrec_buffer.name)) // TODO: compare case-insensitively
508 break;
509 }
510
511 // setup a dnode for the child item
512 status = fsw_dnode_create(dno, dirrec_buffer.ino, FSW_DNODE_TYPE_UNKNOWN, &dirrec_buffer.name, child_dno_out);
513 if (status == FSW_SUCCESS)
514 fsw_memcpy(&(*child_dno_out)->dirrec, dirrec, sizeof(struct iso9660_dirrec));
515
516errorexit:
517 fsw_shandle_close(&shand);
518 return status;
519}
520
521/**
522 * Get the next directory entry when reading a directory. This function is called during
523 * directory iteration to retrieve the next directory entry. A dnode is constructed for
524 * the entry and returned. The core makes sure that fsw_iso9660_dnode_fill has been called
525 * and the dnode is actually a directory. The shandle provided by the caller is used to
526 * record the position in the directory between calls.
527 */
528
529static fsw_status_t fsw_iso9660_dir_read(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
530 struct fsw_shandle *shand, struct fsw_iso9660_dnode **child_dno_out)
531{
532 fsw_status_t status;
533 struct iso9660_dirrec_buffer dirrec_buffer;
534 struct iso9660_dirrec *dirrec = &dirrec_buffer.dirrec;
535
536 // Preconditions: The caller has checked that dno is a directory node. The caller
537 // has opened a storage handle to the directory's storage and keeps it around between
538 // calls.
539 /* (vasily) direcory nodes are 4096 bytes that is two logical blocks so read dir operation
540 * should read both blocks.
541 */
542
543 while (1) {
544 // read next entry
545 if (shand->pos >= dno->g.size)
546 return FSW_NOT_FOUND; // end of directory
547 status = fsw_iso9660_read_dirrec(vol, shand, &dirrec_buffer);
548 if (status)
549 return status;
550 if (dirrec->dirrec_length == 0)
551 {
552 // try the next block
553 shand->pos =(shand->pos & ~(vol->g.log_blocksize - 1)) + vol->g.log_blocksize;
554 continue;
555 }
556
557 // skip . and ..
558 if (dirrec->file_identifier_length == 1 &&
559 (dirrec->file_identifier[0] == 0 || dirrec->file_identifier[0] == 1))
560 continue;
561 break;
562 }
563
564 // setup a dnode for the child item
565 status = fsw_dnode_create(dno, dirrec_buffer.ino, FSW_DNODE_TYPE_UNKNOWN, &dirrec_buffer.name, child_dno_out);
566 if (status == FSW_SUCCESS)
567 fsw_memcpy(&(*child_dno_out)->dirrec, dirrec, sizeof(struct iso9660_dirrec));
568
569 return status;
570}
571
572/**
573 * Read a directory entry from the directory's raw data. This internal function is used
574 * to read a raw iso9660 directory entry into memory. The shandle's position pointer is adjusted
575 * to point to the next entry.
576 */
577
578static fsw_status_t fsw_iso9660_read_dirrec(struct fsw_iso9660_volume *vol, struct fsw_shandle *shand, struct iso9660_dirrec_buffer *dirrec_buffer)
579{
580 fsw_status_t status;
581 fsw_u32 i, buffer_size, remaining_size, name_len;
582 struct fsw_rock_ridge_susp_sp *sp = NULL;
583 struct iso9660_dirrec *dirrec = &dirrec_buffer->dirrec;
584 int sp_off;
585 int rc;
586
587 dirrec_buffer->ino = (ISOINT(((struct fsw_iso9660_dnode *)shand->dnode)->dirrec.extent_location)
588 << ISO9660_BLOCKSIZE_BITS)
589 + (fsw_u32)shand->pos;
590
591 // read fixed size part of directory record
592 buffer_size = 33;
593 status = fsw_shandle_read(shand, &buffer_size, dirrec);
594 if (status)
595 {
596 DEBUG((DEBUG_INFO, "%a:%d \n", __FILE__, __LINE__));
597 return status;
598 }
599
600 if (buffer_size < 33 || dirrec->dirrec_length == 0) {
601 // end of directory reached
602 fsw_u8 *r;
603 r = (fsw_u8 *)dirrec;
604 DEBUG((DEBUG_INFO, "%a:%d bs:%d dl:%d\n", __FILE__, __LINE__, buffer_size, dirrec->dirrec_length));
605 for(i = 0; i < buffer_size; ++i)
606 {
607 DEBUG((DEBUG_INFO, "r[%d]:%c", i, r[i]));
608 }
609 dirrec->dirrec_length = 0;
610 return FSW_SUCCESS;
611 }
612 if (dirrec->dirrec_length < 33 ||
613 dirrec->dirrec_length < 33 + dirrec->file_identifier_length)
614 return FSW_VOLUME_CORRUPTED;
615
616 DEBUG((DEBUG_INFO, "%a:%d, dirrec_length: %d\n", __FILE__, __LINE__, dirrec->dirrec_length));
617
618 // read variable size part of directory record
619 buffer_size = remaining_size = dirrec->dirrec_length - 33;
620 status = fsw_shandle_read(shand, &buffer_size, dirrec->file_identifier);
621 if (status)
622 return status;
623 if (buffer_size < remaining_size)
624 return FSW_VOLUME_CORRUPTED;
625
626 dump_dirrec(dirrec);
627 if (vol->fRockRidge)
628 {
629 sp_off = sizeof(*dirrec) + dirrec->file_identifier_length;
630 rc = rr_find_sp(dirrec, &sp);
631 if ( rc == FSW_SUCCESS
632 && sp != NULL)
633 {
634 sp_off = (fsw_u8 *)&sp[1] - (fsw_u8*)dirrec + sp->skip;
635 }
636 rc = rr_find_nm(vol, dirrec, sp_off, &dirrec_buffer->name);
637 if (rc == FSW_SUCCESS)
638 return FSW_SUCCESS;
639 }
640
641 // setup name
642 name_len = dirrec->file_identifier_length;
643 for (i = name_len - 1; i > 0; i--) {
644 if (dirrec->file_identifier[i] == ';') {
645 name_len = i; // cut the ISO9660 version number off
646 break;
647 }
648 }
649 if (name_len > 0 && dirrec->file_identifier[name_len-1] == '.')
650 name_len--; // also cut the extension separator if the extension is empty
651 dirrec_buffer->name.type = FSW_STRING_TYPE_ISO88591;
652 dirrec_buffer->name.len = dirrec_buffer->name.size = name_len;
653 dirrec_buffer->name.data = dirrec->file_identifier;
654 DEBUG((DEBUG_INFO, "%a:%d: dirrec_buffer->name.data:%a\n", __FILE__, __LINE__, dirrec_buffer->name.data));
655 return FSW_SUCCESS;
656}
657
658/**
659 * Get the target path of a symbolic link. This function is called when a symbolic
660 * link needs to be resolved. The core makes sure that the fsw_iso9660_dnode_fill has been
661 * called on the dnode and that it really is a symlink.
662 *
663 * For iso9660, the target path can be stored inline in the inode structure (in the space
664 * otherwise occupied by the block pointers) or in the inode's data. There is no flag
665 * indicating this, only the number of blocks entry (i_blocks) can be used as an
666 * indication. The check used here comes from the Linux kernel.
667 */
668
669static fsw_status_t fsw_iso9660_readlink(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
670 struct fsw_string *link_target)
671{
672 fsw_status_t status;
673
674 if (dno->g.size > FSW_PATH_MAX)
675 return FSW_VOLUME_CORRUPTED;
676
677 status = fsw_dnode_readlink_data(dno, link_target);
678
679 return status;
680}
681
682// EOF
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette