From: kay.sievers@vrfy.org Date: Sat, 5 Feb 2005 03:10:48 +0000 (+0100) Subject: [PATCH] udev_volume_id: volume_id version 032 X-Git-Tag: 052~20 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7979e3d4b7c56acee2fe0e9a9fefb3fe0d83771e;p=systemd [PATCH] udev_volume_id: volume_id version 032 --- diff --git a/extras/volume_id/Makefile b/extras/volume_id/Makefile index d273ed79..bfe4cf74 100644 --- a/extras/volume_id/Makefile +++ b/extras/volume_id/Makefile @@ -47,6 +47,7 @@ VOLUME_ID_OBJS= \ 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 @@ -68,6 +69,7 @@ VOLUME_ID_HEADERS= \ 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 diff --git a/extras/volume_id/volume_id/cramfs/cramfs.c b/extras/volume_id/volume_id/cramfs/cramfs.c new file mode 100644 index 00000000..69ab2c7a --- /dev/null +++ b/extras/volume_id/volume_id/cramfs/cramfs.c @@ -0,0 +1,75 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2004 Kay Sievers + * + * 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 +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include "../volume_id.h" +#include "../logging.h" +#include "../util.h" +#include "cramfs.h" + +struct cramfs_super { + __u8 magic[4]; + __u32 size; + __u32 flags; + __u32 future; + __u8 signature[16]; + struct cramfs_info { + __u32 crc; + __u32 edition; + __u32 blocks; + __u32 files; + } __attribute__((__packed__)) info; + __u8 name[16]; +} __attribute__((__packed__)); + +int volume_id_probe_cramfs(struct volume_id *id, __u64 off) +{ + struct cramfs_super *cs; + + cs = (struct cramfs_super *) volume_id_get_buffer(id, off, 0x200); + if (cs == NULL) + return -1; + + if (memcmp(cs->magic, "\x45\x3d\xcd\x28", 4) == 0) { + volume_id_set_label_raw(id, cs->name, 16); + volume_id_set_label_string(id, cs->name, 16); + + volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); + id->type = "cramfs"; + return 0; + } + + return -1; +} diff --git a/extras/volume_id/volume_id/cramfs/cramfs.h b/extras/volume_id/volume_id/cramfs/cramfs.h new file mode 100644 index 00000000..b94445b8 --- /dev/null +++ b/extras/volume_id/volume_id/cramfs/cramfs.h @@ -0,0 +1,26 @@ +/* + * volume_id - reads filesystem label and uuid + * + * Copyright (C) 2004 Kay Sievers + * + * 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_CRAMFS_ +#define _VOLUME_ID_CRAMFS_ + +extern int volume_id_probe_cramfs(struct volume_id *id, __u64 off); + +#endif diff --git a/extras/volume_id/volume_id/fat/fat.c b/extras/volume_id/volume_id/fat/fat.c index e6f01076..219207e8 100644 --- a/extras/volume_id/volume_id/fat/fat.c +++ b/extras/volume_id/volume_id/fat/fat.c @@ -166,22 +166,22 @@ int volume_id_probe_vfat(struct volume_id *id, __u64 off) /* believe only that's fat, don't trust the version * the cluster_count will tell us */ - if (strncmp(vs->sysid, "NTFS", 4) == 0) + if (memcmp(vs->sysid, "NTFS", 4) == 0) return -1; - if (strncmp(vs->type.fat32.magic, "MSWIN", 5) == 0) + if (memcmp(vs->type.fat32.magic, "MSWIN", 5) == 0) goto valid; - if (strncmp(vs->type.fat32.magic, "FAT32 ", 8) == 0) + if (memcmp(vs->type.fat32.magic, "FAT32 ", 8) == 0) goto valid; - if (strncmp(vs->type.fat.magic, "FAT16 ", 8) == 0) + if (memcmp(vs->type.fat.magic, "FAT16 ", 8) == 0) goto valid; - if (strncmp(vs->type.fat.magic, "MSDOS", 5) == 0) + if (memcmp(vs->type.fat.magic, "MSDOS", 5) == 0) goto valid; - if (strncmp(vs->type.fat.magic, "FAT12 ", 8) == 0) + if (memcmp(vs->type.fat.magic, "FAT12 ", 8) == 0) goto valid; /* @@ -272,10 +272,10 @@ valid: if (vs == NULL) return -1; - if (label != NULL && strncmp(label, "NO NAME ", 11) != 0) { + if (label != NULL && memcmp(label, "NO NAME ", 11) != 0) { volume_id_set_label_raw(id, label, 11); volume_id_set_label_string(id, label, 11); - } else if (strncmp(vs->type.fat.label, "NO NAME ", 11) != 0) { + } else if (memcmp(vs->type.fat.label, "NO NAME ", 11) != 0) { volume_id_set_label_raw(id, vs->type.fat.label, 11); volume_id_set_label_string(id, vs->type.fat.label, 11); } @@ -333,10 +333,10 @@ fat32: if (vs == NULL) return -1; - if (label != NULL && strncmp(label, "NO NAME ", 11) != 0) { + if (label != NULL && memcmp(label, "NO NAME ", 11) != 0) { volume_id_set_label_raw(id, label, 11); volume_id_set_label_string(id, label, 11); - } else if (strncmp(vs->type.fat32.label, "NO NAME ", 11) != 0) { + } else if (memcmp(vs->type.fat32.label, "NO NAME ", 11) != 0) { volume_id_set_label_raw(id, vs->type.fat32.label, 11); volume_id_set_label_string(id, vs->type.fat32.label, 11); } diff --git a/extras/volume_id/volume_id/hfs/hfs.c b/extras/volume_id/volume_id/hfs/hfs.c index 638aabad..a4ae86b5 100644 --- a/extras/volume_id/volume_id/hfs/hfs.c +++ b/extras/volume_id/volume_id/hfs/hfs.c @@ -178,11 +178,11 @@ int volume_id_probe_hfs_hfsplus(struct volume_id *id, __u64 off) return -1; hfs = (struct hfs_mdb *) buf; - if (strncmp(hfs->signature, "BD", 2) != 0) + if (memcmp(hfs->signature, "BD", 2) != 0) goto checkplus; /* it may be just a hfs wrapper for hfs+ */ - if (strncmp(hfs->embed_sig, "H+", 2) == 0) { + if (memcmp(hfs->embed_sig, "H+", 2) == 0) { alloc_block_size = be32_to_cpu(hfs->al_blk_size); dbg("alloc_block_size 0x%x", alloc_block_size); @@ -216,9 +216,9 @@ int volume_id_probe_hfs_hfsplus(struct volume_id *id, __u64 off) checkplus: hfsplus = (struct hfsplus_vol_header *) buf; - if (strncmp(hfsplus->signature, "H+", 2) == 0) + if (memcmp(hfsplus->signature, "H+", 2) == 0) goto hfsplus; - if (strncmp(hfsplus->signature, "HX", 2) == 0) + if (memcmp(hfsplus->signature, "HX", 2) == 0) goto hfsplus; return -1; diff --git a/extras/volume_id/volume_id/iso9660/iso9660.c b/extras/volume_id/volume_id/iso9660/iso9660.c index 6af9e8be..fa769d3c 100644 --- a/extras/volume_id/volume_id/iso9660/iso9660.c +++ b/extras/volume_id/volume_id/iso9660/iso9660.c @@ -70,7 +70,7 @@ int volume_id_probe_iso9660(struct volume_id *id, __u64 off) if (is == NULL) return -1; - if (strncmp(is->iso.id, "CD001", 5) == 0) { + if (memcmp(is->iso.id, "CD001", 5) == 0) { char root_label[VOLUME_ID_LABEL_SIZE+1]; int vd_offset; int i; @@ -96,14 +96,14 @@ int volume_id_probe_iso9660(struct volume_id *id, __u64 off) } if (!found_svd || - (found_svd && !strncmp(root_label, id->label, 16))) + (found_svd && !memcmp(root_label, id->label, 16))) { volume_id_set_label_raw(id, root_label, 32); volume_id_set_label_string(id, root_label, 32); } goto found; } - if (strncmp(is->hs.id, "CDROM", 5) == 0) + if (memcmp(is->hs.id, "CDROM", 5) == 0) goto found; return -1; diff --git a/extras/volume_id/volume_id/jfs/jfs.c b/extras/volume_id/volume_id/jfs/jfs.c index 3e7e9d6a..c9dce84e 100644 --- a/extras/volume_id/volume_id/jfs/jfs.c +++ b/extras/volume_id/volume_id/jfs/jfs.c @@ -60,7 +60,7 @@ int volume_id_probe_jfs(struct volume_id *id, __u64 off) if (js == NULL) return -1; - if (strncmp(js->magic, "JFS1", 4) != 0) + if (memcmp(js->magic, "JFS1", 4) != 0) return -1; volume_id_set_label_raw(id, js->label, 16); 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 7ca49760..d34b22c5 100644 --- a/extras/volume_id/volume_id/linux_swap/linux_swap.c +++ b/extras/volume_id/volume_id/linux_swap/linux_swap.c @@ -61,12 +61,12 @@ int volume_id_probe_linux_swap(struct volume_id *id, __u64 off) if (buf == NULL) return -1; - if (strncmp(buf, "SWAP-SPACE", 10) == 0) { + if (memcmp(buf, "SWAP-SPACE", 10) == 0) { strcpy(id->type_version, "1"); goto found; } - if (strncmp(buf, "SWAPSPACE2", 10) == 0) { + if (memcmp(buf, "SWAPSPACE2", 10) == 0) { sw = (struct swap_header_v1_2 *) volume_id_get_buffer(id, off, sizeof(struct swap_header_v1_2)); if (sw == NULL) return -1; diff --git a/extras/volume_id/volume_id/lvm/lvm.c b/extras/volume_id/volume_id/lvm/lvm.c index d95b6bf2..e736f4ed 100644 --- a/extras/volume_id/volume_id/lvm/lvm.c +++ b/extras/volume_id/volume_id/lvm/lvm.c @@ -56,7 +56,7 @@ int volume_id_probe_lvm1(struct volume_id *id, __u64 off) lvm = (struct lvm2_super_block *) buf; - if (strncmp(lvm->id, LVM1_MAGIC, 2) != 0) + if (memcmp(lvm->id, LVM1_MAGIC, 2) != 0) return -1; volume_id_set_usage(id, VOLUME_ID_RAID); @@ -89,7 +89,7 @@ int volume_id_probe_lvm2(struct volume_id *id, __u64 off) for (soff = 0; soff < LVM2LABEL_SCAN_SECTORS * 0x200; soff += 0x200) { lvm = (struct lvm2_super_block *) &buf[soff]; - if (strncmp(lvm->id, LVM2_LABEL_ID, 8) == 0) + if (memcmp(lvm->id, LVM2_LABEL_ID, 8) == 0) goto found; } diff --git a/extras/volume_id/volume_id/mac/mac.c b/extras/volume_id/volume_id/mac/mac.c index 7265b288..5872b722 100644 --- a/extras/volume_id/volume_id/mac/mac.c +++ b/extras/volume_id/volume_id/mac/mac.c @@ -64,8 +64,8 @@ int volume_id_probe_mac_partition_map(struct volume_id *id, __u64 off) return -1; part = (struct mac_partition *) buf; - if ((strncmp(part->signature, "PM", 2) == 0) && - (strncmp(part->type, "Apple_partition_map", 19) == 0)) { + if ((memcmp(part->signature, "PM", 2) == 0) && + (memcmp(part->type, "Apple_partition_map", 19) == 0)) { /* linux creates an own subdevice for the map * just return the type if the drive header is missing */ volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE); @@ -74,7 +74,7 @@ int volume_id_probe_mac_partition_map(struct volume_id *id, __u64 off) } driver = (struct mac_driver_desc *) buf; - if (strncmp(driver->signature, "ER", 2) == 0) { + if (memcmp(driver->signature, "ER", 2) == 0) { /* we are on a main device, like a CD * just try to probe the first partition from the map */ unsigned int bsize = be16_to_cpu(driver->block_size); @@ -87,7 +87,7 @@ int volume_id_probe_mac_partition_map(struct volume_id *id, __u64 off) return -1; part = (struct mac_partition *) buf; - if (strncmp(part->signature, "PM", 2) != 0) + if (memcmp(part->signature, "PM", 2) != 0) return -1; part_count = be32_to_cpu(part->map_count); @@ -112,7 +112,7 @@ int volume_id_probe_mac_partition_map(struct volume_id *id, __u64 off) return -1; part = (struct mac_partition *) buf; - if (strncmp(part->signature, "PM", 2) != 0) + if (memcmp(part->signature, "PM", 2) != 0) return -1; poff = be32_to_cpu(part->start_block) * bsize; @@ -123,9 +123,9 @@ int volume_id_probe_mac_partition_map(struct volume_id *id, __u64 off) id->partitions[i].off = poff; id->partitions[i].len = plen; - if (strncmp(part->type, "Apple_Free", 10) == 0) { + if (memcmp(part->type, "Apple_Free", 10) == 0) { volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNUSED); - } else if (strncmp(part->type, "Apple_partition_map", 19) == 0) { + } else if (memcmp(part->type, "Apple_partition_map", 19) == 0) { volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_PARTITIONTABLE); } else { volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNPROBED); diff --git a/extras/volume_id/volume_id/msdos/msdos.c b/extras/volume_id/volume_id/msdos/msdos.c index 915c1b29..08124fad 100644 --- a/extras/volume_id/volume_id/msdos/msdos.c +++ b/extras/volume_id/volume_id/msdos/msdos.c @@ -84,7 +84,7 @@ int volume_id_probe_msdos_part_table(struct volume_id *id, __u64 off) if (buf == NULL) return -1; - if (strncmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0) + if (memcmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0) return -1; /* check flags on all entries for a valid partition table */ @@ -158,7 +158,7 @@ int volume_id_probe_msdos_part_table(struct volume_id *id, __u64 off) part = (struct msdos_partition_entry*) &buf[MSDOS_PARTTABLE_OFFSET]; - if (strncmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0) + if (memcmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0) break; next = 0; diff --git a/extras/volume_id/volume_id/ntfs/ntfs.c b/extras/volume_id/volume_id/ntfs/ntfs.c index 4e1f5085..bf87f9d8 100644 --- a/extras/volume_id/volume_id/ntfs/ntfs.c +++ b/extras/volume_id/volume_id/ntfs/ntfs.c @@ -122,7 +122,7 @@ int volume_id_probe_ntfs(struct volume_id *id, __u64 off) if (ns == NULL) return -1; - if (strncmp(ns->oem_id, "NTFS", 4) != 0) + if (memcmp(ns->oem_id, "NTFS", 4) != 0) return -1; volume_id_set_uuid(id, ns->volume_serial, UUID_NTFS); @@ -153,7 +153,7 @@ int volume_id_probe_ntfs(struct volume_id *id, __u64 off) mftr = (struct master_file_table_record*) buf; dbg("mftr->magic '%c%c%c%c'", mftr->magic[0], mftr->magic[1], mftr->magic[2], mftr->magic[3]); - if (strncmp(mftr->magic, "FILE", 4) != 0) + if (memcmp(mftr->magic, "FILE", 4) != 0) goto found; attr_off = le16_to_cpu(mftr->attrs_offset); diff --git a/extras/volume_id/volume_id/reiserfs/reiserfs.c b/extras/volume_id/volume_id/reiserfs/reiserfs.c index 8fd8b51b..5653214e 100644 --- a/extras/volume_id/volume_id/reiserfs/reiserfs.c +++ b/extras/volume_id/volume_id/reiserfs/reiserfs.c @@ -64,12 +64,12 @@ int volume_id_probe_reiserfs(struct volume_id *id, __u64 off) if (rs == NULL) return -1; - if (strncmp(rs->magic, "ReIsEr2Fs", 9) == 0) { + if (memcmp(rs->magic, "ReIsEr2Fs", 9) == 0) { strcpy(id->type_version, "3.6"); goto found; } - if (strncmp(rs->magic, "ReIsEr3Fs", 9) == 0) { + if (memcmp(rs->magic, "ReIsEr3Fs", 9) == 0) { strcpy(id->type_version, "JR"); goto found; } @@ -78,7 +78,7 @@ int volume_id_probe_reiserfs(struct volume_id *id, __u64 off) if (rs == NULL) return -1; - if (strncmp(rs->magic, "ReIsErFs", 8) == 0) { + if (memcmp(rs->magic, "ReIsErFs", 8) == 0) { strcpy(id->type_version, "3.5"); goto found; } diff --git a/extras/volume_id/volume_id/udf/udf.c b/extras/volume_id/volume_id/udf/udf.c index b91e3cce..ff23b310 100644 --- a/extras/volume_id/volume_id/udf/udf.c +++ b/extras/volume_id/volume_id/udf/udf.c @@ -87,19 +87,19 @@ int volume_id_probe_udf(struct volume_id *id, __u64 off) if (vsd == NULL) return -1; - if (strncmp(vsd->id, "NSR02", 5) == 0) + if (memcmp(vsd->id, "NSR02", 5) == 0) goto blocksize; - if (strncmp(vsd->id, "NSR03", 5) == 0) + if (memcmp(vsd->id, "NSR03", 5) == 0) goto blocksize; - if (strncmp(vsd->id, "BEA01", 5) == 0) + if (memcmp(vsd->id, "BEA01", 5) == 0) goto blocksize; - if (strncmp(vsd->id, "BOOT2", 5) == 0) + if (memcmp(vsd->id, "BOOT2", 5) == 0) goto blocksize; - if (strncmp(vsd->id, "CD001", 5) == 0) + if (memcmp(vsd->id, "CD001", 5) == 0) goto blocksize; - if (strncmp(vsd->id, "CDW02", 5) == 0) + if (memcmp(vsd->id, "CDW02", 5) == 0) goto blocksize; - if (strncmp(vsd->id, "TEA03", 5) == 0) + if (memcmp(vsd->id, "TEA03", 5) == 0) goto blocksize; return -1; @@ -127,9 +127,9 @@ nsr: if (vsd->id[0] == '\0') return -1; - if (strncmp(vsd->id, "NSR02", 5) == 0) + if (memcmp(vsd->id, "NSR02", 5) == 0) goto anchor; - if (strncmp(vsd->id, "NSR03", 5) == 0) + if (memcmp(vsd->id, "NSR03", 5) == 0) goto anchor; } return -1; diff --git a/extras/volume_id/volume_id/volume_id.c b/extras/volume_id/volume_id/volume_id.c index e1d4b1c9..78aae37b 100644 --- a/extras/volume_id/volume_id/volume_id.c +++ b/extras/volume_id/volume_id/volume_id.c @@ -55,6 +55,7 @@ #include "linux_swap/linux_swap.h" #include "linux_raid/linux_raid.h" #include "lvm/lvm.h" +#include "cramfs/cramfs.h" #include "mac/mac.h" #include "msdos/msdos.h" @@ -116,6 +117,9 @@ int volume_id_probe_all(struct volume_id *id, unsigned long long off, unsigned l if (volume_id_probe_ntfs(id, off) == 0) goto exit; + if (volume_id_probe_cramfs(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 6c25a243..a8c47bc6 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 31 +#define VOLUME_ID_VERSION 32 #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 b73f565e..67ae2f07 100644 --- a/extras/volume_id/volume_id/xfs/xfs.c +++ b/extras/volume_id/volume_id/xfs/xfs.c @@ -60,7 +60,7 @@ int volume_id_probe_xfs(struct volume_id *id, __u64 off) if (xs == NULL) return -1; - if (strncmp(xs->magic, "XFSB", 4) != 0) + if (memcmp(xs->magic, "XFSB", 4) != 0) return -1; volume_id_set_label_raw(id, xs->fname, 12);