]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: add inode type cell type
authorLennart Poettering <lennart@poettering.net>
Mon, 27 Mar 2023 16:14:02 +0000 (18:14 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 29 Mar 2023 16:27:05 +0000 (18:27 +0200)
src/shared/format-table.c
src/shared/format-table.h

index 351a5ede118445f9cd1eb40726f73b08f954afad..43e6510c4eedf6ff2ed6728ac8a70b59040ac5e8 100644 (file)
@@ -24,6 +24,7 @@
 #include "process-util.h"
 #include "signal-util.h"
 #include "sort-util.h"
+#include "stat-util.h"
 #include "string-util.h"
 #include "strxcpyx.h"
 #include "terminal-util.h"
@@ -348,6 +349,7 @@ static size_t table_data_size(TableDataType type, const void *data) {
                 return sizeof(pid_t);
 
         case TABLE_MODE:
+        case TABLE_MODE_INODE_TYPE:
                 return sizeof(mode_t);
 
         default:
@@ -1022,6 +1024,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
                         break;
 
                 case TABLE_MODE:
+                case TABLE_MODE_INODE_TYPE:
                         buffer.mode = va_arg(ap, mode_t);
                         data = &buffer.mode;
                         break;
@@ -1377,6 +1380,7 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
                         return CMP(a->pid, b->pid);
 
                 case TABLE_MODE:
+                case TABLE_MODE_INODE_TYPE:
                         return CMP(a->mode, b->mode);
 
                 default:
@@ -1882,6 +1886,13 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
                 break;
         }
 
+        case TABLE_MODE_INODE_TYPE:
+
+                if (d->mode == MODE_INVALID)
+                        return table_ersatz_string(t);
+
+                return inode_type_to_string(d->mode);
+
         default:
                 assert_not_reached();
         }
@@ -2696,6 +2707,7 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
                 return json_variant_new_integer(ret, d->int_val);
 
         case TABLE_MODE:
+        case TABLE_MODE_INODE_TYPE:
                 if (d->mode == MODE_INVALID)
                         return json_variant_new_null(ret);
 
index 5a2b366b59c9b9e9f8c3ae59e1df660c3bb80680..dbed6cdee9f92bd186e7e187742237bb919a1a45 100644 (file)
@@ -51,7 +51,8 @@ typedef enum TableDataType {
         TABLE_GID,
         TABLE_PID,
         TABLE_SIGNAL,
-        TABLE_MODE,     /* as in UNIX file mode (mode_t), in typical octal output */
+        TABLE_MODE,            /* as in UNIX file mode (mode_t), in typical octal output */
+        TABLE_MODE_INODE_TYPE, /* also mode_t, but displays only the inode type as string */
         _TABLE_DATA_TYPE_MAX,
 
         /* The following are not really data types, but commands for table_add_cell_many() to make changes to