From 1cba5edefe81b3389f841da712ad21b23bc65ba1 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 13 May 2003 05:25:59 +0000 Subject: [PATCH] Minor mkfs updates - sync up with current mount fs heuristics, add some more large sector changes (disabled). --- doc/CHANGES | 2 + libdisk/fstype.c | 60 ++++++++------- libdisk/fstype.h | 25 ++++++- mkfs/xfs_mkfs.c | 186 ++++++++++++++++++++++++++++------------------- 4 files changed, 165 insertions(+), 108 deletions(-) diff --git a/doc/CHANGES b/doc/CHANGES index 763c85015..b2b672f8f 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -5,6 +5,8 @@ xfsprogs-2.4.10 (12 May 2003) because xfs_repair uses the correct stripe unit value. - Fix a bug in xfs_logprint, when dumping a corrupt log. - FreeBSD updates from Alexander Kabaev. + - Sector size updates for mkfs (disabled at the moment). + - Sync up with aeb's mount source for filesystem detection. xfsprogs-2.4.9 (03 May 2003) - Allow xfs_repair to run on read-only filesystems. diff --git a/libdisk/fstype.c b/libdisk/fstype.c index 147b16d43..ced77c80a 100644 --- a/libdisk/fstype.c +++ b/libdisk/fstype.c @@ -45,6 +45,7 @@ * - util-linux-2.10r ... 06 Dec 00 * - util-linux-2.11g ... 02 Jul 01 * - util-linux-2.11u ... 24 Aug 02 + * - util-linux-2.11z ... 13 May 03 */ #define SIZE(a) (sizeof(a)/sizeof(a[0])) @@ -168,9 +169,9 @@ may_be_adfs(const u_char *s) { static int is_reiserfs_magic_string (struct reiserfs_super_block * rs) { - return (!strncmp (rs->s_magic, REISERFS_SUPER_MAGIC_STRING, + return (!strncmp (rs->s_magic, REISERFS_SUPER_MAGIC_STRING, strlen ( REISERFS_SUPER_MAGIC_STRING)) || - !strncmp (rs->s_magic, REISER2FS_SUPER_MAGIC_STRING, + !strncmp (rs->s_magic, REISER2FS_SUPER_MAGIC_STRING, strlen ( REISER2FS_SUPER_MAGIC_STRING))); } @@ -225,7 +226,8 @@ fstype(const char *device) { /* block 0 */ if (lseek(fd, 0, SEEK_SET) != 0 || read(fd, (char *) &xsb, sizeof(xsb)) != sizeof(xsb)) - goto io_error; + goto try_iso9660; + /* Gyorgy Kovesdi: none of my photocds has a readable block 0 */ if (xiafsmagic(xsb.xiasb) == _XIAFS_SUPER_MAGIC) type = "xiafs"; @@ -240,7 +242,8 @@ fstype(const char *device) { else if(!strncmp(xsb.ntfssb.s_magic, NTFS_SUPER_MAGIC, sizeof(xsb.ntfssb.s_magic))) type = "ntfs"; - else if(cramfsmagic(xsb.cramfssb) == CRAMFS_SUPER_MAGIC) + else if(cramfsmagic(xsb.cramfssb) == CRAMFS_SUPER_MAGIC || + cramfsmagic(xsb.cramfssb) == CRAMFS_SUPER_MAGIC_BE) type = "cramfs"; else if ((!strncmp(xsb.fatsb.s_os, "MSDOS", 5) || !strncmp(xsb.fatsb.s_os, "MSWIN", 5) || @@ -302,32 +305,32 @@ fstype(const char *device) { if (!type) { /* block 1 */ - if (lseek(fd, 0x400, SEEK_SET) != 0x400 - || read(fd, (char *) &hfssb, sizeof(hfssb)) != sizeof(hfssb)) - goto io_error; - - /* also check if block size is equal to 512 bytes, - since the hfs driver currently only has support - for block sizes of 512 bytes long, and to be - more accurate (sb magic is only a short int) */ - if ((hfsmagic(hfssb) == HFS_SUPER_MAGIC && + if (lseek(fd, 0x400, SEEK_SET) != 0x400 + || read(fd, (char *) &hfssb, sizeof(hfssb)) != sizeof(hfssb)) + goto io_error; + + /* also check if block size is equal to 512 bytes, + since the hfs driver currently only has support + for block sizes of 512 bytes long, and to be + more accurate (sb magic is only a short int) */ + if ((hfsmagic(hfssb) == HFS_SUPER_MAGIC && hfsblksize(hfssb) == 0x20000) || - (swapped(hfsmagic(hfssb)) == HFS_SUPER_MAGIC && - hfsblksize(hfssb) == 0x200)) - type = "hfs"; + (swapped(hfsmagic(hfssb)) == HFS_SUPER_MAGIC && + hfsblksize(hfssb) == 0x200)) + type = "hfs"; } if (!type) { /* block 3 */ - if (lseek(fd, 0xc00, SEEK_SET) != 0xc00 - || read(fd, (char *) &adfssb, sizeof(adfssb)) != sizeof(adfssb)) - goto io_error; + if (lseek(fd, 0xc00, SEEK_SET) != 0xc00 + || read(fd, (char *) &adfssb, sizeof(adfssb)) != sizeof(adfssb)) + goto io_error; /* only a weak test */ - if (may_be_adfs((u_char *) &adfssb) - && (adfsblksize(adfssb) >= 8 && - adfsblksize(adfssb) <= 10)) - type = "adfs"; + if (may_be_adfs((u_char *) &adfssb) + && (adfsblksize(adfssb) >= 8 && + adfsblksize(adfssb) <= 10)) + type = "adfs"; } if (!type) { @@ -356,12 +359,12 @@ fstype(const char *device) { if (!type) { /* block 8 */ - if (lseek(fd, 0x2000, SEEK_SET) != 0x2000 - || read(fd, (char *) &hpfssb, sizeof(hpfssb)) != sizeof(hpfssb)) - goto io_error; + if (lseek(fd, 0x2000, SEEK_SET) != 0x2000 + || read(fd, (char *) &hpfssb, sizeof(hpfssb)) != sizeof(hpfssb)) + goto io_error; - if (hpfsmagic(hpfssb) == HPFS_SUPER_MAGIC) - type = "hpfs"; + if (hpfsmagic(hpfssb) == HPFS_SUPER_MAGIC) + type = "hpfs"; } if (!type) { @@ -375,6 +378,7 @@ fstype(const char *device) { if (!type) { /* block 32 */ + try_iso9660: if (lseek(fd, 0x8000, SEEK_SET) != 0x8000 || read(fd, (char *) &isosb, sizeof(isosb)) != sizeof(isosb)) goto io_error; diff --git a/libdisk/fstype.h b/libdisk/fstype.h index ac29cda03..68059374e 100644 --- a/libdisk/fstype.h +++ b/libdisk/fstype.h @@ -39,6 +39,7 @@ * - util-linux-2.10r ... 06 Dec 00 * - util-linux-2.11g ... 02 Jul 01 * - util-linux-2.11u ... 24 Aug 02 + * - util-linux-2.11z ... 13 May 03 */ /* Including became more and more painful. @@ -85,14 +86,14 @@ struct ext_super_block { #define EXT2_SUPER_MAGIC 0xEF53 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 struct ext2_super_block { - u_char s_dummy1[56]; - u_char s_magic[2]; + u_char s_dummy1[56]; + u_char s_magic[2]; u_char s_dummy2[34]; u_char s_feature_compat[4]; u_char s_feature_incompat[4]; u_char s_feature_ro_compat[4]; u_char s_uuid[16]; - u_char s_volume_name[16]; + u_char s_volume_name[16]; u_char s_dummy3[88]; u_char s_journal_inum[4]; /* ext3 only */ }; @@ -158,7 +159,7 @@ struct fat_super_block { u_char s_dummy2[32]; u_char s_label[11]; /* for DOS? */ u_char s_fs[8]; /* "FAT12 " or "FAT16 " or all zero */ - /* OS/2 BM has "FAT " here. */ + /* OS/2 BM has "FAT " here. */ u_char s_dummy3[9]; u_char s_label2[11]; /* for Windows? */ u_char s_fs2[8]; /* garbage or "FAT32 " */ @@ -174,6 +175,7 @@ struct xfs_super_block { }; #define CRAMFS_SUPER_MAGIC 0x28cd3d45 +#define CRAMFS_SUPER_MAGIC_BE 0x453dcd28 struct cramfs_super_block { u_char s_magic[4]; u_char s_dummy[12]; @@ -238,6 +240,21 @@ struct mdp_super_block { #define MD_SB_MAGIC 0xa92b4efc #define mdsbmagic(s) assemble4le(s.md_magic) +struct ocfs_volume_header { + u_char minor_version[4]; + u_char major_version[4]; + u_char signature[128]; +}; + +struct ocfs_volume_label { + u_char disk_lock[48]; + u_char label[64]; + u_char label_len[2]; +}; + +#define ocfslabellen(o) assemble2le(o.label_len) +#define OCFS_MAGIC "OracleCFS" + static inline int assemble2le(unsigned char *p) { return (p[0] | (p[1] << 8)); diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 1e02afd19..fc878be43 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -79,6 +79,10 @@ char *dopts[] = { "su", #define D_SW 9 "sw", +#define D_SECTLOG 10 + "sectlog", +#define D_SECTSIZE 11 + "sectsize", NULL }; @@ -256,14 +260,6 @@ calc_stripe_factors( "conjunction with log su\n")); usage(); } - - if (lsu % lsectsz) { - fprintf(stderr, - _("log su must be a multiple of the " - "sector size (%d)\n"), lsectsz); - usage(); - } - *lsunit = (int)BTOBBT(lsu); } } @@ -399,6 +395,8 @@ main( int lsflag; int lsectorlog; int lsectorsize; + int lslflag; + int lssflag; int lsu; int lsunit; int min_logblocks; @@ -439,12 +437,10 @@ main( textdomain(PACKAGE); agcount = 8; - blflag = bsflag = slflag = ssflag = 0; + blflag = bsflag = slflag = ssflag = lslflag = lssflag = 0; blocklog = blocksize = 0; - sectorlog = XFS_MIN_SECTORSIZE_LOG; - sectorsize = XFS_MIN_SECTORSIZE; - lsectorlog = 0; - lsectorsize = 0; + sectorlog = lsectorlog = XFS_MIN_SECTORSIZE_LOG; + sectorsize = lsectorsize = XFS_MIN_SECTORSIZE; agsize = daflag = dasize = dblocks = 0; ilflag = imflag = ipflag = isflag = 0; liflag = laflag = lsflag = ldflag = lvflag = 0; @@ -612,12 +608,43 @@ main( break; case D_UNWRITTEN: if (!value) - reqval('d', dopts, D_UNWRITTEN); + reqval('d', dopts, D_UNWRITTEN); i = atoi(value); if (i < 0 || i > 1) - illegal(value, "d unwritten"); + illegal(value, "d unwritten"); extent_flagging = i; break; + case D_SECTLOG: + if (!value) + reqval('d', dopts, D_SECTLOG); + if (slflag) + respec('d', dopts, D_SECTLOG); + if (ssflag) + conflict('d', dopts, D_SECTSIZE, + D_SECTLOG); + sectorlog = atoi(value); + if (sectorlog <= 0) + illegal(value, "d sectlog"); + sectorsize = 1 << sectorlog; + slflag = 1; + break; + case D_SECTSIZE: + if (!value) + reqval('d', dopts, D_SECTSIZE); + if (ssflag) + respec('d', dopts, D_SECTSIZE); + if (slflag) + conflict('d', dopts, D_SECTLOG, + D_SECTSIZE); + sectorsize = cvtnum( + blocksize, sectorsize, value); + if (sectorsize <= 0 || + !ispow2(sectorsize)) + illegal(value, "d sectsize"); + sectorlog = + libxfs_highbit32(sectorsize); + ssflag = 1; + break; default: unknown('d', value); } @@ -806,9 +833,9 @@ main( #endif case L_VERSION: if (!value) - reqval('n', nopts, L_VERSION); + reqval('l', lopts, L_VERSION); if (lvflag) - respec('n', nopts, L_VERSION); + respec('l', lopts, L_VERSION); logversion = atoi(value); if (logversion < 1 || logversion > 2) illegal(value, "l version"); @@ -824,19 +851,26 @@ main( break; case L_SECTLOG: if (!value) - reqval('s', sopts, L_SECTLOG); - if (lsectorlog) - respec('s', sopts, L_SECTLOG); + reqval('l', lopts, L_SECTLOG); + if (lslflag) + respec('l', lopts, L_SECTLOG); + if (lssflag) + conflict('l', lopts, L_SECTSIZE, + L_SECTLOG); lsectorlog = atoi(value); if (lsectorlog <= 0) illegal(value, "l sectlog"); lsectorsize = 1 << lsectorlog; + lslflag = 1; break; case L_SECTSIZE: if (!value) reqval('l', lopts, L_SECTSIZE); - if (lsectorsize) + if (lssflag) respec('l', lopts, L_SECTSIZE); + if (lslflag) + conflict('l', lopts, L_SECTLOG, + L_SECTSIZE); lsectorsize = cvtnum( blocksize, sectorsize, value); if (lsectorsize <= 0 || @@ -844,6 +878,7 @@ main( illegal(value, "l sectsize"); lsectorlog = libxfs_highbit32(lsectorsize); + lssflag = 1; break; default: unknown('l', value); @@ -976,35 +1011,39 @@ main( case S_LOG: case S_SECTLOG: if (!value) - reqval('s', sopts, S_LOG); - if (slflag) - respec('s', sopts, S_LOG); - if (ssflag) - conflict('s', sopts, S_SIZE, - S_LOG); + reqval('s', sopts, S_SECTLOG); + if (slflag || lslflag) + respec('s', sopts, S_SECTLOG); + if (ssflag || lssflag) + conflict('s', sopts, S_SECTSIZE, + S_SECTLOG); sectorlog = atoi(value); if (sectorlog <= 0) - illegal(value, "s log"); + illegal(value, "s sectlog"); + lsectorlog = sectorlog; sectorsize = 1 << sectorlog; - slflag = 1; + lsectorsize = sectorsize; + lslflag = slflag = 1; break; case S_SIZE: case S_SECTSIZE: if (!value) - reqval('s', sopts, S_SIZE); - if (ssflag) - respec('s', sopts, S_SIZE); - if (slflag) - conflict('s', sopts, S_LOG, - S_SIZE); + reqval('s', sopts, S_SECTSIZE); + if (ssflag || lssflag) + respec('s', sopts, S_SECTSIZE); + if (slflag || lslflag) + conflict('s', sopts, S_SECTLOG, + S_SECTSIZE); sectorsize = cvtnum( blocksize, sectorsize, value); if (sectorsize <= 0 || !ispow2(sectorsize)) - illegal(value, "s size"); + illegal(value, "s sectsize"); + lsectorsize = sectorsize; sectorlog = libxfs_highbit32(sectorsize); - ssflag = 1; + lsectorlog = sectorlog; + lssflag = ssflag = 1; break; default: unknown('s', value); @@ -1048,33 +1087,28 @@ main( fprintf(stderr, _("illegal sector size %d\n"), sectorsize); usage(); } + if (lsectorsize < XFS_MIN_SECTORSIZE || + lsectorsize > XFS_MAX_SECTORSIZE || lsectorsize > blocksize) { + fprintf(stderr, _("illegal log sector size %d\n"), lsectorsize); + usage(); + } else if (lsectorsize > XFS_MIN_SECTORSIZE && !lsu && !lsunit) { + lsu = blocksize; + logversion = 2; + } /* * Support for non-512 byte sector sizes is a work-in-progress... */ -#ifdef EXPERIMENTAL_LARGE_SECTORS - if (!lsectorsize) { - lsectorlog = XFS_MIN_SECTORSIZE_LOG; - lsectorsize = XFS_MIN_SECTORSIZE; - } - if (lsectorsize < XFS_MIN_SECTORSIZE || - lsectorsize > XFS_MAX_SECTORSIZE || lsectorsize > sectorsize) { - fprintf(stderr, _("illegal log sector size %d\n"), sectorsize); - usage(); - } -#else - if (sectorsize != XFS_MIN_SECTORSIZE || - sectorlog != XFS_MIN_SECTORSIZE_LOG) { - fprintf(stderr, _("illegal sector size %d\n"), sectorsize); +#ifndef EXPERIMENTAL_LARGE_SECTORS + if (sectorsize != XFS_MIN_SECTORSIZE) { + fprintf(stderr, _("unsupported sector size %d\n"), sectorsize); usage(); } - if (lsectorsize != XFS_MIN_SECTORSIZE && lsectorsize) { - fprintf(stderr, _("illegal log sector size %d\n"), lsectorsize); + if (lsectorsize != XFS_MIN_SECTORSIZE) { + fprintf(stderr, _("unsupported log sector size %d\n"), lsectorsize); usage(); } - lsectorlog = XFS_MIN_SECTORSIZE_LOG; - lsectorsize = XFS_MIN_SECTORSIZE; #endif if (!nvflag) @@ -1228,18 +1262,18 @@ main( __uint64_t rtextbytes; dummy1 = rswidth = 0; - - if (!xi.disfile) - get_subvol_stripe_wrapper(dfile, SVTYPE_RT, &dummy1, - &rswidth); + + if (!xi.disfile) + get_subvol_stripe_wrapper(dfile, SVTYPE_RT, &dummy1, + &rswidth); /* check that rswidth is a multiple of fs blocksize */ if (rswidth && !(BBTOB(rswidth) % blocksize)) { rswidth = DTOBT(rswidth); rtextbytes = rswidth << blocklog; if (XFS_MIN_RTEXTSIZE <= rtextbytes && - (rtextbytes <= XFS_MAX_RTEXTSIZE)) { - rtextblocks = rswidth; + (rtextbytes <= XFS_MAX_RTEXTSIZE)) { + rtextblocks = rswidth; } else { rtextblocks = XFS_DFL_RTEXTSIZE >> blocklog; } @@ -1395,13 +1429,13 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), logblocks = (dblocks << blocklog) / 8192; logblocks = logblocks >> blocklog; logblocks = MAX(min_logblocks, logblocks); - logblocks = MAX(logblocks, + logblocks = MAX(logblocks, MAX(XFS_DFL_LOG_SIZE, i * XFS_DFL_LOG_FACTOR)); - logblocks = MIN(logblocks, XFS_MAX_LOG_BLOCKS); + logblocks = MIN(logblocks, XFS_MAX_LOG_BLOCKS); if ((logblocks << blocklog) > XFS_MAX_LOG_BYTES) { logblocks = XFS_MAX_LOG_BYTES >> blocklog; } - } + } if (logblocks < min_logblocks) { fprintf(stderr, _("log size %lld blocks too small, minimum size is %d blocks\n"), @@ -1588,9 +1622,9 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), } xlv_dsunit = xlv_dswidth = 0; - if (!xi.disfile) - get_subvol_stripe_wrapper(dfile, SVTYPE_DATA, &xlv_dsunit, - &xlv_dswidth); + if (!xi.disfile) + get_subvol_stripe_wrapper(dfile, SVTYPE_DATA, + &xlv_dsunit, &xlv_dswidth); if (dsunit) { if (xlv_dsunit && xlv_dsunit != dsunit) { @@ -1626,12 +1660,12 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), * agsize is not a multiple of dsunit */ if ((agsize % dsunit) != 0) { - /* - * Round up to stripe unit boundary. Also make sure + /* + * Round up to stripe unit boundary. Also make sure * that agsize is still larger than * XFS_AG_MIN_BLOCKS(blocklog) */ - tmp_agsize = ((agsize + (dsunit - 1))/ dsunit) * dsunit; + tmp_agsize = ((agsize + (dsunit - 1))/ dsunit) * dsunit; /* * Round down to stripe unit boundary if rounding up * created an AG size that is larger than the AG max. @@ -1648,7 +1682,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), fprintf(stderr, _("agsize rounded to %lld, swidth = %d\n"), (long long)agsize, dswidth); - } else { + } else { if (nodsflag) { dsunit = dswidth = 0; } else { @@ -1657,7 +1691,7 @@ _("Allocation group size (%lld) is not a multiple of the stripe unit (%d)\n"), (long long)agsize, dsunit); exit(1); } - } + } } if (dswidth && ((agsize % dswidth) == 0) && (agcount > 1)) { /* This is a non-optimal configuration because all AGs @@ -1943,7 +1977,7 @@ _("log stripe unit (%d bytes) is too large for kernel to handle (max 256k)\n"), XFS_AG_DADDR(mp, agno, XFS_SB_DADDR), XFS_FSS_TO_BB(mp, 1)); bzero(XFS_BUF_PTR(buf), sectorsize); - libxfs_xlate_sb(XFS_BUF_PTR(buf), sbp, -1, ARCH_CONVERT, + libxfs_xlate_sb(XFS_BUF_PTR(buf), sbp, -1, ARCH_CONVERT, XFS_SB_ALL_BITS); libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE); @@ -2337,10 +2371,10 @@ usage( void ) /* blocksize */ [-b log=n|size=num]\n\ /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\ (sunit=value,swidth=value|su=num,sw=num),\n\ - unwritten=0|1]\n\ + sectlog=n|sectsize=num,unwritten=0|1]\n\ /* inode size */ [-i log=n|perblock=n|size=num,maxpct=n]\n\ -/* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx\n\ - version=n,sunit=value|su=num]\n\ +/* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n\n\ + sunit=value|su=num,sectlog=n|sectsize=num]\n\ /* label */ [-L label (maximum 12 characters)]\n\ /* naming */ [-n log=n|size=num,version=n]\n\ /* prototype file */ [-p fname]\n\ -- 2.47.2