Source-Changes-HG archive

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

[src/trunk]: src/sbin/fsck Provide a simple getdisksize() api for gpt(8).



details:   https://anonhg.NetBSD.org/src/rev/f17bf1923b20
branches:  trunk
changeset: 805329:f17bf1923b20
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Dec 29 16:27:43 2014 +0000

description:
Provide a simple getdisksize() api for gpt(8).

diffstat:

 sbin/fsck/partutil.c |  29 ++++++++++++++++++++++++++---
 sbin/fsck/partutil.h |   5 ++++-
 2 files changed, 30 insertions(+), 4 deletions(-)

diffs (78 lines):

diff -r 9fda0fb2fa53 -r f17bf1923b20 sbin/fsck/partutil.c
--- a/sbin/fsck/partutil.c      Mon Dec 29 16:27:06 2014 +0000
+++ b/sbin/fsck/partutil.c      Mon Dec 29 16:27:43 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: partutil.c,v 1.12 2013/04/13 22:08:57 jakllsch Exp $   */
+/*     $NetBSD: partutil.c,v 1.13 2014/12/29 16:27:43 christos Exp $   */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -30,9 +30,10 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: partutil.c,v 1.12 2013/04/13 22:08:57 jakllsch Exp $");
+__RCSID("$NetBSD: partutil.c,v 1.13 2014/12/29 16:27:43 christos Exp $");
 
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/disklabel.h>
 #include <sys/disk.h>
 #include <sys/ioctl.h>
@@ -135,8 +136,10 @@
                    "DIOCGDINFO for disk device %s", s);
        }
 
+       if (dkw == NULL)
+               return 0;
+
        /* DIOCGDINFO didn't fail */
-
        (void)memset(dkw, 0, sizeof(*dkw));
 
        if (stat(s, &sb) == -1)
@@ -161,3 +164,23 @@
 
        return 0;
 }
+
+int
+getdisksize(const char *name, u_int *secsize, off_t *mediasize)
+{
+       char buf[MAXPATHLEN];
+       struct disk_geom geo;
+       int fd, error;
+
+       if ((fd = opendisk(name, O_RDONLY, buf, sizeof(buf), 0)) == -1)
+               return -1;
+
+       error = getdiskinfo(name, fd, NULL, &geo, NULL);
+       close(fd);
+       if (error)
+               return error;
+
+       *secsize = geo.dg_secsize;
+       *mediasize = geo.dg_secsize * geo.dg_secperunit;
+       return 0;
+}
diff -r 9fda0fb2fa53 -r f17bf1923b20 sbin/fsck/partutil.h
--- a/sbin/fsck/partutil.h      Mon Dec 29 16:27:06 2014 +0000
+++ b/sbin/fsck/partutil.h      Mon Dec 29 16:27:43 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: partutil.h,v 1.2 2008/04/28 20:23:08 martin Exp $      */
+/*     $NetBSD: partutil.h,v 1.3 2014/12/29 16:27:43 christos Exp $    */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -32,8 +32,11 @@
 #define _PARTUTIL_H_
 
 __BEGIN_DECLS
+struct dkwedge_info;
+struct disk_geom;
 int getdiskinfo(const char *, int, const char *,
     struct disk_geom *, struct dkwedge_info *);
+int getdisksize(const char *, u_int *, off_t *);
 __END_DECLS
 
 #endif /* _PARTUTIL_H_ */



Home | Main Index | Thread Index | Old Index