[PATCH 2/2] fuse2fs: track our own writable state

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Darrick J. Wong <djwong@xxxxxxxxxx>

Track our own willingness to write to the filesystem in a separate
variable from that of libext2fs.  There's a small window between opening
the filesystem and mounting it where the library is rw but we might fail
a mount task and therefore don't want to write anything more.

Signed-off-by: "Darrick J. Wong" <djwong@xxxxxxxxxx>
---
 misc/fuse2fs.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index b68ae2d216d5d3..9667f00e366a66 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -164,6 +164,7 @@ struct fuse2fs {
 	uint8_t directio;
 	uint8_t acl;
 	uint8_t dirsync;
+	uint8_t writable;
 
 	int blocklog;
 	unsigned int blockmask;
@@ -434,8 +435,6 @@ static int update_atime(ext2_filsys fs, ext2_ino_t ino)
 	struct ext2_inode_large inode, *pinode;
 	struct timespec atime, mtime, now;
 
-	if (!(fs->flags & EXT2_FLAG_RW))
-		return 0;
 	err = fuse2fs_read_inode(fs, ino, &inode);
 	if (err)
 		return translate_error(fs, ino, err);
@@ -545,9 +544,7 @@ static int fs_can_allocate(struct fuse2fs *ff, blk64_t num)
 
 static int fs_writeable(struct fuse2fs *ff)
 {
-	ext2_filsys fs = ff->fs;
-
-	return (fs->flags & EXT2_FLAG_RW) && (fs->super->s_error_count == 0);
+	return ff->writable && (ff->fs->super->s_error_count == 0);
 }
 
 static inline int is_superuser(struct fuse2fs *ff, struct fuse_context *ctxt)
@@ -701,6 +698,7 @@ static errcode_t open_fs(struct fuse2fs *ff, int libext2_flags)
 	errcode_t err;
 
 	snprintf(options, sizeof(options) - 1, "offset=%lu", ff->offset);
+	ff->writable = 0;
 
 	if (ff->directio)
 		flags |= EXT2_FLAG_DIRECT_IO;
@@ -852,6 +850,7 @@ _("Mounting read-only without recovering journal."));
 			translate_error(fs, 0, err);
 			return err;
 		}
+		ff->writable = 1;
 	}
 
 	if (!(fs->super->s_state & EXT2_VALID_FS))
@@ -895,7 +894,7 @@ static void op_destroy(void *p EXT2FS_ATTR((unused)))
 	fs = ff->fs;
 
 	dbg_printf(ff, "%s: dev=%s\n", __func__, fs->device_name);
-	if (fs->flags & EXT2_FLAG_RW) {
+	if (ff->writable) {
 		fs->super->s_state |= EXT2_VALID_FS;
 		if (fs->super->s_error_count)
 			fs->super->s_state |= EXT2_ERROR_FS;
@@ -1002,7 +1001,7 @@ static void *op_init(struct fuse_conn_info *conn
 	}
 
 	/* Clear the valid flag so that an unclean shutdown forces a fsck */
-	if (fs->flags & EXT2_FLAG_RW) {
+	if (ff->writable) {
 		fs->super->s_mnt_count++;
 		ext2fs_set_tstamp(fs->super, s_mtime, time(NULL));
 		fs->super->s_state &= ~EXT2_VALID_FS;
@@ -3083,7 +3082,7 @@ static int op_statfs(const char *path EXT2FS_ATTR((unused)),
 	fsid ^= *f;
 	buf->f_fsid = fsid;
 	buf->f_flag = 0;
-	if (fs->flags & EXT2_FLAG_RW)
+	if (ff->writable)
 		buf->f_flag |= ST_RDONLY;
 	buf->f_namemax = EXT2_NAME_LEN;
 
@@ -5191,6 +5190,7 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
 		err_printf(ff, "%s\n",
  _("Remounting read-only due to errors."));
 		fs->flags &= ~EXT2_FLAG_RW;
+		ff->writable = 0;
 		break;
 	case EXT2_ERRORS_PANIC:
 		err_printf(ff, "%s\n",





[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux