summaryrefslogtreecommitdiffstats
path: root/disk-utils/fdisk.c
diff options
context:
space:
mode:
authorKarel Zak2014-03-21 14:04:59 +0100
committerKarel Zak2014-03-21 14:04:59 +0100
commite146ae4edb52b0559cbb42717338665c6395b56f (patch)
tree95f86c65e0c0f4d1eed1940b92a955be838dc670 /disk-utils/fdisk.c
parentlibfdisk: clean up debug output (diff)
downloadkernel-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 'disk-utils/fdisk.c')
-rw-r--r--disk-utils/fdisk.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c
index fa7f248cc..bfe3fe3b5 100644
--- a/disk-utils/fdisk.c
+++ b/disk-utils/fdisk.c
@@ -778,7 +778,7 @@ enum {
int main(int argc, char **argv)
{
- int i, c, act = ACT_FDISK;
+ int rc, i, c, act = ACT_FDISK;
int colormode = UL_COLORMODE_UNDEF;
struct fdisk_context *cxt;
@@ -920,7 +920,13 @@ int main(int argc, char **argv)
fdisk_info(cxt, _("Changes will remain in memory only, until you decide to write them.\n"
"Be careful before using the write command.\n"));
- if (fdisk_context_assign_device(cxt, argv[optind], 0) != 0)
+ rc = fdisk_context_assign_device(cxt, argv[optind], 0);
+ if (rc == -EACCES) {
+ rc = fdisk_context_assign_device(cxt, argv[optind], 1);
+ if (rc == 0)
+ fdisk_warnx(cxt, _("Device open in read-only mode."));
+ }
+ if (rc)
err(EXIT_FAILURE, _("cannot open %s"), argv[optind]);
fflush(stdout);