libfdisk: add fdisk_device_is_used()
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
2db3cc4cf3
commit
b9da153254
|
@ -287,6 +287,7 @@ fdisk_context
|
|||
fdisk_assign_device
|
||||
fdisk_deassign_device
|
||||
fdisk_reassign_device
|
||||
fdisk_device_is_used
|
||||
fdisk_enable_bootbits_protection
|
||||
fdisk_enable_details
|
||||
fdisk_enable_listonly
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
# include <blkid.h>
|
||||
#endif
|
||||
|
||||
#include "blkdev.h"
|
||||
#include "loopdev.h"
|
||||
#include "fdiskP.h"
|
||||
|
||||
|
||||
|
@ -733,6 +735,38 @@ int fdisk_reread_partition_table(struct fdisk_context *cxt)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* fdisk_device_is_used:
|
||||
* @cxt: context
|
||||
*
|
||||
* On systems where is no BLKRRPART ioctl the function returns zero and
|
||||
* sets errno to ENOSYS.
|
||||
*
|
||||
* Returns: 1 if the device assigned to the context is used by system, or 0.
|
||||
*/
|
||||
int fdisk_device_is_used(struct fdisk_context *cxt)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
assert(cxt);
|
||||
assert(cxt->dev_fd >= 0);
|
||||
|
||||
errno = 0;
|
||||
|
||||
#ifdef BLKRRPART
|
||||
/* it seems kernel always return EINVAL for BLKRRPART on loopdevices */
|
||||
if (S_ISBLK(cxt->dev_st.st_mode)
|
||||
&& major(cxt->dev_st.st_rdev) != LOOPDEV_MAJOR) {
|
||||
DBG(CXT, ul_debugobj(cxt, "calling re-read ioctl"));
|
||||
rc = ioctl(cxt->dev_fd, BLKRRPART) != 0;
|
||||
}
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
#endif
|
||||
DBG(CXT, ul_debugobj(cxt, "device used: %s [errno=%d]", rc ? "TRUE" : "FALSE", errno));
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* fdisk_is_readonly:
|
||||
* @cxt: context
|
||||
|
|
|
@ -185,6 +185,7 @@ int fdisk_reassign_device(struct fdisk_context *cxt);
|
|||
|
||||
int fdisk_is_readonly(struct fdisk_context *cxt);
|
||||
int fdisk_is_regfile(struct fdisk_context *cxt);
|
||||
int fdisk_device_is_used(struct fdisk_context *cxt);
|
||||
|
||||
int fdisk_enable_details(struct fdisk_context *cxt, int enable);
|
||||
int fdisk_is_details(struct fdisk_context *cxt);
|
||||
|
|
|
@ -285,4 +285,5 @@ FDISK_2.30 {
|
|||
|
||||
FDISK_2.31 {
|
||||
fdisk_reassign_device;
|
||||
fdisk_device_is_used;
|
||||
} FDISK_2.30;
|
||||
|
|
Loading…
Reference in New Issue