From 6654ade6e5ad8ba0c14c4a06a490fc5eb0e6ede3 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Sat, 28 Aug 2004 02:49:28 +0000 Subject: [PATCH] Warn the user if we are not going to use the whole provider's space. --- sbin/geom/class/stripe/geom_stripe.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sbin/geom/class/stripe/geom_stripe.c b/sbin/geom/class/stripe/geom_stripe.c index 9c47ef4e1019..0f23ad1354ae 100644 --- a/sbin/geom/class/stripe/geom_stripe.c +++ b/sbin/geom/class/stripe/geom_stripe.c @@ -127,10 +127,11 @@ stripe_label(struct gctl_req *req) { struct g_stripe_metadata md; intmax_t *stripesizep; + off_t compsize, msize; u_char sector[512]; + unsigned i, ssize; const char *name; char param[16]; - unsigned i; int *hardcode, *nargs, error; nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); @@ -151,10 +152,22 @@ stripe_label(struct gctl_req *req) /* * Clear last sector first to spoil all components if device exists. */ + compsize = 0; for (i = 1; i < (unsigned)*nargs; i++) { snprintf(param, sizeof(param), "arg%u", i); name = gctl_get_asciiparam(req, param); + msize = g_get_mediasize(name); + ssize = g_get_sectorsize(name); + if (msize == 0 || ssize == 0) { + gctl_error(req, "Can't get informations about %s: %s.", + name, strerror(errno)); + return; + } + msize -= ssize; + if (compsize == 0 || (compsize > 0 && msize < compsize)) + compsize = msize; + error = g_metadata_clear(name, NULL); if (error != 0) { gctl_error(req, "Can't store metadata on %s: %s.", name, @@ -187,6 +200,13 @@ stripe_label(struct gctl_req *req) snprintf(param, sizeof(param), "arg%u", i); name = gctl_get_asciiparam(req, param); + msize = g_get_mediasize(name) - g_get_sectorsize(name); + if (compsize < msize) { + fprintf(stderr, + "warning: %s: only %jd bytes from %jd bytes used.\n", + name, (intmax_t)compsize, (intmax_t)msize); + } + md.md_no = i - 1; if (!*hardcode) bzero(md.md_provider, sizeof(md.md_provider));