VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxFsDxe/fsw_iso9660.c@ 80924

Last change on this file since 80924 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

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