From cb0229c5873daee17491aa9a4b1b3cf9c7dd5a47 Mon Sep 17 00:00:00 2001 From: Giuseppe Caizzone Date: Sun, 14 Nov 2010 16:51:45 +0100 Subject: [PATCH] Properly handle deleted files on UDF. * grub-core/fs/udf.c (grub_udf_iterate_dir): Skip directory entries whose "characteristics" field has the bit GRUB_UDF_FID_CHAR_DELETED set. --- ChangeLog | 8 ++++ grub-core/fs/udf.c | 91 ++++++++++++++++++++++++---------------------- 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5cffcfdbd..d944dc0f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-11-14 Giuseppe Caizzone + + Properly handle deleted files on UDF. + + * grub-core/fs/udf.c (grub_udf_iterate_dir): Skip directory entries + whose "characteristics" field has the bit GRUB_UDF_FID_CHAR_DELETED + set. + 2010-11-14 Giuseppe Caizzone Support reading files larger than 2 GiB. diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 1600a4cd5..9e729a349 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -729,57 +729,60 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, return 0; } - child = grub_malloc (sizeof (struct grub_fshelp_node)); - if (!child) - return 0; - - if (grub_udf_read_icb (dir->data, &dirent.icb, child)) - return 0; - offset += sizeof (dirent) + U16 (dirent.imp_use_length); - if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT) + if (!(dirent.characteristics & GRUB_UDF_FID_CHAR_DELETED)) { - /* This is the parent directory. */ - if (hook ("..", GRUB_FSHELP_DIR, child)) - return 1; - } - else - { - enum grub_fshelp_filetype type; - grub_uint8_t raw[dirent.file_ident_length]; - grub_uint16_t utf16[dirent.file_ident_length - 1]; - grub_uint8_t filename[dirent.file_ident_length * 2]; - grub_size_t utf16len = 0; - - type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ? - (GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG)); - - if ((grub_udf_read_file (dir, 0, offset, - dirent.file_ident_length, - (char *) raw)) - != dirent.file_ident_length) + child = grub_malloc (sizeof (struct grub_fshelp_node)); + if (!child) return 0; - if (raw[0] == 8) + if (grub_udf_read_icb (dir->data, &dirent.icb, child)) + return 0; + + if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT) { - unsigned i; - utf16len = dirent.file_ident_length - 1; - for (i = 0; i < utf16len; i++) - utf16[i] = raw[i + 1]; + /* This is the parent directory. */ + if (hook ("..", GRUB_FSHELP_DIR, child)) + return 1; } - if (raw[0] == 16) + else { - unsigned i; - utf16len = (dirent.file_ident_length - 1) / 2; - for (i = 0; i < utf16len; i++) - utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; - } - if (raw[0] == 8 || raw[0] == 16) - { - *grub_utf16_to_utf8 (filename, utf16, utf16len) = '\0'; - - if (hook ((char *) filename, type, child)) - return 1; + enum grub_fshelp_filetype type; + grub_uint8_t raw[dirent.file_ident_length]; + grub_uint16_t utf16[dirent.file_ident_length - 1]; + grub_uint8_t filename[dirent.file_ident_length * 2]; + grub_size_t utf16len = 0; + + type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ? + (GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG)); + + if ((grub_udf_read_file (dir, 0, offset, + dirent.file_ident_length, + (char *) raw)) + != dirent.file_ident_length) + return 0; + + if (raw[0] == 8) + { + unsigned i; + utf16len = dirent.file_ident_length - 1; + for (i = 0; i < utf16len; i++) + utf16[i] = raw[i + 1]; + } + if (raw[0] == 16) + { + unsigned i; + utf16len = (dirent.file_ident_length - 1) / 2; + for (i = 0; i < utf16len; i++) + utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; + } + if (raw[0] == 8 || raw[0] == 16) + { + *grub_utf16_to_utf8 (filename, utf16, utf16len) = '\0'; + + if (hook ((char *) filename, type, child)) + return 1; + } } }