aboutsummaryrefslogtreecommitdiffstats
path: root/disk-utils/cfdisk.c
diff options
context:
space:
mode:
authorDmitriy Chestnykh <dm.chestnykh@gmail.com>2021-01-04 12:17:57 +0100
committerKarel Zak <kzak@redhat.com>2021-01-04 12:17:57 +0100
commit0d182490e3e6d0f23a774b73eb3805d9e8668e07 (patch)
tree50f0dd8b511b3fe5d84f0e247587c22c267cc764 /disk-utils/cfdisk.c
parentb2db5a71b5c37dea3f1d5780664fdce317389d18 (diff)
downloadutil-linux-0d182490e3e6d0f23a774b73eb3805d9e8668e07.tar.gz
cfdisk: Implemented cfdisk's opening in read-only mode
[kzak@redhat.com: - clean up the patch - add note "Changes will remain in memory only."] Addresses: https://github.com/karelzak/util-linux/issues/1209 Addresses: https://github.com/karelzak/util-linux/pull/1213 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/cfdisk.c')
-rw-r--r--disk-utils/cfdisk.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index d96b6e9e03..b549fe95ba 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -2568,7 +2568,7 @@ static int ui_run(struct cfdisk *cf)
ui_draw_extra(cf);
if (fdisk_is_readonly(cf->cxt))
- ui_warnx(_("Device is open in read-only mode."));
+ ui_warnx(_("Device is open in read-only mode. Changes will remain in memory only."));
else if (cf->wrong_order)
ui_info(_("Note that partition table entries are not in disk order now."));
@@ -2667,6 +2667,7 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(_(" -z, --zero start with zeroed partition table\n"), out);
fprintf(out,
_(" --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
+ fputs(_(" -r, --read-only forced open cfdisk in read-only mode\n"), out);
fputs(USAGE_SEPARATOR, out);
printf(USAGE_HELP_OPTIONS(26));
@@ -2679,6 +2680,7 @@ int main(int argc, char *argv[])
{
const char *diskpath = NULL, *lockmode = NULL;
int rc, c, colormode = UL_COLORMODE_UNDEF;
+ int read_only = 0;
struct cfdisk _cf = { .lines_idx = 0 },
*cf = &_cf;
enum {
@@ -2690,6 +2692,7 @@ int main(int argc, char *argv[])
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "zero", no_argument, NULL, 'z' },
+ { "read-only", no_argument, NULL, 'r' },
{ NULL, 0, NULL, 0 },
};
@@ -2698,7 +2701,7 @@ int main(int argc, char *argv[])
textdomain(PACKAGE);
close_stdout_atexit();
- while((c = getopt_long(argc, argv, "L::hVz", longopts, NULL)) != -1) {
+ while((c = getopt_long(argc, argv, "L::hVzr", longopts, NULL)) != -1) {
switch(c) {
case 'h':
usage();
@@ -2709,6 +2712,9 @@ int main(int argc, char *argv[])
colormode = colormode_or_err(optarg,
_("unsupported color mode"));
break;
+ case 'r':
+ read_only = 1;
+ break;
case 'V':
print_version(EXIT_SUCCESS);
case 'z':
@@ -2752,8 +2758,8 @@ int main(int argc, char *argv[])
} else
diskpath = argv[optind];
- rc = fdisk_assign_device(cf->cxt, diskpath, 0);
- if (rc == -EACCES)
+ rc = fdisk_assign_device(cf->cxt, diskpath, read_only);
+ if (rc == -EACCES && read_only == 0)
rc = fdisk_assign_device(cf->cxt, diskpath, 1);
if (rc != 0)
err(EXIT_FAILURE, _("cannot open %s"), diskpath);