Commit Diff


commit - 1abb1c5c81f95aa6b4f89c9a30117f7a68027c40
commit + 2b650bbafb20bb7ab50ebf01fe8df71ac2b15466
blob - a6eff56179843dd72fb4d75a56075ce55b88ac5c
blob + a02b9856bef290df3e828e9902cffaa26ac24240
--- ChangeLog.md
+++ ChangeLog.md
@@ -9,7 +9,17 @@ and this project adheres to [Semantic Versioning](http
 ### Added
 - Options:
   - `-a` print all fields
+  
+### Changed
+- Merge "LABEL" and "MOUNT" fields into "LABEL/MOUNT"
+  because disks can't be mounted but partitions can,
+  and disks can have a label but partitions don't
+  (at least through the disklabel interface).
 
+### Removed
+- Options:
+  - `-l`
+
 ## [1.1] - 2023-05-02
 ### Added
 - Header
blob - f5fe2aafcb81080dafe5bcc38bc2e25e6e926488
blob + 8e263e611381f89b75158489e87a707e66504496
--- README.md
+++ README.md
@@ -19,5 +19,4 @@ doas make unroot
 
 ## TODO
 - [ ] Fancy unicodes: `├─` & `└─`
-- [ ] Where should "LABEL" go? After "NAME" or before "MOUNT"?
 - [ ] `lsblk sd0`
blob - 6238bba72190c015d551b3e7f81b0c9d644e1c49
blob + 947e92a5ce56e2605e5dd19c0016587a2b7fe4ca
--- lsblk.8
+++ lsblk.8
@@ -11,7 +11,7 @@
 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-.TH LSBLK 8 lsblk-@VERSION@ 2023-05-01
+.TH LSBLK 8 lsblk-@VERSION@ 2023-05-04
 .SH NAME
 lsblk \- list block devices
 .SH SYNOPSIS
@@ -28,9 +28,6 @@ prints version information to stdout, then exit.
 .B \-a
 print all fields.
 .TP
-.B \-l
-also print the label (packname) of each disk.
-.TP
 .B \-n
 don't print the header.
 .TP
blob - 3b3d9c5531656b7a10905d542f166791bc46f6cd
blob + 136f6741171ab966b7f00d656702373e038a37b3
--- lsblk.c
+++ lsblk.c
@@ -133,14 +133,13 @@ static void print_size (uint64_t sz)
 
 enum {
     FIELD_NAME  = 0x01,
-    FIELD_LABEL = 0x02,
-    FIELD_SIZE  = 0x04,
-    FIELD_USED  = 0x08,
-    FIELD_FREE  = 0x10,
-    FIELD_TYPE  = 0x20,
-    FIELD_MOUNT = 0x40,
+    FIELD_SIZE  = 0x02,
+    FIELD_USED  = 0x04,
+    FIELD_FREE  = 0x08,
+    FIELD_TYPE  = 0x10,
+    FIELD_LMNT  = 0x20,
 
-    FIELD_DEFAULT = FIELD_NAME | FIELD_SIZE | FIELD_TYPE | FIELD_MOUNT,
+    FIELD_DEFAULT   = FIELD_NAME | FIELD_SIZE | FIELD_TYPE | FIELD_LMNT,
 };
 
 struct my_partinfo {
@@ -158,7 +157,6 @@ struct my_diskinfo {
     char name[4];
     uint64_t size;
     uint64_t used;
-    const char *mount;
     uint8_t num_parts;
     struct my_partinfo parts[MAXPARTITIONS];
 };
@@ -168,9 +166,6 @@ static void print_header (int fields)
     if (fields & FIELD_NAME)
         printf ("%-6s ", "NAME");
 
-    if (fields & FIELD_LABEL)
-        printf ("%-16s ", "LABEL");
-
     if (fields & FIELD_SIZE)
         printf ("%-4s ", "SIZE");
 
@@ -183,8 +178,8 @@ static void print_header (int fields)
     if (fields & FIELD_TYPE)
         printf ("%-8s ", "TYPE");
 
-    if (fields & FIELD_MOUNT)
-        printf ("MOUNT ");
+    if (fields & FIELD_LMNT)
+        printf ("LABEL/MOUNT ");
 
     putchar ('\n');
 }
@@ -194,9 +189,6 @@ static void print_part (const struct my_partinfo *part
     if (fields & FIELD_NAME)
         printf ("  %s ", part->name);
 
-    if (fields & FIELD_LABEL)
-        printf ("%16s ", "");
-
     if (fields & FIELD_SIZE)
         print_size (part->size);
 
@@ -219,7 +211,7 @@ static void print_part (const struct my_partinfo *part
     if (fields & FIELD_TYPE)
         printf ("%-8.16s ", part->fstype);
 
-    if (fields & FIELD_MOUNT && part->mount)
+    if (fields & FIELD_LMNT && part->mount)
         printf ("%s ", part->mount);
 
     putchar ('\n');
@@ -230,9 +222,6 @@ static void print_disk (const struct my_diskinfo *disk
     if (fields & FIELD_NAME)
         printf ("%s    ", disk->name);
 
-    if (fields & FIELD_LABEL)
-        printf ("%-16.16s ", disk->label);
-
     if (fields & FIELD_SIZE)
         print_size (disk->size);
 
@@ -246,8 +235,8 @@ static void print_disk (const struct my_diskinfo *disk
     if (fields & FIELD_TYPE)
         printf ("%-8.16s ", disk->type);
 
-    if (fields & FIELD_MOUNT && disk->mount)
-        printf ("%s ", disk->mount);
+    if (fields & FIELD_LMNT)
+        printf ("%.16s ", disk->label);
 
     putchar ('\n');
 
@@ -282,7 +271,6 @@ static struct my_diskinfo read_disk (const char *name)
     bzero (&disk, sizeof disk);
 
     {   // Read disklabel.
-        const struct statfs *mnt;
         char path[5 + 4 + 1];
         int fd;
 
@@ -293,10 +281,6 @@ static struct my_diskinfo read_disk (const char *name)
         if (ioctl (fd, DIOCGDINFO, &label) < 0)
             die ("ioctl(%s, DIOCGDINFO)", path);
         close (fd);
-
-        mnt = find_mount (path);
-        if (mnt)
-            disk.mount = mnt->f_mntonname;
     }
 
     memcpy (disk.name, name, 3);
@@ -345,7 +329,7 @@ static struct my_diskinfo read_disk (const char *name)
 
 static int usage (void)
 {
-    fputs ("Usage: lsblk [-Valnu]\n", stderr);
+    fputs ("Usage: lsblk [-Vanu]\n", stderr);
     return 1;
 }
 
@@ -361,7 +345,7 @@ int main (int argc, char *argv[])
     if (unveil (NULL, NULL) == -1)
         die ("unveil()");
 
-    while ((option = getopt (argc, argv, ":Valnu")) != -1) {
+    while ((option = getopt (argc, argv, ":Vanu")) != -1) {
         switch (option) {
         case 'V':
             puts ("lsblk-" VERSION);
@@ -369,9 +353,6 @@ int main (int argc, char *argv[])
         case 'a':
             fields = -1;
             break;
-        case 'l':
-            fields |= FIELD_LABEL;
-            break;
         case 'n':
             header = false;
             break;