assert(cf->fields);
assert(tb);
- lb = fdisk_context_get_label(cf->cxt, NULL);
+ lb = fdisk_get_label(cf->cxt, NULL);
assert(lb);
itr = fdisk_new_iter(FDISK_ITER_FORWARD);
/* create cfdisk menu according to libfdisk labels, note that the
* last cm[] item has to be empty -- so nitems + 1 */
- nitems = fdisk_context_get_nlabels(cf->cxt);
+ nitems = fdisk_get_nlabels(cf->cxt);
cm = xcalloc(nitems + 1, sizeof(struct cfdisk_menuitem));
- while (fdisk_context_next_label(cf->cxt, &lb) == 0) {
+ while (fdisk_next_label(cf->cxt, &lb) == 0) {
if (fdisk_label_is_disabled(lb) || strcmp(lb->name, "bsd") == 0)
continue;
cm[i++].name = lb->name;
if (!cf->wrong_order)
ignore[i++] = 's';
- if (fdisk_context_is_readonly(cf->cxt))
+ if (fdisk_is_readonly(cf->cxt))
ignore[i++] = 'W';
return i;
}
char buf[64] = { 0 };
int rc;
- if (fdisk_context_is_readonly(cf->cxt)) {
+ if (fdisk_is_readonly(cf->cxt)) {
warn = _("Device open in read-only mode");
break;
}
if (rc)
return rc;
- if (fdisk_context_is_readonly(cf->cxt))
+ if (fdisk_is_readonly(cf->cxt))
ui_warnx(_("Device open in read-only mode."));
do {
if (!cf->cxt)
err(EXIT_FAILURE, _("failed to allocate libfdisk context"));
- fdisk_context_set_ask(cf->cxt, ask_callback, (void *) cf);
+ fdisk_set_ask(cf->cxt, ask_callback, (void *) cf);
if (optind == argc)
diskpath = access(DEFAULT_DEVICE, F_OK) == 0 ?
else
diskpath = argv[optind];
- rc = fdisk_context_assign_device(cf->cxt, diskpath, 0);
+ rc = fdisk_assign_device(cf->cxt, diskpath, 0);
if (rc == -EACCES)
- rc = fdisk_context_assign_device(cf->cxt, diskpath, 1);
+ rc = fdisk_assign_device(cf->cxt, diskpath, 1);
if (rc != 0)
err(EXIT_FAILURE, _("cannot open %s"),
optind == argc ? DEFAULT_DEVICE : diskpath);
free(cf->linesbuf);
fdisk_unref_table(cf->table);
- rc = fdisk_context_deassign_device(cf->cxt, cf->nwrites == 0);
+ rc = fdisk_deassign_device(cf->cxt, cf->nwrites == 0);
fdisk_free_context(cf->cxt);
DBG(MISC, ul_debug("bye! [rc=%d]", rc));
return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
/* entry wanted for specified labels only */
(e->label && cxt->label && !(e->label & cxt->label->id)) ||
/* exclude non-expert entries in expect mode */
- (e->expert == 0 && fdisk_context_display_details(cxt)) ||
+ (e->expert == 0 && fdisk_is_details(cxt)) ||
/* nested only */
(e->parent && (!cxt->parent || cxt->parent->label->id != e->parent)) ||
/* exclude non-normal entries in normal mode */
- (e->normal == 0 && !fdisk_context_display_details(cxt))) {
+ (e->normal == 0 && !fdisk_is_details(cxt))) {
mc->entry_idx++;
continue;
ON_DBG(FRONTEND, menu_detect_collisions(cxt));
- if (fdisk_context_display_details(cxt))
+ if (fdisk_is_details(cxt))
printf(_("\nHelp (expert commands):\n"));
else
printf(_("\nHelp:\n"));
const char *prompt;
char buf[BUFSIZ];
- if (fdisk_context_display_details(cxt))
+ if (fdisk_is_details(cxt))
prompt = _("Expert command (m for help): ");
else
prompt = _("Command (m for help): ");
list_disklabel(cxt);
break;
case 'w':
- if (fdisk_context_is_readonly(cxt)) {
+ if (fdisk_is_readonly(cxt)) {
fdisk_warnx(cxt, _("Device open in read-only mode."));
break;
}
fdisk_info(cxt, _("The partition table has been altered."));
rc = fdisk_reread_partition_table(cxt);
if (!rc)
- rc = fdisk_context_deassign_device(cxt, 0);
+ rc = fdisk_deassign_device(cxt, 0);
/* fallthrough */
case 'q':
fdisk_free_context(cxt);
rc = fdisk_reorder_partitions(cxt);
break;
case 'r':
- rc = fdisk_context_enable_details(cxt, 0);
+ rc = fdisk_enable_details(cxt, 0);
break;
}
return rc;
change_partition_type(cxt);
break;
case 'u':
- fdisk_context_set_unit(cxt,
- fdisk_context_use_cylinders(cxt) ? "sectors" :
+ fdisk_set_unit(cxt,
+ fdisk_use_cylinders(cxt) ? "sectors" :
"cylinders");
- if (fdisk_context_use_cylinders(cxt))
+ if (fdisk_use_cylinders(cxt))
fdisk_info(cxt, _("Changing display/entry units to cylinders (DEPRECATED!)."));
else
fdisk_info(cxt, _("Changing display/entry units to sectors."));
break;
case 'x':
- fdisk_context_enable_details(cxt, 1);
+ fdisk_enable_details(cxt, 1);
break;
case 'r':
/* return from nested BSD to DOS */
if (!mbr)
return -ENOMEM;
*cxt0 = cxt = mbr;
- fdisk_context_enable_details(cxt, 1); /* keep us in expert mode */
+ fdisk_enable_details(cxt, 1); /* keep us in expert mode */
fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,
_("Entering protective/hybrid MBR disklabel."));
return 0;
rc = fdisk_bsd_write_bootstrap(cxt);
break;
case 's':
- org = fdisk_context_display_details(cxt);
+ org = fdisk_is_details(cxt);
- fdisk_context_enable_details(cxt, 1);
+ fdisk_enable_details(cxt, 1);
list_disklabel(cxt);
- fdisk_context_enable_details(cxt, org);
+ fdisk_enable_details(cxt, org);
break;
case 'x':
rc = fdisk_bsd_link_partition(cxt);
void toggle_dos_compatibility_flag(struct fdisk_context *cxt)
{
- struct fdisk_label *lb = fdisk_context_get_label(cxt, "dos");
+ struct fdisk_label *lb = fdisk_get_label(cxt, "dos");
int flag;
if (!lb)
bytes, (uintmax_t) cxt->total_sectors);
free(strsz);
- if (fdisk_require_geometry(cxt) || fdisk_context_use_cylinders(cxt))
+ if (fdisk_require_geometry(cxt) || fdisk_use_cylinders(cxt))
fdisk_info(cxt, _("Geometry: %d heads, %llu sectors/track, %llu cylinders"),
cxt->geom.heads, cxt->geom.sectors, cxt->geom.cylinders);
fdisk_info(cxt, _("Units: %s of %d * %ld = %ld bytes"),
- fdisk_context_get_unit(cxt, PLURAL),
- fdisk_context_get_units_per_sector(cxt),
+ fdisk_get_unit(cxt, PLURAL),
+ fdisk_get_units_per_sector(cxt),
cxt->sector_size,
- fdisk_context_get_units_per_sector(cxt) * cxt->sector_size);
+ fdisk_get_units_per_sector(cxt) * cxt->sector_size);
fdisk_info(cxt, _("Sector size (logical/physical): %lu bytes / %lu bytes"),
cxt->sector_size, cxt->phy_sector_size);
static void print_device_pt(struct fdisk_context *cxt, char *device, int warnme)
{
- if (fdisk_context_assign_device(cxt, device, 1) != 0) { /* read-only */
+ if (fdisk_assign_device(cxt, device, 1) != 0) { /* read-only */
if (warnme || errno == EACCES)
warn(_("cannot open %s"), device);
return;
if (!cxt)
err(EXIT_FAILURE, _("failed to allocate libfdisk context"));
- fdisk_context_set_ask(cxt, ask_callback, NULL);
+ fdisk_set_ask(cxt, ask_callback, NULL);
while ((c = getopt_long(argc, argv, "b:c::C:hH:lL::sS:t:u::vV",
longopts, NULL)) != -1) {
* actively used label
*/
char *p = *optarg == '=' ? optarg + 1 : optarg;
- struct fdisk_label *lb = fdisk_context_get_label(cxt, "dos");
+ struct fdisk_label *lb = fdisk_get_label(cxt, "dos");
if (!lb)
err(EXIT_FAILURE, _("not found DOS label driver"));
{
struct fdisk_label *lb = NULL;
- while (fdisk_context_next_label(cxt, &lb) == 0)
+ while (fdisk_next_label(cxt, &lb) == 0)
fdisk_label_set_disabled(lb, 1);
- lb = fdisk_context_get_label(cxt, optarg);
+ lb = fdisk_get_label(cxt, optarg);
if (!lb)
errx(EXIT_FAILURE, _("unsupported disklabel: %s"), optarg);
fdisk_label_set_disabled(lb, 0);
case 'u':
if (optarg && *optarg == '=')
optarg++;
- if (fdisk_context_set_unit(cxt, optarg) != 0)
+ if (fdisk_set_unit(cxt, optarg) != 0)
usage(stderr);
break;
case 'V': /* preferred for util-linux */
switch (act) {
case ACT_LIST:
- fdisk_context_enable_listonly(cxt, 1);
+ fdisk_enable_listonly(cxt, 1);
if (argc > optind) {
int k;
fdisk_info(cxt, _("Changes will remain in memory only, until you decide to write them.\n"
"Be careful before using the write command.\n"));
- rc = fdisk_context_assign_device(cxt, argv[optind], 0);
+ rc = fdisk_assign_device(cxt, argv[optind], 0);
if (rc == -EACCES) {
- rc = fdisk_context_assign_device(cxt, argv[optind], 1);
+ rc = fdisk_assign_device(cxt, argv[optind], 1);
if (rc == 0)
fdisk_warnx(cxt, _("Device open in read-only mode."));
}
sector_t fdisk_scround(struct fdisk_context *cxt, sector_t num)
{
- sector_t un = fdisk_context_get_units_per_sector(cxt);
+ sector_t un = fdisk_get_units_per_sector(cxt);
return (num + un - 1) / un;
}
sector_t fdisk_cround(struct fdisk_context *cxt, sector_t num)
{
- return fdisk_context_use_cylinders(cxt) ?
- (num / fdisk_context_get_units_per_sector(cxt)) + 1 : num;
+ return fdisk_use_cylinders(cxt) ?
+ (num / fdisk_get_units_per_sector(cxt)) + 1 : num;
}
int fdisk_reread_partition_table(struct fdisk_context *cxt)
if (!ask)
return -ENOMEM;
fdisk_ask_set_query(ask,
- fdisk_context_use_cylinders(cxt) ?
+ fdisk_use_cylinders(cxt) ?
_("First cylinder") : _("First sector"));
fdisk_ask_set_type(ask, FDISK_ASKTYPE_NUMBER);
fdisk_ask_number_set_low(ask, fdisk_cround(cxt, begin));
fdisk_free_ask(ask);
if (rc)
return rc;
- if (fdisk_context_use_cylinders(cxt))
+ if (fdisk_use_cylinders(cxt))
begin = (begin - 1) * d->d_secpercyl;
}
return -ENOMEM;
fdisk_ask_set_type(ask, FDISK_ASKTYPE_OFFSET);
- if (fdisk_context_use_cylinders(cxt)) {
+ if (fdisk_use_cylinders(cxt)) {
fdisk_ask_set_query(ask, _("Last cylinder, +cylinders or +size{K,M,G,T,P}"));
fdisk_ask_number_set_unit(ask,
cxt->sector_size *
- fdisk_context_get_units_per_sector(cxt));
+ fdisk_get_units_per_sector(cxt));
} else {
fdisk_ask_set_query(ask, _("Last sector, +sectors or +size{K,M,G,T,P}"));
fdisk_ask_number_set_unit(ask,cxt->sector_size);
fdisk_free_ask(ask);
if (rc)
return rc;
- if (fdisk_context_use_cylinders(cxt))
+ if (fdisk_use_cylinders(cxt))
end = end * d->d_secpercyl - 1;
}
rc = bsd_initlabel(cxt);
if (!rc) {
- int org = fdisk_context_display_details(cxt);
+ int org = fdisk_is_details(cxt);
cxt->label->nparts_cur = d->d_npartitions;
cxt->label->nparts_max = BSD_MAXPARTITIONS;
- fdisk_context_enable_details(cxt, 1);
+ fdisk_enable_details(cxt, 1);
bsd_list_disklabel(cxt);
- fdisk_context_enable_details(cxt, org);
+ fdisk_enable_details(cxt, org);
}
return rc;
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, BSD));
- if (fdisk_context_display_details(cxt)) {
+ if (fdisk_is_details(cxt)) {
fdisk_info(cxt, "# %s:", cxt->dev_path);
if ((unsigned) d->d_type < BSD_DKMAXTYPES)
if (!pa->used)
return 0;
- if (fdisk_context_use_cylinders(cxt) && d->d_secpercyl) {
+ if (fdisk_use_cylinders(cxt) && d->d_secpercyl) {
pa->start_post = p->p_offset % d->d_secpercyl ? '*' : ' ';
pa->end_post = (p->p_offset + p->p_size) % d->d_secpercyl ? '*' : ' ';
}
#include "fdiskP.h"
+/**
+ * fdisk_new_context:
+ *
+ * Returns: newly allocated libfdisk handler
+ */
struct fdisk_context *fdisk_new_context(void)
{
struct fdisk_context *cxt;
return cxt;
}
+/**
+ * fdisk_new_nested_context:
+ * @parent: parental context
+ * @name: optional label name (e.g. "bsd")
+ *
+ * This is supported for MBR+BSD and GPT+pMBR only.
+ *
+ * Returns: new context for nested partiton table.
+ */
struct fdisk_context *fdisk_new_nested_context(struct fdisk_context *parent,
const char *name)
{
cxt->label = lb;
if (lb->op->probe(cxt) == 1)
- __fdisk_context_switch_label(cxt, lb);
+ __fdisk_switch_label(cxt, lb);
else {
DBG(CXT, ul_debugobj(cxt, "not found %s label", lb->name));
if (lb->op->deinit)
}
-/*
- * Returns the current label if no name specified.
+/**
+ * fdisk_get_label:
+ * @cxt: context instance
+ * @name: label name (e.g. "gpt")
+ *
+ * If no @name specified then returns the current context label.
+ *
+ * Returns: label struct or NULL in case of error.
*/
-struct fdisk_label *fdisk_context_get_label(struct fdisk_context *cxt, const char *name)
+struct fdisk_label *fdisk_get_label(struct fdisk_context *cxt, const char *name)
{
size_t i;
return NULL;
}
-int fdisk_context_next_label(struct fdisk_context *cxt, struct fdisk_label **lb)
+/**
+ * fdisk_next_label:
+ * @cxt: context instance
+ * @lb: returns pointer to the next label
+ *
+ * <informalexample>
+ * <programlisting>
+ * // print all supported labels
+ * struct fdisk_context *cxt = fdisk_new_context();
+ * struct fdisk_label *lb = NULL;
+ *
+ * while (fdisk_next_label(cxt, &lb) == 0)
+ * print("label name: %s\n", fdisk_label_get_name(lb));
+ * fdisk_free_context(cxt);
+ * </programlisting>
+ * </informalexample>
+ *
+ * Returns: <0 in case of error, 0 on success, 1 at the end.
+ */
+int fdisk_next_label(struct fdisk_context *cxt, struct fdisk_label **lb)
{
size_t i;
struct fdisk_label *res = NULL;
return res ? 0 : 1;
}
-size_t fdisk_context_get_nlabels(struct fdisk_context *cxt)
+/**
+ * fdisk_get_nlabels:
+ * @cxt: context
+ *
+ * Returns: number of supported label types
+ */
+size_t fdisk_get_nlabels(struct fdisk_context *cxt)
{
return cxt ? cxt->nlabels : 0;
}
-int __fdisk_context_switch_label(struct fdisk_context *cxt,
- struct fdisk_label *lb)
+int __fdisk_switch_label(struct fdisk_context *cxt, struct fdisk_label *lb)
{
if (!lb || !cxt)
return -EINVAL;
return 0;
}
-int fdisk_context_switch_label(struct fdisk_context *cxt, const char *name)
+/**
+ * fdisk_switch_label:
+ * @cxt: context
+ * @name: label name (e.g. "gpt")
+ *
+ * Forces libfdisk to use the label driver.
+ *
+ * Returns: 0 on succes, <0 in case of error.
+ */
+int fdisk_switch_label(struct fdisk_context *cxt, const char *name)
{
- return __fdisk_context_switch_label(cxt,
- fdisk_context_get_label(cxt, name));
+ return __fdisk_switch_label(cxt, fdisk_get_label(cxt, name));
}
}
/**
- * fdisk_context_assign_device:
+ * fdisk_assign_device:
* @fname: path to the device to be handled
* @readonly: how to open the device
*
+ * Open the device, discovery topology, geometry, and detect disklabel.
+ *
* Returns: 0 on success, < 0 on error.
*/
-int fdisk_context_assign_device(struct fdisk_context *cxt,
- const char *fname, int readonly)
+int fdisk_assign_device(struct fdisk_context *cxt,
+ const char *fname, int readonly)
{
int fd;
/* warn about obsolete stuff on the device if we aren't in
* list-only mode and there is not PT yet */
- if (!fdisk_context_listonly(cxt) && !fdisk_dev_has_disklabel(cxt))
+ if (!fdisk_is_listonly(cxt) && !fdisk_dev_has_disklabel(cxt))
warn_wipe(cxt);
DBG(CXT, ul_debugobj(cxt, "initialized for %s [%s]",
return -errno;
}
-int fdisk_context_deassign_device(struct fdisk_context *cxt, int nosync)
+int fdisk_deassign_device(struct fdisk_context *cxt, int nosync)
{
assert(cxt);
assert(cxt->dev_fd >= 0);
return 0;
}
-int fdisk_context_is_readonly(struct fdisk_context *cxt)
+int fdisk_is_readonly(struct fdisk_context *cxt)
{
assert(cxt);
return cxt->readonly;
}
/**
- * fdisk_context_set_ask:
+ * fdisk_set_ask:
* @cxt: context
* @ask_cb: callback
* @data: callback data
*
+ * Set callbacks for dialog driven partitioning and library warnings/errors.
+ *
* Returns: 0 on success, < 0 on error.
*/
-int fdisk_context_set_ask(struct fdisk_context *cxt,
+int fdisk_set_ask(struct fdisk_context *cxt,
int (*ask_cb)(struct fdisk_context *, struct fdisk_ask *, void *),
void *data)
{
}
/**
- * fdisk_context_enable_details:
- * cxt: context
- * enable: true/flase
+ * fdisk_enable_details:
+ * @cxt: context
+ * @enable: true/flase
*
- * Enables or disables "details" display mode.
+ * Enables or disables "details" display mode. This function has effect to
+ * fdisk_partition_to_string() function.
*
* Returns: 0 on success, < 0 on error.
*/
-int fdisk_context_enable_details(struct fdisk_context *cxt, int enable)
+int fdisk_enable_details(struct fdisk_context *cxt, int enable)
{
assert(cxt);
cxt->display_details = enable ? 1 : 0;
return 0;
}
-int fdisk_context_display_details(struct fdisk_context *cxt)
+/**
+ * fdisk_is_details:
+ * @cxt: context
+ *
+ * Returns: 1 if details are enabled
+ */
+int fdisk_is_details(struct fdisk_context *cxt)
{
assert(cxt);
return cxt->display_details == 1;
}
/**
- * fdisk_context_enable_listonly:
- * cxt: context
- * enable: true/flase
+ * fdisk_enable_listonly:
+ * @cxt: context
+ * @enable: true/flase
*
* Just list partition only, don't care about another details, mistakes, ...
*
* Returns: 0 on success, < 0 on error.
*/
-int fdisk_context_enable_listonly(struct fdisk_context *cxt, int enable)
+int fdisk_enable_listonly(struct fdisk_context *cxt, int enable)
{
assert(cxt);
cxt->listonly = enable ? 1 : 0;
return 0;
}
-int fdisk_context_listonly(struct fdisk_context *cxt)
+/**
+ * fdisk_is_listonly:
+ * @cxt: context
+ *
+ * Returns: 1 if list-only mode enabled
+ */
+int fdisk_is_listonly(struct fdisk_context *cxt)
{
assert(cxt);
return cxt->listonly == 1;
}
-/*
+/**
+ * fdisk_set_unit:
+ * @cxt: context
* @str: "cylinder" or "sector".
*
* This is pure shit, unfortunately for example Sun addresses begin of the
* partition by cylinders...
+ *
+ * Returns: 0 on succes, <0 on error.
*/
-int fdisk_context_set_unit(struct fdisk_context *cxt, const char *str)
+int fdisk_set_unit(struct fdisk_context *cxt, const char *str)
{
assert(cxt);
else if (strcmp(str, "sector") == 0 || strcmp(str, "sectors") == 0)
cxt->display_in_cyl_units = 0;
- DBG(CXT, ul_debugobj(cxt, "display unit: %s", fdisk_context_get_unit(cxt, 0)));
+ DBG(CXT, ul_debugobj(cxt, "display unit: %s", fdisk_get_unit(cxt, 0)));
return 0;
}
-const char *fdisk_context_get_unit(struct fdisk_context *cxt, int n)
+/**
+ * fdisk_get_unit:
+ * @cxt: context
+ *
+ * Returns: unit name.
+ */
+const char *fdisk_get_unit(struct fdisk_context *cxt, int n)
{
assert(cxt);
- if (fdisk_context_use_cylinders(cxt))
+ if (fdisk_use_cylinders(cxt))
return P_("cylinder", "cylinders", n);
return P_("sector", "sectors", n);
}
-/* Returns 1 if user wants to display in cylinders. */
-int fdisk_context_use_cylinders(struct fdisk_context *cxt)
+/**
+ * fdisk_use_cylinders:
+ * @@cxt: context
+ *
+ * Returns 1 if user wants to display in cylinders.
+ */
+int fdisk_use_cylinders(struct fdisk_context *cxt)
{
assert(cxt);
return cxt->display_in_cyl_units == 1;
}
-/* Returns number of "units" per sector, default is 1 if display unit is sector.
+/**
+ * fdisk_get_units_per_sector:
+ * @cxt: context
+ *
+ * This is neccessary only for brain dead situations when we use "cylinders";
+ *
+ * Returns: number of "units" per sector, default is 1 if display unit is sector.
*/
-unsigned int fdisk_context_get_units_per_sector(struct fdisk_context *cxt)
+unsigned int fdisk_get_units_per_sector(struct fdisk_context *cxt)
{
assert(cxt);
- if (fdisk_context_use_cylinders(cxt)) {
+ if (fdisk_use_cylinders(cxt)) {
assert(cxt->geom.heads);
return cxt->geom.heads * cxt->geom.sectors;
}
return 1;
}
+
+/**
+ * fdisk_get_optimal_iosize:
+ * @cxt: context
+ *
+ * Returns: optimal I/O size
+ */
+unsigned long fdisk_get_optimal_iosize(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->optimal_io_size;
+}
+
+/**
+ * fdisk_get_minimal_iosize:
+ * @cxt: context
+ *
+ * Returns: minimal I/O size
+ */
+unsigned long fdisk_get_minimal_size(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->min_io_size;
+}
+
+/**
+ * fdisk_get_physector_size:
+ * @cxt: context
+ *
+ * Returns: physical sector size
+ */
+unsigned long fdisk_get_physector_size(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->phy_sector_size;
+}
+
+/**
+ * fdisk_get_sector_size:
+ * @cxt: context
+ *
+ * Returns: sector size
+ */
+unsigned long fdisk_get_sector_size(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->sector_size;
+}
+
+/**
+ * fdisk_get_alignment_offset
+ * @cxt: context
+ *
+ * Returns: alignment offset (used by 4K disks for backward compatibility with DOS tools).
+ */
+unsigned long fdisk_get_alignment_offset(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->alignment_offset;
+}
+
+/**
+ * fdisk_get_grain_size:
+ * @cxt: context
+ *
+ * Returns: usual grain used to align partitions
+ */
+unsigned long fdisk_get_grain_size(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->grain;
+}
+
+/**
+ * fdisk_get_first_lba:
+ * @cxt: context
+ *
+ * Returns: first possible LBA on disk for data partitions.
+ */
+unsigned long fdisk_get_first_lba(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->first_lba;
+}
+
+/**
+ * fdisk_get_nsectors:
+ * @cxt: context
+ *
+ * Returns: size of the device in (real) sectors.
+ */
+unsigned long fdisk_get_nsectors(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->total_sectors;
+}
+
+/**
+ * fdisk_get_devname:
+ * @cxt: context
+ *
+ * Returns: device name.
+ */
+const char *fdisk_get_devname(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return cxt->dev_path;
+}
#define is_dos_compatible(_x) \
(fdisk_is_disklabel(_x, DOS) && \
- fdisk_dos_is_compatible(fdisk_context_get_label(_x, NULL)))
+ fdisk_dos_is_compatible(fdisk_get_label(_x, NULL)))
#define cround(c, n) fdisk_cround(c, n)
pe->changed = 0;
}
- if (fdisk_context_listonly(cxt))
+ if (fdisk_is_listonly(cxt))
return;
/*
* Various warnings...
"I/O) size boundary is recommended, or performance may be impacted."));
}
- if (fdisk_context_use_cylinders(cxt))
+ if (fdisk_use_cylinders(cxt))
fdisk_warnx(cxt, _("Cylinders as display units are deprecated."));
if (cxt->total_sectors > UINT_MAX) {
if (!ask)
return -ENOMEM;
fdisk_ask_set_query(ask,
- fdisk_context_use_cylinders(cxt) ?
+ fdisk_use_cylinders(cxt) ?
_("First cylinder") : _("First sector"));
fdisk_ask_set_type(ask, FDISK_ASKTYPE_NUMBER);
fdisk_ask_number_set_low(ask, fdisk_cround(cxt, low));
fdisk_free_ask(ask);
if (rc)
return rc;
- if (fdisk_context_use_cylinders(cxt)) {
+ if (fdisk_use_cylinders(cxt)) {
*start = (*start - 1)
- * fdisk_context_get_units_per_sector(cxt);
+ * fdisk_get_units_per_sector(cxt);
if (*start < low)
*start = low;
}
else
start = cxt->first_lba;
- if (fdisk_context_use_cylinders(cxt) || !cxt->total_sectors)
+ if (fdisk_use_cylinders(cxt) || !cxt->total_sectors)
limit = cxt->geom.heads * cxt->geom.sectors * cxt->geom.cylinders - 1;
else
limit = cxt->total_sectors - 1;
start = l->ext_offset + cxt->first_lba;
limit = get_abs_partition_end(ext_pe);
}
- if (fdisk_context_use_cylinders(cxt))
+ if (fdisk_use_cylinders(cxt))
for (i = 0; i < cxt->label->nparts_max; i++) {
first[i] = (fdisk_cround(cxt, first[i]) - 1)
- * fdisk_context_get_units_per_sector(cxt);
+ * fdisk_get_units_per_sector(cxt);
}
/*
dflt = start;
if (start > limit)
break;
- if (start >= temp + fdisk_context_get_units_per_sector(cxt)
+ if (start >= temp + fdisk_get_units_per_sector(cxt)
&& read) {
fdisk_info(cxt, _("Sector %llu is already allocated."),
temp);
return -ENOMEM;
fdisk_ask_set_type(ask, FDISK_ASKTYPE_OFFSET);
- if (fdisk_context_use_cylinders(cxt)) {
+ if (fdisk_use_cylinders(cxt)) {
fdisk_ask_set_query(ask, _("Last cylinder, +cylinders or +size{K,M,G,T,P}"));
fdisk_ask_number_set_unit(ask,
cxt->sector_size *
- fdisk_context_get_units_per_sector(cxt));
+ fdisk_get_units_per_sector(cxt));
} else {
fdisk_ask_set_query(ask, _("Last sector, +sectors or +size{K,M,G,T,P}"));
fdisk_ask_number_set_unit(ask,cxt->sector_size);
fdisk_free_ask(ask);
if (rc)
return rc;
- if (fdisk_context_use_cylinders(cxt)) {
- stop = stop * fdisk_context_get_units_per_sector(cxt) - 1;
+ if (fdisk_use_cylinders(cxt)) {
+ stop = stop * fdisk_get_units_per_sector(cxt) - 1;
if (stop >limit)
stop = limit;
}
/* note that the defauls is to display a column always */
enum {
- FDISK_FIELDFL_DETAIL = (1 << 1), /* only display if fdisk_context_display_details() */
- FDISK_FIELDFL_EYECANDY = (1 << 2), /* don't display if fdisk_context_display_details() */
+ FDISK_FIELDFL_DETAIL = (1 << 1), /* only display if fdisk_is_details() */
+ FDISK_FIELDFL_EYECANDY = (1 << 2), /* don't display if fdisk_is_details() */
FDISK_FIELDFL_NUMBER = (1 << 3), /* column display numbers */
};
};
/* context.c */
-extern int __fdisk_context_switch_label(struct fdisk_context *cxt,
+extern int __fdisk_switch_label(struct fdisk_context *cxt,
struct fdisk_label *lb);
-extern int fdisk_context_enable_listonly(struct fdisk_context *cxt, int enable);
-extern int fdisk_context_listonly(struct fdisk_context *cxt);
-
-
/* alignment.c */
extern sector_t fdisk_scround(struct fdisk_context *cxt, sector_t num);
extern sector_t fdisk_cround(struct fdisk_context *cxt, sector_t num);
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, GPT));
- if (fdisk_context_display_details(cxt)) {
+ if (fdisk_is_details(cxt)) {
struct gpt_header *h = self_label(cxt)->pheader;
fdisk_info(cxt, _("First LBA: %ju"), h->first_usable_lba);
#include "fdiskP.h"
/*
- * Don't use this function derectly, use fdisk_new_context_from_filename()
+ * Don't use this function derectly
*/
int fdisk_probe_labels(struct fdisk_context *cxt)
{
continue;
}
- __fdisk_context_switch_label(cxt, lb);
+ __fdisk_switch_label(cxt, lb);
return 0;
}
(!cxt->geom.heads || !cxt->geom.sectors
|| !cxt->geom.cylinders));
- if (rc && !fdisk_context_listonly(cxt))
+ if (rc && !fdisk_is_listonly(cxt))
fdisk_warnx(cxt, _("Incomplete geometry setting."));
return rc;
*
* This function returns the default or all fields for the current label.
* Note that the set of the default fields depends on
- * fdisk_context_enable_details() function. If the details are enabled then
+ * fdisk_enable_details() function. If the details are enabled then
* this function usually returns more fields.
*
* Returns 0 on success, otherwise, a corresponding error.
int id = cxt->label->fields[i].id;
if (!all &&
- ((fdisk_context_display_details(cxt) &&
+ ((fdisk_is_details(cxt) &&
(cxt->label->fields[i].flags & FDISK_FIELDFL_EYECANDY))
- || (!fdisk_context_display_details(cxt) &&
+ || (!fdisk_is_details(cxt) &&
(cxt->label->fields[i].flags & FDISK_FIELDFL_DETAIL))
|| (id == FDISK_FIELD_SECTORS &&
- fdisk_context_use_cylinders(cxt))
+ fdisk_use_cylinders(cxt))
|| (id == FDISK_FIELD_CYLINDERS &&
- !fdisk_context_use_cylinders(cxt))))
+ !fdisk_use_cylinders(cxt))))
continue;
c[n++] = id;
haslabel = 1;
}
- lb = fdisk_context_get_label(cxt, name);
+ lb = fdisk_get_label(cxt, name);
if (!lb || lb->disabled)
return -EINVAL;
if (!lb->op->create)
return -ENOSYS;
- __fdisk_context_switch_label(cxt, lb);
+ __fdisk_switch_label(cxt, lb);
if (haslabel && !cxt->parent)
fdisk_reset_device_properties(cxt);
extern void fdisk_init_debug(int mask);
/* context.h */
-extern struct fdisk_context *fdisk_new_context(void);
-extern struct fdisk_context *fdisk_new_nested_context(
- struct fdisk_context *parent, const char *name);
-extern void fdisk_free_context(struct fdisk_context *cxt);
-
-extern int fdisk_context_set_ask(struct fdisk_context *cxt,
- int (*ask_cb)(struct fdisk_context *, struct fdisk_ask *, void *),
- void *data);
-
-extern int fdisk_context_is_readonly(struct fdisk_context *cxt);
-extern int fdisk_context_assign_device(struct fdisk_context *cxt,
- const char *fname, int readonly);
-extern int fdisk_context_deassign_device(struct fdisk_context *cxt, int nosync);
-
-extern struct fdisk_label *fdisk_context_get_label(struct fdisk_context *cxt,
- const char *name);
-extern int fdisk_context_next_label(struct fdisk_context *cxt, struct fdisk_label **lb);
-extern size_t fdisk_context_get_nlabels(struct fdisk_context *cxt);
-
-extern int fdisk_context_switch_label(struct fdisk_context *cxt,
- const char *name);
-
-extern int fdisk_context_set_unit(struct fdisk_context *cxt, const char *str);
#define PLURAL 0
#define SINGULAR 1
-extern const char *fdisk_context_get_unit(struct fdisk_context *cxt, int n);
-extern unsigned int fdisk_context_get_units_per_sector(struct fdisk_context *cxt);
-extern int fdisk_context_enable_details(struct fdisk_context *cxt, int enable);
-extern int fdisk_context_use_cylinders(struct fdisk_context *cxt);
-extern int fdisk_context_display_details(struct fdisk_context *cxt);
+struct fdisk_context *fdisk_new_context(void);
+struct fdisk_context *fdisk_new_nested_context(struct fdisk_context *parent, const char *name);
+void fdisk_free_context(struct fdisk_context *cxt);
+
+struct fdisk_label *fdisk_get_label(struct fdisk_context *cxt, const char *name);
+int fdisk_next_label(struct fdisk_context *cxt, struct fdisk_label **lb);
+size_t fdisk_get_nlabels(struct fdisk_context *cxt);
+int fdisk_switch_label(struct fdisk_context *cxt, const char *name);
+
+int fdisk_assign_device(struct fdisk_context *cxt,
+ const char *fname, int readonly);
+int fdisk_deassign_device(struct fdisk_context *cxt, int nosync);
+int fdisk_is_readonly(struct fdisk_context *cxt);
+
+int fdisk_set_ask(struct fdisk_context *cxt,
+ int (*ask_cb)(struct fdisk_context *, struct fdisk_ask *, void *),
+ void *data);
+
+int fdisk_enable_details(struct fdisk_context *cxt, int enable);
+int fdisk_is_details(struct fdisk_context *cxt);
+
+int fdisk_enable_listonly(struct fdisk_context *cxt, int enable);
+int fdisk_is_listonly(struct fdisk_context *cxt);
+
+int fdisk_set_unit(struct fdisk_context *cxt, const char *str);
+const char *fdisk_get_unit(struct fdisk_context *cxt, int n);
+int fdisk_use_cylinders(struct fdisk_context *cxt);
+unsigned int fdisk_get_units_per_sector(struct fdisk_context *cxt);
+
+unsigned long fdisk_get_optimal_iosize(struct fdisk_context *cxt);
+unsigned long fdisk_get_minimal_size(struct fdisk_context *cxt);
+unsigned long fdisk_get_physector_size(struct fdisk_context *cxt);
+unsigned long fdisk_get_sector_size(struct fdisk_context *cxt);
+unsigned long fdisk_get_alignment_offset(struct fdisk_context *cxt);
+unsigned long fdisk_get_grain_size(struct fdisk_context *cxt);
+unsigned long fdisk_get_first_lba(struct fdisk_context *cxt);
+unsigned long fdisk_get_nsectors(struct fdisk_context *cxt);
+const char *fdisk_get_devname(struct fdisk_context *cxt);
/* parttype.c */
extern struct fdisk_parttype *fdisk_get_parttype_from_code(struct fdisk_context *cxt,
{
uint64_t sz = pa->size * cxt->sector_size;
- if (fdisk_context_display_details(cxt)) {
+ if (fdisk_is_details(cxt)) {
rc = pa->size_post ?
asprintf(&p, "%ju%c", sz, pa->size_post) :
asprintf(&p, "%ju", sz);
struct sgi_device_parameter *sgiparam = &sgilabel->devparam;
int rc = 0;
- if (fdisk_context_display_details(cxt))
+ if (fdisk_is_details(cxt))
fdisk_info(cxt, _(
"Label geometry: %d heads, %llu sectors\n"
" %llu cylinders, %d physical cylinders\n"
return -ERANGE;
} else {
snprintf(mesg, sizeof(mesg), _("First %s"),
- fdisk_context_get_unit(cxt, SINGULAR));
+ fdisk_get_unit(cxt, SINGULAR));
ask = fdisk_new_ask();
if (!ask)
return -ENOMEM;
if (rc)
return rc;
- if (fdisk_context_use_cylinders(cxt))
- first *= fdisk_context_get_units_per_sector(cxt);
+ if (fdisk_use_cylinders(cxt))
+ first *= fdisk_get_units_per_sector(cxt);
}
if (first && sys == SGI_TYPE_ENTIRE_DISK)
} else {
snprintf(mesg, sizeof(mesg),
_("Last %s or +%s or +size{K,M,G,T,P}"),
- fdisk_context_get_unit(cxt, SINGULAR),
- fdisk_context_get_unit(cxt, PLURAL));
+ fdisk_get_unit(cxt, SINGULAR),
+ fdisk_get_unit(cxt, PLURAL));
ask = fdisk_new_ask();
if (!ask)
fdisk_ask_number_set_high(ask, fdisk_scround(cxt, last) - 1);/* maximal */
fdisk_ask_number_set_base(ask, fdisk_scround(cxt, first));
- if (fdisk_context_use_cylinders(cxt))
+ if (fdisk_use_cylinders(cxt))
fdisk_ask_number_set_unit(ask,
cxt->sector_size *
- fdisk_context_get_units_per_sector(cxt));
+ fdisk_get_units_per_sector(cxt));
else
fdisk_ask_number_set_unit(ask,cxt->sector_size);
fdisk_free_ask(ask);
if (rc)
return rc;
- if (fdisk_context_use_cylinders(cxt))
- last *= fdisk_context_get_units_per_sector(cxt);
+ if (fdisk_use_cylinders(cxt))
+ last *= fdisk_get_units_per_sector(cxt);
}
if (sys == SGI_TYPE_ENTIRE_DISK
struct fdisk_ask *ask;
snprintf(mesg, sizeof(mesg), _("First %s"),
- fdisk_context_get_unit(cxt, SINGULAR));
+ fdisk_get_unit(cxt, SINGULAR));
for (;;) {
ask = fdisk_new_ask();
if (!ask)
if (rc)
return rc;
- if (fdisk_context_use_cylinders(cxt))
- first *= fdisk_context_get_units_per_sector(cxt);
+ if (fdisk_use_cylinders(cxt))
+ first *= fdisk_get_units_per_sector(cxt);
/* ewt asks to add: "don't start a partition at cyl 0"
However, edmundo@rano.demon.co.uk writes:
"third partition covers the whole disk "
"and is of type `Whole disk'"));
- if (!fdisk_context_use_cylinders(cxt)) {
+ if (!fdisk_use_cylinders(cxt)) {
/* Starting sector has to be properly aligned */
int cs = cxt->geom.heads * cxt->geom.sectors;
int x = first % cs;
snprintf(mesg, sizeof(mesg),
_("Last %s or +%s or +size{K,M,G,T,P}"),
- fdisk_context_get_unit(cxt, SINGULAR),
- fdisk_context_get_unit(cxt, PLURAL));
+ fdisk_get_unit(cxt, SINGULAR),
+ fdisk_get_unit(cxt, PLURAL));
fdisk_ask_set_query(ask, mesg);
fdisk_ask_set_type(ask, FDISK_ASKTYPE_OFFSET);
fdisk_ask_number_set_base(ask, fdisk_scround(cxt, first));
}
- if (fdisk_context_use_cylinders(cxt))
+ if (fdisk_use_cylinders(cxt))
fdisk_ask_number_set_unit(ask,
cxt->sector_size *
- fdisk_context_get_units_per_sector(cxt));
+ fdisk_get_units_per_sector(cxt));
else
fdisk_ask_number_set_unit(ask, cxt->sector_size);
fdisk_free_ask(ask);
if (rc)
return rc;
- if (fdisk_context_use_cylinders(cxt))
- last *= fdisk_context_get_units_per_sector(cxt);
+ if (fdisk_use_cylinders(cxt))
+ last *= fdisk_get_units_per_sector(cxt);
}
if (n == 2 && !first) {
_("You haven't covered the whole disk with the 3rd partition, but your value\n"
"%lu %s covers some other partition. Your entry has been changed\n"
"to %lu %s"),
- (unsigned long) fdisk_scround(cxt, last), fdisk_context_get_unit(cxt, SINGULAR),
- (unsigned long) fdisk_scround(cxt, stop), fdisk_context_get_unit(cxt, SINGULAR));
+ (unsigned long) fdisk_scround(cxt, last), fdisk_get_unit(cxt, SINGULAR),
+ (unsigned long) fdisk_scround(cxt, stop), fdisk_get_unit(cxt, SINGULAR));
last = stop;
}
} else if (!whole_disk && last > stop)
sunlabel = self_disklabel(cxt);
- if (fdisk_context_display_details(cxt)) {
+ if (fdisk_is_details(cxt)) {
fdisk_info(cxt,
_("Label geometry: %d rpm, %d alternate and %d physical cylinders,\n"
" %d extra sects/cyl, interleave %d:1"),