summaryrefslogtreecommitdiffstats
path: root/shlibs/mount/src/utils.c
diff options
context:
space:
mode:
authorKarel Zak2010-11-02 13:54:47 +0100
committerKarel Zak2011-01-03 12:28:46 +0100
commit70bf97aed95539feb2496f09316709d06b76b33d (patch)
tree65e7e0b67df8ab16dfc5dbf14115b084f48eee87 /shlibs/mount/src/utils.c
parentlibmount: fix comment for mnt_unlock_file() (diff)
downloadkernel-qcow2-util-linux-70bf97aed95539feb2496f09316709d06b76b33d.tar.gz
kernel-qcow2-util-linux-70bf97aed95539feb2496f09316709d06b76b33d.tar.xz
kernel-qcow2-util-linux-70bf97aed95539feb2496f09316709d06b76b33d.zip
libmount: improve function for work with mtab paths
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/utils.c')
-rw-r--r--shlibs/mount/src/utils.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c
index f2c1bf25b..924284965 100644
--- a/shlibs/mount/src/utils.c
+++ b/shlibs/mount/src/utils.c
@@ -407,15 +407,29 @@ done:
/*
* Returns 1 if /etc/mtab is a reqular file.
*/
-int mnt_has_regular_mtab(const char **mtab)
+int mnt_has_regular_mtab(const char **mtab, int *writeable)
{
struct stat st;
- const char *x = mnt_get_mtab_path();
+ int rc;
+ const char *x = mtab && *mtab ? *mtab : mnt_get_mtab_path();
- if (mtab)
+ if (mtab && !*mtab)
*mtab = x;
-
- return (lstat(x, &st) == 0 && S_ISREG(st.st_mode));
+ rc = (lstat(x, &st) == 0 && S_ISREG(st.st_mode));
+
+ if (writable) {
+ if (rc) {
+ /* TODO: use utimensat() */
+ int fd = open(path, O_RDWR, 0644);
+ if (fd >= 0) {
+ close(fd);
+ *writable = 1;
+ return rc;
+ }
+ }
+ *writable = 0;
+ }
+ return rc;
}
/**
@@ -456,27 +470,6 @@ const char *mnt_get_utab_path(void)
return p ? : MNT_PATH_UTAB;
}
-/**
- * mnt_get_writable_mtab_path:
- *
- * Returns: pointer to the static string with path to mtab or NULL if writable
- * mtab is unsupported.
- */
-const char *mnt_get_writable_mtab_path(void)
-{
- struct stat st;
- const char *path = mnt_get_mtab_path();
-
- if (lstat(path, &st) && S_ISREG(st.st_mode)) {
- int fd = open(path, O_RDWR, 0644);
- if (fd >= 0) {
- close(fd);
- return path;
- }
- }
-
- return NULL;
-}
/* returns file descriptor or -errno, @name returns uniques filename
*/