Changeset View
Changeset View
Standalone View
Standalone View
sbin/tunefs/tunefs.c
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
static void journal_clear(void); | static void journal_clear(void); | ||||
static void sbdirty(void); | static void sbdirty(void); | ||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
const char *avalue, *jvalue, *Jvalue, *Lvalue, *lvalue, *Nvalue, *nvalue; | const char *avalue, *jvalue, *Jvalue, *Lvalue, *lvalue, *Nvalue, *nvalue; | ||||
const char *tvalue; | const char *tvalue; | ||||
const char *special, *on; | const char *special; | ||||
const char *name; | const char *name; | ||||
int active; | char *diskname; | ||||
int Aflag, aflag, eflag, evalue, fflag, fvalue, jflag, Jflag, kflag; | int Aflag, aflag, eflag, evalue, fflag, fvalue, jflag, Jflag, kflag; | ||||
int kvalue, Lflag, lflag, mflag, mvalue, Nflag, nflag, oflag, ovalue; | int kvalue, Lflag, lflag, mflag, mvalue, Nflag, nflag, oflag, ovalue; | ||||
int pflag, sflag, svalue, Svalue, tflag; | int pflag, sflag, svalue, Svalue, tflag; | ||||
int ch, found_arg, i; | int ch, found_arg, i; | ||||
int iovlen = 0; | |||||
const char *chg[2]; | const char *chg[2]; | ||||
struct statfs stfs; | |||||
struct iovec *iov = NULL; | |||||
char errmsg[255] = {0}; | |||||
if (argc < 3) | if (argc < 3) | ||||
usage(); | usage(); | ||||
Aflag = aflag = eflag = fflag = jflag = Jflag = kflag = Lflag = 0; | Aflag = aflag = eflag = fflag = jflag = Jflag = kflag = Lflag = 0; | ||||
lflag = mflag = Nflag = nflag = oflag = pflag = sflag = tflag = 0; | lflag = mflag = Nflag = nflag = oflag = pflag = sflag = tflag = 0; | ||||
avalue = jvalue = Jvalue = Lvalue = lvalue = Nvalue = nvalue = NULL; | avalue = jvalue = Jvalue = Lvalue = lvalue = Nvalue = nvalue = NULL; | ||||
evalue = fvalue = mvalue = ovalue = svalue = Svalue = 0; | evalue = fvalue = mvalue = ovalue = svalue = Svalue = 0; | ||||
active = 0; | |||||
found_arg = 0; /* At least one arg is required. */ | found_arg = 0; /* At least one arg is required. */ | ||||
while ((ch = getopt(argc, argv, "Aa:e:f:j:J:k:L:l:m:N:n:o:ps:S:t:")) | while ((ch = getopt(argc, argv, "Aa:e:f:j:J:k:L:l:m:N:n:o:ps:S:t:")) | ||||
!= -1) | != -1) | ||||
switch (ch) { | switch (ch) { | ||||
case 'A': | case 'A': | ||||
found_arg++; | found_arg++; | ||||
Aflag++; | Aflag++; | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | while ((ch = getopt(argc, argv, "Aa:e:f:j:J:k:L:l:m:N:n:o:ps:S:t:")) | ||||
default: | default: | ||||
usage(); | usage(); | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
if (found_arg == 0 || argc != 1) | if (found_arg == 0 || argc != 1) | ||||
usage(); | usage(); | ||||
on = special = argv[0]; | special = argv[0]; | ||||
if (ufs_disk_fillout(&disk, special) == -1) | if (ufs_disk_fillout(&disk, special) == -1) | ||||
goto err; | goto err; | ||||
/* | /* | ||||
* Check for unclean filesystem. | * Check for unclean filesystem. | ||||
*/ | */ | ||||
if ((sblock.fs_clean == 0 || | if ((sblock.fs_clean == 0 || | ||||
(sblock.fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) != 0) && | (sblock.fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) != 0) && | ||||
(found_arg > 1 || !pflag)) | (found_arg > 1 || !pflag)) | ||||
errx(1, "%s is not clean - run fsck.\n", special); | errx(1, "%s is not clean - run fsck.\n", special); | ||||
if (disk.d_name != special) { | |||||
if (statfs(special, &stfs) != 0) | |||||
warn("Can't stat %s", special); | |||||
if (strcmp(special, stfs.f_mntonname) == 0) | |||||
active = 1; | |||||
} | |||||
if (pflag) { | if (pflag) { | ||||
printfs(); | printfs(); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
if (Lflag) { | if (Lflag) { | ||||
name = "volume label"; | name = "volume label"; | ||||
strncpy(sblock.fs_volname, Lvalue, MAXVOLLEN); | strncpy(sblock.fs_volname, Lvalue, MAXVOLLEN); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | if (strcmp(tvalue, "enable") == 0) { | ||||
sblock.fs_flags &= ~FS_TRIM; | sblock.fs_flags &= ~FS_TRIM; | ||||
warnx("%s cleared", name); | warnx("%s cleared", name); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (sbwrite(&disk, Aflag) == -1) | if (sbwrite(&disk, Aflag) == -1) | ||||
goto err; | goto err; | ||||
diskname = strdup(disk.d_name); | |||||
ufs_disk_close(&disk); | ufs_disk_close(&disk); | ||||
if (active) { | chkdoreload(getmntpoint(diskname), warnx); | ||||
build_iovec_argf(&iov, &iovlen, "fstype", "ufs"); | |||||
build_iovec_argf(&iov, &iovlen, "fspath", "%s", on); | |||||
build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg)); | |||||
if (nmount(iov, iovlen, | |||||
stfs.f_flags | MNT_UPDATE | MNT_RELOAD) < 0) { | |||||
if (errmsg[0]) | |||||
err(9, "%s: reload: %s", special, errmsg); | |||||
else | |||||
err(9, "%s: reload", special); | |||||
} | |||||
warnx("file system reloaded"); | |||||
} | |||||
exit(0); | exit(0); | ||||
err: | err: | ||||
if (disk.d_error != NULL) | if (disk.d_error != NULL) | ||||
errx(11, "%s: %s", special, disk.d_error); | errx(11, "%s: %s", special, disk.d_error); | ||||
else | else | ||||
err(12, "%s", special); | err(12, "%s", special); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 547 Lines • Show Last 20 Lines |