From c23186d3ee6001b78c843fc3609575306c687ba2 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 20 Mar 2016 11:13:22 -0700 Subject: blkid: Handle short/empty vfat labels; update tests 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. --- toys/other/blkid.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'toys/other/blkid.c') diff --git a/toys/other/blkid.c b/toys/other/blkid.c index 2880812a..c701c800 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, -- cgit v1.2.3