Simplify code a bit by using g_*() API from libgeom.
MFC after: 1 week
This commit is contained in:
parent
5e6dce4bf0
commit
5cd61a1fb7
@ -1268,7 +1268,7 @@ eli_resize(struct gctl_req *req)
|
|||||||
struct g_eli_metadata md;
|
struct g_eli_metadata md;
|
||||||
const char *prov;
|
const char *prov;
|
||||||
unsigned char *sector;
|
unsigned char *sector;
|
||||||
unsigned secsize;
|
ssize_t secsize;
|
||||||
off_t mediasize, oldsize;
|
off_t mediasize, oldsize;
|
||||||
int nargs, provfd;
|
int nargs, provfd;
|
||||||
|
|
||||||
@ -1283,21 +1283,15 @@ eli_resize(struct gctl_req *req)
|
|||||||
sector = NULL;
|
sector = NULL;
|
||||||
secsize = 0;
|
secsize = 0;
|
||||||
|
|
||||||
provfd = open(prov, O_RDWR);
|
provfd = g_open(prov, 1);
|
||||||
if (provfd == -1 && errno == ENOENT && prov[0] != '/') {
|
|
||||||
char devprov[MAXPATHLEN];
|
|
||||||
|
|
||||||
snprintf(devprov, sizeof(devprov), "%s%s", _PATH_DEV, prov);
|
|
||||||
provfd = open(devprov, O_RDWR);
|
|
||||||
}
|
|
||||||
if (provfd == -1) {
|
if (provfd == -1) {
|
||||||
gctl_error(req, "Cannot open %s: %s.", prov, strerror(errno));
|
gctl_error(req, "Cannot open %s: %s.", prov, strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
mediasize = g_get_mediasize(prov);
|
mediasize = g_mediasize(provfd);
|
||||||
secsize = g_get_sectorsize(prov);
|
secsize = g_sectorsize(provfd);
|
||||||
if (mediasize == 0 || secsize == 0) {
|
if (mediasize == -1 || secsize == -1) {
|
||||||
gctl_error(req, "Cannot get information about %s: %s.", prov,
|
gctl_error(req, "Cannot get information about %s: %s.", prov,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
@ -1316,8 +1310,7 @@ eli_resize(struct gctl_req *req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read metadata from the 'oldsize' offset. */
|
/* Read metadata from the 'oldsize' offset. */
|
||||||
if (pread(provfd, sector, secsize, oldsize - secsize) !=
|
if (pread(provfd, sector, secsize, oldsize - secsize) != secsize) {
|
||||||
(ssize_t)secsize) {
|
|
||||||
gctl_error(req, "Cannot read old metadata: %s.",
|
gctl_error(req, "Cannot read old metadata: %s.",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
@ -1344,23 +1337,21 @@ eli_resize(struct gctl_req *req)
|
|||||||
*/
|
*/
|
||||||
md.md_provsize = mediasize;
|
md.md_provsize = mediasize;
|
||||||
eli_metadata_encode(&md, sector);
|
eli_metadata_encode(&md, sector);
|
||||||
if (pwrite(provfd, sector, secsize, mediasize - secsize) !=
|
if (pwrite(provfd, sector, secsize, mediasize - secsize) != secsize) {
|
||||||
(ssize_t)secsize) {
|
|
||||||
gctl_error(req, "Cannot write metadata: %s.", strerror(errno));
|
gctl_error(req, "Cannot write metadata: %s.", strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now trash the old metadata. */
|
/* Now trash the old metadata. */
|
||||||
arc4rand(sector, secsize);
|
arc4rand(sector, secsize);
|
||||||
if (pwrite(provfd, sector, secsize, oldsize - secsize) !=
|
if (pwrite(provfd, sector, secsize, oldsize - secsize) != secsize) {
|
||||||
(ssize_t)secsize) {
|
|
||||||
gctl_error(req, "Failed to clobber old metadata: %s.",
|
gctl_error(req, "Failed to clobber old metadata: %s.",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
if (provfd > 0)
|
if (provfd >= 0)
|
||||||
close(provfd);
|
(void)g_close(provfd);
|
||||||
if (sector != NULL) {
|
if (sector != NULL) {
|
||||||
bzero(sector, secsize);
|
bzero(sector, secsize);
|
||||||
free(sector);
|
free(sector);
|
||||||
|
Loading…
Reference in New Issue
Block a user