Module Name: src
Committed By: christos
Date: Mon Dec 29 16:27:43 UTC 2014
Modified Files:
src/sbin/fsck: partutil.c partutil.h
Log Message:
Provide a simple getdisksize() api for gpt(8).
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sbin/fsck/partutil.c
cvs rdiff -u -r1.2 -r1.3 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.13
--- src/sbin/fsck/partutil.c:1.12 Sat Apr 13 18:08:57 2013
+++ src/sbin/fsck/partutil.c Mon Dec 29 11:27:43 2014
@@ -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 @@ 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.3
--- src/sbin/fsck/partutil.h:1.2 Mon Apr 28 16:23:08 2008
+++ src/sbin/fsck/partutil.h Mon Dec 29 11:27:43 2014
@@ -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_ */