oops... attached wrong patch. now with right patch...
On Mon, Jul 29, 2019 at 11:59 AM enh <[email protected]> wrote:
>
> This gets the tests passing on the host too, with util-linux 2.32.1
> blkid at least, except for the fact that we still don't support ntfs'
> $VOLUME_NAME attribute. Chasing that is quite a bit more work, and it's
> time I admitted to myself I'm unlikely to get round to it and just send
> this patch as is. "Half an eye is better than no eye".
> ---
> tests/blkid.test | 10 +++++-----
> toys/other/blkid.c | 43 ++++++++++++++++++++++++++++++-------------
> 2 files changed, 35 insertions(+), 18 deletions(-)
From 95af7ceb5a10fc3365c20ab47af9f029a1ad2f01 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Mon, 29 Jul 2019 11:55:07 -0700
Subject: [PATCH] blkid: add SEC_TYPE, f2fs LABEL, and fix vfat/ntfs UUID.
This gets the tests passing on the host too, with util-linux 2.32.1
blkid at least, except for the fact that we still don't support ntfs'
$VOLUME_NAME attribute. Chasing that is quite a bit more work, and it's
time I admitted to myself I'm unlikely to get round to it and just send
this patch as is. "Half an eye is better than no eye".
---
tests/blkid.test | 10 +++++-----
toys/other/blkid.c | 43 ++++++++++++++++++++++++++++++-------------
2 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/tests/blkid.test b/tests/blkid.test
index 436a0950..a669092d 100755
--- a/tests/blkid.test
+++ b/tests/blkid.test
@@ -17,24 +17,24 @@ testing "ext2" "BLKID ext2" \
'temp.img: LABEL="myext2" UUID="e59093ba-4135-4fdb-bcc4-f20beae4dfaf" TYPE="ext2"\n' \
"" ""
testing "ext3" "BLKID ext3" \
- 'temp.img: LABEL="myext3" UUID="79d1c877-1a0f-4e7d-b21d-fc32ae3ef101" TYPE="ext3"\n' \
+ 'temp.img: LABEL="myext3" UUID="79d1c877-1a0f-4e7d-b21d-fc32ae3ef101" SEC_TYPE="ext2" TYPE="ext3"\n' \
"" ""
testing "ext4" "BLKID ext4" \
'temp.img: LABEL="myext4" UUID="dc4b7c00-c0c0-4600-af7e-0335f09770fa" TYPE="ext4"\n' \
"" ""
testing "f2fs" "BLKID f2fs" \
- 'temp.img: UUID="b53d3619-c204-4c0b-8504-36363578491c" TYPE="f2fs"\n' \
+ 'temp.img: LABEL="myf2fs" UUID="b53d3619-c204-4c0b-8504-36363578491c" TYPE="f2fs"\n' \
"" ""
testing "msdos" "BLKID msdos" \
- 'temp.img: LABEL="mymsdos" UUID="5108-1e6e" TYPE="vfat"\n' "" ""
+ 'temp.img: SEC_TYPE="msdos" LABEL="mymsdos" UUID="6E1E-0851" TYPE="vfat"\n' "" ""
testing "ntfs" "BLKID ntfs" \
- 'temp.img: UUID="8585600838bfe16e" TYPE="ntfs"\n' "" ""
+ 'temp.img: UUID="6EE1BF3808608585" TYPE="ntfs"\n' "" ""
testing "reiserfs" "BLKID reiser3" \
'temp.img: LABEL="myreiser" UUID="a5b99bec-45cc-41d7-986e-32f4b6fc28f2" TYPE="reiserfs"\n' \
"" ""
testing "squashfs" "BLKID squashfs" 'temp.img: TYPE="squashfs"\n' "" ""
testing "vfat" "BLKID vfat" \
- 'temp.img: LABEL="myvfat" UUID="1db9-5673" TYPE="vfat"\n' "" ""
+ 'temp.img: SEC_TYPE="msdos" LABEL="myvfat" UUID="7356-B91D" TYPE="vfat"\n' "" ""
testing "xfs" "BLKID xfs" \
'temp.img: 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 38559981..eecbffe3 100644
--- a/toys/other/blkid.c
+++ b/toys/other/blkid.c
@@ -39,13 +39,13 @@ struct fstype {
{"swap", 0x4341505350415753LL, 8, 4086, 1036, 15, 1052},
// NTFS label actually 8/16 0x4d80 but horrible: 16 bit wide characters via
// codepage, something called a uuid that's only 8 bytes long...
- {"ntfs", 0x5346544e, 4, 3, 0x48+(8<<24), 0, 0},
+ {"ntfs", 0x5346544e, 4, 3, 0x48, 0, 0},
{"adfs", 0xadf5, 2, 0xc00, 0,0,0},
{"bfs", 0x1badface, 4, 0, 0,0,0},
{"btrfs", 0x4D5F53665248425FULL, 8, 65600, 65803, 256, 65819},
{"cramfs", 0x28cd3d45, 4, 0, 0, 16, 48},
- {"f2fs", 0xF2F52010, 4, 1024, 1132, 16, 1110},
+ {"f2fs", 0xF2F52010, 4, 1024, 1132, 512, 0x47c},
{"jfs", 0x3153464a, 4, 32768, 32920, 16, 32904},
{"nilfs", 0x3434, 2, 1030, 1176, 80, 1192},
{"reiserfs", 0x724573496552ULL, 6, 8244, 8276, 16, 8292},
@@ -54,8 +54,8 @@ struct fstype {
{"squashfs", 0x73717368, 4, 0, 0,0,0},
{"xiafs", 0x012fd16d, 4, 572, 0,0,0},
{"xfs", 0x42534658, 4, 0, 32, 12, 108},
- {"vfat", 0x3233544146ULL, 5, 82, 67+(4<<24), 11, 71}, // fat32
- {"vfat", 0x31544146, 4, 54, 39+(4<<24), 11, 43} // fat1
+ {"vfat", 0x3233544146ULL, 5, 82, 67, 11, 71}, // fat32
+ {"vfat", 0x31544146, 4, 54, 39, 11, 43} // fat1
};
static void flagshow(char *s, char *name)
@@ -112,8 +112,6 @@ static void do_blkid(int fd, char *name)
if (toybuf[1120]&64) type = "ext4";
}
- // Could special case NTFS here...
-
// Output for fstype
if (*toys.which->name == 'f') {
puts(type);
@@ -127,11 +125,21 @@ static void do_blkid(int fd, char *name)
if (!FLAG(U) && len) {
s = toybuf+fstypes[i].label_off-off;
if (!strcmp(type, "vfat")) {
+ printf(" SEC_TYPE=\"msdos\"");
while (len && s[len-1]==' ') len--;
if (strstart(&s, "NO NAME")) len=0;
}
- if (len && *s) {
- sprintf(buf, "%.*s", len, s);
+ // TODO: special case NTFS $VOLUME_NAME here...
+ if (len) {
+ if (!strcmp(type, "f2fs")) {
+ // Convert UTF16LE to ASCII by replacing non-ASCII with '?'.
+ // TODO: support non-ASCII.
+ for (j=0; j<len; j++) {
+ buf[j] = s[2*j];
+ if (s[2*j+1]) buf[j]='?';
+ if (!buf[j]) break;
+ }
+ } else sprintf(buf, "%.*s", len, s);
if (FLAG(L)) return flagshow(buf, name);
printf(" LABEL=\"%s\"", buf);
}
@@ -139,18 +147,27 @@ static void do_blkid(int fd, char *name)
len = fstypes[i].uuid_off;
if (!FLAG(L) && len) {
- int bits = 0x550, size = len >> 24, uoff = (len&((1<<24)-1))-off;
+ int uoff = len-off;
// Assemble UUID with whatever size and set of dashes this filesystem uses
- if (size) bits = 4*(size == 4);
- else size = 16;
- for (j = 0, s = buf; j < size; j++)
- s += sprintf(s, "-%02x"+!(bits & (1<<j)), toybuf[uoff+j]);
+ s = buf;
+ if (!strcmp(type, "ntfs")) {
+ for (j = 7; j >= 0; --j) s += sprintf(s, "%02X", toybuf[uoff+j]);
+ } else if (!strcmp(type, "vfat")) {
+ s += sprintf(s, "%02X%02X-%02X%02X", toybuf[uoff+3], toybuf[uoff+2],
+ toybuf[uoff+1], toybuf[uoff]);
+ } else {
+ for (j = 0; j < 16; j++)
+ s += sprintf(s, "-%02x"+!(0x550 & (1<<j)), toybuf[uoff+j]);
+ }
if (FLAG(U)) return flagshow(buf, name);
printf(" UUID=\"%s\"", buf);
}
+ if ((!strcmp(type, "ext3")||!strcmp(type,"ext4")) && !(toybuf[1120]&~0x12))
+ printf(" SEC_TYPE=\"ext2\"");
+
if (toys.optflags) return;
printf(" TYPE=\"%s\"\n", type);
--
2.22.0.709.g102302147b-goog
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net