Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/resize_ffs Make get_dev_size work on regular files too.



details:   https://anonhg.NetBSD.org/src/rev/a0133e23a3ff
branches:  trunk
changeset: 336969:a0133e23a3ff
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Mar 28 17:22:46 2015 +0000

description:
Make get_dev_size work on regular files too.

diffstat:

 sbin/resize_ffs/resize_ffs.c |  17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diffs (48 lines):

diff -r 5b857839d4be -r a0133e23a3ff sbin/resize_ffs/resize_ffs.c
--- a/sbin/resize_ffs/resize_ffs.c      Sat Mar 28 17:08:53 2015 +0000
+++ b/sbin/resize_ffs/resize_ffs.c      Sat Mar 28 17:22:46 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: resize_ffs.c,v 1.38 2013/06/23 22:03:34 dholland Exp $ */
+/*     $NetBSD: resize_ffs.c,v 1.39 2015/03/28 17:22:46 riastradh Exp $        */
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: resize_ffs.c,v 1.38 2013/06/23 22:03:34 dholland Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.39 2015/03/28 17:22:46 riastradh Exp $");
 
 #include <sys/disk.h>
 #include <sys/disklabel.h>
@@ -2026,22 +2026,23 @@
        struct dkwedge_info dkw;
        struct partition *pp;
        struct disklabel lp;
+       struct stat st;
        size_t ptn;
 
        /* Get info about partition/wedge */
-       if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == -1) {
-               if (ioctl(fd, DIOCGDINFO, &lp) == -1)
-                       return 0;
-
+       if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == 0)
+               return dkw.dkw_size;
+       if (ioctl(fd, DIOCGDINFO, &lp) == 0) {
                ptn = strchr(dev_name, '\0')[-1] - 'a';
                if (ptn >= lp.d_npartitions)
                        return 0;
-
                pp = &lp.d_partitions[ptn];
                return pp->p_size;
        }
+       if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode))
+               return st.st_size;
 
-       return dkw.dkw_size;
+       return 0;
 }
 
 /*



Home | Main Index | Thread Index | Old Index