From d1e9e1e479794c57320207dbeaceef57d1d1d839 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 4 Dec 2008 14:40:56 +0100 Subject: [PATCH] blkid: add sysv and xenix Signed-off-by: Karel Zak --- libs/blkid/src/probe.c | 3 +- libs/blkid/src/probers/Makefile.am | 1 + libs/blkid/src/probers/probers.h | 2 + libs/blkid/src/probers/sysv.c | 141 +++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 libs/blkid/src/probers/sysv.c diff --git a/libs/blkid/src/probe.c b/libs/blkid/src/probe.c index 7c01546a..806938d7 100644 --- a/libs/blkid/src/probe.c +++ b/libs/blkid/src/probe.c @@ -73,7 +73,8 @@ static const struct blkid_idinfo *idinfos[] = &hfs_idinfo, &ufs_idinfo, &hpfs_idinfo, - /* TODO: sysv / xenix */ + &sysv_idinfo, + &xenix_idinfo, &ntfs_idinfo, &cramfs_idinfo, &romfs_idinfo, diff --git a/libs/blkid/src/probers/Makefile.am b/libs/blkid/src/probers/Makefile.am index 36d9fa90..ff07ff86 100644 --- a/libs/blkid/src/probers/Makefile.am +++ b/libs/blkid/src/probers/Makefile.am @@ -37,6 +37,7 @@ libprobers_a_SOURCES = probers.h \ hpfs.c \ squashfs.c \ netware.c \ + sysv.c \ lvm.c all-local: $(lib_LIBRARIES) diff --git a/libs/blkid/src/probers/probers.h b/libs/blkid/src/probers/probers.h index 76a3c795..b31938f2 100644 --- a/libs/blkid/src/probers/probers.h +++ b/libs/blkid/src/probers/probers.h @@ -52,6 +52,8 @@ extern const struct blkid_idinfo highpoint37x_idinfo; extern const struct blkid_idinfo highpoint45x_idinfo; extern const struct blkid_idinfo squashfs_idinfo; extern const struct blkid_idinfo netware_idinfo; +extern const struct blkid_idinfo sysv_idinfo; +extern const struct blkid_idinfo xenix_idinfo; #endif /* _BLKID_PROBE_H */ diff --git a/libs/blkid/src/probers/sysv.c b/libs/blkid/src/probers/sysv.c new file mode 100644 index 00000000..933163a2 --- /dev/null +++ b/libs/blkid/src/probers/sysv.c @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2008 Karel Zak + * + * This is written from sratch according to Linux kernel fs/sysv/super.c file. + * It seems that sysv probing code in libvolume_id and also in the original + * blkid is useless. + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ +#include +#include +#include +#include + +#include "blkidP.h" + +#define XENIX_NICINOD 100 +#define XENIX_NICFREE 100 + +struct xenix_super_block { + uint16_t s_isize; + uint32_t s_fsize; + uint16_t s_nfree; + uint32_t s_free[XENIX_NICFREE]; + uint16_t s_ninode; + uint16_t s_inode[XENIX_NICINOD]; + uint8_t s_flock; + uint8_t s_ilock; + uint8_t s_fmod; + uint8_t s_ronly; + uint32_t s_time; + uint32_t s_tfree; + uint16_t s_tinode; + uint16_t s_dinfo[4]; + uint8_t s_fname[6]; + uint8_t s_fpack[6]; + uint8_t s_clean; + uint8_t s_fill[371]; + uint32_t s_magic; + uint32_t s_type; +}; + + +#define SYSV_NICINOD 100 +#define SYSV_NICFREE 50 + +struct sysv_super_block +{ + uint16_t s_isize; + uint16_t s_pad0; + uint32_t s_fsize; + uint16_t s_nfree; + uint16_t s_pad1; + uint32_t s_free[SYSV_NICFREE]; + uint16_t s_ninode; + uint16_t s_pad2; + uint16_t s_inode[SYSV_NICINOD]; + uint8_t s_flock; + uint8_t s_ilock; + uint8_t s_fmod; + uint8_t s_ronly; + uint32_t s_time; + uint16_t s_dinfo[4]; + uint32_t s_tfree; + uint16_t s_tinode; + uint16_t s_pad3; + uint8_t s_fname[6]; + uint8_t s_fpack[6]; + uint32_t s_fill[12]; + uint32_t s_state; + uint32_t s_magic; + uint32_t s_type; +}; + +static int probe_xenix(blkid_probe pr, const struct blkid_idmag *mag) +{ + struct xenix_super_block *sb; + + sb = blkid_probe_get_sb(pr, mag, struct xenix_super_block); + if (!sb) + return -1; + blkid_probe_set_label(pr, sb->s_fname, sizeof(sb->s_fname)); + return 0; +} + +#define SYSV_BLOCK_SIZE 1024 + +/* Note that we don't probe for Coherent FS, this FS does not have + * magic string. (It requires to probe fname/fpack field..) + */ +static int probe_sysv(blkid_probe pr, const struct blkid_idmag *mag) +{ + struct sysv_super_block *sb; + int blocks[] = {0, 9, 15, 18}; + int i; + + for (i = 0; i < ARRAY_SIZE(blocks); i++) { + int off = blocks[i] * SYSV_BLOCK_SIZE + SYSV_BLOCK_SIZE/2; + + sb = (struct sysv_super_block *) + blkid_probe_get_buffer(pr, + off, + sizeof(struct sysv_super_block)); + if (!sb) + return -1; + + if (sb->s_magic == cpu_to_le32(0xfd187e20) || + sb->s_magic == cpu_to_be32(0xfd187e20)) { + blkid_probe_set_label(pr, sb->s_fname, sizeof(sb->s_fname)); + return 0; + } + } + return 1; +} + +const struct blkid_idinfo xenix_idinfo = +{ + .name = "xenix", + .usage = BLKID_USAGE_FILESYSTEM, + .probefunc = probe_xenix, + .magics = + { + { .magic = "\x2b\x55\x44", .len = 3, .kboff = 1, .sboff = 0x400 }, + { .magic = "\x44\x55\x2b", .len = 3, .kboff = 1, .sboff = 0x400 }, + { NULL } + } +}; + +const struct blkid_idinfo sysv_idinfo = +{ + .name = "sysv", + .usage = BLKID_USAGE_FILESYSTEM, + .probefunc = probe_sysv, + + /* SYSV is BE and LE and superblock could be on four positions. It's + * simpler to probe for the magic string by .probefunc(). + */ + .magics = BLKID_NONE_MAGIC +}; + -- 2.39.5