int check_flags;
};
+enum fuse2fs_opstate {
+ F2OP_READONLY,
+ F2OP_WRITABLE,
+};
+
/* Main program context */
#define FUSE2FS_MAGIC (0xEF53DEADUL)
struct fuse2fs {
int acl;
int dirsync;
+ enum fuse2fs_opstate opstate;
int logfd;
int blocklog;
int oom_score_adj;
ext2_filsys fs = ff->fs;
if (!fs || !ext2fs_has_feature_mmp(fs->super) ||
- !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP))
+ ff->opstate != F2OP_WRITABLE || (fs->flags & EXT2_FLAG_SKIP_MMP))
return false;
return true;
}
struct timespec atime, mtime, now;
double datime, dmtime, dnow;
- if (!(fs->flags & EXT2_FLAG_RW))
- return 0;
err = fuse2fs_read_inode(fs, ino, &inode);
if (err)
return translate_error(fs, ino, err);
static int fuse2fs_is_writeable(struct fuse2fs *ff)
{
- ext2_filsys fs = ff->fs;
-
- return (fs->flags & EXT2_FLAG_RW) && (fs->super->s_error_count == 0);
+ return ff->opstate == F2OP_WRITABLE &&
+ (ff->fs->super->s_error_count == 0);
}
static inline int is_superuser(struct fuse2fs *ff, struct fuse_context *ctxt)
}
snprintf(options, sizeof(options) - 1, "offset=%lu", ff->offset);
+ ff->opstate = F2OP_READONLY;
if (ff->directio)
flags |= EXT2_FLAG_DIRECT_IO;
_("Warning: fuse2fs does not support using the journal.\n"
"There may be file system corruption or data loss if\n"
"the file system is not gracefully unmounted.\n"));
+ ff->opstate = F2OP_WRITABLE;
}
if (!(fs->super->s_state & EXT2_VALID_FS))
ff->errors_behavior = fs->super->s_errors;
/* Clear the valid flag so that an unclean shutdown forces a fsck */
- if (fs->flags & EXT2_FLAG_RW) {
+ if (ff->opstate == F2OP_WRITABLE) {
fs->super->s_mnt_count++;
ext2fs_set_tstamp(fs->super, s_mtime, time(NULL));
fs->super->s_state &= ~EXT2_VALID_FS;
fs = fuse2fs_start(ff);
dbg_printf(ff, "%s: dev=%s\n", __func__, fs->device_name);
- if (fs->flags & EXT2_FLAG_RW) {
+ if (ff->opstate == F2OP_WRITABLE) {
fs->super->s_state |= EXT2_VALID_FS;
if (fs->super->s_error_count)
fs->super->s_state |= EXT2_ERROR_FS;
cfg->nullpath_ok = 1;
#endif
- if (ff->fs->flags & EXT2_FLAG_RW)
+ if (ff->opstate == F2OP_WRITABLE)
fuse2fs_read_bitmaps(ff);
/*
fsid ^= *f;
buf->f_fsid = fsid;
buf->f_flag = 0;
- if (!(fs->flags & EXT2_FLAG_RW))
+ if (ff->opstate != F2OP_WRITABLE)
buf->f_flag |= ST_RDONLY;
buf->f_namemax = EXT2_NAME_LEN;
fuse2fs_finish(ff, 0);
.logfd = -1,
.bfl = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER,
.oom_score_adj = -500,
+ .opstate = F2OP_WRITABLE,
};
errcode_t err;
FILE *orig_stderr = stderr;
_("Continuing after errors; is this a good idea?"));
break;
case EXT2_ERRORS_RO:
- if (fs->flags & EXT2_FLAG_RW)
+ if (ff->opstate == F2OP_WRITABLE) {
err_printf(ff, "%s\n",
_("Remounting read-only due to errors."));
+ ff->opstate = F2OP_READONLY;
+ }
fuse2fs_mmp_cancel(ff);
fs->flags &= ~EXT2_FLAG_RW;
break;