diff options
author | Karel Zak | 2014-03-21 14:04:59 +0100 |
---|---|---|
committer | Karel Zak | 2014-03-21 14:04:59 +0100 |
commit | e146ae4edb52b0559cbb42717338665c6395b56f (patch) | |
tree | 95f86c65e0c0f4d1eed1940b92a955be838dc670 /libfdisk/src/context.c | |
parent | libfdisk: clean up debug output (diff) | |
download | kernel-qcow2-util-linux-e146ae4edb52b0559cbb42717338665c6395b56f.tar.gz kernel-qcow2-util-linux-e146ae4edb52b0559cbb42717338665c6395b56f.tar.xz kernel-qcow2-util-linux-e146ae4edb52b0559cbb42717338665c6395b56f.zip |
libfdisk: properly implement read-only mode
Don't use fallback to read-only mode in fdisk_context_assign_device(),
it's application responsibility open the device in the right mode.
The commands fdisk and cfdisk check (and report) read-only mode now.
Reported-by: Maciej MaĆecki <me@mmalecki.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/context.c')
-rw-r--r-- | libfdisk/src/context.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 7d7b0c668..ec0b6d84f 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -260,12 +260,11 @@ int fdisk_context_assign_device(struct fdisk_context *cxt, reset_context(cxt); - if (readonly == 1 || (fd = open(fname, O_RDWR|O_CLOEXEC)) < 0) { - if ((fd = open(fname, O_RDONLY|O_CLOEXEC)) < 0) - return -errno; - readonly = 1; - } + fd = open(fname, (readonly ? O_RDONLY : O_RDWR ) | O_CLOEXEC); + if (fd < 0) + return -errno; + cxt->readonly = readonly; cxt->dev_fd = fd; cxt->dev_path = strdup(fname); if (!cxt->dev_path) @@ -315,6 +314,12 @@ int fdisk_context_deassign_device(struct fdisk_context *cxt) return 0; } +int fdisk_context_is_readonly(struct fdisk_context *cxt) +{ + assert(cxt); + return cxt->readonly; +} + /** * fdisk_free_context: * @cxt: fdisk context |