[Toybox] [PATCH 2/2] blkid: Handle short/empty vfat labels; update tests

samuel at sholland.org samuel at sholland.org
Sun Mar 20 11:13:22 PDT 2016


From: Samuel Holland <samuel at sholland.org>

vfat labels have a fixed space allocated for them. In the case of a
shorter label, the remaining bytes are padded with spaces. A vfat
filesystem with no label (i.e. that will show up in Windows as "Local
Disk (X:)" or "Removable Disk (X:)") is stored as "NO NAME    ".

Both of these changes match behavior from util-linux.
---
 tests/blkid.test   |  4 ++--
 toys/other/blkid.c | 14 +++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/tests/blkid.test b/tests/blkid.test
index 9cde489..c99b2a4 100755
--- a/tests/blkid.test
+++ b/tests/blkid.test
@@ -25,7 +25,7 @@ testing "f2fs" 'bzcat "$BDIR"/f2fs.bz2 | blkid -' \
   '-: LABEL="" UUID="b53d3619-c204-4c0b-8504-36363578491c" TYPE="f2fs"\n' \
   "" ""
 testing "msdos" 'bzcat "$BDIR"/msdos.bz2 | blkid -' \
-  '-: LABEL="mymsdos    " UUID="5108-1e6e" TYPE="vfat"\n' "" ""
+  '-: LABEL="mymsdos" UUID="5108-1e6e" TYPE="vfat"\n' "" ""
 testing "ntfs" 'bzcat "$BDIR"/ntfs.bz2 | blkid -' \
   '-: UUID="8585600838bfe16e" TYPE="ntfs"\n' "" ""
 testing "reiserfs" 'bzcat "$BDIR"/reiser3.bz2 | blkid -' \
@@ -34,7 +34,7 @@ testing "reiserfs" 'bzcat "$BDIR"/reiser3.bz2 | blkid -' \
 testing "squashfs" 'bzcat "$BDIR"/squashfs.bz2 | blkid -' \
   '-: TYPE="squashfs"\n' "" ""
 testing "vfat" 'bzcat "$BDIR"/vfat.bz2 | blkid -' \
-  '-: LABEL="myvfat     " UUID="1db9-5673" TYPE="vfat"\n' "" ""
+  '-: LABEL="myvfat" UUID="1db9-5673" TYPE="vfat"\n' "" ""
 testing "xfs" 'bzcat "$BDIR"/xfs.bz2 | blkid -' \
   '-: LABEL="XFS_test" UUID="d63a1dc3-27d5-4dd4-8b38-f4f97f495c6f" TYPE="xfs"\n' \
   "" ""
diff --git a/toys/other/blkid.c b/toys/other/blkid.c
index 2880812..c701c80 100644
--- a/toys/other/blkid.c
+++ b/toys/other/blkid.c
@@ -115,9 +115,17 @@ static void do_blkid(int fd, char *name)
   // output for blkid
   printf("%s:",name);
 
-  if (fstypes[i].label_len)
-    printf(" LABEL=\"%.*s\"", fstypes[i].label_len,
-           toybuf+fstypes[i].label_off-off);
+  if (fstypes[i].label_len) {
+    int label_len = fstypes[i].label_len, loff = fstypes[i].label_off-off;
+    if (!strcmp(fstypes[i].name, "vfat")) {
+      if (!strncmp(toybuf+loff, "NO NAME    ", label_len))
+        label_len=0;
+      else while (toybuf[loff+label_len-1] == ' ')
+        label_len--;
+    }
+    if (label_len)
+      printf(" LABEL=\"%.*s\"", label_len, toybuf+loff);
+  }
 
   if (fstypes[i].uuid_off) {
     int bits = 0x550, size = fstypes[i].uuid_off >> 24,
-- 
2.7.3


 1458497602.0


More information about the Toybox mailing list