aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2018-01-26 00:58:32 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2018-01-26 00:58:32 +0000
commitdffce2150eeac1c7f424324a5cade7a97b308979 (patch)
tree3de8c223a1cb007078f3bb3e3c062127eb1b80a8 /usr.sbin
parenta99028fc70be602db425c092b70dd0221e253bb3 (diff)
Notes
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/fstyp/Makefile2
-rw-r--r--usr.sbin/fstyp/ufs.c71
-rw-r--r--usr.sbin/quot/Makefile1
-rw-r--r--usr.sbin/quot/quot.c37
4 files changed, 26 insertions, 85 deletions
diff --git a/usr.sbin/fstyp/Makefile b/usr.sbin/fstyp/Makefile
index 34be663fc362..f3fb038ed542 100644
--- a/usr.sbin/fstyp/Makefile
+++ b/usr.sbin/fstyp/Makefile
@@ -37,7 +37,7 @@ CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/head
CFLAGS+=-I${SRCTOP}/sys
-LIBADD= geom md
+LIBADD= geom md ufs
.if ${MK_ZFS} != "no"
LIBADD+=nvpair zfs
diff --git a/usr.sbin/fstyp/ufs.c b/usr.sbin/fstyp/ufs.c
index 8b27ca00fe43..340119dada4c 100644
--- a/usr.sbin/fstyp/ufs.c
+++ b/usr.sbin/fstyp/ufs.c
@@ -33,77 +33,32 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
+
+#include <errno.h>
+#include <libufs.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ufs/ufs/dinode.h>
-#include <ufs/ffs/fs.h>
-
#include "fstyp.h"
-static const int superblocks[] = SBLOCKSEARCH;
-
int
fstyp_ufs(FILE *fp, char *label, size_t labelsize)
{
- int sb, superblock;
struct fs *fs;
- /*
- * Walk through the standard places that superblocks hide and look
- * for UFS magic. If we find magic, then check that the size in the
- * superblock corresponds to the size of the underlying provider.
- * Finally, look for a volume label and create an appropriate
- * provider based on that.
- */
- for (sb = 0; (superblock = superblocks[sb]) != -1; sb++) {
- fs = (struct fs *)read_buf(fp, superblock, SBLOCKSIZE);
- if (fs == NULL)
- continue;
- /*
- * Check for magic. We also need to check if file system size is equal
- * to providers size, because sysinstall(8) used to bogusly put first
- * partition at offset 0 instead of 16, and glabel/ufs would find file
- * system on slice instead of partition.
- */
-#ifdef notyet
- if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_fsize > 0 &&
- ((pp->mediasize / fs->fs_fsize == fs->fs_old_size) ||
- (pp->mediasize / fs->fs_fsize == fs->fs_providersize))) {
- /* Valid UFS1. */
- } else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0 &&
- ((pp->mediasize / fs->fs_fsize == fs->fs_size) ||
- (pp->mediasize / fs->fs_fsize == fs->fs_providersize))) {
- /* Valid UFS2. */
- } else {
- g_free(fs);
- continue;
- }
-#else
- if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_fsize > 0) {
- /* Valid UFS1. */
- } else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0) {
- /* Valid UFS2. */
- } else {
- free(fs);
- continue;
- }
-#endif
-
- if (fs->fs_sblockloc != superblock || fs->fs_ncg < 1 ||
- fs->fs_bsize < MINBSIZE ||
- (size_t)fs->fs_bsize < sizeof(struct fs)) {
- free(fs);
- continue;
- }
-
+ switch (sbget(fileno(fp), &fs, -1)) {
+ case 0:
strlcpy(label, fs->fs_volname, labelsize);
-
- free(fs);
return (0);
+ case ENOENT:
+ /* Cannot find file system superblock */
+ return (1);
+ default:
+ /* Unable to read file system superblock */
+ return (1);
}
-
- return (1);
}
diff --git a/usr.sbin/quot/Makefile b/usr.sbin/quot/Makefile
index 07bcc7eff1cf..3ec74b02ce5c 100644
--- a/usr.sbin/quot/Makefile
+++ b/usr.sbin/quot/Makefile
@@ -2,6 +2,7 @@
PROG= quot
MAN= quot.8
+LIBADD= ufs
WARNS?= 2
diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c
index 49822e4d84ad..348946ff7dbb 100644
--- a/usr.sbin/quot/quot.c
+++ b/usr.sbin/quot/quot.c
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
#include <fcntl.h>
#include <fstab.h>
#include <errno.h>
+#include <libufs.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
@@ -535,16 +536,10 @@ usage(void)
exit(1);
}
-/*
- * Possible superblock locations ordered from most to least likely.
- */
-static int sblock_try[] = SBLOCKSEARCH;
-static char superblock[SBLOCKSIZE];
-
void
quot(char *name, char *mp)
{
- int i, fd;
+ int fd;
struct fs *fs;
get_inode(-1, NULL, 0); /* flush cache */
@@ -555,25 +550,15 @@ quot(char *name, char *mp)
close(fd);
return;
}
- for (i = 0; sblock_try[i] != -1; i++) {
- if (lseek(fd, sblock_try[i], 0) != sblock_try[i]) {
- close(fd);
- return;
- }
- if (read(fd, superblock, SBLOCKSIZE) != SBLOCKSIZE) {
- close(fd);
- return;
- }
- fs = (struct fs *)superblock;
- 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) {
- warnx("%s: not a BSD filesystem",name);
+ switch (sbget(fd, &fs, -1)) {
+ case 0:
+ break;
+ case ENOENT:
+ warn("Cannot find file system superblock");
+ close(fd);
+ return;
+ default:
+ warn("Unable to read file system superblock");
close(fd);
return;
}