diff -Naur e2fsprogs-1.22/misc/get_device_by_label.c e2fsprogs/misc/get_device_by_label.c --- e2fsprogs-1.22/misc/get_device_by_label.c Sat Jun 23 06:25:59 2001 +++ e2fsprogs/misc/get_device_by_label.c Sat Jun 30 01:39:54 2001 @@ -48,6 +48,16 @@ }; #define ext2magic(s) ((unsigned int) s.s_magic[0] + (((unsigned int) s.s_magic[1]) << 8)) +#define XFS_SUPER_MAGIC "XFSB" +#define XFS_SUPER_MAGIC2 "BSFX" +struct xfs_super_block { + unsigned char s_magic[4]; + unsigned char s_dummy[28]; + unsigned char s_uuid[16]; + unsigned char s_dummy2[60]; + unsigned char s_fname[12]; +}; + static struct uuidCache_s { struct uuidCache_s *next; char uuid[16]; @@ -55,35 +65,44 @@ char *device; } *uuidCache = NULL; -/* for now, only ext2 is supported */ +/* for now, only ext2 and xfs are supported */ static int get_label_uuid(const char *device, char **label, char *uuid) { - /* start with a test for ext2, taken from mount_guess_fstype */ + /* start with ext2 and xfs tests, taken from mount_guess_fstype */ /* should merge these later */ int fd; + int rv = 1; + size_t namesize; struct ext2_super_block e2sb; + struct xfs_super_block xfsb; fd = open(device, O_RDONLY); if (fd < 0) - return 1; + return rv; - if (lseek(fd, 1024, SEEK_SET) != 1024 - || read(fd, (char *) &e2sb, sizeof(e2sb)) != sizeof(e2sb) - || (ext2magic(e2sb) != EXT2_SUPER_MAGIC)) { - close(fd); - return 1; + if (lseek(fd, 1024, SEEK_SET) == 1024 + && read(fd, (char *) &e2sb, sizeof(e2sb)) == sizeof(e2sb) + && (ext2magic(e2sb) == EXT2_SUPER_MAGIC)) { + memcpy(uuid, e2sb.s_uuid, sizeof(e2sb.s_uuid)); + namesize = sizeof(e2sb.s_volume_name); + if ((*label = calloc(namesize + 1, 1)) != NULL) + memcpy(*label, e2sb.s_volume_name, namesize); + rv = 0; + } + else if (lseek(fd, 0, SEEK_SET) == 0 + && read(fd, (char *) &xfsb, sizeof(xfsb)) == sizeof(xfsb) + && (strncmp((char *) &xfsb.s_magic, XFS_SUPER_MAGIC, 4) == 0 || + strncmp((char *) &xfsb.s_magic, XFS_SUPER_MAGIC2,4) == 0)) { + memcpy(uuid, xfsb.s_uuid, sizeof(xfsb.s_uuid)); + namesize = sizeof(xfsb.s_fname); + if ((*label = calloc(namesize + 1, 1)) != NULL) + memcpy(*label, xfsb.s_fname, namesize); + rv = 0; } close(fd); - - /* superblock is ext2 - now what is its label? */ - memcpy(uuid, e2sb.s_uuid, sizeof(e2sb.s_uuid)); - - *label = calloc(sizeof(e2sb.s_volume_name) + 1, 1); - memcpy(*label, e2sb.s_volume_name, sizeof(e2sb.s_volume_name)); - - return 0; + return rv; } static void