diff -up ecryptfs-utils-87/src/libecryptfs/main.c.mtabfix ecryptfs-utils-87/src/libecryptfs/main.c --- ecryptfs-utils-87/src/libecryptfs/main.c.mtabfix 2011-03-09 14:30:32.000000000 +0100 +++ ecryptfs-utils-87/src/libecryptfs/main.c 2011-07-11 14:10:40.525812683 +0200 @@ -382,6 +382,7 @@ out: int ecryptfs_mount(char *source, char *target, unsigned long flags, char *opts) { + char dummy; FILE *mtab_fd = NULL; struct mntent mountent; char *fullpath_source = NULL; @@ -425,11 +426,14 @@ int ecryptfs_mount(char *source, char *t syslog(LOG_ERR, "Failed to perform eCryptfs mount: [%m]\n"); goto out; } - mtab_fd = setmntent("/etc/mtab", "a"); - if (!mtab_fd) { - rc = -EACCES; - syslog(LOG_ERR, "Failed to update the mount table\n"); - goto out; + /* it's possible that /etc/mtab is just a symlink to /proc/mounts */ + if (readlink("/etc/mtab", &dummy, 1) < 0) { + mtab_fd = setmntent("/etc/mtab", "a"); + if (!mtab_fd) { + rc = -EACCES; + syslog(LOG_ERR, "Failed to update the mount table\n"); + goto out; + } } mountent.mnt_fsname = fullpath_source; mountent.mnt_dir = fullpath_target; @@ -464,7 +468,7 @@ int ecryptfs_mount(char *source, char *t } mountent.mnt_freq = 0; mountent.mnt_passno = 0; - if (addmntent(mtab_fd, &mountent)) { + if (mtab_fd && addmntent(mtab_fd, &mountent)) { rc = -EIO; syslog(LOG_ERR, "Failed to write to the mount " "table\n"); diff -up ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c.mtabfix ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c --- ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c.mtabfix 2011-07-11 13:53:36.942438496 +0200 +++ ecryptfs-utils-87/src/utils/mount.ecryptfs_private.c 2011-07-11 13:53:36.954438583 +0200 @@ -219,9 +219,18 @@ int check_ownerships(int uid, char *path int update_mtab(char *dev, char *mnt, char *opt) { -/* Update /etc/mtab with new mount entry. +/* Update /etc/mtab with new mount entry unless it is a symbolic link * Return 0 on success, 1 on failure. */ + char dummy; + int useMtab; + /* Check if mtab is a symlink */ + useMtab = (readlink("/etc/mtab", &dummy, 1) < 0); + if (!useMtab) { + /* No need updating mtab */ + return 0; + } + FILE *fh; struct mntent m; fh = setmntent("/etc/mtab", "a");