From: Lennart Poettering Date: Mon, 27 Mar 2023 16:14:02 +0000 (+0200) Subject: format-table: add inode type cell type X-Git-Tag: v254-rc1~864^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd33207bb11ad3d7c704e23b3860338fcfaab98b;p=thirdparty%2Fsystemd.git format-table: add inode type cell type --- diff --git a/src/shared/format-table.c b/src/shared/format-table.c index 351a5ede118..43e6510c4ee 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -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); diff --git a/src/shared/format-table.h b/src/shared/format-table.h index 5a2b366b59c..dbed6cdee9f 100644 --- a/src/shared/format-table.h +++ b/src/shared/format-table.h @@ -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