aboutsummaryrefslogtreecommitdiff
path: root/sbin/quotacheck/quotacheck.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/quotacheck/quotacheck.c')
-rw-r--r--sbin/quotacheck/quotacheck.c45
1 files changed, 20 insertions, 25 deletions
diff --git a/sbin/quotacheck/quotacheck.c b/sbin/quotacheck/quotacheck.c
index c7582b09dc53..7071aaf9dea5 100644
--- a/sbin/quotacheck/quotacheck.c
+++ b/sbin/quotacheck/quotacheck.c
@@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$");
#include <fcntl.h>
#include <fstab.h>
#include <grp.h>
+#include <libufs.h>
#include <libutil.h>
#include <pwd.h>
#include <stdint.h>
@@ -121,7 +122,7 @@ int fi; /* open disk file descriptor */
struct fileusage *
addid(u_long, int, char *, const char *);
-void bread(ufs2_daddr_t, char *, long);
+void blkread(ufs2_daddr_t, char *, long);
void freeinodebuf(void);
union dinode *
getnextinode(ino_t);
@@ -244,11 +245,6 @@ usage(void)
}
/*
- * Possible superblock locations ordered from most to least likely.
- */
-static int sblock_try[] = SBLOCKSEARCH;
-
-/*
* Scan the specified file system to check quota(s) present on it.
*/
int
@@ -256,7 +252,8 @@ chkquota(char *specname, struct quotafile *qfu, struct quotafile *qfg)
{
struct fileusage *fup;
union dinode *dp;
- int cg, i, mode, errs = 0;
+ struct fs *fs;
+ int cg, i, ret, mode, errs = 0;
ino_t ino, inosused, userino = 0, groupino = 0;
dev_t dev, userdev = 0, groupdev = 0;
struct stat sb;
@@ -323,26 +320,24 @@ chkquota(char *specname, struct quotafile *qfu, struct quotafile *qfg)
}
}
sync();
- dev_bsize = 1;
- for (i = 0; sblock_try[i] != -1; i++) {
- bread(sblock_try[i], (char *)&sblock, (long)SBLOCKSIZE);
- if ((sblock.fs_magic == FS_UFS1_MAGIC ||
- (sblock.fs_magic == FS_UFS2_MAGIC &&
- sblock.fs_sblockloc == sblock_try[i])) &&
- sblock.fs_bsize <= MAXBSIZE &&
- sblock.fs_bsize >= sizeof(struct fs))
- break;
- }
- if (sblock_try[i] == -1) {
- warn("Cannot find file system superblock");
- return (1);
+ if ((ret = sbget(fi, &fs, -1)) != 0) {
+ switch (ret) {
+ case ENOENT:
+ warn("Cannot find file system superblock");
+ return (1);
+ default:
+ warn("Unable to read file system superblock");
+ return (1);
+ }
}
+ bcopy(fs, &sblock, fs->fs_sbsize);
+ free(fs);
dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
maxino = sblock.fs_ncg * sblock.fs_ipg;
for (cg = 0; cg < sblock.fs_ncg; cg++) {
ino = cg * sblock.fs_ipg;
setinodebuf(ino);
- bread(fsbtodb(&sblock, cgtod(&sblock, cg)), (char *)(&cgblk),
+ blkread(fsbtodb(&sblock, cgtod(&sblock, cg)), (char *)(&cgblk),
sblock.fs_cgsize);
if (sblock.fs_magic == FS_UFS2_MAGIC)
inosused = cgblk.cg_initediblk;
@@ -618,10 +613,10 @@ getnextinode(ino_t inumber)
lastinum += fullcnt;
}
/*
- * If bread returns an error, it will already have zeroed
+ * If blkread returns an error, it will already have zeroed
* out the buffer, so we do not need to do so here.
*/
- bread(dblk, inodebuf, size);
+ blkread(dblk, inodebuf, size);
nextinop = inodebuf;
}
dp = (union dinode *)nextinop;
@@ -680,12 +675,12 @@ freeinodebuf(void)
* Read specified disk blocks.
*/
void
-bread(ufs2_daddr_t bno, char *buf, long cnt)
+blkread(ufs2_daddr_t bno, char *buf, long cnt)
{
if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0 ||
read(fi, buf, cnt) != cnt)
- errx(1, "bread failed on block %ld", (long)bno);
+ errx(1, "blkread failed on block %ld", (long)bno);
}
/*