fdisk_get_alignment_offset
fdisk_get_collision
fdisk_get_devfd
+fdisk_get_devmodel
fdisk_get_devname
+fdisk_get_devno
fdisk_get_disklabel_item
fdisk_get_first_lba
fdisk_get_geom_cylinders
cxt->protect_bootbits = parent->protect_bootbits;
}
+ free(cxt->dev_model);
+ cxt->dev_model = NULL;
+ cxt->dev_model_probed = 0;
+
free(cxt->dev_path);
cxt->dev_path = NULL;
free(cxt->dev_path);
cxt->dev_path = NULL;
+ free(cxt->dev_model);
+ cxt->dev_model = NULL;
+ cxt->dev_model_probed = 0;
+
free(cxt->collision);
cxt->collision = NULL;
return cxt->dev_path;
}
+/**
+ * fdisk_get_devno:
+ * @cxt: context
+ *
+ * Returns: device number or zero for non-block devices
+ */
+dev_t fdisk_get_devno(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return S_ISBLK(cxt->dev_st.st_mode) ? cxt->dev_st.st_rdev : 0;
+}
+
+/**
+ * fdisk_get_devmodel:
+ * @cxt: context
+ *
+ * Returns: device model string or NULL.
+ */
+const char *fdisk_get_devmodel(struct fdisk_context *cxt)
+{
+#ifdef __linux__
+ assert(cxt);
+
+ if (cxt->dev_model_probed)
+ return cxt->dev_model;
+
+ if (fdisk_get_devno(cxt)) {
+ struct path_cxt *pc = ul_new_sysfs_path(fdisk_get_devno(cxt), NULL, NULL);
+
+ if (pc) {
+ ul_path_read_string(pc, &cxt->dev_model, "device/model");
+ ul_unref_path(pc);
+ }
+ }
+ cxt->dev_model_probed = 1;
+ return cxt->dev_model;
+#else
+ return NULL;
+#endif
+
+}
+
/**
* fdisk_get_devfd:
* @cxt: context
struct fdisk_context {
int dev_fd; /* device descriptor */
char *dev_path; /* device path */
+ char *dev_model; /* on linux /sys/block/<name>/device/model or NULL */
struct stat dev_st; /* stat(2) result */
int refcount;
protect_bootbits : 1, /* don't zeroize first sector */
pt_collision : 1, /* another PT detected by libblkid */
no_disalogs : 1, /* disable dialog-driven partititoning */
+ dev_model_probed : 1, /* tried to read from sys */
listonly : 1; /* list partition, nothing else */
char *collision; /* name of already existing FS/PT */
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
+#include <sys/types.h>
/**
* LIBFDISK_VERSION:
fdisk_sector_t fdisk_get_last_lba(struct fdisk_context *cxt);
fdisk_sector_t fdisk_set_last_lba(struct fdisk_context *cxt, fdisk_sector_t lba);
fdisk_sector_t fdisk_get_nsectors(struct fdisk_context *cxt);
+
const char *fdisk_get_devname(struct fdisk_context *cxt);
int fdisk_get_devfd(struct fdisk_context *cxt);
+dev_t fdisk_get_devno(struct fdisk_context *cxt);
+const char *fdisk_get_devmodel(struct fdisk_context *cxt);
+
unsigned int fdisk_get_geom_heads(struct fdisk_context *cxt);
fdisk_sector_t fdisk_get_geom_sectors(struct fdisk_context *cxt);
FDISK_2.33 {
fdisk_ask_number_is_wrap_negative;
+ fdisk_get_devmodel;
+ fdisk_get_devno;
} FDISK_2.32;