diff options
Diffstat (limited to 'extras/volume_id')
29 files changed, 974 insertions, 532 deletions
diff --git a/extras/volume_id/Makefile b/extras/volume_id/Makefile index bfe4cf74af..9c274212a6 100644 --- a/extras/volume_id/Makefile +++ b/extras/volume_id/Makefile @@ -30,49 +30,8 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM} override CFLAGS+=-D_FILE_OFFSET_BITS=64 -VOLUME_ID_OBJS= \ - volume_id/ext/ext.o \ - volume_id/fat/fat.o \ - volume_id/hfs/hfs.o \ - volume_id/highpoint/highpoint.o \ - volume_id/iso9660/iso9660.o \ - volume_id/jfs/jfs.o \ - volume_id/linux_raid/linux_raid.o \ - volume_id/linux_swap/linux_swap.o \ - volume_id/lvm/lvm.o \ - volume_id/mac/mac.o \ - volume_id/msdos/msdos.o \ - volume_id/ntfs/ntfs.o \ - volume_id/reiserfs/reiserfs.o \ - volume_id/udf/udf.o \ - volume_id/ufs/ufs.o \ - volume_id/xfs/xfs.o \ - volume_id/cramfs/cramfs.o \ - volume_id/dasd/dasd.o \ - volume_id/volume_id.o \ - volume_id/util.o - -VOLUME_ID_HEADERS= \ - volume_id/ext/ext.h \ - volume_id/fat/fat.h \ - volume_id/hfs/hfs.h \ - volume_id/highpoint/highpoint.h \ - volume_id/iso9660/iso9660.h \ - volume_id/jfs/jfs.h \ - volume_id/linux_raid/linux_raid.h \ - volume_id/linux_swap/linux_swap.h \ - volume_id/lvm/lvm.h \ - volume_id/mac/mac.h \ - volume_id/msdos/msdos.h \ - volume_id/ntfs/ntfs.h \ - volume_id/reiserfs/reiserfs.h \ - volume_id/udf/udf.h \ - volume_id/ufs/ufs.h \ - volume_id/xfs/xfs.h \ - volume_id/cramfs/cramfs.h \ - volume_id/dasd/dasd.h \ - volume_id/volume_id.h \ - volume_id/util.h +VOLUME_ID_BASE=volume_id +include $(VOLUME_ID_BASE)/Makefile.inc OBJS = udev_volume_id.o $(VOLUME_ID_OBJS) $(SYSFS) HEADERS = $(VOLUME_ID_HEADERS) diff --git a/extras/volume_id/volume_id/Makefile.inc b/extras/volume_id/volume_id/Makefile.inc new file mode 100644 index 0000000000..d010f7778e --- /dev/null +++ b/extras/volume_id/volume_id/Makefile.inc @@ -0,0 +1,48 @@ +VOLUME_ID_OBJS= \ + $(VOLUME_ID_BASE)/ext/ext.o \ + $(VOLUME_ID_BASE)/fat/fat.o \ + $(VOLUME_ID_BASE)/hfs/hfs.o \ + $(VOLUME_ID_BASE)/highpoint/highpoint.o \ + $(VOLUME_ID_BASE)/iso9660/iso9660.o \ + $(VOLUME_ID_BASE)/jfs/jfs.o \ + $(VOLUME_ID_BASE)/linux_raid/linux_raid.o \ + $(VOLUME_ID_BASE)/linux_swap/linux_swap.o \ + $(VOLUME_ID_BASE)/lvm/lvm.o \ + $(VOLUME_ID_BASE)/mac/mac.o \ + $(VOLUME_ID_BASE)/msdos/msdos.o \ + $(VOLUME_ID_BASE)/ntfs/ntfs.o \ + $(VOLUME_ID_BASE)/reiserfs/reiserfs.o \ + $(VOLUME_ID_BASE)/udf/udf.o \ + $(VOLUME_ID_BASE)/ufs/ufs.o \ + $(VOLUME_ID_BASE)/xfs/xfs.o \ + $(VOLUME_ID_BASE)/cramfs/cramfs.o \ + $(VOLUME_ID_BASE)/hpfs/hpfs.o \ + $(VOLUME_ID_BASE)/romfs/romfs.o \ + $(VOLUME_ID_BASE)/sysv/sysv.o \ + $(VOLUME_ID_BASE)/dasd/dasd.o \ + $(VOLUME_ID_BASE)/volume_id.o \ + $(VOLUME_ID_BASE)/util.o + +VOLUME_ID_HEADERS= \ + $(VOLUME_ID_BASE)/ext/ext.h \ + $(VOLUME_ID_BASE)/fat/fat.h \ + $(VOLUME_ID_BASE)/hfs/hfs.h \ + $(VOLUME_ID_BASE)/highpoint/highpoint.h \ + $(VOLUME_ID_BASE)/iso9660/iso9660.h \ + $(VOLUME_ID_BASE)/jfs/jfs.h \ + $(VOLUME_ID_BASE)/linux_raid/linux_raid.h \ + $(VOLUME_ID_BASE)/linux_swap/linux_swap.h \ + $(VOLUME_ID_BASE)/lvm/lvm.h \ + $(VOLUME_ID_BASE)/mac/mac.h \ + $(VOLUME_ID_BASE)/msdos/msdos.h \ + $(VOLUME_ID_BASE)/ntfs/ntfs.h \ + $(VOLUME_ID_BASE)/reiserfs/reiserfs.h \ + $(VOLUME_ID_BASE)/udf/udf.h \ + $(VOLUME_ID_BASE)/ufs/ufs.h \ + $(VOLUME_ID_BASE)/xfs/xfs.h \ + $(VOLUME_ID_BASE)/cramfs/cramfs.h \ + $(VOLUME_ID_BASE)/sysv/sysv.h \ + $(VOLUME_ID_BASE)/romfs/romfs.h \ + $(VOLUME_ID_BASE)/dasd/dasd.h \ + $(VOLUME_ID_BASE)/volume_id.h \ + $(VOLUME_ID_BASE)/util.h diff --git a/extras/volume_id/volume_id/cramfs/cramfs.c b/extras/volume_id/volume_id/cramfs/cramfs.c index 69ab2c7a44..a1d51f107d 100644 --- a/extras/volume_id/volume_id/cramfs/cramfs.c +++ b/extras/volume_id/volume_id/cramfs/cramfs.c @@ -58,6 +58,8 @@ int volume_id_probe_cramfs(struct volume_id *id, __u64 off) { struct cramfs_super *cs; + dbg("probing at offset %llu", off); + cs = (struct cramfs_super *) volume_id_get_buffer(id, off, 0x200); if (cs == NULL) return -1; diff --git a/extras/volume_id/volume_id/dasd/dasd.c b/extras/volume_id/volume_id/dasd/dasd.c index 5623f69d36..4548190ce2 100644 --- a/extras/volume_id/volume_id/dasd/dasd.c +++ b/extras/volume_id/volume_id/dasd/dasd.c @@ -35,6 +35,7 @@ #include <asm/types.h> #include "../volume_id.h" +#include "../logging.h" #include "../util.h" #include "dasd.h" @@ -141,7 +142,7 @@ typedef struct dasd_information_t { unsigned int confdata_size; char characteristics[64]; /* from read_device_characteristics */ char configuration_data[256]; /* from read_configuration_data */ -} dasd_information_t; +} __attribute__((__packed__)) dasd_information_t; #define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 @@ -168,6 +169,8 @@ int volume_id_probe_dasd_partition(struct volume_id *id) __u8 *label_raw; unsigned char name[7]; + dbg("probing"); + if (ioctl(id->fd, BIODASDINFO, &info) != 0) return -1; diff --git a/extras/volume_id/volume_id/ext/ext.c b/extras/volume_id/volume_id/ext/ext.c index 50ffa85372..0940e452fc 100644 --- a/extras/volume_id/volume_id/ext/ext.c +++ b/extras/volume_id/volume_id/ext/ext.c @@ -39,30 +39,34 @@ #include "../logging.h" #include "ext.h" +struct ext2_super_block { + __u32 inodes_count; + __u32 blocks_count; + __u32 r_blocks_count; + __u32 free_blocks_count; + __u32 free_inodes_count; + __u32 first_data_block; + __u32 log_block_size; + __u32 dummy3[7]; + __u8 magic[2]; + __u16 state; + __u32 dummy5[8]; + __u32 feature_compat; + __u32 feature_incompat; + __u32 feature_ro_compat; + __u8 uuid[16]; + __u8 volume_name[16]; +} __attribute__((__packed__)); + #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x00000004 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x00000008 #define EXT_SUPERBLOCK_OFFSET 0x400 int volume_id_probe_ext(struct volume_id *id, __u64 off) { - struct ext2_super_block { - __u32 inodes_count; - __u32 blocks_count; - __u32 r_blocks_count; - __u32 free_blocks_count; - __u32 free_inodes_count; - __u32 first_data_block; - __u32 log_block_size; - __u32 dummy3[7]; - __u8 magic[2]; - __u16 state; - __u32 dummy5[8]; - __u32 feature_compat; - __u32 feature_incompat; - __u32 feature_ro_compat; - __u8 uuid[16]; - __u8 volume_name[16]; - } __attribute__((__packed__)) *es; + struct ext2_super_block *es; + + dbg("probing at offset %llu", off); es = (struct ext2_super_block *) volume_id_get_buffer(id, off + EXT_SUPERBLOCK_OFFSET, 0x200); if (es == NULL) diff --git a/extras/volume_id/volume_id/fat/fat.c b/extras/volume_id/volume_id/fat/fat.c index 219207e81d..c6bb491f70 100644 --- a/extras/volume_id/volume_id/fat/fat.c +++ b/extras/volume_id/volume_id/fat/fat.c @@ -159,6 +159,8 @@ int volume_id_probe_vfat(struct volume_id *id, __u64 off) __u32 next; int maxloop; + dbg("probing at offset %llu", off); + vs = (struct vfat_super_block *) volume_id_get_buffer(id, off, 0x200); if (vs == NULL) return -1; diff --git a/extras/volume_id/volume_id/hfs/hfs.c b/extras/volume_id/volume_id/hfs/hfs.c index a4ae86b56a..905471cb35 100644 --- a/extras/volume_id/volume_id/hfs/hfs.c +++ b/extras/volume_id/volume_id/hfs/hfs.c @@ -39,119 +39,119 @@ #include "../util.h" #include "hfs.h" +struct hfs_finder_info{ + __u32 boot_folder; + __u32 start_app; + __u32 open_folder; + __u32 os9_folder; + __u32 reserved; + __u32 osx_folder; + __u8 id[8]; +} __attribute__((__packed__)); + +struct hfs_mdb { + __u8 signature[2]; + __u32 cr_date; + __u32 ls_Mod; + __u16 atrb; + __u16 nm_fls; + __u16 vbm_st; + __u16 alloc_ptr; + __u16 nm_al_blks; + __u32 al_blk_size; + __u32 clp_size; + __u16 al_bl_st; + __u32 nxt_cnid; + __u16 free_bks; + __u8 label_len; + __u8 label[27]; + __u32 vol_bkup; + __u16 vol_seq_num; + __u32 wr_cnt; + __u32 xt_clump_size; + __u32 ct_clump_size; + __u16 num_root_dirs; + __u32 file_count; + __u32 dir_count; + struct hfs_finder_info finder_info; + __u8 embed_sig[2]; + __u16 embed_startblock; + __u16 embed_blockcount; +} __attribute__((__packed__)) *hfs; + +struct hfsplus_bnode_descriptor { + __u32 next; + __u32 prev; + __u8 type; + __u8 height; + __u16 num_recs; + __u16 reserved; +} __attribute__((__packed__)); + +struct hfsplus_bheader_record { + __u16 depth; + __u32 root; + __u32 leaf_count; + __u32 leaf_head; + __u32 leaf_tail; + __u16 node_size; +} __attribute__((__packed__)); + +struct hfsplus_catalog_key { + __u16 key_len; + __u32 parent_id; + __u16 unicode_len; + __u8 unicode[255 * 2]; +} __attribute__((__packed__)); + +struct hfsplus_extent { + __u32 start_block; + __u32 block_count; +} __attribute__((__packed__)); + +#define HFSPLUS_EXTENT_COUNT 8 +struct hfsplus_fork { + __u64 total_size; + __u32 clump_size; + __u32 total_blocks; + struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT]; +} __attribute__((__packed__)); + +struct hfsplus_vol_header { + __u8 signature[2]; + __u16 version; + __u32 attributes; + __u32 last_mount_vers; + __u32 reserved; + __u32 create_date; + __u32 modify_date; + __u32 backup_date; + __u32 checked_date; + __u32 file_count; + __u32 folder_count; + __u32 blocksize; + __u32 total_blocks; + __u32 free_blocks; + __u32 next_alloc; + __u32 rsrc_clump_sz; + __u32 data_clump_sz; + __u32 next_cnid; + __u32 write_count; + __u64 encodings_bmp; + struct hfs_finder_info finder_info; + struct hfsplus_fork alloc_file; + struct hfsplus_fork ext_file; + struct hfsplus_fork cat_file; + struct hfsplus_fork attr_file; + struct hfsplus_fork start_file; +} __attribute__((__packed__)) *hfsplus; + #define HFS_SUPERBLOCK_OFFSET 0x400 #define HFS_NODE_LEAF 0xff #define HFSPLUS_POR_CNID 1 -#define HFSPLUS_EXTENT_COUNT 8 int volume_id_probe_hfs_hfsplus(struct volume_id *id, __u64 off) { - struct hfs_finder_info{ - __u32 boot_folder; - __u32 start_app; - __u32 open_folder; - __u32 os9_folder; - __u32 reserved; - __u32 osx_folder; - __u8 id[8]; - } __attribute__((__packed__)); - - struct hfs_mdb { - __u8 signature[2]; - __u32 cr_date; - __u32 ls_Mod; - __u16 atrb; - __u16 nm_fls; - __u16 vbm_st; - __u16 alloc_ptr; - __u16 nm_al_blks; - __u32 al_blk_size; - __u32 clp_size; - __u16 al_bl_st; - __u32 nxt_cnid; - __u16 free_bks; - __u8 label_len; - __u8 label[27]; - __u32 vol_bkup; - __u16 vol_seq_num; - __u32 wr_cnt; - __u32 xt_clump_size; - __u32 ct_clump_size; - __u16 num_root_dirs; - __u32 file_count; - __u32 dir_count; - struct hfs_finder_info finder_info; - __u8 embed_sig[2]; - __u16 embed_startblock; - __u16 embed_blockcount; - } __attribute__((__packed__)) *hfs; - - struct hfsplus_bnode_descriptor { - __u32 next; - __u32 prev; - __u8 type; - __u8 height; - __u16 num_recs; - __u16 reserved; - } __attribute__((__packed__)); - - struct hfsplus_bheader_record { - __u16 depth; - __u32 root; - __u32 leaf_count; - __u32 leaf_head; - __u32 leaf_tail; - __u16 node_size; - } __attribute__((__packed__)); - - struct hfsplus_catalog_key { - __u16 key_len; - __u32 parent_id; - __u16 unicode_len; - __u8 unicode[255 * 2]; - } __attribute__((__packed__)); - - struct hfsplus_extent { - __u32 start_block; - __u32 block_count; - } __attribute__((__packed__)); - - struct hfsplus_fork { - __u64 total_size; - __u32 clump_size; - __u32 total_blocks; - struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT]; - } __attribute__((__packed__)); - - struct hfsplus_vol_header { - __u8 signature[2]; - __u16 version; - __u32 attributes; - __u32 last_mount_vers; - __u32 reserved; - __u32 create_date; - __u32 modify_date; - __u32 backup_date; - __u32 checked_date; - __u32 file_count; - __u32 folder_count; - __u32 blocksize; - __u32 total_blocks; - __u32 free_blocks; - __u32 next_alloc; - __u32 rsrc_clump_sz; - __u32 data_clump_sz; - __u32 next_cnid; - __u32 write_count; - __u64 encodings_bmp; - struct hfs_finder_info finder_info; - struct hfsplus_fork alloc_file; - struct hfsplus_fork ext_file; - struct hfsplus_fork cat_file; - struct hfsplus_fork attr_file; - struct hfsplus_fork start_file; - } __attribute__((__packed__)) *hfsplus; - unsigned int blocksize; unsigned int cat_block; unsigned int ext_block_start; @@ -173,6 +173,8 @@ int volume_id_probe_hfs_hfsplus(struct volume_id *id, __u64 off) struct hfsplus_extent extents[HFSPLUS_EXTENT_COUNT]; const __u8 *buf; + dbg("probing at offset %llu", off); + buf = volume_id_get_buffer(id, off + HFS_SUPERBLOCK_OFFSET, 0x200); if (buf == NULL) return -1; diff --git a/extras/volume_id/volume_id/highpoint/highpoint.c b/extras/volume_id/volume_id/highpoint/highpoint.c index 3236d6b2fd..b301450086 100644 --- a/extras/volume_id/volume_id/highpoint/highpoint.c +++ b/extras/volume_id/volume_id/highpoint/highpoint.c @@ -39,21 +39,23 @@ #include "../util.h" #include "highpoint.h" +struct hpt37x { + __u8 filler1[32]; + __u32 magic; + __u32 magic_0; + __u32 magic_1; +} __attribute__((packed)) *hpt; + #define HPT37X_CONFIG_OFF 0x1200 #define HPT37X_MAGIC_OK 0x5a7816f0 #define HPT37X_MAGIC_BAD 0x5a7816fd int volume_id_probe_highpoint_ataraid(struct volume_id *id, __u64 off) { - struct hpt37x { - __u8 filler1[32]; - __u32 magic; - __u32 magic_0; - __u32 magic_1; - } __attribute__((packed)) *hpt; - const __u8 *buf; + dbg("probing at offset %llu", off); + buf = volume_id_get_buffer(id, off + HPT37X_CONFIG_OFF, 0x200); if (buf == NULL) return -1; diff --git a/extras/volume_id/volume_id/hpfs/hpfs.c b/extras/volume_id/volume_id/hpfs/hpfs.c new file mode 100644 index 0000000000..212e74ee41 --- /dev/null +++ b/extras/volume_id/volume_id/hpfs/hpfs.c @@ -0,0 +1,69 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <ctype.h> +#include <asm/types.h> + +#include "../volume_id.h" +#include "../logging.h" +#include "../util.h" +#include "hpfs.h" + +struct hpfs_super +{ + __u8 magic[4]; + __u8 version; +} __attribute__((__packed__)); + +#define HPFS_SUPERBLOCK_OFFSET 0x2000 + +int volume_id_probe_hpfs(struct volume_id *id, __u64 off) +{ + struct hpfs_super *hs; + + dbg("probing at offset %llu", off); + + hs = (struct hpfs_super *) volume_id_get_buffer(id, off + HPFS_SUPERBLOCK_OFFSET, 0x200); + if (hs == NULL) + return -1; + + if (memcmp(hs->magic, "\x49\xe8\x95\xf9", 4) == 0) { + snprintf(id->type_version, VOLUME_ID_FORMAT_SIZE-1, "%u", hs->version); + + volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); + id->type = "hpfs"; + return 0; + } + + return -1; +} diff --git a/extras/volume_id/volume_id/hpfs/hpfs.h b/extras/volume_id/volume_id/hpfs/hpfs.h new file mode 100644 index 0000000000..bd8d4c90c9 --- /dev/null +++ b/extras/volume_id/volume_id/hpfs/hpfs.h @@ -0,0 +1,26 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _VOLUME_ID_HPFS_ +#define _VOLUME_ID_HPFS_ + +extern int volume_id_probe_hpfs(struct volume_id *id, __u64 off); + +#endif diff --git a/extras/volume_id/volume_id/iso9660/iso9660.c b/extras/volume_id/volume_id/iso9660/iso9660.c index fa769d3ca3..1d7cfd5037 100644 --- a/extras/volume_id/volume_id/iso9660/iso9660.c +++ b/extras/volume_id/volume_id/iso9660/iso9660.c @@ -47,24 +47,28 @@ #define ISO_VD_END 0xff #define ISO_VD_MAX 16 +union iso_super_block { + struct iso_header { + __u8 type; + __u8 id[5]; + __u8 version; + __u8 unused1; + __u8 system_id[32]; + __u8 volume_id[32]; + } __attribute__((__packed__)) iso; + struct hs_header { + __u8 foo[8]; + __u8 type; + __u8 id[4]; + __u8 version; + } __attribute__((__packed__)) hs; +} __attribute__((__packed__)); + int volume_id_probe_iso9660(struct volume_id *id, __u64 off) { - union iso_super_block { - struct iso_header { - __u8 type; - __u8 id[5]; - __u8 version; - __u8 unused1; - __u8 system_id[32]; - __u8 volume_id[32]; - } __attribute__((__packed__)) iso; - struct hs_header { - __u8 foo[8]; - __u8 type; - __u8 id[4]; - __u8 version; - } __attribute__((__packed__)) hs; - } __attribute__((__packed__)) *is; + union iso_super_block *is; + + dbg("probing at offset %llu", off); is = (union iso_super_block *) volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200); if (is == NULL) diff --git a/extras/volume_id/volume_id/jfs/jfs.c b/extras/volume_id/volume_id/jfs/jfs.c index c9dce84ecb..ab0b83081c 100644 --- a/extras/volume_id/volume_id/jfs/jfs.c +++ b/extras/volume_id/volume_id/jfs/jfs.c @@ -39,22 +39,26 @@ #include "../util.h" #include "jfs.h" +struct jfs_super_block { + __u8 magic[4]; + __u32 version; + __u64 size; + __u32 bsize; + __u32 dummy1; + __u32 pbsize; + __u32 dummy2[27]; + __u8 uuid[16]; + __u8 label[16]; + __u8 loguuid[16]; +} __attribute__((__packed__)); + #define JFS_SUPERBLOCK_OFFSET 0x8000 int volume_id_probe_jfs(struct volume_id *id, __u64 off) { - struct jfs_super_block { - __u8 magic[4]; - __u32 version; - __u64 size; - __u32 bsize; - __u32 dummy1; - __u32 pbsize; - __u32 dummy2[27]; - __u8 uuid[16]; - __u8 label[16]; - __u8 loguuid[16]; - } __attribute__((__packed__)) *js; + struct jfs_super_block *js; + + dbg("probing at offset %llu", off); js = (struct jfs_super_block *) volume_id_get_buffer(id, off + JFS_SUPERBLOCK_OFFSET, 0x200); if (js == NULL) diff --git a/extras/volume_id/volume_id/linux_raid/linux_raid.c b/extras/volume_id/volume_id/linux_raid/linux_raid.c index b55c6ca6e8..ca03030ee4 100644 --- a/extras/volume_id/volume_id/linux_raid/linux_raid.c +++ b/extras/volume_id/volume_id/linux_raid/linux_raid.c @@ -39,34 +39,36 @@ #include "../util.h" #include "linux_raid.h" +struct mdp_super_block { + __u32 md_magic; + __u32 major_version; + __u32 minor_version; + __u32 patch_version; + __u32 gvalid_words; + __u32 set_uuid0; + __u32 ctime; + __u32 level; + __u32 size; + __u32 nr_disks; + __u32 raid_disks; + __u32 md_minor; + __u32 not_persistent; + __u32 set_uuid1; + __u32 set_uuid2; + __u32 set_uuid3; +} __attribute__((packed)) *mdp; + #define MD_RESERVED_BYTES 0x10000 #define MD_MAGIC 0xa92b4efc int volume_id_probe_linux_raid(struct volume_id *id, __u64 off, __u64 size) { - struct mdp_super_block { - __u32 md_magic; - __u32 major_version; - __u32 minor_version; - __u32 patch_version; - __u32 gvalid_words; - __u32 set_uuid0; - __u32 ctime; - __u32 level; - __u32 size; - __u32 nr_disks; - __u32 raid_disks; - __u32 md_minor; - __u32 not_persistent; - __u32 set_uuid1; - __u32 set_uuid2; - __u32 set_uuid3; - } __attribute__((packed)) *mdp; - const __u8 *buf; __u64 sboff; __u8 uuid[16]; + dbg("probing at offset %llu", off); + if (size < 0x10000) return -1; diff --git a/extras/volume_id/volume_id/linux_swap/linux_swap.c b/extras/volume_id/volume_id/linux_swap/linux_swap.c index d34b22c590..2fb16377a8 100644 --- a/extras/volume_id/volume_id/linux_swap/linux_swap.c +++ b/extras/volume_id/volume_id/linux_swap/linux_swap.c @@ -39,22 +39,24 @@ #include "../util.h" #include "linux_swap.h" +struct swap_header_v1_2 { + __u8 bootbits[1024]; + __u32 version; + __u32 last_page; + __u32 nr_badpages; + __u8 uuid[16]; + __u8 volume_name[16]; +} __attribute__((__packed__)) *sw; + #define LARGEST_PAGESIZE 0x4000 int volume_id_probe_linux_swap(struct volume_id *id, __u64 off) { - struct swap_header_v1_2 { - __u8 bootbits[1024]; - __u32 version; - __u32 last_page; - __u32 nr_badpages; - __u8 uuid[16]; - __u8 volume_name[16]; - } __attribute__((__packed__)) *sw; - const __u8 *buf; unsigned int page; + dbg("probing at offset %llu", off); + /* the swap signature is at the end of the PAGE_SIZE */ for (page = 0x1000; page <= LARGEST_PAGESIZE; page <<= 1) { buf = volume_id_get_buffer(id, off + page-10, 10); diff --git a/extras/volume_id/volume_id/lvm/lvm.c b/extras/volume_id/volume_id/lvm/lvm.c index e736f4ed4a..ed1a83aeb4 100644 --- a/extras/volume_id/volume_id/lvm/lvm.c +++ b/extras/volume_id/volume_id/lvm/lvm.c @@ -39,22 +39,33 @@ #include "../util.h" #include "lvm.h" +struct lvm1_super_block { + __u8 id[2]; +} __attribute__((packed)); + +struct lvm2_super_block { + __u8 id[8]; + __u64 sector_xl; + __u32 crc_xl; + __u32 offset_xl; + __u8 type[8]; +} __attribute__((packed)); + #define LVM1_SB_OFF 0x400 #define LVM1_MAGIC "HM" int volume_id_probe_lvm1(struct volume_id *id, __u64 off) { - struct lvm2_super_block { - __u8 id[2]; - } __attribute__((packed)) *lvm; - const __u8 *buf; + struct lvm1_super_block *lvm; + + dbg("probing at offset %llu", off); buf = volume_id_get_buffer(id, off + LVM1_SB_OFF, 0x800); if (buf == NULL) return -1; - lvm = (struct lvm2_super_block *) buf; + lvm = (struct lvm1_super_block *) buf; if (memcmp(lvm->id, LVM1_MAGIC, 2) != 0) return -1; @@ -70,16 +81,11 @@ int volume_id_probe_lvm1(struct volume_id *id, __u64 off) int volume_id_probe_lvm2(struct volume_id *id, __u64 off) { - struct lvm2_super_block { - __u8 id[8]; - __u64 sector_xl; - __u32 crc_xl; - __u32 offset_xl; - __u8 type[8]; - } __attribute__((packed)) *lvm; - const __u8 *buf; unsigned int soff; + struct lvm2_super_block *lvm; + + dbg("probing at offset %llu", off); buf = volume_id_get_buffer(id, off, LVM2LABEL_SCAN_SECTORS * 0x200); if (buf == NULL) diff --git a/extras/volume_id/volume_id/mac/mac.c b/extras/volume_id/volume_id/mac/mac.c index 5872b722b4..895316d26c 100644 --- a/extras/volume_id/volume_id/mac/mac.c +++ b/extras/volume_id/volume_id/mac/mac.c @@ -39,25 +39,29 @@ #include "../util.h" #include "mac.h" +struct mac_driver_desc { + __u8 signature[2]; + __u16 block_size; + __u32 block_count; +} __attribute__((__packed__)); + +struct mac_partition { + __u8 signature[2]; + __u16 res1; + __u32 map_count; + __u32 start_block; + __u32 block_count; + __u8 name[32]; + __u8 type[32]; +} __attribute__((__packed__)); + int volume_id_probe_mac_partition_map(struct volume_id *id, __u64 off) { - struct mac_driver_desc { - __u8 signature[2]; - __u16 block_size; - __u32 block_count; - } __attribute__((__packed__)) *driver; - - struct mac_partition { - __u8 signature[2]; - __u16 res1; - __u32 map_count; - __u32 start_block; - __u32 block_count; - __u8 name[32]; - __u8 type[32]; - } __attribute__((__packed__)) *part; - const __u8 *buf; + struct mac_driver_desc *driver; + struct mac_partition *part; + + dbg("probing at offset %llu", off); buf = volume_id_get_buffer(id, off, 0x200); if (buf == NULL) diff --git a/extras/volume_id/volume_id/msdos/msdos.c b/extras/volume_id/volume_id/msdos/msdos.c index 08124fad2d..a90b9efc33 100644 --- a/extras/volume_id/volume_id/msdos/msdos.c +++ b/extras/volume_id/volume_id/msdos/msdos.c @@ -39,6 +39,19 @@ #include "../util.h" #include "msdos.h" +struct msdos_partition_entry { + __u8 boot_ind; + __u8 head; + __u8 sector; + __u8 cyl; + __u8 sys_ind; + __u8 end_head; + __u8 end_sector; + __u8 end_cyl; + __u32 start_sect; + __u32 nr_sects; +} __attribute__((packed)); + #define MSDOS_MAGIC "\x55\xaa" #define MSDOS_PARTTABLE_OFFSET 0x1be #define MSDOS_SIG_OFF 0x1fe @@ -56,19 +69,6 @@ int volume_id_probe_msdos_part_table(struct volume_id *id, __u64 off) { - struct msdos_partition_entry { - __u8 boot_ind; - __u8 head; - __u8 sector; - __u8 cyl; - __u8 sys_ind; - __u8 end_head; - __u8 end_sector; - __u8 end_cyl; - __u32 start_sect; - __u32 nr_sects; - } __attribute__((packed)) *part; - const __u8 *buf; int i; __u64 poff; @@ -78,8 +78,11 @@ int volume_id_probe_msdos_part_table(struct volume_id *id, __u64 off) __u64 next; int limit; int empty = 1; + struct msdos_partition_entry *part; struct volume_id_partition *p; + dbg("probing at offset %llu", off); + buf = volume_id_get_buffer(id, off, 0x200); if (buf == NULL) return -1; diff --git a/extras/volume_id/volume_id/ntfs/ntfs.c b/extras/volume_id/volume_id/ntfs/ntfs.c index bf87f9d8d0..e46bc64bb2 100644 --- a/extras/volume_id/volume_id/ntfs/ntfs.c +++ b/extras/volume_id/volume_id/ntfs/ntfs.c @@ -39,6 +39,64 @@ #include "../util.h" #include "ntfs.h" +struct ntfs_super_block { + __u8 jump[3]; + __u8 oem_id[8]; + __u16 bytes_per_sector; + __u8 sectors_per_cluster; + __u16 reserved_sectors; + __u8 fats; + __u16 root_entries; + __u16 sectors; + __u8 media_type; + __u16 sectors_per_fat; + __u16 sectors_per_track; + __u16 heads; + __u32 hidden_sectors; + __u32 large_sectors; + __u16 unused[2]; + __u64 number_of_sectors; + __u64 mft_cluster_location; + __u64 mft_mirror_cluster_location; + __s8 cluster_per_mft_record; + __u8 reserved1[3]; + __s8 cluster_per_index_record; + __u8 reserved2[3]; + __u8 volume_serial[8]; + __u16 checksum; +} __attribute__((__packed__)) *ns; + +struct master_file_table_record { + __u8 magic[4]; + __u16 usa_ofs; + __u16 usa_count; + __u64 lsn; + __u16 sequence_number; + __u16 link_count; + __u16 attrs_offset; + __u16 flags; + __u32 bytes_in_use; + __u32 bytes_allocated; +} __attribute__((__packed__)) *mftr; + +struct file_attribute { + __u32 type; + __u32 len; + __u8 non_resident; + __u8 name_len; + __u16 name_offset; + __u16 flags; + __u16 instance; + __u32 value_len; + __u16 value_offset; +} __attribute__((__packed__)) *attr; + +struct volume_info { + __u64 reserved; + __u8 major_ver; + __u8 minor_ver; +} __attribute__((__packed__)) *info; + #define MFT_RECORD_VOLUME 3 #define MFT_RECORD_ATTR_VOLUME_NAME 0x60 #define MFT_RECORD_ATTR_VOLUME_INFO 0x70 @@ -47,64 +105,6 @@ int volume_id_probe_ntfs(struct volume_id *id, __u64 off) { - struct ntfs_super_block { - __u8 jump[3]; - __u8 oem_id[8]; - __u16 bytes_per_sector; - __u8 sectors_per_cluster; - __u16 reserved_sectors; - __u8 fats; - __u16 root_entries; - __u16 sectors; - __u8 media_type; - __u16 sectors_per_fat; - __u16 sectors_per_track; - __u16 heads; - __u32 hidden_sectors; - __u32 large_sectors; - __u16 unused[2]; - __u64 number_of_sectors; - __u64 mft_cluster_location; - __u64 mft_mirror_cluster_location; - __s8 cluster_per_mft_record; - __u8 reserved1[3]; - __s8 cluster_per_index_record; - __u8 reserved2[3]; - __u8 volume_serial[8]; - __u16 checksum; - } __attribute__((__packed__)) *ns; - - struct master_file_table_record { - __u8 magic[4]; - __u16 usa_ofs; - __u16 usa_count; - __u64 lsn; - __u16 sequence_number; - __u16 link_count; - __u16 attrs_offset; - __u16 flags; - __u32 bytes_in_use; - __u32 bytes_allocated; - } __attribute__((__packed__)) *mftr; - - struct file_attribute { - __u32 type; - __u32 len; - __u8 non_resident; - __u8 name_len; - __u16 name_offset; - __u16 flags; - __u16 instance; - __u32 value_len; - __u16 value_offset; - } __attribute__((__packed__)) *attr; - - struct volume_info { - __u64 reserved; - __u8 major_ver; - __u8 minor_ver; - } __attribute__((__packed__)) *info; - unsigned int sector_size; unsigned int cluster_size; __u64 mft_cluster; @@ -118,6 +118,8 @@ int volume_id_probe_ntfs(struct volume_id *id, __u64 off) const __u8 *buf; const __u8 *val; + dbg("probing at offset %llu", off); + ns = (struct ntfs_super_block *) volume_id_get_buffer(id, off, 0x200); if (ns == NULL) return -1; diff --git a/extras/volume_id/volume_id/reiserfs/reiserfs.c b/extras/volume_id/volume_id/reiserfs/reiserfs.c index 5653214e9d..d54013e4c5 100644 --- a/extras/volume_id/volume_id/reiserfs/reiserfs.c +++ b/extras/volume_id/volume_id/reiserfs/reiserfs.c @@ -39,26 +39,30 @@ #include "../util.h" #include "reiserfs.h" +struct reiserfs_super_block { + __u32 blocks_count; + __u32 free_blocks; + __u32 root_block; + __u32 journal_block; + __u32 journal_dev; + __u32 orig_journal_size; + __u32 dummy2[5]; + __u16 blocksize; + __u16 dummy3[3]; + __u8 magic[12]; + __u32 dummy4[5]; + __u8 uuid[16]; + __u8 label[16]; +} __attribute__((__packed__)); + #define REISERFS1_SUPERBLOCK_OFFSET 0x2000 #define REISERFS_SUPERBLOCK_OFFSET 0x10000 int volume_id_probe_reiserfs(struct volume_id *id, __u64 off) { - struct reiserfs_super_block { - __u32 blocks_count; - __u32 free_blocks; - __u32 root_block; - __u32 journal_block; - __u32 journal_dev; - __u32 orig_journal_size; - __u32 dummy2[5]; - __u16 blocksize; - __u16 dummy3[3]; - __u8 magic[12]; - __u32 dummy4[5]; - __u8 uuid[16]; - __u8 label[16]; - } __attribute__((__packed__)) *rs; + struct reiserfs_super_block *rs; + + dbg("probing at offset %llu", off); rs = (struct reiserfs_super_block *) volume_id_get_buffer(id, off + REISERFS_SUPERBLOCK_OFFSET, 0x200); if (rs == NULL) diff --git a/extras/volume_id/volume_id/romfs/romfs.c b/extras/volume_id/volume_id/romfs/romfs.c new file mode 100644 index 0000000000..c04dc98f10 --- /dev/null +++ b/extras/volume_id/volume_id/romfs/romfs.c @@ -0,0 +1,73 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <ctype.h> +#include <asm/types.h> + +#include "../volume_id.h" +#include "../logging.h" +#include "../util.h" +#include "romfs.h" + +struct romfs_super { + __u8 magic[8]; + __u32 size; + __u32 checksum; + __u8 name[0]; +} __attribute__((__packed__)); + +int volume_id_probe_romfs(struct volume_id *id, __u64 off) +{ + struct romfs_super *rfs; + + dbg("probing at offset %llu", off); + + rfs = (struct romfs_super *) volume_id_get_buffer(id, off, 0x200); + if (rfs == NULL) + return -1; + + if (memcmp(rfs->magic, "-rom1fs-", 4) == 0) { + size_t len = strlen(rfs->name); + + if (len) { + volume_id_set_label_raw(id, rfs->name, len); + volume_id_set_label_string(id, rfs->name, len); + } + + volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); + id->type = "romfs"; + return 0; + } + + return -1; +} diff --git a/extras/volume_id/volume_id/romfs/romfs.h b/extras/volume_id/volume_id/romfs/romfs.h new file mode 100644 index 0000000000..b0108f3dde --- /dev/null +++ b/extras/volume_id/volume_id/romfs/romfs.h @@ -0,0 +1,26 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _VOLUME_ID_ROMFS_ +#define _VOLUME_ID_ROMFS_ + +extern int volume_id_probe_romfs(struct volume_id *id, __u64 off); + +#endif diff --git a/extras/volume_id/volume_id/sysv/sysv.c b/extras/volume_id/volume_id/sysv/sysv.c new file mode 100644 index 0000000000..313ac1732a --- /dev/null +++ b/extras/volume_id/volume_id/sysv/sysv.c @@ -0,0 +1,146 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <ctype.h> +#include <asm/types.h> + +#include "../volume_id.h" +#include "../logging.h" +#include "../util.h" +#include "sysv.h" + +#define SYSV_NICINOD 100 +#define SYSV_NICFREE 50 + +struct sysv_super +{ + __u16 s_isize; + __u16 s_pad0; + __u32 s_fsize; + __u16 s_nfree; + __u16 s_pad1; + __u32 s_free[SYSV_NICFREE]; + __u16 s_ninode; + __u16 s_pad2; + __u16 s_inode[SYSV_NICINOD]; + __u8 s_flock; + __u8 s_ilock; + __u8 s_fmod; + __u8 s_ronly; + __u32 s_time; + __u16 s_dinfo[4]; + __u32 s_tfree; + __u16 s_tinode; + __u16 s_pad3; + __u8 s_fname[6]; + __u8 s_fpack[6]; + __u32 s_fill[12]; + __u32 s_state; + __u32 s_magic; + __u32 s_type; +} __attribute__((__packed__)); + +#define XENIX_NICINOD 100 +#define XENIX_NICFREE 100 + +struct xenix_super { + __u16 s_isize; + __u32 s_fsize; + __u16 s_nfree; + __u32 s_free[XENIX_NICFREE]; + __u16 s_ninode; + __u16 s_inode[XENIX_NICINOD]; + __u8 s_flock; + __u8 s_ilock; + __u8 s_fmod; + __u8 s_ronly; + __u32 s_time; + __u32 s_tfree; + __u16 s_tinode; + __u16 s_dinfo[4]; + __u8 s_fname[6]; + __u8 s_fpack[6]; + __u8 s_clean; + __u8 s_fill[371]; + __u32 s_magic; + __u32 s_type; +} __attribute__((__packed__)); + +#define SYSV_SUPERBLOCK_BLOCK 0x01 +#define SYSV_MAGIC 0xfd187e20 +#define XENIX_SUPERBLOCK_BLOCK 0x18 +#define XENIX_MAGIC 0x2b5544 +#define SYSV_MAX_BLOCKSIZE 0x800 + +int volume_id_probe_sysv(struct volume_id *id, __u64 off) +{ + struct sysv_super *vs; + struct xenix_super *xs; + unsigned int boff; + + dbg("probing at offset %llu", off); + + for (boff = 0x200; boff <= SYSV_MAX_BLOCKSIZE; boff <<= 1) { + vs = (struct sysv_super *) + volume_id_get_buffer(id, off + (boff * SYSV_SUPERBLOCK_BLOCK), 0x200); + if (vs == NULL) + return -1; + + if (vs->s_magic == cpu_to_le32(SYSV_MAGIC) || vs->s_magic == cpu_to_be32(SYSV_MAGIC)) { + volume_id_set_label_raw(id, vs->s_fname, 6); + volume_id_set_label_string(id, vs->s_fname, 6); + id->type = "sysv"; + goto found; + } + } + + for (boff = 0x200; boff <= SYSV_MAX_BLOCKSIZE; boff <<= 1) { + xs = (struct xenix_super *) + volume_id_get_buffer(id, off + (boff + XENIX_SUPERBLOCK_BLOCK), 0x200); + if (xs == NULL) + return -1; + + if (xs->s_magic == cpu_to_le32(XENIX_MAGIC) || xs->s_magic == cpu_to_be32(XENIX_MAGIC)) { + volume_id_set_label_raw(id, xs->s_fname, 6); + volume_id_set_label_string(id, xs->s_fname, 6); + id->type = "xenix"; + goto found; + } + } + + return -1; + +found: + volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); + return 0; +} diff --git a/extras/volume_id/volume_id/sysv/sysv.h b/extras/volume_id/volume_id/sysv/sysv.h new file mode 100644 index 0000000000..bd5a3500fb --- /dev/null +++ b/extras/volume_id/volume_id/sysv/sysv.h @@ -0,0 +1,26 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _VOLUME_ID_SYSV_ +#define _VOLUME_ID_SYSV_ + +extern int volume_id_probe_sysv(struct volume_id *id, __u64 off); + +#endif diff --git a/extras/volume_id/volume_id/udf/udf.c b/extras/volume_id/volume_id/udf/udf.c index ff23b31039..79d25ad890 100644 --- a/extras/volume_id/volume_id/udf/udf.c +++ b/extras/volume_id/volume_id/udf/udf.c @@ -39,43 +39,45 @@ #include "../util.h" #include "udf.h" +struct volume_descriptor { + struct descriptor_tag { + __u16 id; + __u16 version; + __u8 checksum; + __u8 reserved; + __u16 serial; + __u16 crc; + __u16 crc_len; + __u32 location; + } __attribute__((__packed__)) tag; + union { + struct anchor_descriptor { + __u32 length; + __u32 location; + } __attribute__((__packed__)) anchor; + struct primary_descriptor { + __u32 seq_num; + __u32 desc_num; + struct dstring { + __u8 clen; + __u8 c[31]; + } __attribute__((__packed__)) ident; + } __attribute__((__packed__)) primary; + } __attribute__((__packed__)) type; +} __attribute__((__packed__)); + +struct volume_structure_descriptor { + __u8 type; + __u8 id[5]; + __u8 version; +} __attribute__((__packed__)); + #define UDF_VSD_OFFSET 0x8000 int volume_id_probe_udf(struct volume_id *id, __u64 off) { - struct volume_descriptor { - struct descriptor_tag { - __u16 id; - __u16 version; - __u8 checksum; - __u8 reserved; - __u16 serial; - __u16 crc; - __u16 crc_len; - __u32 location; - } __attribute__((__packed__)) tag; - union { - struct anchor_descriptor { - __u32 length; - __u32 location; - } __attribute__((__packed__)) anchor; - struct primary_descriptor { - __u32 seq_num; - __u32 desc_num; - struct dstring { - __u8 clen; - __u8 c[31]; - } __attribute__((__packed__)) ident; - } __attribute__((__packed__)) primary; - } __attribute__((__packed__)) type; - } __attribute__((__packed__)) *vd; - - struct volume_structure_descriptor { - __u8 type; - __u8 id[5]; - __u8 version; - } *vsd; - + struct volume_descriptor *vd; + struct volume_structure_descriptor *vsd; unsigned int bs; unsigned int b; unsigned int type; @@ -83,6 +85,8 @@ int volume_id_probe_udf(struct volume_id *id, __u64 off) unsigned int loc; unsigned int clen; + dbg("probing at offset %llu", off); + vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET, 0x200); if (vsd == NULL) return -1; diff --git a/extras/volume_id/volume_id/ufs/ufs.c b/extras/volume_id/volume_id/ufs/ufs.c index bab1d4cfad..12672ffe01 100644 --- a/extras/volume_id/volume_id/ufs/ufs.c +++ b/extras/volume_id/volume_id/ufs/ufs.c @@ -39,6 +39,143 @@ #include "../util.h" #include "ufs.h" +struct ufs_super_block { + __u32 fs_link; + __u32 fs_rlink; + __u32 fs_sblkno; + __u32 fs_cblkno; + __u32 fs_iblkno; + __u32 fs_dblkno; + __u32 fs_cgoffset; + __u32 fs_cgmask; + __u32 fs_time; + __u32 fs_size; + __u32 fs_dsize; + __u32 fs_ncg; + __u32 fs_bsize; + __u32 fs_fsize; + __u32 fs_frag; + __u32 fs_minfree; + __u32 fs_rotdelay; + __u32 fs_rps; + __u32 fs_bmask; + __u32 fs_fmask; + __u32 fs_bshift; + __u32 fs_fshift; + __u32 fs_maxcontig; + __u32 fs_maxbpg; + __u32 fs_fragshift; + __u32 fs_fsbtodb; + __u32 fs_sbsize; + __u32 fs_csmask; + __u32 fs_csshift; + __u32 fs_nindir; + __u32 fs_inopb; + __u32 fs_nspf; + __u32 fs_optim; + __u32 fs_npsect_state; + __u32 fs_interleave; + __u32 fs_trackskew; + __u32 fs_id[2]; + __u32 fs_csaddr; + __u32 fs_cssize; + __u32 fs_cgsize; + __u32 fs_ntrak; + __u32 fs_nsect; + __u32 fs_spc; + __u32 fs_ncyl; + __u32 fs_cpg; + __u32 fs_ipg; + __u32 fs_fpg; + struct ufs_csum { + __u32 cs_ndir; + __u32 cs_nbfree; + __u32 cs_nifree; + __u32 cs_nffree; + } __attribute__((__packed__)) fs_cstotal; + __s8 fs_fmod; + __s8 fs_clean; + __s8 fs_ronly; + __s8 fs_flags; + union { + struct { + __s8 fs_fsmnt[512]; + __u32 fs_cgrotor; + __u32 fs_csp[31]; + __u32 fs_maxcluster; + __u32 fs_cpc; + __u16 fs_opostbl[16][8]; + } __attribute__((__packed__)) fs_u1; + struct { + __s8 fs_fsmnt[468]; + __u8 fs_volname[32]; + __u64 fs_swuid; + __s32 fs_pad; + __u32 fs_cgrotor; + __u32 fs_ocsp[28]; + __u32 fs_contigdirs; + __u32 fs_csp; + __u32 fs_maxcluster; + __u32 fs_active; + __s32 fs_old_cpc; + __s32 fs_maxbsize; + __s64 fs_sparecon64[17]; + __s64 fs_sblockloc; + struct ufs2_csum_total { + __u64 cs_ndir; + __u64 cs_nbfree; + __u64 cs_nifree; + __u64 cs_nffree; + __u64 cs_numclusters; + __u64 cs_spare[3]; + } __attribute__((__packed__)) fs_cstotal; + struct ufs_timeval { + __s32 tv_sec; + __s32 tv_usec; + } __attribute__((__packed__)) fs_time; + __s64 fs_size; + __s64 fs_dsize; + __u64 fs_csaddr; + __s64 fs_pendingblocks; + __s32 fs_pendinginodes; + } __attribute__((__packed__)) fs_u2; + } fs_u11; + union { + struct { + __s32 fs_sparecon[53]; + __s32 fs_reclaim; + __s32 fs_sparecon2[1]; + __s32 fs_state; + __u32 fs_qbmask[2]; + __u32 fs_qfmask[2]; + } __attribute__((__packed__)) fs_sun; + struct { + __s32 fs_sparecon[53]; + __s32 fs_reclaim; + __s32 fs_sparecon2[1]; + __u32 fs_npsect; + __u32 fs_qbmask[2]; + __u32 fs_qfmask[2]; + } __attribute__((__packed__)) fs_sunx86; + struct { + __s32 fs_sparecon[50]; + __s32 fs_contigsumsize; + __s32 fs_maxsymlinklen; + __s32 fs_inodefmt; + __u32 fs_maxfilesize[2]; + __u32 fs_qbmask[2]; + __u32 fs_qfmask[2]; + __s32 fs_state; + } __attribute__((__packed__)) fs_44; + } fs_u2; + __s32 fs_postblformat; + __s32 fs_nrpos; + __s32 fs_postbloff; + __s32 fs_rotbloff; + __u32 fs_magic; + __u8 fs_space[1]; +} __attribute__((__packed__)); + #define UFS_MAGIC 0x00011954 #define UFS2_MAGIC 0x19540119 #define UFS_MAGIC_FEA 0x00195612 @@ -46,147 +183,13 @@ int volume_id_probe_ufs(struct volume_id *id, __u64 off) { - struct ufs_super_block { - __u32 fs_link; - __u32 fs_rlink; - __u32 fs_sblkno; - __u32 fs_cblkno; - __u32 fs_iblkno; - __u32 fs_dblkno; - __u32 fs_cgoffset; - __u32 fs_cgmask; - __u32 fs_time; - __u32 fs_size; - __u32 fs_dsize; - __u32 fs_ncg; - __u32 fs_bsize; - __u32 fs_fsize; - __u32 fs_frag; - __u32 fs_minfree; - __u32 fs_rotdelay; - __u32 fs_rps; - __u32 fs_bmask; - __u32 fs_fmask; - __u32 fs_bshift; - __u32 fs_fshift; - __u32 fs_maxcontig; - __u32 fs_maxbpg; - __u32 fs_fragshift; - __u32 fs_fsbtodb; - __u32 fs_sbsize; - __u32 fs_csmask; - __u32 fs_csshift; - __u32 fs_nindir; - __u32 fs_inopb; - __u32 fs_nspf; - __u32 fs_optim; - __u32 fs_npsect_state; - __u32 fs_interleave; - __u32 fs_trackskew; - __u32 fs_id[2]; - __u32 fs_csaddr; - __u32 fs_cssize; - __u32 fs_cgsize; - __u32 fs_ntrak; - __u32 fs_nsect; - __u32 fs_spc; - __u32 fs_ncyl; - __u32 fs_cpg; - __u32 fs_ipg; - __u32 fs_fpg; - struct ufs_csum { - __u32 cs_ndir; - __u32 cs_nbfree; - __u32 cs_nifree; - __u32 cs_nffree; - } __attribute__((__packed__)) fs_cstotal; - __s8 fs_fmod; - __s8 fs_clean; - __s8 fs_ronly; - __s8 fs_flags; - union { - struct { - __s8 fs_fsmnt[512]; - __u32 fs_cgrotor; - __u32 fs_csp[31]; - __u32 fs_maxcluster; - __u32 fs_cpc; - __u16 fs_opostbl[16][8]; - } __attribute__((__packed__)) fs_u1; - struct { - __s8 fs_fsmnt[468]; - __u8 fs_volname[32]; - __u64 fs_swuid; - __s32 fs_pad; - __u32 fs_cgrotor; - __u32 fs_ocsp[28]; - __u32 fs_contigdirs; - __u32 fs_csp; - __u32 fs_maxcluster; - __u32 fs_active; - __s32 fs_old_cpc; - __s32 fs_maxbsize; - __s64 fs_sparecon64[17]; - __s64 fs_sblockloc; - struct ufs2_csum_total { - __u64 cs_ndir; - __u64 cs_nbfree; - __u64 cs_nifree; - __u64 cs_nffree; - __u64 cs_numclusters; - __u64 cs_spare[3]; - } __attribute__((__packed__)) fs_cstotal; - struct ufs_timeval { - __s32 tv_sec; - __s32 tv_usec; - } __attribute__((__packed__)) fs_time; - __s64 fs_size; - __s64 fs_dsize; - __u64 fs_csaddr; - __s64 fs_pendingblocks; - __s32 fs_pendinginodes; - } __attribute__((__packed__)) fs_u2; - } fs_u11; - union { - struct { - __s32 fs_sparecon[53]; - __s32 fs_reclaim; - __s32 fs_sparecon2[1]; - __s32 fs_state; - __u32 fs_qbmask[2]; - __u32 fs_qfmask[2]; - } __attribute__((__packed__)) fs_sun; - struct { - __s32 fs_sparecon[53]; - __s32 fs_reclaim; - __s32 fs_sparecon2[1]; - __u32 fs_npsect; - __u32 fs_qbmask[2]; - __u32 fs_qfmask[2]; - } __attribute__((__packed__)) fs_sunx86; - struct { - __s32 fs_sparecon[50]; - __s32 fs_contigsumsize; - __s32 fs_maxsymlinklen; - __s32 fs_inodefmt; - __u32 fs_maxfilesize[2]; - __u32 fs_qbmask[2]; - __u32 fs_qfmask[2]; - __s32 fs_state; - } __attribute__((__packed__)) fs_44; - } fs_u2; - __s32 fs_postblformat; - __s32 fs_nrpos; - __s32 fs_postbloff; - __s32 fs_rotbloff; - __u32 fs_magic; - __u8 fs_space[1]; - } __attribute__((__packed__)) *ufs; - __u32 magic; int i; + struct ufs_super_block *ufs; int offsets[] = {0, 8, 64, 256, -1}; + dbg("probing at offset %llu", off); + for (i = 0; offsets[i] >= 0; i++) { ufs = (struct ufs_super_block *) volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800); if (ufs == NULL) diff --git a/extras/volume_id/volume_id/util.h b/extras/volume_id/volume_id/util.h index e5cd63e1aa..22fd1b94e2 100644 --- a/extras/volume_id/volume_id/util.h +++ b/extras/volume_id/volume_id/util.h @@ -58,12 +58,16 @@ #define le64_to_cpu(x) (x) #define be16_to_cpu(x) bswap16(x) #define be32_to_cpu(x) bswap32(x) +#define cpu_to_le32(x) (x) +#define cpu_to_be32(x) bswap32(x) #elif (__BYTE_ORDER == __BIG_ENDIAN) #define le16_to_cpu(x) bswap16(x) #define le32_to_cpu(x) bswap32(x) #define le64_to_cpu(x) bswap64(x) #define be16_to_cpu(x) (x) #define be32_to_cpu(x) (x) +#define cpu_to_le32(x) bswap32(x) +#define cpu_to_be32(x) (x) #endif enum uuid_format { diff --git a/extras/volume_id/volume_id/volume_id.c b/extras/volume_id/volume_id/volume_id.c index 78aae37ba0..95f7f5b127 100644 --- a/extras/volume_id/volume_id/volume_id.c +++ b/extras/volume_id/volume_id/volume_id.c @@ -56,6 +56,8 @@ #include "linux_raid/linux_raid.h" #include "lvm/lvm.h" #include "cramfs/cramfs.h" +#include "hpfs/hpfs.h" +#include "romfs/romfs.h" #include "mac/mac.h" #include "msdos/msdos.h" @@ -120,6 +122,12 @@ int volume_id_probe_all(struct volume_id *id, unsigned long long off, unsigned l if (volume_id_probe_cramfs(id, off) == 0) goto exit; + if (volume_id_probe_romfs(id, off) == 0) + goto exit; + + if (volume_id_probe_hpfs(id, off) == 0) + goto exit; + return -1; exit: diff --git a/extras/volume_id/volume_id/volume_id.h b/extras/volume_id/volume_id/volume_id.h index 5a4b136c32..5b845602c6 100644 --- a/extras/volume_id/volume_id/volume_id.h +++ b/extras/volume_id/volume_id/volume_id.h @@ -21,7 +21,7 @@ #ifndef _VOLUME_ID_H_ #define _VOLUME_ID_H_ -#define VOLUME_ID_VERSION 33 +#define VOLUME_ID_VERSION 34 #define VOLUME_ID_LABEL_SIZE 64 #define VOLUME_ID_UUID_SIZE 16 diff --git a/extras/volume_id/volume_id/xfs/xfs.c b/extras/volume_id/volume_id/xfs/xfs.c index 67ae2f07d5..efbe06ec58 100644 --- a/extras/volume_id/volume_id/xfs/xfs.c +++ b/extras/volume_id/volume_id/xfs/xfs.c @@ -39,22 +39,26 @@ #include "../util.h" #include "xfs.h" +struct xfs_super_block { + __u8 magic[4]; + __u32 blocksize; + __u64 dblocks; + __u64 rblocks; + __u32 dummy1[2]; + __u8 uuid[16]; + __u32 dummy2[15]; + __u8 fname[12]; + __u32 dummy3[2]; + __u64 icount; + __u64 ifree; + __u64 fdblocks; +} __attribute__((__packed__)); + int volume_id_probe_xfs(struct volume_id *id, __u64 off) { - struct xfs_super_block { - __u8 magic[4]; - __u32 blocksize; - __u64 dblocks; - __u64 rblocks; - __u32 dummy1[2]; - __u8 uuid[16]; - __u32 dummy2[15]; - __u8 fname[12]; - __u32 dummy3[2]; - __u64 icount; - __u64 ifree; - __u64 fdblocks; - } __attribute__((__packed__)) *xs; + struct xfs_super_block *xs; + + dbg("probing at offset %llu", off); xs = (struct xfs_super_block *) volume_id_get_buffer(id, off, 0x200); if (xs == NULL) |