diff options
author | Karel Zak | 2017-07-10 12:32:26 +0200 |
---|---|---|
committer | Karel Zak | 2017-07-10 12:32:26 +0200 |
commit | 2469ba36774f1cc982fe3bace2e8c21aa26701d6 (patch) | |
tree | f6983c866efa43fc37d01ff6e38e8e2f38380ee2 /libfdisk/src/context.c | |
parent | agetty: print /etc/issue on --skip-login (diff) | |
download | kernel-qcow2-util-linux-2469ba36774f1cc982fe3bace2e8c21aa26701d6.tar.gz kernel-qcow2-util-linux-2469ba36774f1cc982fe3bace2e8c21aa26701d6.tar.xz kernel-qcow2-util-linux-2469ba36774f1cc982fe3bace2e8c21aa26701d6.zip |
libfdisk: add fdisk_reassign_device()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/context.c')
-rw-r--r-- | libfdisk/src/context.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 951310ffa..666ebbba0 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -632,6 +632,8 @@ int fdisk_deassign_device(struct fdisk_context *cxt, int nosync) return rc; } + DBG(CXT, ul_debugobj(cxt, "de-assigning device %s", cxt->dev_path)); + if (cxt->readonly) close(cxt->dev_fd); else { @@ -656,6 +658,40 @@ int fdisk_deassign_device(struct fdisk_context *cxt, int nosync) } /** + * fdisk_reassign_device: + * @cxt: context + * + * This function is "hard reset" of the context and it does not write anything + * to the device. All in-memory changes associated with the context will be + * lost. It's recommended to use this function after some fatal problem when the + * context (and label specific driver) is in an undefined state. + * + * Returns: 0 on success, < 0 on error. + */ +int fdisk_reassign_device(struct fdisk_context *cxt) +{ + char *devname; + int rdonly, rc; + + assert(cxt); + assert(cxt->dev_fd >= 0); + + DBG(CXT, ul_debugobj(cxt, "re-assigning device %s", cxt->dev_path)); + + devname = strdup(cxt->dev_path); + if (!devname) + return -ENOMEM; + + rdonly = cxt->readonly; + + fdisk_deassign_device(cxt, 1); + rc = fdisk_assign_device(cxt, devname, rdonly); + free(devname); + + return rc; +} + +/** * fdisk_is_readonly: * @cxt: context * |