summaryrefslogtreecommitdiffstats
path: root/sbin/tunefs
diff options
context:
space:
mode:
authorluoqi <luoqi@FreeBSD.org>1999-01-20 01:22:39 +0000
committerluoqi <luoqi@FreeBSD.org>1999-01-20 01:22:39 +0000
commitbfbf2fe72fa4e290fbb93a373a5d385c65be6ea5 (patch)
tree57befde5d3be7211240f31880562f543f6b1b5f8 /sbin/tunefs
parentb1b3d7c0bc86c238851d17d111c902846e0d3aad (diff)
downloadFreeBSD-src-bfbf2fe72fa4e290fbb93a373a5d385c65be6ea5.zip
FreeBSD-src-bfbf2fe72fa4e290fbb93a373a5d385c65be6ea5.tar.gz
Allow tuning of read-only mounted file system.
Reviewed by: Bruce Evans <bde@zeta.org.au>
Diffstat (limited to 'sbin/tunefs')
-rw-r--r--sbin/tunefs/tunefs.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/sbin/tunefs/tunefs.c b/sbin/tunefs/tunefs.c
index 682c6e2..8a32cb1 100644
--- a/sbin/tunefs/tunefs.c
+++ b/sbin/tunefs/tunefs.c
@@ -42,16 +42,18 @@ static const char copyright[] =
static char sccsid[] = "@(#)tunefs.c 8.2 (Berkeley) 4/19/94";
#endif
static const char rcsid[] =
- "$Id$";
+ "$Id: tunefs.c,v 1.6 1998/08/03 06:41:20 charnier Exp $";
#endif /* not lint */
/*
* tunefs: change layout parameters to an existing file system.
*/
#include <sys/param.h>
+#include <sys/mount.h>
#include <sys/stat.h>
#include <ufs/ffs/fs.h>
+#include <ufs/ufs/ufsmount.h>
#include <err.h>
#include <fcntl.h>
@@ -59,6 +61,7 @@ static const char rcsid[] =
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
/* the optimization warning string template */
@@ -78,6 +81,7 @@ int bread(daddr_t, char *, int);
void getsb(struct fs *, char *);
void usage __P((void));
void printfs __P((void));
+char *rawname __P((char *, char *));
int
main(argc, argv)
@@ -87,17 +91,27 @@ main(argc, argv)
char *cp, *special, *name, *action;
struct stat st;
int i;
- int Aflag = 0;
+ int Aflag = 0, active = 0;
struct fstab *fs;
char *chg[2], device[MAXPATHLEN];
+ struct ufs_args args;
+ struct statfs stfs;
argc--, argv++;
if (argc < 2)
usage();
special = argv[argc - 1];
fs = getfsfile(special);
- if (fs)
- special = fs->fs_spec;
+ if (fs) {
+ if (statfs(special, &stfs) == 0) {
+ if ((stfs.f_flags & MNT_RDONLY) == 0) {
+ errx(1, "cannot work on read-write mounted file system");
+ }
+ active = 1;
+ special = rawname(fs->fs_spec, device);
+ } else
+ special = fs->fs_spec;
+ }
again:
if (stat(special, &st) < 0) {
if (*special != '/') {
@@ -245,6 +259,13 @@ again:
bwrite(fsbtodb(&sblock, cgsblock(&sblock, i)),
(char *)&sblock, SBSIZE);
close(fi);
+ if (active) {
+ bzero(&args, sizeof(args));
+ if (mount("ufs", fs->fs_file,
+ stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0)
+ err(9, "%s: reload", special);
+ warnx("file system reloaded");
+ }
exit(0);
}
@@ -327,3 +348,25 @@ bread(bno, buf, cnt)
}
return (0);
}
+
+char *
+rawname(special, pathbuf)
+ char *special;
+ char *pathbuf;
+{
+ char *p;
+ int n;
+
+ p = strrchr(special, '/');
+ if (p) {
+ n = ++p - special;
+ bcopy(special, pathbuf, n);
+ } else {
+ strcpy(pathbuf, _PATH_DEV);
+ n = strlen(pathbuf);
+ p = special;
+ }
+ pathbuf[n++] = 'r';
+ strcpy(pathbuf + n, p);
+ return pathbuf;
+}
OpenPOWER on IntegriCloud