summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2010-09-23 10:50:17 +0000
committerpjd <pjd@FreeBSD.org>2010-09-23 10:50:17 +0000
commit1b2b33546afa49ca04d7eac70b53b0b054cf9c98 (patch)
treeb55050f04470378811333e929ce1e1b9d5a2334c /sbin
parent9a528e9595b5178c8542dbb20609cf32054da4cf (diff)
downloadFreeBSD-src-1b2b33546afa49ca04d7eac70b53b0b054cf9c98.zip
FreeBSD-src-1b2b33546afa49ca04d7eac70b53b0b054cf9c98.tar.gz
Simplify code a bit by using g_*() API from libgeom.
MFC after: 1 week
Diffstat (limited to 'sbin')
-rw-r--r--sbin/geom/class/eli/geom_eli.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/sbin/geom/class/eli/geom_eli.c b/sbin/geom/class/eli/geom_eli.c
index 9c01652..7078632 100644
--- a/sbin/geom/class/eli/geom_eli.c
+++ b/sbin/geom/class/eli/geom_eli.c
@@ -1268,7 +1268,7 @@ eli_resize(struct gctl_req *req)
struct g_eli_metadata md;
const char *prov;
unsigned char *sector;
- unsigned secsize;
+ ssize_t secsize;
off_t mediasize, oldsize;
int nargs, provfd;
@@ -1283,21 +1283,15 @@ eli_resize(struct gctl_req *req)
sector = NULL;
secsize = 0;
- provfd = open(prov, O_RDWR);
- if (provfd == -1 && errno == ENOENT && prov[0] != '/') {
- char devprov[MAXPATHLEN];
-
- snprintf(devprov, sizeof(devprov), "%s%s", _PATH_DEV, prov);
- provfd = open(devprov, O_RDWR);
- }
+ provfd = g_open(prov, 1);
if (provfd == -1) {
gctl_error(req, "Cannot open %s: %s.", prov, strerror(errno));
goto out;
}
- mediasize = g_get_mediasize(prov);
- secsize = g_get_sectorsize(prov);
- if (mediasize == 0 || secsize == 0) {
+ mediasize = g_mediasize(provfd);
+ secsize = g_sectorsize(provfd);
+ if (mediasize == -1 || secsize == -1) {
gctl_error(req, "Cannot get information about %s: %s.", prov,
strerror(errno));
goto out;
@@ -1316,8 +1310,7 @@ eli_resize(struct gctl_req *req)
}
/* Read metadata from the 'oldsize' offset. */
- if (pread(provfd, sector, secsize, oldsize - secsize) !=
- (ssize_t)secsize) {
+ if (pread(provfd, sector, secsize, oldsize - secsize) != secsize) {
gctl_error(req, "Cannot read old metadata: %s.",
strerror(errno));
goto out;
@@ -1344,23 +1337,21 @@ eli_resize(struct gctl_req *req)
*/
md.md_provsize = mediasize;
eli_metadata_encode(&md, sector);
- if (pwrite(provfd, sector, secsize, mediasize - secsize) !=
- (ssize_t)secsize) {
+ if (pwrite(provfd, sector, secsize, mediasize - secsize) != secsize) {
gctl_error(req, "Cannot write metadata: %s.", strerror(errno));
goto out;
}
/* Now trash the old metadata. */
arc4rand(sector, secsize);
- if (pwrite(provfd, sector, secsize, oldsize - secsize) !=
- (ssize_t)secsize) {
+ if (pwrite(provfd, sector, secsize, oldsize - secsize) != secsize) {
gctl_error(req, "Failed to clobber old metadata: %s.",
strerror(errno));
goto out;
}
out:
- if (provfd > 0)
- close(provfd);
+ if (provfd >= 0)
+ (void)g_close(provfd);
if (sector != NULL) {
bzero(sector, secsize);
free(sector);
OpenPOWER on IntegriCloud