--- util-linux-2.12q/configure +++ util-linux-2.12q/configure @@ -190,6 +190,7 @@ # # H9. For raw.c: do we have ? +# H10. For guessfstype of CD-Extra, do we have ? # if ./testincl "linux/raw.h"; then echo "HAVE_RAW_H=yes" >> make_include @@ -552,6 +553,12 @@ echo "HAVE_XGETTEXT=no" >> make_include fi +# +# H10. For guessfstype of CD-Extra, do we have +# +if ./testincl "linux/cdrom.h"; then + echo "#define HAVE_cdrom_h" >> defines.h +fi # # 8. For err.c: do we have __progname? --- util-linux-2.12q/mount/mount_guess_fstype.c +++ util-linux-2.12q/mount/mount_guess_fstype.c @@ -26,6 +26,9 @@ * 2001-10-26 Tim Launchbury * added sysv magic. * + * 2003-11-21 Mads Martin Joergensen + * added guessfstype support for CD-Extra + * * aeb - many changes. * */ @@ -37,11 +40,16 @@ #include #include #include +#include #include "linux_fs.h" #include "mount_blkid.h" #include "mount_guess_fstype.h" #include "sundries.h" /* for xstrdup */ #include "nls.h" +#include "../defines.h" +#ifdef HAVE_cdrom_h +#include +#endif #define ETC_FILESYSTEMS "/etc/filesystems" #define PROC_FILESYSTEMS "/proc/filesystems" @@ -249,7 +257,51 @@ return 0; /* do seeks and reads in disk order, otherwise a very short - partition may cause a failure because of read error */ + partition may cause a failure because of read error + Rearranged a tiny bit to check ext2/3 before vfat. We still + have to make sure it's not iso9660 first, or otherwise we + might bail out wrongly due to an io-error */ + + if (!type) { + /* block 0 */ + if (lseek(fd, 0, SEEK_SET) != 0 + || read(fd, (char *) &xsb, sizeof(xsb)) != sizeof(xsb)) + goto try_iso9660; + } + + if (!type) { + /* block 1 */ + if (lseek(fd, 1024, SEEK_SET) != 1024 || + read(fd, (char *) &sb, sizeof(sb)) != sizeof(sb)) + goto io_error; + + /* ext2 has magic in little-endian on disk, so "swapped" is + superfluous; however, there have existed strange byteswapped + PPC ext2 systems */ + if (ext2magic(sb.e2s) == EXT2_SUPER_MAGIC || + ext2magic(sb.e2s) == EXT2_PRE_02B_MAGIC || + ext2magic(sb.e2s) == swapped(EXT2_SUPER_MAGIC)) { + type = "ext2"; + + /* maybe even ext3? */ + if ((assemble4le(sb.e2s.s_feature_compat) + & EXT3_FEATURE_COMPAT_HAS_JOURNAL) && + assemble4le(sb.e2s.s_journal_inum) != 0) + type = "ext3"; /* "ext3,ext2" */ + } + + else if (minixmagic(sb.ms) == MINIX_SUPER_MAGIC || + minixmagic(sb.ms) == MINIX_SUPER_MAGIC2 || + minixmagic(sb.ms) == MINIX2_SUPER_MAGIC || + minixmagic(sb.ms) == MINIX2_SUPER_MAGIC2) + type = "minix"; + + else if (extmagic(sb.es) == EXT_SUPER_MAGIC) + type = "ext"; + + else if (vxfsmagic(sb.vs) == VXFS_SUPER_MAGIC) + type = "vxfs"; + } if (!type) { /* block 0 */ @@ -307,40 +359,6 @@ type = "sysv"; } - if (!type) { - /* block 1 */ - if (lseek(fd, 1024, SEEK_SET) != 1024 || - read(fd, (char *) &sb, sizeof(sb)) != sizeof(sb)) - goto io_error; - - /* ext2 has magic in little-endian on disk, so "swapped" is - superfluous; however, there have existed strange byteswapped - PPC ext2 systems */ - if (ext2magic(sb.e2s) == EXT2_SUPER_MAGIC || - ext2magic(sb.e2s) == EXT2_PRE_02B_MAGIC || - ext2magic(sb.e2s) == swapped(EXT2_SUPER_MAGIC)) { - type = "ext2"; - - /* maybe even ext3? */ - if ((assemble4le(sb.e2s.s_feature_compat) - & EXT3_FEATURE_COMPAT_HAS_JOURNAL) && - assemble4le(sb.e2s.s_journal_inum) != 0) - type = "ext3"; /* "ext3,ext2" */ - } - - else if (minixmagic(sb.ms) == MINIX_SUPER_MAGIC || - minixmagic(sb.ms) == MINIX_SUPER_MAGIC2 || - minixmagic(sb.ms) == swapped(MINIX_SUPER_MAGIC2) || - minixmagic(sb.ms) == MINIX2_SUPER_MAGIC || - minixmagic(sb.ms) == MINIX2_SUPER_MAGIC2) - type = "minix"; - - else if (extmagic(sb.es) == EXT_SUPER_MAGIC) - type = "ext"; - - else if (vxfsmagic(sb.vs) == VXFS_SUPER_MAGIC) - type = "vxfs"; - } if (!type) { /* block 1 */ @@ -416,8 +434,34 @@ /* block 32 */ try_iso9660: if (lseek(fd, 0x8000, SEEK_SET) != 0x8000 - || read(fd, (char *) &isosb, sizeof(isosb)) != sizeof(isosb)) - goto io_error; + || read(fd, (char *) &isosb, sizeof(isosb)) != sizeof(isosb)) { +#ifdef HAVE_cdrom_h + /* Try and see if we have an iso9660 data track later on */ + char toc_header[2]; + struct cdrom_tocentry *toc[CDROM_LEADOUT + 1]; + int i, offset; + + if (ioctl(fd, CDROMREADTOCHDR, &toc_header)) + goto io_error; + for (i = toc_header[0]; i <= toc_header[1]; i++) { + toc[i] = malloc(sizeof(struct cdrom_tocentry)); + memset(toc[i],0,sizeof(struct cdrom_tocentry)); + toc[i]->cdte_track = i; + toc[i]->cdte_format = CDROM_LBA; + if(ioctl(fd,CDROMREADTOCENTRY,toc[i])) + goto io_error; + if((toc[i]->cdte_ctrl & CDROM_DATA_TRACK)) { + offset = 2048 * (toc[i]->cdte_addr.lba + 16); + if(lseek(fd, offset, SEEK_SET) != offset) + goto io_error; + if(read(fd,(char *) &isosb,sizeof(isosb))==-1) + goto io_error; + } + } +#else + goto io_error; +#endif + } if (strncmp(isosb.hs.id, HS_STANDARD_ID, sizeof(isosb.hs.id)) == 0) { /* "CDROM" */