On 07/11/12 23:43, Jan Stary wrote:
> On Jul 11 19:18:21, Alexander Hall wrote:
>> This adds DUID support to ncheck_ffs.
>> Testers? ok?
> 
> This indeed enables ncheck_ffs for DUIDs,
> but breaks ncheck_ffs for /dev/wd0x
> 
> My fstab says
> 
> 5d2ade1fc5a8d569.n /tmp       ffs rw,softdep,nodev,nosuid     1 2
> 
> With your diff I can do 'ncheck_ffs /tmp',
> which previously said
> 
>       5d2ade1fc5a8d569.n: no such file or directory
> 
> But I can no longer do 'ncheck_ffs /dev/wd0n'
> which worked before this diff, but now says
> 
>       ncheck_ffs: cannot open /dev/wd0n: Device busy
> 
> 'ncheck_ffs /dev/rwd0n' works though.

Indeed, thanks.

Another try follows, with less entangled diff. Does it work better?

/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        12 Jul 2012 20:51:26 -0000
@@ -542,8 +542,16 @@ main(int argc, char *argv[])
        if (optind != argc - 1 || (mflag && format))
                usage();
 
-       odisk = argv[optind];
-       if (realpath(odisk, rdisk) == NULL)
+        disk = argv[optind];
+        if ((diskfd = opendev(disk, O_RDONLY, 0, NULL)) >= 0) {
+                if (fstat(diskfd, &stblock))
+                        err(1, "cannot stat %s", disk);
+                if (S_ISCHR(stblock.st_mode))
+                        goto gotdev;
+                close(diskfd);
+        }
+
+       if (realpath(disk, rdisk) == NULL)
                err(1, "cannot find real path for %s", odisk);
        disk = rdisk;
 
@@ -558,8 +566,10 @@ main(int argc, char *argv[])
                 disk = rawname(fsp->fs_spec);
         }
 
-       if ((diskfd = open(disk, O_RDONLY)) < 0)
+       if ((diskfd = opendev(disk, O_RDONLY, 0, NULL)) < 0)
                err(1, "cannot open %s", disk);
+
+gotdev:
        sblock = (struct fs *)sblock_buf;
        for (i = 0; sblock_try[i] != -1; i++) {
                n = pread(diskfd, sblock, SBLOCKSIZE, (off_t)sblock_try[i]);

Reply via email to