From owner-freebsd-bugs@FreeBSD.ORG Thu Aug 19 12:30:42 2010 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1E09310656A8; Thu, 19 Aug 2010 12:30:42 +0000 (UTC) (envelope-from walter.pelissero@iesy.net) Received: from mail01.ish.de (mailout.ish.de [80.69.98.250]) by mx1.freebsd.org (Postfix) with ESMTP id 54C3E8FC1A; Thu, 19 Aug 2010 12:30:40 +0000 (UTC) Received: from [95.222.206.96] (account walter.pelissero@iesy.net HELO zaphod.home.lan) by mail-fe-03.mail01.ish.de (CommuniGate Pro SMTP 5.2.18) with ESMTPSA id 403702132; Thu, 19 Aug 2010 14:30:38 +0200 Received: from zaphod.home.lan (localhost [127.0.0.1]) by zaphod.home.lan (8.14.4/8.14.4) with ESMTP id o7JCQQGd002665; Thu, 19 Aug 2010 14:26:26 +0200 (CEST) (envelope-from wcp@zaphod.home.lan) Received: (from wcp@localhost) by zaphod.home.lan (8.14.4/8.14.4/Submit) id o7JCQQbA002664; Thu, 19 Aug 2010 14:26:26 +0200 (CEST) (envelope-from wcp) From: walter@pelissero.de (Walter C. Pelissero) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <19565.8946.444567.257102@zaphod.home.lan> Date: Thu, 19 Aug 2010 14:26:26 +0200 To: jhell In-Reply-To: <4C6C7518.7010906@DataIX.net> References: <4C6C7518.7010906@DataIX.net> X-Mailer: VM 8.1.1 under 23.2.1 (i386-portbld-freebsd8.1) X-Attribution: WP X-For-Spammers: blacklistme@pelissero.de X-MArch-Archive-ID: 129522 X-MArch-Processing-Time: 0.47s Cc: freebsd-bugs@FreeBSD.ORG, bug-followup@FreeBSD.org Subject: Re: kern/149762: volume labels with rogue characters X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: walter@pelissero.de List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Aug 2010 12:30:42 -0000 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