From f94a09b1519443deffd0356bbb2a4f26a8ec66e8 Mon Sep 17 00:00:00 2001 From: szaka Date: Fri, 27 Jun 2008 12:37:02 +0000 Subject: [PATCH] fix: mount failed if /etc/mtab didn't exist or was on a read-only file system (Miklos Szeredi, Szabolcs Szakacsits) --- libfuse-lite/mount_util.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/libfuse-lite/mount_util.c b/libfuse-lite/mount_util.c index e8154d21..5e162bf6 100644 --- a/libfuse-lite/mount_util.c +++ b/libfuse-lite/mount_util.c @@ -23,17 +23,35 @@ static int mtab_needs_update(const char *mnt) { - struct stat stbuf; + int res; + struct stat stbuf; - /* If mtab is within new mount, don't touch it */ - if (strncmp(mnt, _PATH_MOUNTED, strlen(mnt)) == 0 && - _PATH_MOUNTED[strlen(mnt)] == '/') - return 0; + /* If mtab is within new mount, don't touch it */ + if (strncmp(mnt, _PATH_MOUNTED, strlen(mnt)) == 0 && + _PATH_MOUNTED[strlen(mnt)] == '/') + return 0; - if (lstat(_PATH_MOUNTED, &stbuf) != -1 && S_ISLNK(stbuf.st_mode)) - return 0; + /* + * Skip mtab update if /etc/mtab: + * + * - doesn't exist, + * - is a symlink, + * - is on a read-only filesystem. + */ + res = lstat(_PATH_MOUNTED, &stbuf); + if (res == -1) { + if (errno == ENOENT) + return 0; + } else { + if (S_ISLNK(stbuf.st_mode)) + return 0; - return 1; + res = access(_PATH_MOUNTED, W_OK); + if (res == -1 && errno == EROFS) + return 0; + } + + return 1; } int fuse_mnt_add_mount(const char *progname, const char *fsname,