Lines Matching +full:- +full:- +full:add +full:- +full:label

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
48 #include <geom/label/g_label.h>
53 SYSCTL_NODE(_kern_geom, OID_AUTO, label, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
68 #define G_LABEL_DIRPREFIX "label/"
85 * To add a new file system where you want to look for volume labels,
87 * 1. Add a file g_label_<file system>.c which implements labels recognition.
88 * 2. Add an 'extern const struct g_label_desc g_label_<file system>;' into
90 * 3. Add an element to the table below '&g_label_<file system>,'.
91 * 4. Add your file to sys/conf/files.
92 * 5. Add your file to sys/modules/geom/geom_label/Makefile.
93 * 6. Add your file system to manual page sbin/geom/class/label/glabel.8.
114 g_label_rtrim(char *label, size_t size)
118 for (i = size - 1; i >= 0; i--) {
119 if (label[i] == '\0')
121 else if (label[i] == ' ')
122 label[i] = '\0';
144 G_LABEL_DEBUG(1, "Label %s removed.",
145 LIST_FIRST(&cp->geom->provider)->name);
153 G_LABEL_DEBUG(1, "Label %s removed.",
154 LIST_FIRST(&cp->geom->provider)->name);
162 G_LABEL_DEBUG(1, "Label %s resized.",
163 LIST_FIRST(&cp->geom->provider)->name);
165 g_slice_config(cp->geom, 0, G_SLICE_CONFIG_FORCE, (off_t)0,
166 cp->provider->mediasize, cp->provider->sectorsize, "notused");
170 g_label_is_name_ok(const char *label)
174 /* Check if the label starts from ../ */
175 if (strncmp(label, "../", 3) == 0)
177 /* Check if the label contains /../ */
178 if (strstr(label, "/../") != NULL)
180 /* Check if the label ends at ../ */
181 if ((s = strstr(label, "/..")) != NULL && s[3] == '\0')
187 g_label_mangle_name(char *label, size_t size)
194 len = strlen(label);
195 for (i = len; i > 0; i--) {
196 if (isspace(label[i - 1]))
197 label[i - 1] = '\0';
201 if (*label == '\0')
205 for (c = label; *c != '\0'; c++) {
215 label[0] = '\0';
217 strlcpy(label, sbuf_data(sb), size);
223 const char *label, const char *dirprefix, off_t mediasize)
232 if (!g_label_is_name_ok(label)) {
233 G_LABEL_DEBUG(0, "%s contains suspicious label, skipping.",
234 pp->name);
235 G_LABEL_DEBUG(1, "%s suspicious label is: %s", pp->name, label);
237 gctl_error(req, "Label name %s is invalid.", label);
242 if (snprintf(name, sizeof(name), "%s%s", dirprefix, label) >= sizeof(name)) {
244 gctl_error(req, "Label name %s is too long.", label);
247 LIST_FOREACH(gp, &mp->geom, geom) {
248 pp2 = LIST_FIRST(&gp->provider);
251 if ((pp2->flags & G_PF_ORPHAN) != 0)
253 if (strcmp(pp2->name, name) == 0) {
254 G_LABEL_DEBUG(1, "Label %s(%s) already exists (%s).",
255 label, name, pp->name);
265 G_LABEL_DEBUG(0, "Cannot create slice %s.", label);
267 gctl_error(req, "Cannot create slice %s.", label);
270 gp->orphan = g_label_orphan;
271 gp->spoiled = g_label_spoiled;
272 gp->resize = g_label_resize;
273 g_access(cp, -1, 0, 0);
275 pp->sectorsize, "%s", name);
276 G_LABEL_DEBUG(1, "Label for provider %s is %s.", pp->name, name);
286 pp = LIST_FIRST(&gp->provider);
287 if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
290 "can't be definitely removed.", pp->name);
293 "Provider %s is still open (r%dw%de%d).", pp->name,
294 pp->acr, pp->acw, pp->ace);
298 G_LABEL_DEBUG(1, "Label %s removed.", pp->name);
299 g_slice_spoiled(LIST_FIRST(&gp->consumer));
310 pp = cp->provider;
311 if (pp->sectorsize < sizeof(*md))
313 buf = g_read_data(cp, pp->mediasize - pp->sectorsize, pp->sectorsize,
348 g_label_generic_taste(struct g_consumer *cp, char *label, size_t size)
354 label[0] = '\0';
355 pp = cp->provider;
365 pp->name);
372 if (md.md_version >= 2 && md.md_provsize != pp->mediasize)
375 strlcpy(label, md.md_label, size);
386 g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, pp->name);
389 G_LABEL_DEBUG(2, "Tasting %s.", pp->name);
392 if (pp->acw > 0)
396 if (pp->sectorsize == 0)
399 if (strcmp(pp->geom->class->name, mp->name) == 0)
402 gp = g_new_geomf(mp, "label:taste");
403 gp->start = g_label_start_taste;
404 gp->access = g_label_access_taste;
405 gp->orphan = g_label_orphan_taste;
407 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
413 char label[128];
415 if (g_labels[i]->ld_enabled == 0)
418 g_labels[i]->ld_taste(cp, label, sizeof(label));
419 g_label_mangle_name(label, sizeof(label));
421 if (label[0] == '\0')
424 mediasize = pp->mediasize;
426 mediasize = pp->mediasize - pp->sectorsize;
428 g_label_create(NULL, mp, pp, label,
429 g_labels[i]->ld_dirprefix, mediasize);
431 g_access(cp, -1, 0, 0);
465 * arg0 is the label.
472 g_label_create(req, mp, pp, name, G_LABEL_DIRPREFIX, pp->mediasize);
483 if (strncmp(name, g_labels[i]->ld_dirprefix,
484 strlen(g_labels[i]->ld_dirprefix)) == 0) {
485 name += strlen(g_labels[i]->ld_dirprefix);
500 LIST_FOREACH(gp, &mp->geom, geom) {
501 pp = LIST_FIRST(&gp->provider);
502 pname = g_label_skip_dir(pp->name);
543 G_LABEL_DEBUG(1, "Label %s is invalid.", name);
544 gctl_error(req, "Label %s is invalid.", name);
549 gctl_error(req, "Cannot destroy label %s (error=%d).",
550 LIST_FIRST(&gp->provider)->name, error);