summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/context.c
diff options
context:
space:
mode:
authorKarel Zak2017-01-13 11:23:23 +0100
committerKarel Zak2017-01-13 11:23:23 +0100
commit7526c305b459f1387dad72d1543308246fc12877 (patch)
tree2947ea35cf9f0f5b688d991bb3ec1d05a2b5c9d4 /libfdisk/src/context.c
parentIf mtab support is disabled, disable ro/rw mtab checks (diff)
downloadkernel-qcow2-util-linux-7526c305b459f1387dad72d1543308246fc12877.tar.gz
kernel-qcow2-util-linux-7526c305b459f1387dad72d1543308246fc12877.tar.xz
kernel-qcow2-util-linux-7526c305b459f1387dad72d1543308246fc12877.zip
libfdisk: don't use blkdev ioctls for regular files
$ fdisk <diskimage> open("sdc.img", O_RDONLY|O_CLOEXEC) = 3 ioctl(3, BLKSSZGET, 0x7ffcf51357c4) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(3, BLKGETSIZE64, 0x7ffcf51357b0) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(3, BLKGETSIZE, 0x7ffcf51356c8) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(3, FDGETPRM, 0x7ffcf51356d0) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(3, HDIO_GETGEO, 0x7ffcf5135790) = -1 ENOTTY (Inappropriate ioctl for device) Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/context.c')
-rw-r--r--libfdisk/src/context.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c
index 90f97a565..947f104fa 100644
--- a/libfdisk/src/context.c
+++ b/libfdisk/src/context.c
@@ -488,6 +488,8 @@ static void reset_context(struct fdisk_context *cxt)
free(cxt->collision);
cxt->collision = NULL;
+ memset(&cxt->dev_st, 0, sizeof(cxt->dev_st));
+
cxt->dev_fd = -1;
cxt->firstsector = NULL;
cxt->firstsector_bufsz = 0;
@@ -581,7 +583,7 @@ int fdisk_assign_device(struct fdisk_context *cxt,
int rc, org = fdisk_is_listonly(cxt->parent);
/* assign_device() is sensitive to "listonly" mode, so let's
- * follow the current context setting for the parent to avoid
+ * follow the current context setting for the parent to avoid
* unwanted extra warnings. */
fdisk_enable_listonly(cxt->parent, fdisk_is_listonly(cxt));
@@ -601,6 +603,8 @@ int fdisk_assign_device(struct fdisk_context *cxt,
if (fd < 0)
return -errno;
+ fstat(fd, &cxt->dev_st);
+
cxt->readonly = readonly;
cxt->dev_fd = fd;
cxt->dev_path = strdup(fname);
@@ -693,6 +697,18 @@ int fdisk_is_readonly(struct fdisk_context *cxt)
}
/**
+ * fdisk_is_regfile:
+ * @cxt: context
+ *
+ * Returns: 1 if open file descriptor is regular file rather than a block device.
+ */
+int fdisk_is_regfile(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return S_ISREG(cxt->dev_st.st_mode);
+}
+
+/**
* fdisk_unref_context:
* @cxt: fdisk context
*