Date: Thu, 23 Sep 2010 11:04:50 +0000 (UTC) From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r213059 - head/sbin/geom/class/eli Message-ID: <201009231104.o8NB4oXl066860@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pjd Date: Thu Sep 23 11:04:50 2010 New Revision: 213059 URL: http://svn.freebsd.org/changeset/base/213059 Log: - Use g_*() API when doing backups. - fsync() created filed. MFC after: 1 week Modified: head/sbin/geom/class/eli/geom_eli.c Modified: head/sbin/geom/class/eli/geom_eli.c ============================================================================== --- head/sbin/geom/class/eli/geom_eli.c Thu Sep 23 10:58:13 2010 (r213058) +++ head/sbin/geom/class/eli/geom_eli.c Thu Sep 23 11:04:50 2010 (r213059) @@ -1081,8 +1081,8 @@ static int eli_backup_create(struct gctl_req *req, const char *prov, const char *file) { struct g_eli_metadata md; - unsigned secsize; unsigned char *sector; + ssize_t secsize; off_t mediasize; int filefd, provfd, ret; @@ -1091,13 +1091,7 @@ eli_backup_create(struct gctl_req *req, sector = NULL; secsize = 0; - provfd = open(prov, O_RDONLY); - if (provfd == -1 && errno == ENOENT && prov[0] != '/') { - char devprov[MAXPATHLEN]; - - snprintf(devprov, sizeof(devprov), "%s%s", _PATH_DEV, prov); - provfd = open(devprov, O_RDONLY); - } + provfd = g_open(prov, 0); if (provfd == -1) { gctl_error(req, "Cannot open %s: %s.", prov, strerror(errno)); goto out; @@ -1108,9 +1102,9 @@ eli_backup_create(struct gctl_req *req, 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 informations about %s: %s.", prov, strerror(errno)); goto out; @@ -1123,8 +1117,7 @@ eli_backup_create(struct gctl_req *req, } /* Read metadata from the provider. */ - if (pread(provfd, sector, secsize, mediasize - secsize) != - (ssize_t)secsize) { + if (pread(provfd, sector, secsize, mediasize - secsize) != secsize) { gctl_error(req, "Cannot read metadata: %s.", strerror(errno)); goto out; } @@ -1134,18 +1127,19 @@ eli_backup_create(struct gctl_req *req, goto out; } /* Write metadata to the destination file. */ - if (write(filefd, sector, secsize) != (ssize_t)secsize) { + if (write(filefd, sector, secsize) != secsize) { gctl_error(req, "Cannot write to %s: %s.", file, strerror(errno)); goto out; } + (void)fsync(filefd); /* Success. */ ret = 0; out: - if (provfd > 0) - close(provfd); - if (filefd > 0) - close(filefd); + if (provfd >= 0) + (void)g_close(provfd); + if (filefd >= 0) + (void)close(filefd); if (sector != NULL) { bzero(sector, secsize); free(sector);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201009231104.o8NB4oXl066860>