version 1.7, 1994/04/20 03:57:08 |
version 1.8, 1994/06/08 19:36:13 |
|
|
/* |
/* |
* Copyright (c) 1983 The Regents of the University of California. |
* Copyright (c) 1983, 1993 |
* All rights reserved. |
* The Regents of the University of California. All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
|
|
*/ |
*/ |
|
|
#ifndef lint |
#ifndef lint |
char copyright[] = |
static char copyright[] = |
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\ |
"@(#) Copyright (c) 1983, 1993\n\ |
All rights reserved.\n"; |
The Regents of the University of California. All rights reserved.\n"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
#ifndef lint |
#ifndef lint |
/*static char sccsid[] = "from: @(#)tunefs.c 5.11 (Berkeley) 6/1/90";*/ |
/*static char sccsid[] = "from: @(#)tunefs.c 8.2 (Berkeley) 4/19/94";*/ |
static char rcsid[] = "$Id$"; |
static char *rcsid = "$Id$"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
/* |
/* |
Line 47 static char rcsid[] = "$Id$"; |
|
Line 47 static char rcsid[] = "$Id$"; |
|
*/ |
*/ |
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <ufs/fs.h> |
|
|
#include <ufs/ffs/fs.h> |
|
|
|
#include <errno.h> |
#include <err.h> |
#include <err.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <fstab.h> |
#include <fstab.h> |
Line 56 static char rcsid[] = "$Id$"; |
|
Line 59 static char rcsid[] = "$Id$"; |
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
/* |
|
* MINFREE gives the minimum acceptable percentage of file system |
|
* blocks which may be free. If the freelist drops below this level |
|
* only the superuser may continue to allocate blocks. This may |
|
* be set to 0 if no reserve of free blocks is deemed necessary, |
|
* however throughput drops by fifty percent if the file system |
|
* is run at between 90% and 100% full; thus the default value of |
|
* fs_minfree is 10%. With 10% free space, fragmentation is not a |
|
* problem, so we choose to optimize for time. |
|
* |
|
* XXX should be in some header common with newfs; snarfed from there. |
|
*/ |
|
#define MINFREE 10 |
|
|
|
/* the optimization warning string template */ |
/* the optimization warning string template */ |
#define OPTWARN "should optimize for %s with minfree %s %d%%" |
#define OPTWARN "should optimize for %s with minfree %s %d%%" |
|
|
union { |
union { |
struct fs sb; |
struct fs sb; |
|
|
} |
} |
if ((st.st_mode & S_IFMT) != S_IFBLK && |
if ((st.st_mode & S_IFMT) != S_IFBLK && |
(st.st_mode & S_IFMT) != S_IFCHR) |
(st.st_mode & S_IFMT) != S_IFCHR) |
errx(1, "%s: not a block or character device", special); |
errx(10, "%s: not a block or character device", special); |
getsb(&sblock, special); |
getsb(&sblock, special); |
for (; argc > 0 && argv[0][0] == '-'; argc--, argv++) { |
for (; argc > 0 && argv[0][0] == '-'; argc--, argv++) { |
for (cp = &argv[0][1]; *cp; cp++) |
for (cp = &argv[0][1]; *cp; cp++) |
|
|
case 'a': |
case 'a': |
name = "maximum contiguous block count"; |
name = "maximum contiguous block count"; |
if (argc < 1) |
if (argc < 1) |
errx(1, "-a: missing %s", name); |
errx(10, "-a: missing %s", name); |
argc--, argv++; |
argc--, argv++; |
i = atoi(*argv); |
i = atoi(*argv); |
if (i < 1) |
if (i < 1) |
errx(1, "%s must be >= 1 (was %s)", |
errx(10, "%s must be >= 1 (was %s)", |
name, *argv); |
name, *argv); |
warnx("%s changes from %d to %d", |
warnx("%s changes from %d to %d", |
name, sblock.fs_maxcontig, i); |
name, sblock.fs_maxcontig, i); |
|
|
name = |
name = |
"rotational delay between contiguous blocks"; |
"rotational delay between contiguous blocks"; |
if (argc < 1) |
if (argc < 1) |
errx(1, "-d: missing %s", name); |
errx(10, "-d: missing %s", name); |
argc--, argv++; |
argc--, argv++; |
i = atoi(*argv); |
i = atoi(*argv); |
warnx("%s changes from %dms to %dms", |
warnx("%s changes from %dms to %dms", |
|
|
name = |
name = |
"maximum blocks per file in a cylinder group"; |
"maximum blocks per file in a cylinder group"; |
if (argc < 1) |
if (argc < 1) |
errx(1, "-e: missing %s", name); |
errx(10, "-e: missing %s", name); |
argc--, argv++; |
argc--, argv++; |
i = atoi(*argv); |
i = atoi(*argv); |
if (i < 1) |
if (i < 1) |
errx(1, "%s must be >= 1 (was %s)", |
errx(10, "%s must be >= 1 (was %s)", |
name, *argv); |
name, *argv); |
warnx("%s changes from %d to %d", |
warnx("%s changes from %d to %d", |
name, sblock.fs_maxbpg, i); |
name, sblock.fs_maxbpg, i); |
|
|
case 'm': |
case 'm': |
name = "minimum percentage of free space"; |
name = "minimum percentage of free space"; |
if (argc < 1) |
if (argc < 1) |
errx(1, "-m: missing %s", name); |
errx(10, "-m: missing %s", name); |
argc--, argv++; |
argc--, argv++; |
i = atoi(*argv); |
i = atoi(*argv); |
if (i < 0 || i > 99) |
if (i < 0 || i > 99) |
errx(1, "bad %s (%s)", name, *argv); |
errx(10, "bad %s (%s)", name, *argv); |
warnx("%s changes from %d%% to %d%%", |
warnx("%s changes from %d%% to %d%%", |
name, sblock.fs_minfree, i); |
name, sblock.fs_minfree, i); |
sblock.fs_minfree = i; |
sblock.fs_minfree = i; |
|
|
case 'o': |
case 'o': |
name = "optimization preference"; |
name = "optimization preference"; |
if (argc < 1) |
if (argc < 1) |
errx(1, "-o: missing %s", name); |
errx(10, "-o: missing %s", name); |
argc--, argv++; |
argc--, argv++; |
chg[FS_OPTSPACE] = "space"; |
chg[FS_OPTSPACE] = "space"; |
chg[FS_OPTTIME] = "time"; |
chg[FS_OPTTIME] = "time"; |
|
|
else if (strcmp(*argv, chg[FS_OPTTIME]) == 0) |
else if (strcmp(*argv, chg[FS_OPTTIME]) == 0) |
i = FS_OPTTIME; |
i = FS_OPTTIME; |
else |
else |
errx(1, "bad %s (options are `space' or `time')", |
errx(10, "bad %s (options are `space' or `time')", |
name); |
name); |
if (sblock.fs_optim == i) { |
if (sblock.fs_optim == i) { |
warnx("%s remains unchanged as %s", |
warnx("%s remains unchanged as %s", |
|
|
void |
void |
usage() |
usage() |
{ |
{ |
fprintf(stderr, "usage: tunefs tuneup-options special-device\n"); |
|
|
fprintf(stderr, "Usage: tunefs 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-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-e maximum blocks per file in a cylinder group\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-m minimum percentage of free space\n"); |
fprintf(stderr, "\t-o optimization preference (`space' or `time')\n"); |
fprintf(stderr, "\t-o optimization preference (`space' or `time')\n"); |
exit(1); |
exit(2); |
} |
} |
|
|
void |
void |
|
|
|
|
fi = open(file, 2); |
fi = open(file, 2); |
if (fi < 0) |
if (fi < 0) |
err(1, "cannot open %s", file); |
err(3, "cannot open %s", file); |
if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE)) |
if (bread((daddr_t)SBOFF, (char *)fs, SBSIZE)) |
err(1, "%s: bad super block", file); |
err(4, "%s: bad super block", file); |
if (fs->fs_magic != FS_MAGIC) |
if (fs->fs_magic != FS_MAGIC) |
err(1, "%s: bad magic number", file); |
err(5, "%s: bad magic number", file); |
dev_bsize = fs->fs_fsize / fsbtodb(fs, 1); |
dev_bsize = fs->fs_fsize / fsbtodb(fs, 1); |
} |
} |
|
|
void |
void |
bwrite(bno, buf, size) |
bwrite(blk, buf, size) |
daddr_t bno; |
daddr_t blk; |
char *buf; |
char *buf; |
int size; |
int size; |
{ |
{ |
if (lseek(fi, bno * dev_bsize, 0) < 0) |
|
err(1, "FS SEEK"); |
if (lseek(fi, (off_t)blk * dev_bsize, SEEK_SET) < 0) |
|
err(6, "FS SEEK"); |
if (write(fi, buf, size) != size) |
if (write(fi, buf, size) != size) |
err(1, "FS WRITE"); |
err(7, "FS WRITE"); |
} |
} |
|
|
int |
int |
Line 281 bread(bno, buf, cnt) |
|
Line 272 bread(bno, buf, cnt) |
|
char *buf; |
char *buf; |
int cnt; |
int cnt; |
{ |
{ |
register i; |
int i; |
|
|
if (lseek(fi, bno * dev_bsize, 0) < 0) |
if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0) |
return(1); |
return(1); |
if ((i = read(fi, buf, cnt)) != cnt) { |
if ((i = read(fi, buf, cnt)) != cnt) { |
for(i=0; i<sblock.fs_bsize; i++) |
for(i=0; i<sblock.fs_bsize; i++) |