Module Name:    src
Committed By:   msaitoh
Date:           Mon May 25 09:10:48 UTC 2015

Modified Files:
        src/sbin/fsck [netbsd-7]: partutil.c partutil.h

Log Message:
Pull up following revision(s) (requested by jnemeth in ticket #793):
        sbin/fsck/partutil.c: revision 1.13
        sbin/fsck/partutil.h: revision 1.3
Provide a simple getdisksize() api for gpt(8).


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.12.6.1 src/sbin/fsck/partutil.c
cvs rdiff -u -r1.2 -r1.2.40.1 src/sbin/fsck/partutil.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/fsck/partutil.c
diff -u src/sbin/fsck/partutil.c:1.12 src/sbin/fsck/partutil.c:1.12.6.1
--- src/sbin/fsck/partutil.c:1.12	Sat Apr 13 22:08:57 2013
+++ src/sbin/fsck/partutil.c	Mon May 25 09:10:48 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: partutil.c,v 1.12 2013/04/13 22:08:57 jakllsch Exp $	*/
+/*	$NetBSD: partutil.c,v 1.12.6.1 2015/05/25 09:10:48 msaitoh 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.12.6.1 2015/05/25 09:10:48 msaitoh 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 @@ getdiskinfo(const char *s, int fd, const
 		    "DIOCGDINFO for disk device %s", s);
 	}
 
-	/* DIOCGDINFO didn't fail */
+	if (dkw == NULL)
+		return 0;
 
+	/* DIOCGDINFO didn't fail */
 	(void)memset(dkw, 0, sizeof(*dkw));
 
 	if (stat(s, &sb) == -1)
@@ -161,3 +164,23 @@ getdiskinfo(const char *s, int fd, const
 
 	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;
+}

Index: src/sbin/fsck/partutil.h
diff -u src/sbin/fsck/partutil.h:1.2 src/sbin/fsck/partutil.h:1.2.40.1
--- src/sbin/fsck/partutil.h:1.2	Mon Apr 28 20:23:08 2008
+++ src/sbin/fsck/partutil.h	Mon May 25 09:10:48 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: partutil.h,v 1.2 2008/04/28 20:23:08 martin Exp $	*/
+/*	$NetBSD: partutil.h,v 1.2.40.1 2015/05/25 09:10:48 msaitoh 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_ */

Reply via email to