Author: mcayland Date: Thu Jun 10 00:30:32 2010 New Revision: 792 URL: http://tracker.coreboot.org/trac/openbios/changeset/792
Log: 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 mark.cave-ayland@siriusit.co.uk
Modified: trunk/openbios-devel/fs/ext2/ext2_fs.c trunk/openbios-devel/fs/ext2/ext2_utils.c trunk/openbios-devel/fs/ext2/ext2_utils.h trunk/openbios-devel/fs/hfs/hfs.c trunk/openbios-devel/fs/hfs/hfs_fs.c trunk/openbios-devel/fs/hfs/include/hfs.h trunk/openbios-devel/fs/hfs/include/volume.h trunk/openbios-devel/fs/hfs/volume.c trunk/openbios-devel/fs/hfsplus/hfsp_fs.c trunk/openbios-devel/fs/hfsplus/include/volume.h trunk/openbios-devel/fs/hfsplus/volume.c trunk/openbios-devel/fs/ioglue.c trunk/openbios-devel/fs/os.h trunk/openbios-devel/include/fs/fs.h trunk/openbios-devel/packages/misc-files.c
Modified: trunk/openbios-devel/fs/ext2/ext2_fs.c ============================================================================== --- trunk/openbios-devel/fs/ext2/ext2_fs.c Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/ext2/ext2_fs.c Thu Jun 10 00:30:32 2010 (r792) @@ -201,3 +201,11 @@
return 0; } + +int fs_ext2_probe(int fd, llong offs) +{ + if (ext2_probe(fd, offs)) + return -1; + + return 0; +}
Modified: trunk/openbios-devel/fs/ext2/ext2_utils.c ============================================================================== --- trunk/openbios-devel/fs/ext2/ext2_utils.c Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/ext2/ext2_utils.c Thu Jun 10 00:30:32 2010 (r792) @@ -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);
Modified: trunk/openbios-devel/fs/ext2/ext2_utils.h ============================================================================== --- trunk/openbios-devel/fs/ext2/ext2_utils.h Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/ext2/ext2_utils.h Thu Jun 10 00:30:32 2010 (r792) @@ -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,
Modified: trunk/openbios-devel/fs/hfs/hfs.c ============================================================================== --- trunk/openbios-devel/fs/hfs/hfs.c Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/hfs/hfs.c Thu Jun 10 00:30:32 2010 (r792) @@ -736,3 +736,12 @@
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); +}
Modified: trunk/openbios-devel/fs/hfs/hfs_fs.c ============================================================================== --- trunk/openbios-devel/fs/hfs/hfs_fs.c Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/hfs/hfs_fs.c Thu Jun 10 00:30:32 2010 (r792) @@ -458,3 +458,12 @@
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
Modified: trunk/openbios-devel/fs/hfs/include/hfs.h ============================================================================== --- trunk/openbios-devel/fs/hfs/include/hfs.h Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/hfs/include/hfs.h Thu Jun 10 00:30:32 2010 (r792) @@ -177,3 +177,4 @@
int hfs_format(const char *, int, int, const char *, unsigned int, const unsigned long []); +int hfs_probe(int fd, llong offset);
Modified: trunk/openbios-devel/fs/hfs/include/volume.h ============================================================================== --- trunk/openbios-devel/fs/hfs/include/volume.h Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/hfs/include/volume.h Thu Jun 10 00:30:32 2010 (r792) @@ -66,5 +66,6 @@
int v_scavenge(hfsvol *);
+int v_probe(int fd, llong offset);
#endif /* _H_VOLUME */
Modified: trunk/openbios-devel/fs/hfs/volume.c ============================================================================== --- trunk/openbios-devel/fs/hfs/volume.c Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/hfs/volume.c Thu Jun 10 00:30:32 2010 (r792) @@ -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 @@ 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
Modified: trunk/openbios-devel/fs/hfsplus/hfsp_fs.c ============================================================================== --- trunk/openbios-devel/fs/hfsplus/hfsp_fs.c Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/hfsplus/hfsp_fs.c Thu Jun 10 00:30:32 2010 (r792) @@ -397,3 +397,12 @@
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
Modified: trunk/openbios-devel/fs/hfsplus/include/volume.h ============================================================================== --- trunk/openbios-devel/fs/hfsplus/include/volume.h Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/hfsplus/include/volume.h Thu Jun 10 00:30:32 2010 (r792) @@ -72,6 +72,8 @@ 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 */
Modified: trunk/openbios-devel/fs/hfsplus/volume.c ============================================================================== --- trunk/openbios-devel/fs/hfsplus/volume.c Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/hfsplus/volume.c Thu Jun 10 00:30:32 2010 (r792) @@ -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 @@ 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
Modified: trunk/openbios-devel/fs/ioglue.c ============================================================================== --- trunk/openbios-devel/fs/ioglue.c Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/ioglue.c Thu Jun 10 00:30:32 2010 (r792) @@ -79,6 +79,12 @@ return blknum; }
+void +os_seek_offset( int fd, llong offset ) +{ + seek_io(fd, offset); +} + int os_same( int fd1, int fd2 ) {
Modified: trunk/openbios-devel/fs/os.h ============================================================================== --- trunk/openbios-devel/fs/os.h Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/fs/os.h Thu Jun 10 00:30:32 2010 (r792) @@ -47,5 +47,11 @@ */ 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 */
Modified: trunk/openbios-devel/include/fs/fs.h ============================================================================== --- trunk/openbios-devel/include/fs/fs.h Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/include/fs/fs.h Thu Jun 10 00:30:32 2010 (r792) @@ -53,14 +53,18 @@
#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 @@
#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_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
Modified: trunk/openbios-devel/packages/misc-files.c ============================================================================== --- trunk/openbios-devel/packages/misc-files.c Tue Jun 8 22:59:08 2010 (r791) +++ trunk/openbios-devel/packages/misc-files.c Thu Jun 10 00:30:32 2010 (r792) @@ -351,25 +351,24 @@
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);