From 372ad163dcd88f6fa0ae8f502dc9c0b883db52df Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Wed, 9 Jun 2010 22:30:32 +0000 Subject: [PATCH] Fix up the majority of the non-grubfs filesystems from my last commit, since they require a "probe with offset" function to allow the partition handler to identify a valid FS before interposition to /packages/misc-files. Signed-off-by: Mark Cave-Ayland git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@792 f158a5a8-5612-0410-a976-696ce0be7e32 --- fs/ext2/ext2_fs.c | 8 ++++++++ fs/ext2/ext2_utils.c | 17 +++++++++++++++++ fs/ext2/ext2_utils.h | 1 + fs/hfs/hfs.c | 9 +++++++++ fs/hfs/hfs_fs.c | 9 +++++++++ fs/hfs/include/hfs.h | 1 + fs/hfs/include/volume.h | 1 + fs/hfs/volume.c | 21 +++++++++++++++++++++ fs/hfsplus/hfsp_fs.c | 9 +++++++++ fs/hfsplus/include/volume.h | 2 ++ fs/hfsplus/volume.c | 20 ++++++++++++++++++++ fs/ioglue.c | 6 ++++++ fs/os.h | 6 ++++++ include/fs/fs.h | 7 +++++++ packages/misc-files.c | 13 ++++++------- 15 files changed, 123 insertions(+), 7 deletions(-) diff --git a/fs/ext2/ext2_fs.c b/fs/ext2/ext2_fs.c index 2886081..1e04b05 100644 --- a/fs/ext2/ext2_fs.c +++ b/fs/ext2/ext2_fs.c @@ -201,3 +201,11 @@ int fs_ext2_open(int fd, fs_ops_t *fs) return 0; } + +int fs_ext2_probe(int fd, llong offs) +{ + if (ext2_probe(fd, offs)) + return -1; + + return 0; +} diff --git a/fs/ext2/ext2_utils.c b/fs/ext2/ext2_utils.c index 7773125..35beb46 100644 --- a/fs/ext2/ext2_utils.c +++ b/fs/ext2/ext2_utils.c @@ -12,6 +12,23 @@ #include "libc/diskio.h" #include "libc/byteorder.h" +int ext2_probe(int fd, llong offset) +{ + struct ext2_super_block *super; + + super = (struct ext2_super_block*)malloc(sizeof(struct ext2_super_block)); + seek_io(fd, 2 * 512 + offset); + read_io(fd, super, sizeof (*super)); + + if (__be16_to_cpu(super->s_magic) != EXT2_SUPER_MAGIC) { + free(super); + return 0; + } + + free(super); + return -1; +} + void ext2_get_super(int fd, struct ext2_super_block *super) { seek_io(fd, 2 * 512); diff --git a/fs/ext2/ext2_utils.h b/fs/ext2/ext2_utils.h index 7a3097b..8348e7b 100644 --- a/fs/ext2/ext2_utils.h +++ b/fs/ext2/ext2_utils.h @@ -36,6 +36,7 @@ /* utilities */ +extern int ext2_probe(int fd, llong offset); extern void ext2_get_super(int fd, struct ext2_super_block *super); extern void ext2_read_block(ext2_VOLUME* volume, unsigned int fsblock); extern void ext2_get_group_desc(ext2_VOLUME* volume, diff --git a/fs/hfs/hfs.c b/fs/hfs/hfs.c index 0615e7c..931cd8a 100644 --- a/fs/hfs/hfs.c +++ b/fs/hfs/hfs.c @@ -736,3 +736,12 @@ int hfs_fstat(hfsfile *file, hfsdirent *ent) return 0; } + +/* + * NAME: hfs->probe() + * DESCRIPTION: return whether a HFS filesystem is present at the given offset + */ +int hfs_probe(int fd, llong offset) +{ + return v_probe(fd, offset); +} diff --git a/fs/hfs/hfs_fs.c b/fs/hfs/hfs_fs.c index 5a5bcc2..1466a17 100644 --- a/fs/hfs/hfs_fs.c +++ b/fs/hfs/hfs_fs.c @@ -458,3 +458,12 @@ fs_hfs_open( int os_fd, fs_ops_t *fs ) return 0; } + +int +fs_hfs_probe( int fd, llong offs ) +{ + if (hfs_probe(fd, offs)) + return -1; + + return 0; +} \ No newline at end of file diff --git a/fs/hfs/include/hfs.h b/fs/hfs/include/hfs.h index 8ea7b32..d07750e 100644 --- a/fs/hfs/include/hfs.h +++ b/fs/hfs/include/hfs.h @@ -177,3 +177,4 @@ int hfs_nparts(const char *); int hfs_format(const char *, int, int, const char *, unsigned int, const unsigned long []); +int hfs_probe(int fd, llong offset); diff --git a/fs/hfs/include/volume.h b/fs/hfs/include/volume.h index 3221cb8..a314fc2 100644 --- a/fs/hfs/include/volume.h +++ b/fs/hfs/include/volume.h @@ -66,5 +66,6 @@ int v_mkdir(hfsvol *, unsigned long, const char *); int v_scavenge(hfsvol *); +int v_probe(int fd, llong offset); #endif /* _H_VOLUME */ diff --git a/fs/hfs/volume.c b/fs/hfs/volume.c index 11710a3..e2d82cf 100644 --- a/fs/hfs/volume.c +++ b/fs/hfs/volume.c @@ -32,6 +32,8 @@ #include "record.h" #include "os.h" +#include "libc/byteorder.h" + /* * NAME: vol->init() * DESCRIPTION: initialize volume structure @@ -589,3 +591,22 @@ done: fail: return -1; } + +/* Determine whether the volume is a HFS volume */ +int +v_probe(int fd, llong offset) +{ + MDB *mdb; + + mdb = (MDB*)malloc(2 * 512); + os_seek_offset( fd, 2 * 512 + offset ); + os_read(fd, mdb, 2, 9); + + if (__be16_to_cpu(mdb->drSigWord) != HFS_SIGWORD) { + free(mdb); + return 0; + } + + free(mdb); + return -1; +} \ No newline at end of file diff --git a/fs/hfsplus/hfsp_fs.c b/fs/hfsplus/hfsp_fs.c index 8f59220..91c3813 100644 --- a/fs/hfsplus/hfsp_fs.c +++ b/fs/hfsplus/hfsp_fs.c @@ -397,3 +397,12 @@ fs_hfsp_open( int os_fd, fs_ops_t *fs ) return 0; } + +int +fs_hfsp_probe(int fd, llong offs) +{ + if (volume_probe(fd, offs)) + return -1; + + return 0; +} \ No newline at end of file diff --git a/fs/hfsplus/include/volume.h b/fs/hfsplus/include/volume.h index 7df1e7d..b767fcd 100644 --- a/fs/hfsplus/include/volume.h +++ b/fs/hfsplus/include/volume.h @@ -72,6 +72,8 @@ static inline btree* volume_get_extents_tree(volume* vol) { return vol->extents; } +/* Determine whether the volume is a HFS-plus volume */ +int volume_probe(int fd, llong offset); #ifdef DEBUG /* Print raw fork information to stdout */ diff --git a/fs/hfsplus/volume.c b/fs/hfsplus/volume.c index 3ab2eda..d496565 100644 --- a/fs/hfsplus/volume.c +++ b/fs/hfsplus/volume.c @@ -35,6 +35,7 @@ #include "swab.h" #include "hfstime.h" + /* Fill a given buffer with the given block in volume. */ int @@ -288,3 +289,22 @@ volume_create_extents_tree(volume* vol) fail: vol->extents = NULL; } + +/* Determine whether the volume is a HFS-plus volume */ +int +volume_probe(int fd, llong offset) +{ + struct hfsp_vh *vol; + + vol = (struct hfsp_vh*)malloc(2 * 1 << HFSP_BLOCKSZ_BITS); + os_seek_offset( fd, 2 * (1 << HFSP_BLOCKSZ_BITS) + offset ); + os_read(fd, vol, 2, HFSP_BLOCKSZ_BITS); + + if (__be16_to_cpu(vol->signature) != HFSP_VOLHEAD_SIG) { + free(vol); + return 0; + } + + free(vol); + return -1; +} \ No newline at end of file diff --git a/fs/ioglue.c b/fs/ioglue.c index e00f96e..95b5612 100644 --- a/fs/ioglue.c +++ b/fs/ioglue.c @@ -79,6 +79,12 @@ os_seek( int fd, ulong blknum, int blksize_bits ) return blknum; } +void +os_seek_offset( int fd, llong offset ) +{ + seek_io(fd, offset); +} + int os_same( int fd1, int fd2 ) { diff --git a/fs/os.h b/fs/os.h index 51eb073..0aaf3a9 100644 --- a/fs/os.h +++ b/fs/os.h @@ -47,5 +47,11 @@ unsigned long os_read( int fd, void *buf, unsigned long len, int blksize_bits); */ unsigned long os_write( int fd, const void *buf, unsigned long len, int blksize_bits); +/* + * NAME: os->seek_offset() + * DESCRIPTION: set a descriptor's seek pointer (offset in bytes) + */ +void os_seek_offset( int fd, llong offset ); + #endif /* _H_OS */ diff --git a/include/fs/fs.h b/include/fs/fs.h index 5828ca8..5bc0760 100644 --- a/include/fs/fs.h +++ b/include/fs/fs.h @@ -53,14 +53,18 @@ const char *fs_get_name( fs_ops_t *fs ); #ifdef CONFIG_HFSP extern int fs_hfsp_open( int fd, fs_ops_t *fs ); +extern int fs_hfsp_probe( int fd, llong offs ); #else static inline int fs_hfsp_open( int fd, fs_ops_t *fs ) { return -1; } +static inline int fs_hfsp_probe( int fd, llong offs ) { return -1; } #endif #ifdef CONFIG_HFS extern int fs_hfs_open( int fd, fs_ops_t *fs ); +extern int fs_hfs_probe( int fd, llong offs ); #else static inline int fs_hfs_open( int fd, fs_ops_t *fs ) { return -1; } +static inline int fs_hfs_probe( int fd, llong offs ) { return -1; } #endif #ifdef CONFIG_ISO9660 @@ -71,8 +75,10 @@ static inline int fs_iso9660_open( int fd, fs_ops_t *fs ) { return -1; } #ifdef CONFIG_EXT2 extern int fs_ext2_open( int fd, fs_ops_t *fs ); +extern int fs_ext2_probe( int fd, llong offs ); #else static inline int fs_ext2_open( int fd, fs_ops_t *fs ) { return -1; } +static inline int fs_ext2_probe( int fd, llong offs ) { return -1; } #endif #ifdef CONFIG_GRUBFS @@ -80,6 +86,7 @@ extern int fs_grubfs_open( int fd, fs_ops_t *fs ); extern int fs_grubfs_probe( int fd, llong offs ); #else static inline int fs_grubfs_open( int fd, fs_ops_t *fs ) { return -1; } +static inline int fs_grubfs_probe( int fd, llong offs ) { return -1; } #endif diff --git a/packages/misc-files.c b/packages/misc-files.c index 3958264..e2004aa 100644 --- a/packages/misc-files.c +++ b/packages/misc-files.c @@ -351,25 +351,24 @@ files_probe( files_info_t *mi ) err = (fd = open_ih(ih)) == -1; if( !err ) { - /* - err = fs_hfsp_open(fd, fs); + + err = fs_hfsp_probe(fd, offs); DPRINTF("--- HFSP returned %d\n", err); if( err ) { - err = fs_hfs_open(fd, fs); + err = fs_hfs_probe(fd, offs); DPRINTF("--- HFS returned %d\n", err); } - +/* if( err ) { err = fs_iso9660_open(fd, fs); DPRINTF("--- ISO9660 returned %d\n", err); } - +*/ if( err ) { - err = fs_ext2_open(fd, fs); + err = fs_ext2_probe(fd, offs); DPRINTF("--- ext2 returned %d\n", err); } - */ if( err ) { err = fs_grubfs_probe(fd, offs);