Re: ncheck_ffs DUID support

2012-07-13 Thread Jan Stary
On Jul 13 11:54:11, Alexander Hall wrote:
> On 07/12/12 22:55, Alexander Hall wrote:
> > 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 /tmpffs 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?
> Bah, fix indendation from spaces to tabs.
> Comments? OK?

Now all of the following work:

ncheck_ffs /dev/wd0n
ncheck_ffs /dev/rwd0n
ncheck_ffs 5d2ade1fc5a8d569.n
ncheck_ffs /tmp


Jan


> 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 -  1.3
> +++ Makefile  11 Jul 2012 13:54:01 -
> @@ -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 -  1.35
> +++ ncheck_ffs.c  13 Jul 2012 09:34:40 -
> @@ -542,24 +542,34 @@ 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;
>  
>   if (stat(disk, &stblock) < 0)
>   err(1, "cannot stat %s", disk);
>  
> -if (S_ISBLK(stblock.st_mode)) {
> + if (S_ISBLK(stblock.st_mode)) {
>   disk = rawname(disk);
>   } else if (!S_ISCHR(stblock.st_mode)) {
>   if ((fsp = getfsfile(disk)) == NULL)
>   err(1, "could not find file system %s", disk);
> -disk = rawname(fsp->fs_spec);
> -}
> + 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]);



Re: ncheck_ffs DUID support

2012-07-13 Thread Alexander Hall
On 07/12/12 22:55, Alexander Hall wrote:
> 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?

Bah, fix indendation from spaces to tabs.

Comments? 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
--- Makefile29 Jun 1996 19:25:09 -  1.3
+++ Makefile11 Jul 2012 13:54:01 -
@@ -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.c27 Oct 2009 23:59:33 -  1.35
+++ ncheck_ffs.c13 Jul 2012 09:34:40 -
@@ -542,24 +542,34 @@ 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;
 
if (stat(disk, &stblock) < 0)
err(1, "cannot stat %s", disk);
 
-if (S_ISBLK(stblock.st_mode)) {
+   if (S_ISBLK(stblock.st_mode)) {
disk = rawname(disk);
} else if (!S_ISCHR(stblock.st_mode)) {
if ((fsp = getfsfile(disk)) == NULL)
err(1, "could not find file system %s", disk);
-disk = rawname(fsp->fs_spec);
-}
+   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]);



Re: ncheck_ffs DUID support

2012-07-12 Thread Alexander Hall
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
--- Makefile29 Jun 1996 19:25:09 -  1.3
+++ Makefile11 Jul 2012 13:54:01 -
@@ -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.c27 Oct 2009 23:59:33 -  1.35
+++ ncheck_ffs.c12 Jul 2012 20:51:26 -
@@ -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]);



Re: ncheck_ffs DUID support

2012-07-11 Thread Jan Stary
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.


Jan



ncheck_ffs DUID support

2012-07-11 Thread Alexander Hall
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
--- Makefile29 Jun 1996 19:25:09 -  1.3
+++ Makefile11 Jul 2012 13:54:01 -
@@ -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.c27 Oct 2009 23:59:33 -  1.35
+++ ncheck_ffs.c11 Jul 2012 17:03:47 -
@@ -70,6 +70,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #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]);