kern/149762: volume labels with rogue characters

Walter C. Pelissero walter at
Thu Aug 19 12:30:42 UTC 2010

jhell writes:
 > This is a hack, something that you would commonly find in Linux
 > code and is neither a proper or viable workaround for the naming of
 > labels.

That's exactly what I keep repeating my friends who run Linux and brag
about features they had first or better implemented.  Just a bunch of
dirty hacks any kid would have whipped up in an afternoon if he just
had the fancy.  Just hacks.

Unfortunately they answer using terms like: self-indulgent inertia,
inconclusive arrogance, bureaucratic attitude, self-important sloth,
pompous underachiever.  Bloody Linux kids, aren't they?

This might be an hack, but in 8 years since this issue has been first
raised nobody has came up with it, so I thought I might as well do

 > Instead, using glabel(8) the admin/user can create a local label to
 > FreeBSD that does not change the original nor does it carry over to any
 > other OS that does not understand geom_label's.
 > >From the manual page:
 > label  Set up a label name for the given provider.  This is the
 >        ``automatic'' method, where metadata is stored in a provider's
 >        last sector.  The kernel module geom_label.ko will be loaded if
 >        it is not loaded already.

Can anyone explain me how metadata stored on media cannot interfere
with other OSs?

Below I include a revised patch that turns kern.geom.label.sanitation
into a bitmask, thus allowing to enable selectively the replacements,
as I have been struck by the fact that slashes in labels might be
desirable, as they create a path (although the parent directory is
left behind after the device disappearance).

Now kern.geom.label.sanitation can be set to zero (default) obtaining
the usual behaviour without "hack".  So that when I meet up with some
Vogon friends, who coincidentally all run exclusively FreeBSD or VMS,
I can revert the sysctl and show them their volume labels coded in
UTF-16.  Well, yes, "show".  Typing those labels at the shell prompt
is another story altogether, but at least they won't scoff at me as if
I was a Linux hacker!

Index: g_label.c
RCS file: /repos/src/sys/geom/label/g_label.c,v
retrieving revision
diff -c -r1.24.2.4 g_label.c
*** g_label.c	22 Jun 2010 08:17:20 -0000
--- g_label.c	19 Aug 2010 11:27:13 -0000
*** 136,141 ****
--- 136,161 ----
  	return (1);
+ static int sanitation_mask = 0;
+ SYSCTL_INT(_kern_geom_label, OID_AUTO, sanitation, CTLFLAG_RW,
+ 	   &sanitation_mask, 0,
+ 	   "Correction applied to labels.  A bitmask of: 0 = none, 1 = replace '/'s, 2 = replace whitespace and ctrls, 4 = replace anything beyond '~'");
+ static void
+ sanitise_name (char *name)
+ {
+ 	unsigned char *p;
+ 	for (p = name; *p; ++p) {
+ 		if ((sanitation_mask & 1) && *p == '/')
+ 			*p = '#';
+ 		else if ((sanitation_mask & 2) && *p <= ' ')
+ 			*p = '_';
+ 		else if ((sanitation_mask & 4) && *p > '~')
+ 			*p = '?';
+ 	}
+ }
  static struct g_geom *
  g_label_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
      const char *label, const char *dir, off_t mediasize)
*** 156,161 ****
--- 176,182 ----
  	gp = NULL;
  	cp = NULL;
  	snprintf(name, sizeof(name), "%s/%s", dir, label);
+ 	sanitise_name(name + strlen(dir) + 1);
  	LIST_FOREACH(gp, &mp->geom, geom) {
  		pp2 = LIST_FIRST(&gp->provider);
  		if (pp2 == NULL)

walter pelissero

More information about the freebsd-bugs mailing list