--lock
--partno
--no-act
+ --no-device-names
--no-reread
--no-tell-kernel
--backup-file
*-n*, *--no-act*::
Do everything except writing to the device.
+*--no-device-names*::
+Do not print device names in *--dump* output.
+
*--no-reread*::
Do not check through the re-read-partition-table ioctl whether the device is in use.
movedata: 1, /* move data after resize */
movefsync: 1, /* use fsync() after each write() */
notell : 1, /* don't tell kernel about new PT */
- noact : 1; /* do not write to device */
+ noact : 1, /* do not write to device */
+ no_device_names : 1; /* do not display device names in partition rows */
};
#define SFDISK_PROMPT ">>> "
if (!dp)
err(EXIT_FAILURE, _("failed to allocate dump struct"));
+ if (sf->no_device_names)
+ fdisk_script_disable_devnames(dp, 1);
+
rc = fdisk_script_read_context(dp, NULL);
if (rc)
errx(EXIT_FAILURE, _("%s: failed to dump partition table"), devname);
_(" --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
fputs(_(" -N, --partno <num> specify partition number\n"), out);
fputs(_(" -n, --no-act do everything except write to device\n"), out);
+ fputs(_(" --no-device-names do not print device names in dump output\n"), out);
fputs(_(" --no-reread do not check whether the device is in use\n"), out);
fputs(_(" --no-tell-kernel do not tell kernel about changes\n"), out);
fputs(_(" -O, --backup-file <path> override default backup file name\n"), out);
OPT_NOTELL,
OPT_RELOCATE,
OPT_LOCK,
- OPT_SECTORSIZE
+ OPT_SECTORSIZE,
+ OPT_NO_DEVICE_NAMES
};
static const struct option longopts[] = {
{ "list-free", no_argument, NULL, 'F' },
{ "list-types", no_argument, NULL, 'T' },
{ "no-act", no_argument, NULL, 'n' },
+ { "no-device-names", no_argument, NULL, OPT_NO_DEVICE_NAMES },
{ "no-reread", no_argument, NULL, OPT_NOREREAD },
{ "no-tell-kernel", no_argument, NULL, OPT_NOTELL },
{ "move-data", optional_argument, NULL, OPT_MOVEDATA },
case OPT_DELETE:
sf->act = ACT_DELETE;
break;
+ case OPT_NO_DEVICE_NAMES:
+ sf->no_device_names = 1;
+ break;
case OPT_NOTELL:
sf->notell = 1;
break;
fdisk_script_set_userdata
fdisk_script_get_userdata
fdisk_unref_script
+fdisk_script_disable_devnames
+fdisk_script_has_devnames
</SECTION>
<SECTION>
int fdisk_script_read_file(struct fdisk_script *dp, FILE *f);
int fdisk_script_read_line(struct fdisk_script *dp, FILE *f, char *buf, size_t bufsz);
+int fdisk_script_disable_devnames(struct fdisk_script *dp, int disable);
+int fdisk_script_has_devnames(struct fdisk_script *dp);
+
int fdisk_set_script(struct fdisk_context *cxt, struct fdisk_script *dp);
struct fdisk_script *fdisk_get_script(struct fdisk_context *cxt);
FDISK_2_42 {
fdisk_is_collision_area;
} FDISK_2_41;
+
+FDISK_2_43 {
+ fdisk_script_disable_devnames;
+ fdisk_script_has_devnames;
+} FDISK_2_42;
unsigned long sector_size; /* as defined by script */
unsigned int json : 1, /* JSON output */
- force_label : 1; /* label: <name> specified */
+ force_label : 1, /* label: <name> specified */
+ no_device_names : 1; /* 1=suppress device name, 0=display device name (default) */
};
static void fdisk_script_free_header(struct fdisk_scriptheader *fi)
free(fi);
}
+/**
+ * fdisk_script_disable_devnames:
+ * @dp: script instance
+ * @disable: 1 to suppress device names, 0 to show them (default)
+ *
+ * After setting this flag, the script output will use partition numbers
+ * instead of device names (e.g., "1 : ..." rather than "/dev/sda1 : ...").
+ * This does not affect the "device" header.
+ *
+ * Returns: 0 on success, negative number in case of error.
+ *
+ * Since: 2.43
+ */
+int fdisk_script_disable_devnames(struct fdisk_script *dp, int disable)
+{
+ if (!dp)
+ return -EINVAL;
+
+ dp->no_device_names = disable ? 1 : 0;
+ return 0;
+}
+
+/**
+ * fdisk_script_has_devnames:
+ * @dp: script instance
+ *
+ * Returns: 1 if device names are shown, 0 if suppressed, negative number in case of error.
+ *
+ * Since: 2.43
+ */
+int fdisk_script_has_devnames(struct fdisk_script *dp)
+{
+ if (!dp)
+ return -EINVAL;
+
+ return dp->no_device_names ? 0 : 1;
+}
+
/**
* fdisk_new_script:
* @cxt: context
else
ul_jsonwrt_value_s(&json, name, fi->data);
- if (strcmp(name, "device") == 0)
+ if (fdisk_script_has_devnames(dp) && strcmp(name, "device") == 0)
devname = fi->data;
}
ul_jsonwrt_object_open(&json, NULL);
if (devname)
p = fdisk_partname(devname, pa->partno + 1);
+ else if (asprintf(&p, "%zu", pa->partno + 1) < 0)
+ return -ENOMEM;
+
if (p) {
DBG_OBJ(SCRIPT, dp, ul_debug("write %s entry", p));
ul_jsonwrt_value_s(&json, "node", p);
list_for_each(h, &dp->headers) {
struct fdisk_scriptheader *fi = list_entry(h, struct fdisk_scriptheader, headers);
fprintf(f, "%s: %s\n", fi->name, fi->data);
- if (strcmp(fi->name, "device") == 0)
+ if (fdisk_script_has_devnames(dp) && strcmp(fi->name, "device") == 0)
devname = fi->data;
}
if (devname)
p = fdisk_partname(devname, pa->partno + 1);
+ else if (asprintf(&p, "%zu", pa->partno + 1) < 0)
+ return -ENOMEM;
+
if (p) {
DBG_OBJ(SCRIPT, dp, ul_debug("write %s entry", p));
fprintf(f, "%s : ", p);