From owner-freebsd-geom@FreeBSD.ORG Thu Aug 19 12:40:03 2010 Return-Path: Delivered-To: freebsd-geom@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 51EBD10656CB for ; Thu, 19 Aug 2010 12:40:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 3CEEE8FC16 for ; Thu, 19 Aug 2010 12:40:03 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o7JCe2sJ005866 for ; Thu, 19 Aug 2010 12:40:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o7JCe2kP005865; Thu, 19 Aug 2010 12:40:02 GMT (envelope-from gnats) Date: Thu, 19 Aug 2010 12:40:02 GMT Message-Id: <201008191240.o7JCe2kP005865@freefall.freebsd.org> To: freebsd-geom@FreeBSD.org From: walter@pelissero.de (Walter C. Pelissero) Cc: Subject: Re: kern/149762: volume labels with rogue characters X-BeenThere: freebsd-geom@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: "Walter C. Pelissero" List-Id: GEOM-specific discussions and implementations List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Aug 2010 12:40:03 -0000 The following reply was made to PR kern/149762; it has been noted by GNATS. From: walter@pelissero.de (Walter C. Pelissero) To: jhell Cc: bug-followup@FreeBSD.org, freebsd-bugs@FreeBSD.ORG Subject: Re: kern/149762: volume labels with rogue characters Date: Thu, 19 Aug 2010 14:26:26 +0200 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 it. > 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 1.24.2.4 diff -c -r1.24.2.4 g_label.c *** g_label.c 22 Jun 2010 08:17:20 -0000 1.24.2.4 --- 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 http://www.pelissero.de