Make tunefs use libufs, it seems to do well enough for printing / setting

things.
This commit is contained in:
Juli Mallett 2003-01-20 21:15:02 +00:00
parent 70be8cba19
commit b1f0fda09f
2 changed files with 15 additions and 108 deletions

View File

@ -2,6 +2,8 @@
# $FreeBSD$ # $FreeBSD$
PROG= tunefs PROG= tunefs
DPADD= -lufs
LDADD= -lufs
MAN= tunefs.8 MAN= tunefs.8
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -60,6 +60,7 @@ static const char rcsid[] =
#include <err.h> #include <err.h>
#include <fcntl.h> #include <fcntl.h>
#include <fstab.h> #include <fstab.h>
#include <libufs.h>
#include <paths.h> #include <paths.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -69,26 +70,14 @@ static const char rcsid[] =
/* 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 { struct uufsd disk;
struct fs sb; #define sblock disk.d_fs
char pad[MAXBSIZE];
} sbun;
#define sblock sbun.sb
int fi;
long dev_bsize = 1;
void bwrite(ufs2_daddr_t, const char *, int);
int bread(ufs2_daddr_t, char *, int);
void getsb(struct fs *, const char *);
void putsb(struct fs *, const char *, int);
void usage(void); void usage(void);
void printfs(void); void printfs(void);
int int
main(argc, argv) main(int argc, char *argv[])
int argc;
char *argv[];
{ {
char *special; char *special;
const char *name; const char *name;
@ -227,7 +216,12 @@ again:
} }
if (fs == NULL && (st.st_mode & S_IFMT) == S_IFDIR) if (fs == NULL && (st.st_mode & S_IFMT) == S_IFDIR)
errx(10, "%s: unknown file system", special); errx(10, "%s: unknown file system", special);
getsb(&sblock, special); if (ufs_disk_fillout(&disk, special) == -1) {
if (disk.d_error != NULL)
errx(11, "%s: %s", special, disk.d_error);
else
err(12, "%s", special);
}
if (pflag) { if (pflag) {
printfs(); printfs();
@ -362,7 +356,7 @@ again:
} }
} }
putsb(&sblock, special, Aflag); sbwrite(&disk, Aflag);
if (active) { if (active) {
bzero(&args, sizeof(args)); bzero(&args, sizeof(args));
if (mount("ufs", fs->fs_file, if (mount("ufs", fs->fs_file,
@ -374,7 +368,7 @@ again:
} }
void void
usage() usage(void)
{ {
fprintf(stderr, "%s\n%s\n%s\n", fprintf(stderr, "%s\n%s\n%s\n",
"usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]", "usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]",
@ -383,66 +377,8 @@ usage()
exit(2); exit(2);
} }
/*
* Possible superblock locations ordered from most to least likely.
*/
static int sblock_try[] = SBLOCKSEARCH;
static ufs2_daddr_t sblockloc;
void void
getsb(fs, file) printfs(void)
struct fs *fs;
const char *file;
{
int i;
fi = open(file, O_RDONLY);
if (fi < 0)
err(3, "cannot open %s", file);
for (i = 0; sblock_try[i] != -1; i++) {
if (bread(sblock_try[i], (char *)fs, SBLOCKSIZE))
err(4, "%s: bad super block", file);
if ((fs->fs_magic == FS_UFS1_MAGIC ||
(fs->fs_magic == FS_UFS2_MAGIC &&
fs->fs_sblockloc == sblock_try[i])) &&
fs->fs_bsize <= MAXBSIZE &&
fs->fs_bsize >= sizeof(struct fs))
break;
}
if (sblock_try[i] == -1)
err(5, "Cannot find file system superblock");
dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
sblockloc = sblock_try[i] / dev_bsize;
}
void
putsb(fs, file, all)
struct fs *fs;
const char *file;
int all;
{
int i;
/*
* Re-open the device read-write. Use the read-only file
* descriptor as an interlock to prevent the device from
* being mounted while we are switching mode.
*/
i = fi;
fi = open(file, O_RDWR);
close(i);
if (fi < 0)
err(3, "cannot open %s", file);
bwrite(sblockloc, (const char *)fs, SBLOCKSIZE);
if (all)
for (i = 0; i < fs->fs_ncg; i++)
bwrite(fsbtodb(fs, cgsblock(fs, i)),
(const char *)fs, SBLOCKSIZE);
close(fi);
}
void
printfs()
{ {
warnx("ACLs: (-a) %s", warnx("ACLs: (-a) %s",
(sblock.fs_flags & FS_ACLS)? "enabled" : "disabled"); (sblock.fs_flags & FS_ACLS)? "enabled" : "disabled");
@ -467,34 +403,3 @@ printfs()
sblock.fs_optim == FS_OPTTIME) sblock.fs_optim == FS_OPTTIME)
warnx(OPTWARN, "space", "<", MINFREE); warnx(OPTWARN, "space", "<", MINFREE);
} }
void
bwrite(blk, buf, size)
ufs2_daddr_t blk;
const char *buf;
int size;
{
if (lseek(fi, (off_t)blk * dev_bsize, SEEK_SET) < 0)
err(6, "FS SEEK");
if (write(fi, buf, size) != size)
err(7, "FS WRITE");
}
int
bread(bno, buf, cnt)
ufs2_daddr_t bno;
char *buf;
int cnt;
{
int i;
if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0)
return(1);
if ((i = read(fi, buf, cnt)) != cnt) {
for(i=0; i<sblock.fs_bsize; i++)
buf[i] = 0;
return (1);
}
return (0);
}