grub/grub-core/fs/udf.c

1110 lines
27 KiB
C
Raw Normal View History

/* udf.c - Universal Disk Format filesystem. */
/*
* GRUB -- GRand Unified Bootloader
2010-01-03 Robert Millan <rmh.grub@aybabtu.com> * boot/i386/pc/boot.S: Update copyright year. * boot/i386/pc/cdboot.S: Likewise. * boot/i386/pc/diskboot.S: Likewise. * boot/i386/pc/lnxboot.S: Likewise. * boot/i386/pc/pxeboot.S: Likewise. * bus/pci.c: Likewise. * commands/cmp.c: Likewise. * commands/help.c: Likewise. * commands/hexdump.c: Likewise. * commands/i386/pc/halt.c: Likewise. * commands/i386/pc/play.c: Likewise. * commands/i386/pc/vbeinfo.c: Likewise. * commands/ls.c: Likewise. * commands/test.c: Likewise. * disk/dmraid_nvidia.c: Likewise. * disk/i386/pc/biosdisk.c: Likewise. * disk/ieee1275/nand.c: Likewise. * disk/ieee1275/ofdisk.c: Likewise. * disk/lvm.c: Likewise. * disk/raid.c: Likewise. * disk/raid6_recover.c: Likewise. * disk/scsi.c: Likewise. * fs/affs.c: Likewise. * fs/cpio.c: Likewise. * fs/ext2.c: Likewise. * fs/hfs.c: Likewise. * fs/iso9660.c: Likewise. * fs/ntfs.c: Likewise. * fs/sfs.c: Likewise. * fs/udf.c: Likewise. * fs/ufs.c: Likewise. * fs/xfs.c: Likewise. * gencmdlist.sh: Likewise. * genmk.rb: Likewise. * include/grub/disk.h: Likewise. * include/grub/efi/api.h: Likewise. * include/grub/efi/efi.h: Likewise. * include/grub/efi/pe32.h: Likewise. * include/grub/elf.h: Likewise. * include/grub/fs.h: Likewise. * include/grub/i386/at_keyboard.h: Likewise. * include/grub/i386/pc/memory.h: Likewise. * include/grub/i386/pc/vbe.h: Likewise. * include/grub/i386/pci.h: Likewise. * include/grub/i386/tsc.h: Likewise. * include/grub/ieee1275/ieee1275.h: Likewise. * include/grub/ntfs.h: Likewise. * include/grub/sparc64/ieee1275/ieee1275.h: Likewise. * include/grub/sparc64/libgcc.h: Likewise. * include/grub/symbol.h: Likewise. * include/grub/types.h: Likewise. * include/multiboot2.h: Likewise. * io/gzio.c: Likewise. * kern/device.c: Likewise. * kern/disk.c: Likewise. * kern/efi/efi.c: Likewise. * kern/efi/mm.c: Likewise. * kern/elf.c: Likewise. * kern/file.c: Likewise. * kern/i386/dl.c: Likewise. * kern/i386/pc/init.c: Likewise. * kern/i386/pc/startup.S: Likewise. * kern/ieee1275/ieee1275.c: Likewise. * kern/ieee1275/init.c: Likewise. * kern/main.c: Likewise. * kern/mm.c: Likewise. * kern/powerpc/dl.c: Likewise. * kern/sparc64/dl.c: Likewise. * kern/x86_64/dl.c: Likewise. * lib/hexdump.c: Likewise. * loader/efi/appleloader.c: Likewise. * loader/i386/ieee1275/linux.c: Likewise. * loader/i386/pc/chainloader.c: Likewise. * loader/i386/pc/linux.c: Likewise. * loader/i386/pc/multiboot2.c: Likewise. * loader/ieee1275/multiboot2.c: Likewise. * loader/multiboot2.c: Likewise. * loader/multiboot_loader.c: Likewise. * loader/powerpc/ieee1275/linux.c: Likewise. * normal/completion.c: Likewise. * normal/menu_entry.c: Likewise. * partmap/apple.c: Likewise. * util/grub.d/10_hurd.in: Likewise. * util/hostfs.c: Likewise. * video/readers/png.c: Likewise.
2010-01-03 22:05:07 +00:00
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/err.h>
#include <grub/file.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/disk.h>
#include <grub/dl.h>
#include <grub/types.h>
#include <grub/fshelp.h>
#include <grub/charset.h>
2010-12-10 16:37:32 +00:00
#include <grub/datetime.h>
#define GRUB_UDF_MAX_PDS 2
#define GRUB_UDF_MAX_PMS 6
#define U16 grub_le_to_cpu16
#define U32 grub_le_to_cpu32
#define U64 grub_le_to_cpu64
#define GRUB_UDF_TAG_IDENT_PVD 0x0001
#define GRUB_UDF_TAG_IDENT_AVDP 0x0002
#define GRUB_UDF_TAG_IDENT_VDP 0x0003
#define GRUB_UDF_TAG_IDENT_IUVD 0x0004
#define GRUB_UDF_TAG_IDENT_PD 0x0005
#define GRUB_UDF_TAG_IDENT_LVD 0x0006
#define GRUB_UDF_TAG_IDENT_USD 0x0007
#define GRUB_UDF_TAG_IDENT_TD 0x0008
#define GRUB_UDF_TAG_IDENT_LVID 0x0009
#define GRUB_UDF_TAG_IDENT_FSD 0x0100
#define GRUB_UDF_TAG_IDENT_FID 0x0101
#define GRUB_UDF_TAG_IDENT_AED 0x0102
#define GRUB_UDF_TAG_IDENT_IE 0x0103
#define GRUB_UDF_TAG_IDENT_TE 0x0104
#define GRUB_UDF_TAG_IDENT_FE 0x0105
#define GRUB_UDF_TAG_IDENT_EAHD 0x0106
#define GRUB_UDF_TAG_IDENT_USE 0x0107
#define GRUB_UDF_TAG_IDENT_SBD 0x0108
#define GRUB_UDF_TAG_IDENT_PIE 0x0109
#define GRUB_UDF_TAG_IDENT_EFE 0x010A
#define GRUB_UDF_ICBTAG_TYPE_UNDEF 0x00
#define GRUB_UDF_ICBTAG_TYPE_USE 0x01
#define GRUB_UDF_ICBTAG_TYPE_PIE 0x02
#define GRUB_UDF_ICBTAG_TYPE_IE 0x03
#define GRUB_UDF_ICBTAG_TYPE_DIRECTORY 0x04
#define GRUB_UDF_ICBTAG_TYPE_REGULAR 0x05
#define GRUB_UDF_ICBTAG_TYPE_BLOCK 0x06
#define GRUB_UDF_ICBTAG_TYPE_CHAR 0x07
#define GRUB_UDF_ICBTAG_TYPE_EA 0x08
#define GRUB_UDF_ICBTAG_TYPE_FIFO 0x09
#define GRUB_UDF_ICBTAG_TYPE_SOCKET 0x0A
#define GRUB_UDF_ICBTAG_TYPE_TE 0x0B
#define GRUB_UDF_ICBTAG_TYPE_SYMLINK 0x0C
#define GRUB_UDF_ICBTAG_TYPE_STREAMDIR 0x0D
#define GRUB_UDF_ICBTAG_FLAG_AD_MASK 0x0007
#define GRUB_UDF_ICBTAG_FLAG_AD_SHORT 0x0000
#define GRUB_UDF_ICBTAG_FLAG_AD_LONG 0x0001
#define GRUB_UDF_ICBTAG_FLAG_AD_EXT 0x0002
#define GRUB_UDF_ICBTAG_FLAG_AD_IN_ICB 0x0003
#define GRUB_UDF_EXT_NORMAL 0x00000000
#define GRUB_UDF_EXT_NREC_ALLOC 0x40000000
#define GRUB_UDF_EXT_NREC_NALLOC 0x80000000
#define GRUB_UDF_EXT_MASK 0xC0000000
#define GRUB_UDF_FID_CHAR_HIDDEN 0x01
#define GRUB_UDF_FID_CHAR_DIRECTORY 0x02
#define GRUB_UDF_FID_CHAR_DELETED 0x04
#define GRUB_UDF_FID_CHAR_PARENT 0x08
#define GRUB_UDF_FID_CHAR_METADATA 0x10
#define GRUB_UDF_STD_IDENT_BEA01 "BEA01"
#define GRUB_UDF_STD_IDENT_BOOT2 "BOOT2"
#define GRUB_UDF_STD_IDENT_CD001 "CD001"
#define GRUB_UDF_STD_IDENT_CDW02 "CDW02"
#define GRUB_UDF_STD_IDENT_NSR02 "NSR02"
#define GRUB_UDF_STD_IDENT_NSR03 "NSR03"
#define GRUB_UDF_STD_IDENT_TEA01 "TEA01"
#define GRUB_UDF_CHARSPEC_TYPE_CS0 0x00
#define GRUB_UDF_CHARSPEC_TYPE_CS1 0x01
#define GRUB_UDF_CHARSPEC_TYPE_CS2 0x02
#define GRUB_UDF_CHARSPEC_TYPE_CS3 0x03
#define GRUB_UDF_CHARSPEC_TYPE_CS4 0x04
#define GRUB_UDF_CHARSPEC_TYPE_CS5 0x05
#define GRUB_UDF_CHARSPEC_TYPE_CS6 0x06
#define GRUB_UDF_CHARSPEC_TYPE_CS7 0x07
#define GRUB_UDF_CHARSPEC_TYPE_CS8 0x08
#define GRUB_UDF_PARTMAP_TYPE_1 1
#define GRUB_UDF_PARTMAP_TYPE_2 2
struct grub_udf_lb_addr
{
grub_uint32_t block_num;
grub_uint16_t part_ref;
} __attribute__ ((packed));
struct grub_udf_short_ad
{
grub_uint32_t length;
grub_uint32_t position;
} __attribute__ ((packed));
struct grub_udf_long_ad
{
grub_uint32_t length;
struct grub_udf_lb_addr block;
grub_uint8_t imp_use[6];
} __attribute__ ((packed));
struct grub_udf_extent_ad
{
grub_uint32_t length;
grub_uint32_t start;
} __attribute__ ((packed));
struct grub_udf_charspec
{
grub_uint8_t charset_type;
grub_uint8_t charset_info[63];
} __attribute__ ((packed));
struct grub_udf_timestamp
{
grub_uint16_t type_and_timezone;
grub_uint16_t year;
grub_uint8_t month;
grub_uint8_t day;
grub_uint8_t hour;
grub_uint8_t minute;
grub_uint8_t second;
grub_uint8_t centi_seconds;
grub_uint8_t hundreds_of_micro_seconds;
grub_uint8_t micro_seconds;
} __attribute__ ((packed));
struct grub_udf_regid
{
grub_uint8_t flags;
grub_uint8_t ident[23];
grub_uint8_t ident_suffix[8];
} __attribute__ ((packed));
struct grub_udf_tag
{
grub_uint16_t tag_ident;
grub_uint16_t desc_version;
grub_uint8_t tag_checksum;
grub_uint8_t reserved;
grub_uint16_t tag_serial_number;
grub_uint16_t desc_crc;
grub_uint16_t desc_crc_length;
grub_uint32_t tag_location;
} __attribute__ ((packed));
struct grub_udf_fileset
{
struct grub_udf_tag tag;
struct grub_udf_timestamp datetime;
grub_uint16_t interchange_level;
grub_uint16_t max_interchange_level;
grub_uint32_t charset_list;
grub_uint32_t max_charset_list;
grub_uint32_t fileset_num;
grub_uint32_t fileset_desc_num;
struct grub_udf_charspec vol_charset;
grub_uint8_t vol_ident[128];
struct grub_udf_charspec fileset_charset;
grub_uint8_t fileset_ident[32];
grub_uint8_t copyright_file_ident[32];
grub_uint8_t abstract_file_ident[32];
struct grub_udf_long_ad root_icb;
struct grub_udf_regid domain_ident;
struct grub_udf_long_ad next_ext;
struct grub_udf_long_ad streamdir_icb;
} __attribute__ ((packed));
struct grub_udf_icbtag
{
grub_uint32_t prior_recorded_num_direct_entries;
grub_uint16_t strategy_type;
grub_uint16_t strategy_parameter;
grub_uint16_t num_entries;
grub_uint8_t reserved;
grub_uint8_t file_type;
struct grub_udf_lb_addr parent_idb;
grub_uint16_t flags;
} __attribute__ ((packed));
struct grub_udf_file_ident
{
struct grub_udf_tag tag;
grub_uint16_t version_num;
grub_uint8_t characteristics;
grub_uint8_t file_ident_length;
struct grub_udf_long_ad icb;
grub_uint16_t imp_use_length;
} __attribute__ ((packed));
struct grub_udf_file_entry
{
struct grub_udf_tag tag;
struct grub_udf_icbtag icbtag;
grub_uint32_t uid;
grub_uint32_t gid;
grub_uint32_t permissions;
grub_uint16_t link_count;
grub_uint8_t record_format;
grub_uint8_t record_display_attr;
grub_uint32_t record_length;
grub_uint64_t file_size;
grub_uint64_t blocks_recorded;
struct grub_udf_timestamp access_time;
struct grub_udf_timestamp modification_time;
struct grub_udf_timestamp attr_time;
grub_uint32_t checkpoint;
struct grub_udf_long_ad extended_attr_idb;
struct grub_udf_regid imp_ident;
grub_uint64_t unique_id;
grub_uint32_t ext_attr_length;
grub_uint32_t alloc_descs_length;
grub_uint8_t ext_attr[1872];
} __attribute__ ((packed));
struct grub_udf_extended_file_entry
{
struct grub_udf_tag tag;
struct grub_udf_icbtag icbtag;
grub_uint32_t uid;
grub_uint32_t gid;
grub_uint32_t permissions;
grub_uint16_t link_count;
grub_uint8_t record_format;
grub_uint8_t record_display_attr;
grub_uint32_t record_length;
grub_uint64_t file_size;
grub_uint64_t object_size;
grub_uint64_t blocks_recorded;
struct grub_udf_timestamp access_time;
struct grub_udf_timestamp modification_time;
struct grub_udf_timestamp create_time;
struct grub_udf_timestamp attr_time;
grub_uint32_t checkpoint;
grub_uint32_t reserved;
struct grub_udf_long_ad extended_attr_icb;
struct grub_udf_long_ad streamdir_icb;
struct grub_udf_regid imp_ident;
grub_uint64_t unique_id;
grub_uint32_t ext_attr_length;
grub_uint32_t alloc_descs_length;
grub_uint8_t ext_attr[1832];
} __attribute__ ((packed));
struct grub_udf_vrs
{
grub_uint8_t type;
grub_uint8_t magic[5];
grub_uint8_t version;
} __attribute__ ((packed));
struct grub_udf_avdp
{
struct grub_udf_tag tag;
struct grub_udf_extent_ad vds;
} __attribute__ ((packed));
struct grub_udf_pd
{
struct grub_udf_tag tag;
grub_uint32_t seq_num;
grub_uint16_t flags;
grub_uint16_t part_num;
struct grub_udf_regid contents;
grub_uint8_t contents_use[128];
grub_uint32_t access_type;
grub_uint32_t start;
grub_uint32_t length;
} __attribute__ ((packed));
struct grub_udf_partmap
{
grub_uint8_t type;
grub_uint8_t length;
union
{
struct
{
grub_uint16_t seq_num;
grub_uint16_t part_num;
} type1;
struct
{
grub_uint8_t ident[62];
} type2;
};
};
struct grub_udf_lvd
{
struct grub_udf_tag tag;
grub_uint32_t seq_num;
struct grub_udf_charspec charset;
grub_uint8_t ident[128];
grub_uint32_t bsize;
struct grub_udf_regid domain_ident;
struct grub_udf_long_ad root_fileset;
grub_uint32_t map_table_length;
grub_uint32_t num_part_maps;
struct grub_udf_regid imp_ident;
grub_uint8_t imp_use[128];
struct grub_udf_extent_ad integrity_seq_ext;
grub_uint8_t part_maps[1608];
} __attribute__ ((packed));
struct grub_udf_aed
{
struct grub_udf_tag tag;
grub_uint32_t prev_ae;
grub_uint32_t ae_len;
} __attribute__ ((packed));
struct grub_udf_data
{
grub_disk_t disk;
struct grub_udf_lvd lvd;
struct grub_udf_pd pds[GRUB_UDF_MAX_PDS];
struct grub_udf_partmap *pms[GRUB_UDF_MAX_PMS];
struct grub_udf_long_ad root_icb;
int npd, npm, lbshift;
};
struct grub_fshelp_node
{
struct grub_udf_data *data;
union
{
struct grub_udf_file_entry fe;
struct grub_udf_extended_file_entry efe;
};
int part_ref;
};
static grub_dl_t my_mod;
static grub_uint32_t
grub_udf_get_block (struct grub_udf_data *data,
grub_uint16_t part_ref, grub_uint32_t block)
{
part_ref = U16 (part_ref);
if (part_ref >= data->npm)
{
grub_error (GRUB_ERR_BAD_FS, "invalid part ref");
return 0;
}
return (U32 (data->pds[data->pms[part_ref]->type1.part_num].start)
+ U32 (block));
}
static grub_err_t
grub_udf_read_icb (struct grub_udf_data *data,
struct grub_udf_long_ad *icb,
struct grub_fshelp_node *node)
{
grub_uint32_t block;
block = grub_udf_get_block (data,
icb->block.part_ref,
icb->block.block_num);
if (grub_errno)
return grub_errno;
if (grub_disk_read (data->disk, block << data->lbshift, 0,
sizeof (struct grub_udf_file_entry),
&node->fe))
return grub_errno;
if ((U16 (node->fe.tag.tag_ident) != GRUB_UDF_TAG_IDENT_FE) &&
(U16 (node->fe.tag.tag_ident) != GRUB_UDF_TAG_IDENT_EFE))
return grub_error (GRUB_ERR_BAD_FS, "invalid fe/efe descriptor");
node->part_ref = icb->block.part_ref;
node->data = data;
return 0;
}
2008-05-20 Bean <bean123ch@gmail.com> * fs/fshelp.c (grub_fshelp_map_block): New function. (grub_fshelp_find_file): Use 64-bit type for pos and block address. Use `>>' and `&' operator to avoid 64-bit divide and modulo. * include/grub/fshelp.h (grub_fshelp_journal_type): New enum. (GRUB_FSHELP_JOURNAL_UNUSED_MAPPING): New macro. (grub_fshelp_journal): New structure. (grub_fshelp_map_block): New function prototype. (grub_fshelp_read_file): Use grub_disk_addr_t as block type. (grub_fshelp_map_block): Likewise. * fs/ext2.c (EXT3_FEATURE_COMPAT_HAS_JOURNAL): New macro. (EXT3_JOURNAL_MAGIC_NUMBER): Likewise. (EXT3_JOURNAL_DESCRIPTOR_BLOCK): Likewise. (EXT3_JOURNAL_COMMIT_BLOCK): Likewise. (EXT3_JOURNAL_SUPERBLOCK_V1): Likewise. (EXT3_JOURNAL_SUPERBLOCK_V2): Likewise. (EXT3_JOURNAL_REVOKE_BLOCK): Likewise. (EXT3_JOURNAL_FLAG_ESCAPE): Likewise. (EXT3_JOURNAL_FLAG_SAME_UUID): Likewise. (EXT3_JOURNAL_FLAG_DELETED): Likewise. (EXT3_JOURNAL_FLAG_LAST_TAG): Likewise. (grub_ext2_sblock): New members for journal support. (grub_ext3_journal_header): New structure. (grub_ext3_journal_revoke_header): Likewise. (grub_ext3_journal_block_tag): Likewise. (grub_ext3_journal_sblock): Likewise. (grub_fshelp_node): New members logfile and journal. (grub_ext2_read_block): Change block type to grub_disk_addr_t. Use grub_fshelp_map_block to get real block number. (grub_ext2_blockgroup): Use grub_fshelp_map_block to get real block number. (grub_ext2_read_inode): Likewise. (grub_ext3_get_journal): New function. (grub_read_inode): Initialize journal using grub_ext3_get_journal. (grub_ext2_close): Release memory used by journal. * fs/reiserfs.c (REISERFS_MAGIC_STRING): Changed to "ReIsEr". (REISERFS_MAGIC_DESC_BLOCK): New macro. (grub_reiserfs_transaction_header): Renamed to grub_reiserfs_description_block, replace field data with real_blocks. (grub_reiserfs_commit_block): New structure. (grub_reiserfs_data): New member journal. (grub_reiserfs_get_item): Use grub_fshelp_map_block to get real block number. (grub_reiserfs_read_symlink): Likewise. (grub_reiserfs_iterate_dir): Likewise. (grub_reiserfs_open): Likewise. (grub_reiserfs_read): Likewise. (grub_reiserfs_get_journal): New function. (grub_reiserfs_mount): Use "ReIsEr" as super block magic, as there are three varieties ReIsErFs, ReIsEr2Fs and ReIsEr3Fs. Initialize journal using grub_reiserfs_get_journal. (grub_reiserfs_close): Release memory used by journal. * fs/affs.c (grub_affs_read_block): Change block type to grub_disk_addr_t. Use grub_divmod64 to do 64-bit division. * fs/afs.c (grub_afs_read_block): Change block type to grub_disk_addr_t. * fs/hfsplus.c (grub_hfsplus_read_block): Likewise. * fs/ntfs.c (grub_ntfs_read_block): Likewise. * fs/udf.c (grub_udf_read_block): Change block type to grub_disk_addr_t. Use type cast to avoid warning. * fs/xfs.c (grub_xfs_read_block): Likewise.
2008-05-20 05:00:53 +00:00
static grub_disk_addr_t
grub_udf_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
{
char *buf = NULL;
char *ptr;
grub_ssize_t len;
grub_disk_addr_t filebytes;
switch (U16 (node->fe.tag.tag_ident))
{
case GRUB_UDF_TAG_IDENT_FE:
ptr = (char *) &node->fe.ext_attr[0] + U32 (node->fe.ext_attr_length);
len = U32 (node->fe.alloc_descs_length);
break;
case GRUB_UDF_TAG_IDENT_EFE:
ptr = (char *) &node->efe.ext_attr[0] + U32 (node->efe.ext_attr_length);
len = U32 (node->efe.alloc_descs_length);
break;
default:
grub_error (GRUB_ERR_BAD_FS, "invalid file entry");
return 0;
}
if ((U16 (node->fe.icbtag.flags) & GRUB_UDF_ICBTAG_FLAG_AD_MASK)
== GRUB_UDF_ICBTAG_FLAG_AD_SHORT)
{
struct grub_udf_short_ad *ad = (struct grub_udf_short_ad *) ptr;
filebytes = fileblock * U32 (node->data->lvd.bsize);
while (len >= (grub_ssize_t) sizeof (struct grub_udf_short_ad))
{
grub_uint32_t adlen = U32 (ad->length) & 0x3fffffff;
grub_uint32_t adtype = U32 (ad->length) >> 30;
if (adtype == 3)
{
struct grub_udf_aed *extension;
grub_disk_addr_t sec = grub_udf_get_block(node->data,
node->part_ref,
ad->position);
if (!buf)
{
buf = grub_malloc (U32 (node->data->lvd.bsize));
if (!buf)
return 0;
}
if (grub_disk_read (node->data->disk, sec << node->data->lbshift,
0, adlen, buf))
goto fail;
extension = (struct grub_udf_aed *) buf;
if (U16 (extension->tag.tag_ident) != GRUB_UDF_TAG_IDENT_AED)
{
grub_error (GRUB_ERR_BAD_FS, "invalid aed tag");
goto fail;
}
len = U32 (extension->ae_len);
ad = (struct grub_udf_short_ad *)
(buf + sizeof (struct grub_udf_aed));
continue;
}
if (filebytes < adlen)
{
grub_uint32_t ad_pos = ad->position;
grub_free (buf);
return ((U32 (ad_pos) & GRUB_UDF_EXT_MASK) ? 0 :
(grub_udf_get_block (node->data, node->part_ref, ad_pos)
+ (filebytes >> (GRUB_DISK_SECTOR_BITS
+ node->data->lbshift))));
}
filebytes -= adlen;
ad++;
len -= sizeof (struct grub_udf_short_ad);
}
}
else
{
struct grub_udf_long_ad *ad = (struct grub_udf_long_ad *) ptr;
filebytes = fileblock * U32 (node->data->lvd.bsize);
while (len >= (grub_ssize_t) sizeof (struct grub_udf_long_ad))
{
grub_uint32_t adlen = U32 (ad->length) & 0x3fffffff;
grub_uint32_t adtype = U32 (ad->length) >> 30;
if (adtype == 3)
{
struct grub_udf_aed *extension;
grub_disk_addr_t sec = grub_udf_get_block(node->data,
ad->block.part_ref,
ad->block.block_num);
if (!buf)
{
buf = grub_malloc (U32 (node->data->lvd.bsize));
if (!buf)
return 0;
}
if (grub_disk_read (node->data->disk, sec << node->data->lbshift,
0, adlen, buf))
goto fail;
extension = (struct grub_udf_aed *) buf;
if (U16 (extension->tag.tag_ident) != GRUB_UDF_TAG_IDENT_AED)
{
grub_error (GRUB_ERR_BAD_FS, "invalid aed tag");
goto fail;
}
len = U32 (extension->ae_len);
ad = (struct grub_udf_long_ad *)
(buf + sizeof (struct grub_udf_aed));
continue;
}
if (filebytes < adlen)
{
grub_uint32_t ad_block_num = ad->block.block_num;
grub_uint32_t ad_part_ref = ad->block.part_ref;
grub_free (buf);
return ((U32 (ad_block_num) & GRUB_UDF_EXT_MASK) ? 0 :
(grub_udf_get_block (node->data, ad_part_ref,
ad_block_num)
+ (filebytes >> (GRUB_DISK_SECTOR_BITS
+ node->data->lbshift))));
}
filebytes -= adlen;
ad++;
len -= sizeof (struct grub_udf_long_ad);
}
}
fail:
if (buf)
grub_free (buf);
return 0;
}
static grub_ssize_t
grub_udf_read_file (grub_fshelp_node_t node,
void NESTED_FUNC_ATTR
(*read_hook) (grub_disk_addr_t sector,
unsigned offset, unsigned length),
grub_off_t pos, grub_size_t len, char *buf)
{
switch (U16 (node->fe.icbtag.flags) & GRUB_UDF_ICBTAG_FLAG_AD_MASK)
{
case GRUB_UDF_ICBTAG_FLAG_AD_IN_ICB:
{
char *ptr;
ptr = ((U16 (node->fe.tag.tag_ident) == GRUB_UDF_TAG_IDENT_FE) ?
((char *) &node->fe.ext_attr[0]
+ U32 (node->fe.ext_attr_length)) :
((char *) &node->efe.ext_attr[0]
+ U32 (node->efe.ext_attr_length)));
grub_memcpy (buf, ptr + pos, len);
return len;
}
case GRUB_UDF_ICBTAG_FLAG_AD_EXT:
grub_error (GRUB_ERR_BAD_FS, "invalid extent type");
return 0;
}
return grub_fshelp_read_file (node->data->disk, node, read_hook,
pos, len, buf, grub_udf_read_block,
U64 (node->fe.file_size),
node->data->lbshift);
}
static unsigned sblocklist[] = { 256, 512, 0 };
static struct grub_udf_data *
grub_udf_mount (grub_disk_t disk)
{
struct grub_udf_data *data = 0;
struct grub_udf_fileset root_fs;
unsigned *sblklist;
grub_uint32_t block, vblock;
int i, lbshift;
data = grub_malloc (sizeof (struct grub_udf_data));
if (!data)
return 0;
data->disk = disk;
/* Search for Anchor Volume Descriptor Pointer (AVDP)
* and determine logical block size. */
block = 0;
for (lbshift = 0; lbshift < 4; lbshift++)
{
for (sblklist = sblocklist; *sblklist; sblklist++)
{
struct grub_udf_avdp avdp;
if (grub_disk_read (disk, *sblklist << lbshift, 0,
sizeof (struct grub_udf_avdp), &avdp))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
if (U16 (avdp.tag.tag_ident) == GRUB_UDF_TAG_IDENT_AVDP &&
U32 (avdp.tag.tag_location) == *sblklist)
{
block = U32 (avdp.vds.start);
break;
}
}
if (block)
break;
}
if (!block)
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
data->lbshift = lbshift;
/* Search for Volume Recognition Sequence (VRS). */
for (vblock = (32767 >> (lbshift + GRUB_DISK_SECTOR_BITS)) + 1;;
vblock += (2047 >> (lbshift + GRUB_DISK_SECTOR_BITS)) + 1)
{
struct grub_udf_vrs vrs;
if (grub_disk_read (disk, vblock << lbshift, 0,
sizeof (struct grub_udf_vrs), &vrs))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
if ((!grub_memcmp (vrs.magic, GRUB_UDF_STD_IDENT_NSR03, 5)) ||
(!grub_memcmp (vrs.magic, GRUB_UDF_STD_IDENT_NSR02, 5)))
break;
if ((grub_memcmp (vrs.magic, GRUB_UDF_STD_IDENT_BEA01, 5)) &&
(grub_memcmp (vrs.magic, GRUB_UDF_STD_IDENT_BOOT2, 5)) &&
(grub_memcmp (vrs.magic, GRUB_UDF_STD_IDENT_CD001, 5)) &&
(grub_memcmp (vrs.magic, GRUB_UDF_STD_IDENT_CDW02, 5)) &&
(grub_memcmp (vrs.magic, GRUB_UDF_STD_IDENT_TEA01, 5)))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
}
data->npd = data->npm = 0;
/* Locate Partition Descriptor (PD) and Logical Volume Descriptor (LVD). */
while (1)
{
struct grub_udf_tag tag;
if (grub_disk_read (disk, block << lbshift, 0,
sizeof (struct grub_udf_tag), &tag))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
tag.tag_ident = U16 (tag.tag_ident);
if (tag.tag_ident == GRUB_UDF_TAG_IDENT_PD)
{
if (data->npd >= GRUB_UDF_MAX_PDS)
{
grub_error (GRUB_ERR_BAD_FS, "too many PDs");
goto fail;
}
if (grub_disk_read (disk, block << lbshift, 0,
sizeof (struct grub_udf_pd),
&data->pds[data->npd]))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
data->npd++;
}
else if (tag.tag_ident == GRUB_UDF_TAG_IDENT_LVD)
{
int k;
struct grub_udf_partmap *ppm;
if (grub_disk_read (disk, block << lbshift, 0,
sizeof (struct grub_udf_lvd),
&data->lvd))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
if (data->npm + U32 (data->lvd.num_part_maps) > GRUB_UDF_MAX_PMS)
{
grub_error (GRUB_ERR_BAD_FS, "too many partition maps");
goto fail;
}
ppm = (struct grub_udf_partmap *) &data->lvd.part_maps;
for (k = U32 (data->lvd.num_part_maps); k > 0; k--)
{
if (ppm->type != GRUB_UDF_PARTMAP_TYPE_1)
{
grub_error (GRUB_ERR_BAD_FS, "partmap type not supported");
goto fail;
}
data->pms[data->npm++] = ppm;
ppm = (struct grub_udf_partmap *) ((char *) ppm +
U32 (ppm->length));
}
}
else if (tag.tag_ident > GRUB_UDF_TAG_IDENT_TD)
{
grub_error (GRUB_ERR_BAD_FS, "invalid tag ident");
goto fail;
}
else if (tag.tag_ident == GRUB_UDF_TAG_IDENT_TD)
break;
block++;
}
for (i = 0; i < data->npm; i++)
{
int j;
for (j = 0; j < data->npd; j++)
if (data->pms[i]->type1.part_num == data->pds[j].part_num)
{
data->pms[i]->type1.part_num = j;
break;
}
if (j == data->npd)
{
grub_error (GRUB_ERR_BAD_FS, "can\'t find PD");
goto fail;
}
}
block = grub_udf_get_block (data,
data->lvd.root_fileset.block.part_ref,
data->lvd.root_fileset.block.block_num);
if (grub_errno)
goto fail;
if (grub_disk_read (disk, block << lbshift, 0,
sizeof (struct grub_udf_fileset), &root_fs))
{
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
goto fail;
}
if (U16 (root_fs.tag.tag_ident) != GRUB_UDF_TAG_IDENT_FSD)
{
grub_error (GRUB_ERR_BAD_FS, "invalid fileset descriptor");
goto fail;
}
data->root_icb = root_fs.root_icb;
return data;
fail:
grub_free (data);
return 0;
}
2010-12-10 17:34:46 +00:00
static char *
read_string (grub_uint8_t *raw, grub_size_t sz)
{
grub_uint16_t *utf16;
char *ret;
grub_size_t utf16len = 0;
if (raw[0] != 8 && raw[0] != 16)
return NULL;
if (raw[0] == 8)
{
unsigned i;
utf16len = sz - 1;
utf16 = grub_malloc (utf16len * sizeof (utf16[0]));
if (!utf16)
return NULL;
for (i = 0; i < utf16len; i++)
utf16[i] = raw[i + 1];
}
if (raw[0] == 16)
{
unsigned i;
utf16len = (sz - 1) / 2;
utf16 = grub_malloc (utf16len * sizeof (utf16[0]));
if (!utf16)
return NULL;
for (i = 0; i < utf16len; i++)
utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2];
}
ret = grub_malloc (utf16len * 3 + 1);
if (ret)
*grub_utf16_to_utf8 ((grub_uint8_t *) ret, utf16, utf16len) = '\0';
grub_free (utf16);
return ret;
}
static int
grub_udf_iterate_dir (grub_fshelp_node_t dir,
int NESTED_FUNC_ATTR
(*hook) (const char *filename,
enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node))
{
grub_fshelp_node_t child;
struct grub_udf_file_ident dirent;
grub_off_t offset = 0;
child = grub_malloc (sizeof (struct grub_fshelp_node));
if (!child)
return 0;
/* The current directory is not stored. */
grub_memcpy ((char *) child, (char *) dir,
sizeof (struct grub_fshelp_node));
if (hook (".", GRUB_FSHELP_DIR, child))
return 1;
while (offset < U64 (dir->fe.file_size))
{
if (grub_udf_read_file (dir, 0, offset, sizeof (dirent),
(char *) &dirent) != sizeof (dirent))
return 0;
if (U16 (dirent.tag.tag_ident) != GRUB_UDF_TAG_IDENT_FID)
{
grub_error (GRUB_ERR_BAD_FS, "invalid fid tag");
return 0;
}
offset += sizeof (dirent) + U16 (dirent.imp_use_length);
if (!(dirent.characteristics & GRUB_UDF_FID_CHAR_DELETED))
{
child = grub_malloc (sizeof (struct grub_fshelp_node));
if (!child)
return 0;
if (grub_udf_read_icb (dir->data, &dirent.icb, child))
return 0;
if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT)
{
/* This is the parent directory. */
if (hook ("..", GRUB_FSHELP_DIR, child))
return 1;
}
else
{
enum grub_fshelp_filetype type;
2010-12-10 17:34:46 +00:00
char *filename;
grub_uint8_t raw[dirent.file_ident_length];
type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ?
(GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG));
2010-12-11 05:04:21 +00:00
if (child->fe.icbtag.file_type == GRUB_UDF_ICBTAG_TYPE_SYMLINK)
type = GRUB_FSHELP_SYMLINK;
if ((grub_udf_read_file (dir, 0, offset,
dirent.file_ident_length,
(char *) raw))
!= dirent.file_ident_length)
return 0;
2010-12-10 17:34:46 +00:00
filename = read_string (raw, dirent.file_ident_length);
2010-12-10 17:34:46 +00:00
if (filename && hook (filename, type, child))
{
grub_free (filename);
return 1;
}
2010-12-10 17:34:46 +00:00
grub_free (filename);
}
}
/* Align to dword boundary. */
offset = (offset + dirent.file_ident_length + 3) & (~3);
}
return 0;
}
2010-12-11 05:04:21 +00:00
static char *
grub_ufs_read_symlink (grub_fshelp_node_t node)
{
grub_size_t sz = U64 (node->fe.file_size);
grub_uint8_t *raw;
char *ret;
if (sz < 4)
return NULL;
raw = grub_malloc (sz - 4);
if (!raw)
return NULL;
if (grub_udf_read_file (node, NULL, 4, sz - 4, (char *) raw) < 0)
return NULL;
ret = read_string (raw, sz - 4);
grub_free (raw);
return ret;
}
static grub_err_t
grub_udf_dir (grub_device_t device, const char *path,
2009-06-10 21:04:23 +00:00
int (*hook) (const char *filename,
2009-04-05 Vladimir Serbinenko <phcoder@gmail.com> Support for mtime and further expandability of dir command * include/grub/lib/datetime.h: moved to ... * include/grub/datetime.h: ... moved here and added declaration of grub_unixtime2datetime. All users updated * include/grub/fs.h: new syntax for dir and mtime functionin struct grub_fs * include/grub/fshelp.h: new declarations of GRUB_FSHELP_TYPE_MASK and GRUB_FSHELP_FLAGS_MASK * commands/ls.c (grub_ls_list_files): Write mtime in long format * fs/ext2.c (grub_ext2_dir): use new dir syntax and supply mtime (grub_ext2_mtime): new function * fs/hfsplus.c (grub_hfsplus_dir): use new dir syntax and supply mtime (grub_hfsplus_mtime): new function * fs/ufs.c (GRUB_UFS_ATTR_TYPE): new definition (GRUB_UFS_ATTR_FILE): likewise (GRUB_UFS_ATTR_LNK): likewise (struct grub_ufs_sblock): new fields mtime (grub_ufs_read_inode): new parameter to read inode to a separate buffer all users updated (grub_ufs_dir): mtime support (grub_ufs_mtime): new function * fs/affs.c (grub_affs_dir): use new dir syntax * fs/afs.c (grub_afs_dir): likewise * fs/cpio.c (grub_cpio_dir): likewise * fs/fat.c (grub_fat_find_dir): likewise * fs/hfs.c (grub_hfs_dir): likewise * fs/iso9660.c (grub_iso9660_dir): likewise * fs/jfs.c (grub_jfs_dir): likewise * fs/minix.c (grub_minix_dir): likewise * fs/ntfs.c (grub_ntfs_dir): likewise * fs/reiserfs.c (grub_reiserfs_dir): likewise * fs/sfs.c (grub_sfs_dir): likewise * fs/xfs.c (grub_xfs_dir): likewise * util/hostfs.c (grub_hostfs_dir): likewise * lib/datetime.c: moved to ... * normal/datetime.c: ... moved here (grub_unixtime2datetime): new function * kern/rescue.c (grub_rescue_print_files): use new dir syntax * normal/completition.c (iterate_dir): use new dir syntax * normal/misc.c (grub_normal_print_device_info): tell the last modification time of a volume * kern/fs.c (grub_fs_probe): updated dummy function to use new syntax * conf/common.rmk: added lib/datetime.c to ls.mod * conf/i386-coreboot.rmk (grub_emu_SOURCES): add normal/datetime.c (normal_mod_SOURCES): likewise (datetime_mod_SOURCES): Removed lib/datetime.c * conf/i386-efi.rmk: likewise * conf/i386-ieee1275.rmk: likewise * conf/i386-pc.rmk: likewise * conf/powerpc-ieee1275.rmk: likewise * conf/sparc64-ieee1275.rmk: likewise * conf/x86_64-efi.rmk: likewise
2009-04-05 20:19:05 +00:00
const struct grub_dirhook_info *info))
{
struct grub_udf_data *data = 0;
struct grub_fshelp_node rootnode;
struct grub_fshelp_node *foundnode;
auto int NESTED_FUNC_ATTR iterate (const char *filename,
enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node);
int NESTED_FUNC_ATTR iterate (const char *filename,
enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node)
{
2009-04-05 Vladimir Serbinenko <phcoder@gmail.com> Support for mtime and further expandability of dir command * include/grub/lib/datetime.h: moved to ... * include/grub/datetime.h: ... moved here and added declaration of grub_unixtime2datetime. All users updated * include/grub/fs.h: new syntax for dir and mtime functionin struct grub_fs * include/grub/fshelp.h: new declarations of GRUB_FSHELP_TYPE_MASK and GRUB_FSHELP_FLAGS_MASK * commands/ls.c (grub_ls_list_files): Write mtime in long format * fs/ext2.c (grub_ext2_dir): use new dir syntax and supply mtime (grub_ext2_mtime): new function * fs/hfsplus.c (grub_hfsplus_dir): use new dir syntax and supply mtime (grub_hfsplus_mtime): new function * fs/ufs.c (GRUB_UFS_ATTR_TYPE): new definition (GRUB_UFS_ATTR_FILE): likewise (GRUB_UFS_ATTR_LNK): likewise (struct grub_ufs_sblock): new fields mtime (grub_ufs_read_inode): new parameter to read inode to a separate buffer all users updated (grub_ufs_dir): mtime support (grub_ufs_mtime): new function * fs/affs.c (grub_affs_dir): use new dir syntax * fs/afs.c (grub_afs_dir): likewise * fs/cpio.c (grub_cpio_dir): likewise * fs/fat.c (grub_fat_find_dir): likewise * fs/hfs.c (grub_hfs_dir): likewise * fs/iso9660.c (grub_iso9660_dir): likewise * fs/jfs.c (grub_jfs_dir): likewise * fs/minix.c (grub_minix_dir): likewise * fs/ntfs.c (grub_ntfs_dir): likewise * fs/reiserfs.c (grub_reiserfs_dir): likewise * fs/sfs.c (grub_sfs_dir): likewise * fs/xfs.c (grub_xfs_dir): likewise * util/hostfs.c (grub_hostfs_dir): likewise * lib/datetime.c: moved to ... * normal/datetime.c: ... moved here (grub_unixtime2datetime): new function * kern/rescue.c (grub_rescue_print_files): use new dir syntax * normal/completition.c (iterate_dir): use new dir syntax * normal/misc.c (grub_normal_print_device_info): tell the last modification time of a volume * kern/fs.c (grub_fs_probe): updated dummy function to use new syntax * conf/common.rmk: added lib/datetime.c to ls.mod * conf/i386-coreboot.rmk (grub_emu_SOURCES): add normal/datetime.c (normal_mod_SOURCES): likewise (datetime_mod_SOURCES): Removed lib/datetime.c * conf/i386-efi.rmk: likewise * conf/i386-ieee1275.rmk: likewise * conf/i386-pc.rmk: likewise * conf/powerpc-ieee1275.rmk: likewise * conf/sparc64-ieee1275.rmk: likewise * conf/x86_64-efi.rmk: likewise
2009-04-05 20:19:05 +00:00
struct grub_dirhook_info info;
2010-12-10 16:37:32 +00:00
const struct grub_udf_timestamp *tstamp = NULL;
2009-04-05 Vladimir Serbinenko <phcoder@gmail.com> Support for mtime and further expandability of dir command * include/grub/lib/datetime.h: moved to ... * include/grub/datetime.h: ... moved here and added declaration of grub_unixtime2datetime. All users updated * include/grub/fs.h: new syntax for dir and mtime functionin struct grub_fs * include/grub/fshelp.h: new declarations of GRUB_FSHELP_TYPE_MASK and GRUB_FSHELP_FLAGS_MASK * commands/ls.c (grub_ls_list_files): Write mtime in long format * fs/ext2.c (grub_ext2_dir): use new dir syntax and supply mtime (grub_ext2_mtime): new function * fs/hfsplus.c (grub_hfsplus_dir): use new dir syntax and supply mtime (grub_hfsplus_mtime): new function * fs/ufs.c (GRUB_UFS_ATTR_TYPE): new definition (GRUB_UFS_ATTR_FILE): likewise (GRUB_UFS_ATTR_LNK): likewise (struct grub_ufs_sblock): new fields mtime (grub_ufs_read_inode): new parameter to read inode to a separate buffer all users updated (grub_ufs_dir): mtime support (grub_ufs_mtime): new function * fs/affs.c (grub_affs_dir): use new dir syntax * fs/afs.c (grub_afs_dir): likewise * fs/cpio.c (grub_cpio_dir): likewise * fs/fat.c (grub_fat_find_dir): likewise * fs/hfs.c (grub_hfs_dir): likewise * fs/iso9660.c (grub_iso9660_dir): likewise * fs/jfs.c (grub_jfs_dir): likewise * fs/minix.c (grub_minix_dir): likewise * fs/ntfs.c (grub_ntfs_dir): likewise * fs/reiserfs.c (grub_reiserfs_dir): likewise * fs/sfs.c (grub_sfs_dir): likewise * fs/xfs.c (grub_xfs_dir): likewise * util/hostfs.c (grub_hostfs_dir): likewise * lib/datetime.c: moved to ... * normal/datetime.c: ... moved here (grub_unixtime2datetime): new function * kern/rescue.c (grub_rescue_print_files): use new dir syntax * normal/completition.c (iterate_dir): use new dir syntax * normal/misc.c (grub_normal_print_device_info): tell the last modification time of a volume * kern/fs.c (grub_fs_probe): updated dummy function to use new syntax * conf/common.rmk: added lib/datetime.c to ls.mod * conf/i386-coreboot.rmk (grub_emu_SOURCES): add normal/datetime.c (normal_mod_SOURCES): likewise (datetime_mod_SOURCES): Removed lib/datetime.c * conf/i386-efi.rmk: likewise * conf/i386-ieee1275.rmk: likewise * conf/i386-pc.rmk: likewise * conf/powerpc-ieee1275.rmk: likewise * conf/sparc64-ieee1275.rmk: likewise * conf/x86_64-efi.rmk: likewise
2009-04-05 20:19:05 +00:00
grub_memset (&info, 0, sizeof (info));
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
2010-12-10 16:37:32 +00:00
if (U16 (node->fe.tag.tag_ident) == GRUB_UDF_TAG_IDENT_FE)
tstamp = &node->fe.modification_time;
else if (U16 (node->fe.tag.tag_ident) == GRUB_UDF_TAG_IDENT_EFE)
tstamp = &node->efe.modification_time;
if (tstamp && (U16 (tstamp->type_and_timezone) & 0xf000) == 0x1000)
{
grub_int16_t tz;
struct grub_datetime datetime;
datetime.year = U16 (tstamp->year);
datetime.month = tstamp->month;
datetime.day = tstamp->day;
datetime.hour = tstamp->hour;
datetime.minute = tstamp->minute;
datetime.second = tstamp->second;
tz = U16 (tstamp->type_and_timezone) & 0xfff;
if (tz & 0x800)
tz |= 0xf000;
if (tz == -2047)
tz = 0;
info.mtimeset = !!grub_datetime2unixtime (&datetime, &info.mtime);
info.mtime -= 60 * tz;
}
2009-04-05 Vladimir Serbinenko <phcoder@gmail.com> Support for mtime and further expandability of dir command * include/grub/lib/datetime.h: moved to ... * include/grub/datetime.h: ... moved here and added declaration of grub_unixtime2datetime. All users updated * include/grub/fs.h: new syntax for dir and mtime functionin struct grub_fs * include/grub/fshelp.h: new declarations of GRUB_FSHELP_TYPE_MASK and GRUB_FSHELP_FLAGS_MASK * commands/ls.c (grub_ls_list_files): Write mtime in long format * fs/ext2.c (grub_ext2_dir): use new dir syntax and supply mtime (grub_ext2_mtime): new function * fs/hfsplus.c (grub_hfsplus_dir): use new dir syntax and supply mtime (grub_hfsplus_mtime): new function * fs/ufs.c (GRUB_UFS_ATTR_TYPE): new definition (GRUB_UFS_ATTR_FILE): likewise (GRUB_UFS_ATTR_LNK): likewise (struct grub_ufs_sblock): new fields mtime (grub_ufs_read_inode): new parameter to read inode to a separate buffer all users updated (grub_ufs_dir): mtime support (grub_ufs_mtime): new function * fs/affs.c (grub_affs_dir): use new dir syntax * fs/afs.c (grub_afs_dir): likewise * fs/cpio.c (grub_cpio_dir): likewise * fs/fat.c (grub_fat_find_dir): likewise * fs/hfs.c (grub_hfs_dir): likewise * fs/iso9660.c (grub_iso9660_dir): likewise * fs/jfs.c (grub_jfs_dir): likewise * fs/minix.c (grub_minix_dir): likewise * fs/ntfs.c (grub_ntfs_dir): likewise * fs/reiserfs.c (grub_reiserfs_dir): likewise * fs/sfs.c (grub_sfs_dir): likewise * fs/xfs.c (grub_xfs_dir): likewise * util/hostfs.c (grub_hostfs_dir): likewise * lib/datetime.c: moved to ... * normal/datetime.c: ... moved here (grub_unixtime2datetime): new function * kern/rescue.c (grub_rescue_print_files): use new dir syntax * normal/completition.c (iterate_dir): use new dir syntax * normal/misc.c (grub_normal_print_device_info): tell the last modification time of a volume * kern/fs.c (grub_fs_probe): updated dummy function to use new syntax * conf/common.rmk: added lib/datetime.c to ls.mod * conf/i386-coreboot.rmk (grub_emu_SOURCES): add normal/datetime.c (normal_mod_SOURCES): likewise (datetime_mod_SOURCES): Removed lib/datetime.c * conf/i386-efi.rmk: likewise * conf/i386-ieee1275.rmk: likewise * conf/i386-pc.rmk: likewise * conf/powerpc-ieee1275.rmk: likewise * conf/sparc64-ieee1275.rmk: likewise * conf/x86_64-efi.rmk: likewise
2009-04-05 20:19:05 +00:00
grub_free (node);
return hook (filename, &info);
}
grub_dl_ref (my_mod);
data = grub_udf_mount (device->disk);
if (!data)
goto fail;
if (grub_udf_read_icb (data, &data->root_icb, &rootnode))
goto fail;
if (grub_fshelp_find_file (path, &rootnode,
&foundnode,
2010-12-11 05:04:21 +00:00
grub_udf_iterate_dir, grub_ufs_read_symlink,
GRUB_FSHELP_DIR))
goto fail;
grub_udf_iterate_dir (foundnode, iterate);
if (foundnode != &rootnode)
grub_free (foundnode);
fail:
grub_free (data);
grub_dl_unref (my_mod);
return grub_errno;
}
static grub_err_t
grub_udf_open (struct grub_file *file, const char *name)
{
struct grub_udf_data *data;
struct grub_fshelp_node rootnode;
struct grub_fshelp_node *foundnode;
grub_dl_ref (my_mod);
data = grub_udf_mount (file->device->disk);
if (!data)
goto fail;
if (grub_udf_read_icb (data, &data->root_icb, &rootnode))
goto fail;
if (grub_fshelp_find_file (name, &rootnode,
&foundnode,
2010-12-11 05:04:21 +00:00
grub_udf_iterate_dir, grub_ufs_read_symlink,
GRUB_FSHELP_REG))
goto fail;
file->data = foundnode;
file->offset = 0;
file->size = U64 (foundnode->fe.file_size);
return 0;
fail:
grub_dl_unref (my_mod);
grub_free (data);
return grub_errno;
}
static grub_ssize_t
grub_udf_read (grub_file_t file, char *buf, grub_size_t len)
{
struct grub_fshelp_node *node = (struct grub_fshelp_node *) file->data;
return grub_udf_read_file (node, file->read_hook, file->offset, len, buf);
}
static grub_err_t
grub_udf_close (grub_file_t file)
{
if (file->data)
{
struct grub_fshelp_node *node = (struct grub_fshelp_node *) file->data;
grub_free (node->data);
grub_free (node);
}
grub_dl_unref (my_mod);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_udf_label (grub_device_t device, char **label)
{
struct grub_udf_data *data;
data = grub_udf_mount (device->disk);
if (data)
{
2010-12-10 17:34:46 +00:00
*label = read_string (data->lvd.ident, sizeof (data->lvd.ident));
grub_free (data);
}
else
*label = 0;
return grub_errno;
}
static struct grub_fs grub_udf_fs = {
.name = "udf",
.dir = grub_udf_dir,
.open = grub_udf_open,
.read = grub_udf_read,
.close = grub_udf_close,
.label = grub_udf_label,
.next = 0
};
GRUB_MOD_INIT (udf)
{
grub_fs_register (&grub_udf_fs);
my_mod = mod;
}
GRUB_MOD_FINI (udf)
{
grub_fs_unregister (&grub_udf_fs);
}