sfdisk: add --no-device-names option · util-linux/util-linux@bd8e7e9 · GitHub
Skip to content

Commit bd8e7e9

Browse files
Leefancykarelzak
authored andcommitted
sfdisk: add --no-device-names option
Add --no-device-names option to suppress device names in --dump output, using partition numbers instead (e.g., "1 : ..." rather than "/dev/sda1 : ..."). The new libfdisk API: - fdisk_script_disable_devnames() - fdisk_script_has_devnames() Addresses: #3737 [kzak@redhat.com: - fix gtk-doc comments format - move new symbols to FDISK_2_43 - simplify error handling in command_dump - fix man page to mention --dump - move --no-device-names in usage() with --no-* group] Signed-off-by: Leefancy <lijian01@kylinos.cn> Signed-off-by: Karel Zak <kzak@redhat.com>
1 parent da32260 commit bd8e7e9

7 files changed

Lines changed: 74 additions & 5 deletions

File tree

‎bash-completion/sfdisk‎

Lines changed: 1 addition & 0 deletions

‎disk-utils/sfdisk.8.adoc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ to avoid collisions with *systemd-udevd*(8) or other tools.
181181
*-n*, *--no-act*::
182182
Do everything except writing to the device.
183183

184+
*--no-device-names*::
185+
Do not print device names in *--dump* output.
186+
184187
*--no-reread*::
185188
Do not check through the re-read-partition-table ioctl whether the device is in use.
186189

‎disk-utils/sfdisk.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ struct sfdisk {
120120
movedata: 1, /* move data after resize */
121121
movefsync: 1, /* use fsync() after each write() */
122122
notell : 1, /* don't tell kernel about new PT */
123-
noact : 1; /* do not write to device */
123+
noact : 1, /* do not write to device */
124+
no_device_names : 1; /* do not display device names in partition rows */
124125
};
125126

126127
#define SFDISK_PROMPT ">>> "
@@ -1068,6 +1069,9 @@ static int command_dump(struct sfdisk *sf, int argc, char **argv)
10681069
if (!dp)
10691070
err(EXIT_FAILURE, _("failed to allocate dump struct"));
10701071

1072+
if (sf->no_device_names)
1073+
fdisk_script_disable_devnames(dp, 1);
1074+
10711075
rc = fdisk_script_read_context(dp, NULL);
10721076
if (rc)
10731077
errx(EXIT_FAILURE, _("%s: failed to dump partition table"), devname);
@@ -2185,6 +2189,7 @@ static void __attribute__((__noreturn__)) usage(void)
21852189
_(" --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
21862190
fputs(_(" -N, --partno <num> specify partition number\n"), out);
21872191
fputs(_(" -n, --no-act do everything except write to device\n"), out);
2192+
fputs(_(" --no-device-names do not print device names in dump output\n"), out);
21882193
fputs(_(" --no-reread do not check whether the device is in use\n"), out);
21892194
fputs(_(" --no-tell-kernel do not tell kernel about changes\n"), out);
21902195
fputs(_(" -O, --backup-file <path> override default backup file name\n"), out);
@@ -2244,7 +2249,8 @@ int main(int argc, char *argv[])
22442249
OPT_NOTELL,
22452250
OPT_RELOCATE,
22462251
OPT_LOCK,
2247-
OPT_SECTORSIZE
2252+
OPT_SECTORSIZE,
2253+
OPT_NO_DEVICE_NAMES
22482254
};
22492255

22502256
static const struct option longopts[] = {
@@ -2267,6 +2273,7 @@ int main(int argc, char *argv[])
22672273
{ "list-free", no_argument, NULL, 'F' },
22682274
{ "list-types", no_argument, NULL, 'T' },
22692275
{ "no-act", no_argument, NULL, 'n' },
2276+
{ "no-device-names", no_argument, NULL, OPT_NO_DEVICE_NAMES },
22702277
{ "no-reread", no_argument, NULL, OPT_NOREREAD },
22712278
{ "no-tell-kernel", no_argument, NULL, OPT_NOTELL },
22722279
{ "move-data", optional_argument, NULL, OPT_MOVEDATA },
@@ -2464,6 +2471,9 @@ int main(int argc, char *argv[])
24642471
case OPT_DELETE:
24652472
sf->act = ACT_DELETE;
24662473
break;
2474+
case OPT_NO_DEVICE_NAMES:
2475+
sf->no_device_names = 1;
2476+
break;
24672477
case OPT_NOTELL:
24682478
sf->notell = 1;
24692479
break;

‎libfdisk/docs/libfdisk-sections.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ fdisk_script_write_file
149149
fdisk_script_set_userdata
150150
fdisk_script_get_userdata
151151
fdisk_unref_script
152+
fdisk_script_disable_devnames
153+
fdisk_script_has_devnames
152154
</SECTION>
153155

154156
<SECTION>

‎libfdisk/src/libfdisk.h.in‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,9 @@ int fdisk_script_write_file(struct fdisk_script *dp, FILE *f);
824824
int fdisk_script_read_file(struct fdisk_script *dp, FILE *f);
825825
int fdisk_script_read_line(struct fdisk_script *dp, FILE *f, char *buf, size_t bufsz);
826826

827+
int fdisk_script_disable_devnames(struct fdisk_script *dp, int disable);
828+
int fdisk_script_has_devnames(struct fdisk_script *dp);
829+
827830
int fdisk_set_script(struct fdisk_context *cxt, struct fdisk_script *dp);
828831
struct fdisk_script *fdisk_get_script(struct fdisk_context *cxt);
829832

‎libfdisk/src/libfdisk.sym‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,8 @@ FDISK_2_41 {
332332
FDISK_2_42 {
333333
fdisk_is_collision_area;
334334
} FDISK_2_41;
335+
336+
FDISK_2_43 {
337+
fdisk_script_disable_devnames;
338+
fdisk_script_has_devnames;
339+
} FDISK_2_42;

‎libfdisk/src/script.c‎

Lines changed: 48 additions & 3 deletions

0 commit comments

Comments
 (0)