BSD 4_4_Lite2 release
[unix-history] / usr / src / sbin / tunefs / tunefs.c
index 583dbff..d5868eb 100644 (file)
@@ -38,7 +38,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)tunefs.c   8.2 (Berkeley) 4/19/94";
+static char sccsid[] = "@(#)tunefs.c   8.3 (Berkeley) 5/3/95";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -47,6 +47,7 @@ static char sccsid[] = "@(#)tunefs.c  8.2 (Berkeley) 4/19/94";
 #include <sys/param.h>
 #include <sys/stat.h>
 
 #include <sys/param.h>
 #include <sys/stat.h>
 
+#include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
 
 #include <errno.h>
 #include <ufs/ffs/fs.h>
 
 #include <errno.h>
@@ -83,7 +84,7 @@ main(argc, argv)
        char *cp, *special, *name;
        struct stat st;
        int i;
        char *cp, *special, *name;
        struct stat st;
        int i;
-       int Aflag = 0;
+       int Aflag = 0, Nflag = 0;
        struct fstab *fs;
        char *chg[2], device[MAXPATHLEN];
 
        struct fstab *fs;
        char *chg[2], device[MAXPATHLEN];
 
@@ -109,6 +110,8 @@ again:
            (st.st_mode & S_IFMT) != S_IFCHR)
                errx(10, "%s: not a block or character device", special);
        getsb(&sblock, special);
            (st.st_mode & S_IFMT) != S_IFCHR)
                errx(10, "%s: not a block or character device", special);
        getsb(&sblock, special);
+       chg[FS_OPTSPACE] = "space";
+       chg[FS_OPTTIME] = "time";
        for (; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
                for (cp = &argv[0][1]; *cp; cp++)
                        switch (*cp) {
        for (; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
                for (cp = &argv[0][1]; *cp; cp++)
                        switch (*cp) {
@@ -117,6 +120,10 @@ again:
                                Aflag++;
                                continue;
 
                                Aflag++;
                                continue;
 
+                       case 'N':
+                               Nflag++;
+                               continue;
+
                        case 'a':
                                name = "maximum contiguous block count";
                                if (argc < 1)
                        case 'a':
                                name = "maximum contiguous block count";
                                if (argc < 1)
@@ -182,8 +189,6 @@ again:
                                if (argc < 1)
                                        errx(10, "-o: missing %s", name);
                                argc--, argv++;
                                if (argc < 1)
                                        errx(10, "-o: missing %s", name);
                                argc--, argv++;
-                               chg[FS_OPTSPACE] = "space";
-                               chg[FS_OPTTIME] = "time";
                                if (strcmp(*argv, chg[FS_OPTSPACE]) == 0)
                                        i = FS_OPTSPACE;
                                else if (strcmp(*argv, chg[FS_OPTTIME]) == 0)
                                if (strcmp(*argv, chg[FS_OPTSPACE]) == 0)
                                        i = FS_OPTSPACE;
                                else if (strcmp(*argv, chg[FS_OPTTIME]) == 0)
@@ -207,12 +212,48 @@ again:
                                        warnx(OPTWARN, "space", "<", MINFREE);
                                continue;
 
                                        warnx(OPTWARN, "space", "<", MINFREE);
                                continue;
 
+                       case 't':
+                               name = "track skew in sectors";
+                               if (argc < 1)
+                                       errx(10, "-t: missing %s", name);
+                               argc--, argv++;
+                               i = atoi(*argv);
+                               if (i < 0)
+                                       errx(10, "%s: %s must be >= 0",
+                                               *argv, name);
+                               warnx("%s changes from %d to %d",
+                                       name, sblock.fs_trackskew, i);
+                               sblock.fs_trackskew = i;
+                               continue;
+
                        default:
                                usage();
                        }
        }
        if (argc != 1)
                usage();
                        default:
                                usage();
                        }
        }
        if (argc != 1)
                usage();
+       if (Nflag) {
+               fprintf(stdout, "tunefs: current settings\n");
+               fprintf(stdout, "\tmaximum contiguous block count %d\n",
+                   sblock.fs_maxcontig);
+               fprintf(stdout,
+                   "\trotational delay between contiguous blocks %dms\n",
+                   sblock.fs_rotdelay);
+               fprintf(stdout,
+                   "\tmaximum blocks per file in a cylinder group %d\n",
+                   sblock.fs_maxbpg);
+               fprintf(stdout, "\tminimum percentage of free space %d%%\n",
+                   sblock.fs_minfree);
+               fprintf(stdout, "\toptimization preference: %s\n",
+                   chg[sblock.fs_optim]);
+               fprintf(stdout, "\ttrack skew %d sectors\n",
+                       sblock.fs_trackskew);
+               fprintf(stdout, "tunefs: no changes made\n");
+               exit(0);
+       }
+       fi = open(special, 1);
+       if (fi < 0)
+               err(3, "cannot open %s for writing", special);
        bwrite((daddr_t)SBOFF / dev_bsize, (char *)&sblock, SBSIZE);
        if (Aflag)
                for (i = 0; i < sblock.fs_ncg; i++)
        bwrite((daddr_t)SBOFF / dev_bsize, (char *)&sblock, SBSIZE);
        if (Aflag)
                for (i = 0; i < sblock.fs_ncg; i++)
@@ -226,13 +267,14 @@ void
 usage()
 {
 
 usage()
 {
 
-       fprintf(stderr, "Usage: tunefs tuneup-options special-device\n");
+       fprintf(stderr, "Usage: tunefs [-AN] tuneup-options special-device\n");
        fprintf(stderr, "where tuneup-options are:\n");
        fprintf(stderr, "where tuneup-options are:\n");
-       fprintf(stderr, "\t-a maximum contiguous blocks\n");
        fprintf(stderr, "\t-d rotational delay between contiguous blocks\n");
        fprintf(stderr, "\t-d rotational delay between contiguous blocks\n");
+       fprintf(stderr, "\t-a maximum contiguous blocks\n");
        fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
        fprintf(stderr, "\t-m minimum percentage of free space\n");
        fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
        fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
        fprintf(stderr, "\t-m minimum percentage of free space\n");
        fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
+       fprintf(stderr, "\t-t track skew in sectors\n");
        exit(2);
 }
 
        exit(2);
 }
 
@@ -242,14 +284,15 @@ getsb(fs, file)
        char *file;
 {
 
        char *file;
 {
 
-       fi = open(file, 2);
+       fi = open(file, 0);
        if (fi < 0)
        if (fi < 0)
-               err(3, "cannot open %s", file);
+               err(3, "cannot open %s for reading", file);
        if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE))
                err(4, "%s: bad super block", file);
        if (fs->fs_magic != FS_MAGIC)
                err(5, "%s: bad magic number", file);
        dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
        if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE))
                err(4, "%s: bad super block", file);
        if (fs->fs_magic != FS_MAGIC)
                err(5, "%s: bad magic number", file);
        dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
+       close(fi);
 }
 
 void
 }
 
 void