* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)tunefs.c 8.2 (Berkeley) %G%";
* tunefs: change layout parameters to an existing file system.
/* the optimization warning string template */
#define OPTWARN "should optimize for %s with minfree %s %d%%"
void bwrite(daddr_t
, char *, int);
int bread(daddr_t
, char *, int);
void getsb(struct fs
*, char *);
char *cp
, *special
, *name
;
char *chg
[2], device
[MAXPATHLEN
];
special
= argv
[argc
- 1];
if (stat(special
, &st
) < 0) {
(void)sprintf(device
, "%s/%s", _PATH_DEV
, special
);
if ((st
.st_mode
& S_IFMT
) != S_IFBLK
&&
(st
.st_mode
& S_IFMT
) != S_IFCHR
)
errx(10, "%s: not a block or character device", special
);
for (; argc
> 0 && argv
[0][0] == '-'; argc
--, argv
++) {
for (cp
= &argv
[0][1]; *cp
; cp
++)
name
= "maximum contiguous block count";
errx(10, "-a: missing %s", name
);
errx(10, "%s must be >= 1 (was %s)",
warnx("%s changes from %d to %d",
name
, sblock
.fs_maxcontig
, i
);
"rotational delay between contiguous blocks";
errx(10, "-d: missing %s", name
);
warnx("%s changes from %dms to %dms",
name
, sblock
.fs_rotdelay
, i
);
"maximum blocks per file in a cylinder group";
errx(10, "-e: missing %s", name
);
errx(10, "%s must be >= 1 (was %s)",
warnx("%s changes from %d to %d",
name
, sblock
.fs_maxbpg
, i
);
name
= "minimum percentage of free space";
errx(10, "-m: missing %s", name
);
errx(10, "bad %s (%s)", name
, *argv
);
warnx("%s changes from %d%% to %d%%",
name
, sblock
.fs_minfree
, i
);
sblock
.fs_optim
== FS_OPTSPACE
)
warnx(OPTWARN
, "time", ">=", MINFREE
);
sblock
.fs_optim
== FS_OPTTIME
)
warnx(OPTWARN
, "space", "<", MINFREE
);
name
= "optimization preference";
errx(10, "-o: missing %s", name
);
chg
[FS_OPTSPACE
] = "space";
chg
[FS_OPTTIME
] = "time";
if (strcmp(*argv
, chg
[FS_OPTSPACE
]) == 0)
else if (strcmp(*argv
, chg
[FS_OPTTIME
]) == 0)
errx(10, "bad %s (options are `space' or `time')",
if (sblock
.fs_optim
== i
) {
warnx("%s remains unchanged as %s",
warnx("%s changes from %s to %s",
name
, chg
[sblock
.fs_optim
], chg
[i
]);
if (sblock
.fs_minfree
>= MINFREE
&&
warnx(OPTWARN
, "time", ">=", MINFREE
);
if (sblock
.fs_minfree
< MINFREE
&&
warnx(OPTWARN
, "space", "<", MINFREE
);
bwrite((daddr_t
)SBOFF
/ dev_bsize
, (char *)&sblock
, SBSIZE
);
for (i
= 0; i
< sblock
.fs_ncg
; i
++)
bwrite(fsbtodb(&sblock
, cgsblock(&sblock
, i
)),
(char *)&sblock
, SBSIZE
);
fprintf(stderr
, "Usage: tunefs tuneup-options special-device\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-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");
err(3, "cannot open %s", 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 (lseek(fi
, (off_t
)blk
* dev_bsize
, SEEK_SET
) < 0)
if (write(fi
, buf
, size
) != size
)
if (lseek(fi
, (off_t
)bno
* dev_bsize
, SEEK_SET
) < 0)
if ((i
= read(fi
, buf
, cnt
)) != cnt
) {
for(i
=0; i
<sblock
.fs_bsize
; i
++)