This adds DUID support to ncheck_ffs.
Testers? ok?
/Alexander
Index: Makefile
===================================================================
RCS file: /data/openbsd/cvs/src/sbin/ncheck_ffs/Makefile,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile
--- Makefile 29 Jun 1996 19:25:09 -0000 1.3
+++ Makefile 11 Jul 2012 13:54:01 -0000
@@ -1,6 +1,8 @@
# $OpenBSD: Makefile,v 1.3 1996/06/29 19:25:09 mickey Exp $
PROG= ncheck_ffs
+LDADD= -lutil
+DPADD= ${LIBUTIL}
MAN= ncheck_ffs.8
LINKS= ${BINDIR}/ncheck_ffs ${BINDIR}/ncheck
Index: ncheck_ffs.c
===================================================================
RCS file: /data/openbsd/cvs/src/sbin/ncheck_ffs/ncheck_ffs.c,v
retrieving revision 1.35
diff -u -p -r1.35 ncheck_ffs.c
--- ncheck_ffs.c 27 Oct 2009 23:59:33 -0000 1.35
+++ ncheck_ffs.c 11 Jul 2012 17:03:47 -0000
@@ -70,6 +70,7 @@
#include <fstab.h>
#include <errno.h>
#include <err.h>
+#include <util.h>
#define DIP(dp, field) \
((sblock->fs_magic == FS_UFS1_MAGIC) ? \
@@ -542,24 +543,33 @@ main(int argc, char *argv[])
if (optind != argc - 1 || (mflag && format))
usage();
- odisk = argv[optind];
- if (realpath(odisk, rdisk) == NULL)
- err(1, "cannot find real path for %s", odisk);
- disk = rdisk;
+ disk = argv[optind];
+ if ((diskfd = opendev(disk, O_RDONLY, 0, NULL)) == -1 &&
+ (diskfd = open(disk, O_RDONLY, 0, 0)) == -1)
+ err(1, "cannot open %s", disk);
- if (stat(disk, &stblock) < 0)
+ if (fstat(diskfd, &stblock))
err(1, "cannot stat %s", disk);
- if (S_ISBLK(stblock.st_mode)) {
- disk = rawname(disk);
- } else if (!S_ISCHR(stblock.st_mode)) {
+ if (!S_ISCHR(stblock.st_mode)) {
+ close(diskfd);
+
+ /* Try to determine device by mount point */
+ if (realpath(disk, rdisk) == NULL)
+ err(1, "cannot find real path for %s", disk);
+ disk = rdisk;
+
+ if (stat(disk, &stblock))
+ err(1, "cannot stat %s", disk);
+
if ((fsp = getfsfile(disk)) == NULL)
- err(1, "could not find file system %s", disk);
+ errx(1, "could not find file system %s", disk);
disk = rawname(fsp->fs_spec);
- }
- if ((diskfd = open(disk, O_RDONLY)) < 0)
- err(1, "cannot open %s", disk);
+ if ((diskfd = opendev(disk, O_RDONLY, 0, NULL)) == -1)
+ err(1, "cannot open %s", disk);
+ }
+
sblock = (struct fs *)sblock_buf;
for (i = 0; sblock_try[i] != -1; i++) {
n = pread(diskfd, sblock, SBLOCKSIZE, (off_t)sblock_try[i]);