From 3de5bf61060634c5c8c3a0d231e8a7246094a2c2 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 22 Jul 2003 01:06:36 -0400 Subject: [PATCH] probe.c (probe_udf): Add specific UDF probing code, and probe UDF before checking for ISO9660 filesystems. --- lib/blkid/ChangeLog | 5 +++++ lib/blkid/probe.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++------- lib/blkid/probe.h | 8 ++++++++ 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog index 2d01b91..0a4e790 100644 --- a/lib/blkid/ChangeLog +++ b/lib/blkid/ChangeLog @@ -1,3 +1,8 @@ +2003-07-22 Theodore Ts'o + + * probe.c (probe_udf): Add specific UDF probing code, and probe + UDF before checking for ISO9660 filesystems. + 2003-07-21 Theodore Ts'o * probe.c (blkid_known_fstype): New function which returns true if diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c index 2421fff..505400c 100644 --- a/lib/blkid/probe.c +++ b/lib/blkid/probe.c @@ -244,6 +244,50 @@ static int probe_romfs(int fd, blkid_cache cache, blkid_dev dev, return 0; } +static char +*udf_magic[] = { "BEA01", "BOOT2", "CD001", "CDW02", "NSR02", + "NSR03", "TEA01", 0 }; + +static int probe_udf(int fd, blkid_cache cache, blkid_dev dev, + struct blkid_magic *id, unsigned char *buf) +{ + int j, bs; + struct iso_volume_descriptor isosb; + char **m; + + /* determine the block size by scanning in 2K increments + (block sizes larger than 2K will be null padded) */ + for (bs = 1; bs < 16; bs++) { + lseek(fd, bs*2048+32768, SEEK_SET); + if (read(fd, (char *)&isosb, sizeof(isosb)) != sizeof(isosb)) + return 1; + if (isosb.id[0]) + break; + } + + /* Scan up to another 64 blocks looking for additional VSD's */ + for (j = 1; j < 64; j++) { + if (j > 1) { + lseek(fd, j*bs*2048+32768, SEEK_SET); + if (read(fd, (char *)&isosb, sizeof(isosb)) + != sizeof(isosb)) + return 1; + } + /* If we find NSR0x then call it udf: + NSR01 for UDF 1.00 + NSR02 for UDF 1.50 + NSR03 for UDF 2.00 */ + if (!strncmp(isosb.id, "NSR0", 4)) + return 0; + for (m = udf_magic; *m; m++) + if (!strncmp(*m, isosb.id, 5)) + break; + if (*m == 0) + return 1; + } + return 1; +} + /* * BLKID_BLK_OFFS is at least as large as the highest bim_kboff defined * in the type_array table below + bim_kbalign. @@ -283,15 +327,15 @@ static struct blkid_magic type_array[] = { { "bfs", 0, 0, 4, "\316\372\173\033", 0 }, { "cramfs", 0, 0, 4, "E=\315\034", 0 }, { "qnx4", 0, 4, 6, "QNX4FS", 0 }, + { "udf", 32, 1, 5, "BEA01", probe_udf }, + { "udf", 32, 1, 5, "BOOT2", probe_udf }, + { "udf", 32, 1, 5, "CD001", probe_udf }, + { "udf", 32, 1, 5, "CDW02", probe_udf }, + { "udf", 32, 1, 5, "NSR02", probe_udf }, + { "udf", 32, 1, 5, "NSR03", probe_udf }, + { "udf", 32, 1, 5, "TEA01", probe_udf }, { "iso9660", 32, 1, 5, "CD001", 0 }, { "iso9660", 32, 9, 5, "CDROM", 0 }, - { "udf", 32, 1, 5, "BEA01", 0 }, - { "udf", 32, 1, 5, "BOOT2", 0 }, - { "udf", 32, 1, 5, "CD001", 0 }, - { "udf", 32, 1, 5, "CDW02", 0 }, - { "udf", 32, 1, 5, "NSR02", 0 }, - { "udf", 32, 1, 5, "NSR03", 0 }, - { "udf", 32, 1, 5, "TEA01", 0 }, { "jfs", 32, 0, 4, "JFS1", probe_jfs }, { "hfs", 1, 0, 2, "BD", 0 }, { "ufs", 8, 0x55c, 4, "T\031\001\000", 0 }, diff --git a/lib/blkid/probe.h b/lib/blkid/probe.h index 8ab8d72..d418aef 100644 --- a/lib/blkid/probe.h +++ b/lib/blkid/probe.h @@ -209,6 +209,14 @@ struct hfs_super_block { __u32 h_blksize; }; +#define ISODCL(from, to) (to - from + 1) +struct iso_volume_descriptor { + char type[ISODCL(1,1)]; /* 711 */ + char id[ISODCL(2,6)]; + char version[ISODCL(7,7)]; + char data[ISODCL(8,2048)]; +}; + /* * Byte swap functions */ -- 1.8.3.1