The patch also add --bytes to fdisk and fdisk.
Signed-off-by: Karel Zak <kzak@redhat.com>
fputs(_(" -t, --type <type> recognize specified partition table type only\n"), out);
fputs(_(" -u, --units[=<unit>] display units: 'cylinders' or 'sectors' (default)\n"), out);
fputs(_(" -s, --getsz display device size in 512-byte sectors [DEPRECATED]\n"), out);
+ fputs(_(" --bytes print SIZE in bytes rather than in human readable format\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(_(" -C, --cylinders <number> specify the number of cylinders\n"), out);
int colormode = UL_COLORMODE_UNDEF;
struct fdisk_context *cxt;
char *outarg = NULL;
-
+ enum {
+ OPT_BYTES = CHAR_MAX + 1
+ };
static const struct option longopts[] = {
+ { "bytes", no_argument, NULL, OPT_BYTES },
{ "color", optional_argument, NULL, 'L' },
{ "compatibility", optional_argument, NULL, 'c' },
{ "cylinders", required_argument, NULL, 'C' },
return EXIT_SUCCESS;
case 'h':
usage(stdout);
+ case OPT_BYTES:
+ fdisk_set_size_unit(cxt, FDISK_SIZEUNIT_BYTES);
+ break;
default:
usage(stderr);
}
fputs(USAGE_OPTIONS, out);
fputs(_(" -A, --append append partitions to existing partition table\n"), out);
+ fputs(_(" --bytes print SIZE in bytes rather than in human readable format\n"), out);
fputs(_(" -b, --backup backup partition table sectors (see -O)\n"), out);
fputs(_(" -f, --force disable all consistency checking\n"), out);
fputs(_(" -o, --output <list> output columns\n"), out);
OPT_PARTLABEL,
OPT_PARTTYPE,
OPT_PARTATTRS,
+ OPT_BYTES
};
static const struct option longopts[] = {
{ "append", no_argument, NULL, 'A' },
{ "backup", no_argument, NULL, 'b' },
{ "backup-file", required_argument, NULL, 'O' },
+ { "bytes", no_argument, NULL, OPT_BYTES },
{ "dump", no_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
{ "force", no_argument, NULL, 'f' },
textdomain(PACKAGE);
atexit(close_stdout);
+ sfdisk_init(sf);
+
while ((c = getopt_long(argc, argv, "aAbcdfghlLo:O:nN:qsTu:vVX:Y:",
longopts, &longidx)) != -1) {
switch(c) {
case OPT_NOREREAD:
sf->noreread = 1;
break;
-
+ case OPT_BYTES:
+ fdisk_set_size_unit(sf->cxt, FDISK_SIZEUNIT_BYTES);
+ break;
default:
usage(stderr);
}
}
- sfdisk_init(sf);
if (outarg)
init_fields(NULL, outarg, NULL);
fdisk_get_parent
fdisk_get_physector_size
fdisk_get_sector_size
+fdisk_get_size_unit
FDISK_PLURAL
FDISK_SINGULAR
fdisk_get_unit
fdisk_ref_context
fdisk_set_first_lba
fdisk_set_last_lba
+sdisk_set_size_unit
fdisk_set_unit
fdisk_unref_context
fdisk_use_cylinders
return 0;
}
+/**
+ * fdisk_set_size_unit:
+ * @cxt: fdisk context
+ * @unit: FDISK_SIZEUNIT_*
+ *
+ * Sets unit for SIZE output field (see fdisk_partition_to_string()).
+ *
+ * Returns: 0 on success, <0 on error.
+ */
+int fdisk_set_size_unit(struct fdisk_context *cxt, int unit)
+{
+ assert(cxt);
+ cxt->sizeunit = unit;
+ return 0;
+}
+
+/**
+ * fdisk_get_size_unit:
+ * @cxt: fdisk context
+ *
+ * Gets unit for SIZE output field (see fdisk_partition_to_string()).
+ *
+ * Returns: unit
+ */
+int fdisk_get_size_units(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->sizeunit;
+}
/**
* fdisk_get_nsectors:
display_details : 1, /* expert display mode */
listonly : 1; /* list partition, nothing else */
+ int sizeunit; /* SIZE fields, FDISK_SIZEUNIT_* */
+
/* alignment */
unsigned long grain; /* alignment unit */
fdisk_sector_t first_lba; /* recommended begin of the first partition */
fdisk_sector_t fdisk_get_geom_sectors(struct fdisk_context *cxt);
fdisk_sector_t fdisk_get_geom_cylinders(struct fdisk_context *cxt);
+enum {
+ FDISK_SIZEUNIT_HUMAN = 0, /* default, human readable {M,G,P,...} */
+ FDISK_SIZEUNIT_BYTES /* bytes */
+};
+int fdisk_set_size_unit(struct fdisk_context *cxt, int unit);
+int fdisk_get_size_unit(struct fdisk_context *cxt);
/* parttype.c */
fdisk_get_physector_size;
fdisk_get_script;
fdisk_get_sector_size;
+ fdisk_get_size_unit;
fdisk_get_unit;
fdisk_get_units_per_sector;
fdisk_gpt_is_hybrid;
fdisk_set_partition;
fdisk_set_partition_type;
fdisk_set_script;
+ fdisk_set_size_unit;
fdisk_set_unit;
fdisk_sgi_create_info;
fdisk_sgi_set_bootfile;
if (fdisk_partition_has_size(pa)) {
uint64_t sz = pa->size * cxt->sector_size;
- if (fdisk_is_details(cxt)) {
- rc = pa->size_post ?
- asprintf(&p, "%ju%c", sz, pa->size_post) :
- asprintf(&p, "%ju", sz);
- } else {
- p = size_to_human_string(SIZE_SUFFIX_1LETTER, sz);
- if (!p)
- rc = -ENOMEM;
+ switch (cxt->sizeunit) {
+ case FDISK_SIZEUNIT_BYTES:
+ rc = asprintf(&p, "%ju", sz);
+ break;
+ case FDISK_SIZEUNIT_HUMAN:
+ if (fdisk_is_details(cxt))
+ rc = pa->size_post ?
+ asprintf(&p, "%ju%c", sz, pa->size_post) :
+ asprintf(&p, "%ju", sz);
+ else {
+ p = size_to_human_string(SIZE_SUFFIX_1LETTER, sz);
+ if (!p)
+ rc = -ENOMEM;
+ }
+ break;
}
}
break;