UFS label limitations
Rick C. Petty
rick-freebsd2008 at kiwi-computer.com
Sat Dec 13 09:39:03 PST 2008
I always found it strange that when creating or changing a UFS label, you
were restricted to alphanumeric characters. I really wanted some sort of
separator, so I took a look at the code. Since the checks use isalnum(3)
it is possible to create labels that are not 7-bit clean, depending upon
your locale. After further investigation, I can't see any reason (in
geom_label or otherwise) that the characters should be restricted in such
a way.
I applied the attached (inline) patch and have had no troubles creating,
editing, or mounting via UFS labels. The patch allows you to create
labels with any characters except '/' (for obvious reasons) and should
work with most locales (with the tiny exception that multibyte characters
which use 0x2F in subsequent bytes should be rejected, since geom_label
is locale-agnostic).
Would someone mind reviewing and committing this patch? Thank you,
-- Rick C. Petty
--- src/sbin/newfs/newfs.c.orig 2007-03-02 14:07:59.000000000 -0600
+++ src/sbin/newfs/newfs.c 2008-12-12 19:13:19.000000000 -0600
@@ -168,11 +168,10 @@
case 'L':
volumelabel = optarg;
i = -1;
- while (isalnum(volumelabel[++i]));
- if (volumelabel[i] != '\0') {
- errx(1, "bad volume label. Valid characters are alphanumerics.");
- }
- if (strlen(volumelabel) >= MAXVOLLEN) {
+ while ((ch = volumelabel[++i]) != '\0')
+ if (ch == '/')
+ errx(1, "bad volume label. \"/\" not allowed.");
+ if (i >= MAXVOLLEN) {
errx(1, "bad volume label. Length is longer than %d.",
MAXVOLLEN);
}
--- src/sbin/tunefs/tunefs.c.orig 2008-02-26 14:25:35.000000000 -0600
+++ src/sbin/tunefs/tunefs.c 2008-12-12 19:19:33.000000000 -0600
@@ -153,13 +153,12 @@
name = "volume label";
Lvalue = optarg;
i = -1;
- while (isalnum(Lvalue[++i]));
- if (Lvalue[i] != '\0') {
+ while ((ch = Lvalue[++i]) != '\0')
+ if (ch == '/')
errx(10,
- "bad %s. Valid characters are alphanumerics.",
+ "bad %s. \"/\" not allowed.",
name);
- }
- if (strlen(Lvalue) >= MAXVOLLEN) {
+ if (i >= MAXVOLLEN) {
errx(10, "bad %s. Length is longer than %d.",
name, MAXVOLLEN - 1);
}
More information about the freebsd-fs
mailing list