X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=yaffs_vfs_single.c;h=0817ff0c30399db41e0104f112226b9d2210175a;hp=232dc2625328a7173509456dcf227c7411d9da5b;hb=HEAD;hpb=bc62199fe5f099e04e34857b346cfa89df5da1be diff --git a/yaffs_vfs_single.c b/yaffs_vfs_single.c index 232dc26..0817ff0 100644 --- a/yaffs_vfs_single.c +++ b/yaffs_vfs_single.c @@ -1,8 +1,7 @@ /* * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. * - * Copyright (C) 2002-2011 Aleph One Ltd. - * for Toby Churchill Ltd and Brightstar Engineering + * Copyright (C) 2002-2018 Aleph One Ltd. * * Created by Charles Manning * Acknowledgements: @@ -450,7 +449,7 @@ static int yaffs_sync_object(struct file *file, yaffs_trace(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC, "yaffs_sync_object"); yaffs_gross_lock(dev); - yaffs_flush_file(obj, 1, datasync); + yaffs_flush_file(obj, 1, datasync, 0); yaffs_gross_unlock(dev); return 0; } @@ -890,7 +889,7 @@ static int yaffs_file_flush(struct file *file, fl_owner_t id) yaffs_gross_lock(dev); - yaffs_flush_file(obj, 1, 0); + yaffs_flush_file(obj, 1, 0, 0); yaffs_gross_unlock(dev); @@ -1490,15 +1489,34 @@ static void yaffs_flush_inodes(struct super_block *sb) { struct inode *iptr; struct yaffs_obj *obj; + struct yaffs_dev *dev = yaffs_super_to_dev(sb); + spin_lock(&sb->s_inode_list_lock); list_for_each_entry(iptr, &sb->s_inodes, i_sb_list) { + spin_lock(&inode->i_lock); + if (iptr->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) { + spin_unlock(&inode->i_lock); + continue; + } + + __iget(iptr); + spin_unlock(&inode->i_lock); + spin_unlock(&sb->s_inode_list_lock); + obj = yaffs_inode_to_obj(iptr); if (obj) { yaffs_trace(YAFFS_TRACE_OS, "flushing obj %d", obj->obj_id); - yaffs_flush_file(obj, 1, 0); + yaffs_flush_file(obj, 1, 0, 0); } + + yaffs_gross_unlock(dev); + iput(iptr); + yaffs_gross_lock(dev); + + spin_lock(&sb->s_inode_list_lock); } + spin_unlock(&sb->s_inode_list_lock); } static void yaffs_flush_super(struct super_block *sb, int do_checkpoint) @@ -1510,7 +1528,7 @@ static void yaffs_flush_super(struct super_block *sb, int do_checkpoint) yaffs_flush_inodes(sb); yaffs_update_dirty_dirs(dev); - yaffs_flush_whole_cache(dev); + yaffs_flush_whole_cache(dev, 1); if (do_checkpoint) yaffs_checkpoint_save(dev); } @@ -1872,11 +1890,11 @@ static void yaffs_fill_inode_from_obj(struct inode *inode, inode->i_rdev = old_decode_dev(obj->yst_rdev); - inode->i_atime.tv_sec = (time_t) (obj->yst_atime); + inode->i_atime.tv_sec = (YTIME_T) (obj->yst_atime); inode->i_atime.tv_nsec = 0; - inode->i_mtime.tv_sec = (time_t) obj->yst_mtime; + inode->i_mtime.tv_sec = (YTIME_T) obj->yst_mtime; inode->i_mtime.tv_nsec = 0; - inode->i_ctime.tv_sec = (time_t) obj->yst_ctime; + inode->i_ctime.tv_sec = (YTIME_T) obj->yst_ctime; inode->i_ctime.tv_nsec = 0; inode->i_size = yaffs_get_obj_length(obj); inode->i_blocks = (inode->i_size + 511) >> 9; @@ -1943,8 +1961,6 @@ static void yaffs_put_super(struct super_block *sb) kfree(dev); - - if (mtd && mtd->sync) mtd->sync(mtd); @@ -1952,12 +1968,54 @@ static void yaffs_put_super(struct super_block *sb) put_mtd_device(mtd); } +/* the function only is used to change dev->read_only when this file system + * is remounted. + */ +static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data) +{ + int read_only = 0; + struct mtd_info *mtd; + struct yaffs_dev *dev = 0; + + /* Get the device */ + mtd = get_mtd_device(NULL, MINOR(sb->s_dev)); + if (!mtd) { + yaffs_trace(YAFFS_TRACE_ALWAYS, + "MTD device #%u doesn't appear to exist", + MINOR(sb->s_dev)); + return 1; + } + + /* Check it's NAND */ + if (mtd->type != MTD_NANDFLASH) { + yaffs_trace(YAFFS_TRACE_ALWAYS, + "MTD device is not NAND it's type %d", + mtd->type); + return 1; + } + + read_only = ((*flags & MS_RDONLY) != 0); + if (!read_only && !(mtd->flags & MTD_WRITEABLE)) { + read_only = 1; + printk(KERN_INFO + "yaffs: mtd is read only, setting superblock read only"); + *flags |= MS_RDONLY; + } + + dev = sb->s_fs_info; + dev->read_only = read_only; + + return 0; +} + + static const struct super_operations yaffs_super_ops = { .statfs = yaffs_statfs, .put_super = yaffs_put_super, .evict_inode = yaffs_evict_inode, .sync_fs = yaffs_sync_fs, .write_super = yaffs_write_super, + .remount_fs = yaffs_remount_fs, }; static struct super_block *yaffs_internal_read_super(int yaffs_version,