diff options
Diffstat (limited to 'ufs-utils/mkfs.c')
-rw-r--r-- | ufs-utils/mkfs.c | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/ufs-utils/mkfs.c b/ufs-utils/mkfs.c index 43093b9b..aef3ea92 100644 --- a/ufs-utils/mkfs.c +++ b/ufs-utils/mkfs.c @@ -33,7 +33,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)mkfs.c 8.3 (Berkeley) 2/3/94";*/ -static char *rcsid = "$Id: mkfs.c,v 1.13 1996/07/23 23:37:21 miles Exp $"; +static char *rcsid = "$Id: mkfs.c,v 1.22 2006/03/14 23:27:50 tschwinge Exp $"; #endif /* not lint */ #include <unistd.h> @@ -54,6 +54,7 @@ static char *rcsid = "$Id: mkfs.c,v 1.13 1996/07/23 23:37:21 miles Exp $"; #include <sys/stat.h> #include <fcntl.h> #include <dirent.h> +#include <version.h> #include <device/device_types.h> #include <device/disk_status.h> @@ -62,7 +63,7 @@ static char *rcsid = "$Id: mkfs.c,v 1.13 1996/07/23 23:37:21 miles Exp $"; /* Begin misc additions for GNU Hurd */ -/* For GNU Hurd: the ufs DIRSIZ macro is different than the BSD +/* For GNU Hurd: the ufs DIRSIZ macro is different than the BSD 4.4 version that mkfs expects. So we provide here the BSD version. */ #undef DIRSIZ #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -89,6 +90,7 @@ static char *rcsid = "$Id: mkfs.c,v 1.13 1996/07/23 23:37:21 miles Exp $"; #ifndef STANDALONE #include <a.out.h> #include <stdio.h> +#include <time.h> #endif /* @@ -163,7 +165,7 @@ struct dinode zino[MAXBSIZE / sizeof(struct dinode)]; int fsi, fso; daddr_t alloc(); -char *argp_program_version = "mkfs.ufs 1.0 (GNU " HURD_RELEASE ")"; +const char *argp_program_version = STANDARD_HURD_VERSION (mkfs.ufs); #define _STRINGIFY(arg) #arg #define STRINGIFY(arg) _STRINGIFY (arg) @@ -173,22 +175,22 @@ static const struct argp_option options[] = { {"just-print", 'N', 0, 0, "Just print the file system parameters that would be used"}, {"old-format", 'O', 0, 0, "Create a 4.3BSD format filesystem"}, - {"max-contig", 'a', "BLOCKS", 0, + {"max-contig", 'a', "BLOCKS", 0, "The maximum number of contiguous blocks that will be laid out before" " forcing a rotational delay; the default is no limit"}, {"block-size", 'b', "BYTES", 0, "The block size of the file system"}, {"group-cylinders", 'c', "N", 0, "The number of cylinders per cylinder group; the default 16"}, - {"rot-delay", 'd', "MSEC", 0, + {"rot-delay", 'd', "MSEC", 0, "The expected time to service a transfer completion interrupt and" " initiate a new transfer on the same disk; the default is 0"}, - {"max-bpg", 'e', "BLOCKS", 0, + {"max-bpg", 'e', "BLOCKS", 0, "Maximum number of blocks any single file can allocate out of a cylinder" " group before it is forced to begin allocating blocks from another" " cylinder group; the default is about one quarter of the total blocks" " in a cylinder group"}, {"frag-size", 'f', "BYTES", 0, "The fragment size"}, - {"inode-density", 'i', "BYTES", 0, + {"inode-density", 'i', "BYTES", 0, "The density of inodes in the file system, in bytes of data space per" " inode; the default is one inode per 4 filesystem frags"}, {"minfree", 'm', "PERCENT", 0, @@ -210,7 +212,7 @@ static const struct argp_option options[] = { {"tracks", 't', "N", 0, "The number of tracks/cylinder"}, {"sectors", 'u', "N", 0, "The number of sectors per track (does not include sectors reserved for" - " bad block replacement"}, + " bad block replacement"}, {"spare-sectors", 'p', "N", 0, "Spare sectors (for bad sector replacement) at the end of each track"}, {"cyl-spare-sectors", 'x', "N", 0, @@ -219,7 +221,7 @@ static const struct argp_option options[] = { {0, 0} }; static char *args_doc = "DEVICE"; -static char *doc = 0; +static char *doc = "Write a ufs filesystem image onto DEVICE."; struct amark { void *addr; struct amark *next; }; @@ -260,7 +262,7 @@ char *device = 0; #define deverr(code, err, fmt, args...) \ error (code, err, "%s: " fmt, device , ##args) -void +int main (int argc, char **argv) { int fdo, fdi; @@ -276,11 +278,9 @@ main (int argc, char **argv) { case 'N': Nflag = 1; break; case 'O': Oflag = 1; break; - - /* Mark &VAR as being a uparam, and return a lvalue for VAR. */ -#define UP(var) (amarks_add (&uparams, &var), var) - /* Record an integer uparam into VAR. */ -#define UP_INT(var) { int _i = atoi (arg); UP (var) = _i; } + +/* Mark &VAR as being a uparam, and set VAR. */ +#define UP_INT(var) { amarks_add (&uparams, &var); var = atoi (arg); } case 'a': UP_INT (maxcontig); break; case 'b': UP_INT (bsize); break; @@ -301,7 +301,7 @@ main (int argc, char **argv) case 'p': UP_INT (nspares); break; case 'x': UP_INT (ncspares); break; - case 'o': + case 'o': amarks_add (&uparams, &opt); if (strcmp (arg, "time") == 0) opt = FS_OPTTIME; @@ -412,7 +412,7 @@ main (int argc, char **argv) nphyssectors = nsectors + nspares; secpercyl = nsectors * ntracks; - + DEFAULT (rpm, DL_INT (0, d_rpm)); DEFAULT (interleave, DL_INT (0, d_interleave)); DEFAULT (trackskew, DL_SECS (0, d_trackskew)); @@ -421,7 +421,7 @@ main (int argc, char **argv) DEFAULT (fsize, 1024); DEFAULT (bsize, 8192); - + DEFAULT (cpg, 16); DEFAULT (minfree, MINFREE); DEFAULT (opt, DEFAULTOPT); @@ -438,7 +438,7 @@ main (int argc, char **argv) mkfs (0, device, fdi, fdo); - exit (0); + return 0; } void @@ -655,7 +655,7 @@ mkfs(pp, fsys, fi, fo) } else exit(23); - /* + /* * Calculate the number of cylinders per group */ sblock.fs_cpg = cpg; @@ -862,6 +862,7 @@ next: sblock.fs_cstotal.cs_nffree = 0; sblock.fs_fmod = 0; sblock.fs_ronly = 0; + sblock.fs_clean = 1; /* * Dump out summary information about file system. @@ -903,7 +904,7 @@ next: sblock.fs_cssize - i < sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize, ((char *)fscs) + i); - /* + /* * Write out the duplicate super blocks */ for (cylno = 0; cylno < sblock.fs_ncg; cylno++) @@ -961,7 +962,7 @@ initcg(cylno, utime) acg.cg_nclusterblks = acg.cg_ndblk / sblock.fs_frag; acg.cg_btotoff = &acg.cg_space[0] - (u_char *)(&acg.cg_link); acg.cg_boff = acg.cg_btotoff + sblock.fs_cpg * sizeof(long); - acg.cg_iusedoff = acg.cg_boff + + acg.cg_iusedoff = acg.cg_boff + sblock.fs_cpg * sblock.fs_nrpos * sizeof(short); acg.cg_freeoff = acg.cg_iusedoff + howmany(sblock.fs_ipg, NBBY); if (sblock.fs_contigsumsize <= 0) { @@ -1155,6 +1156,14 @@ fsinit(utime) node.di_model = IFDIR | UMASK; node.di_modeh = 0; node.di_nlink = PREDEFDIR; + + /* Set the uid/gid to non-root if run by a non-root user. This + is what mke2fs does in e2fsprogs-1.18 (actually it uses the + real IDs iff geteuid()!=0, but that is just wrong). */ + node.di_uid = geteuid(); + if (node.di_uid != 0) + node.di_gid = getegid(); + if (Oflag) node.di_size = makedir((struct directory_entry *)oroot_dir, PREDEFDIR); else @@ -1268,7 +1277,7 @@ iput(ip, ino) sblock.fs_cstotal.cs_nifree--; fscs[0].cs_nifree--; if (ino >= sblock.fs_ipg * sblock.fs_ncg) - deverr (32, 0, "fsinit: inode value out of range (%d)", ino); + deverr (32, 0, "fsinit: inode value out of range (%Ld)", ino); d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino)); rdfs(d, sblock.fs_bsize, buf); buf[ino_to_fsbo(&sblock, ino)] = *ip; |