2424#include <linux/blkdev.h>
2525#include <linux/mtd/mtd.h>
2626#include <linux/mtd/super.h>
27+ #include <linux/fs_context.h>
2728#include <linux/slab.h>
2829#include <linux/vfs.h>
2930#include <linux/mutex.h>
@@ -506,18 +507,19 @@ static void cramfs_kill_sb(struct super_block *sb)
506507 kfree (sbi );
507508}
508509
509- static int cramfs_remount (struct super_block * sb , int * flags , char * data )
510+ static int cramfs_reconfigure (struct fs_context * fc )
510511{
511- sync_filesystem (sb );
512- * flags |= SB_RDONLY ;
512+ sync_filesystem (fc -> root -> d_sb );
513+ fc -> sb_flags |= SB_RDONLY ;
513514 return 0 ;
514515}
515516
516- static int cramfs_read_super (struct super_block * sb ,
517- struct cramfs_super * super , int silent )
517+ static int cramfs_read_super (struct super_block * sb , struct fs_context * fc ,
518+ struct cramfs_super * super )
518519{
519520 struct cramfs_sb_info * sbi = CRAMFS_SB (sb );
520521 unsigned long root_offset ;
522+ bool silent = fc -> sb_flags & SB_SILENT ;
521523
522524 /* We don't know the real size yet */
523525 sbi -> size = PAGE_SIZE ;
@@ -532,7 +534,7 @@ static int cramfs_read_super(struct super_block *sb,
532534 /* check for wrong endianness */
533535 if (super -> magic == CRAMFS_MAGIC_WEND ) {
534536 if (!silent )
535- pr_err ( " wrong endianness\n " );
537+ errorf ( fc , "cramfs: wrong endianness" );
536538 return - EINVAL ;
537539 }
538540
@@ -544,22 +546,22 @@ static int cramfs_read_super(struct super_block *sb,
544546 mutex_unlock (& read_mutex );
545547 if (super -> magic != CRAMFS_MAGIC ) {
546548 if (super -> magic == CRAMFS_MAGIC_WEND && !silent )
547- pr_err ( " wrong endianness\n " );
549+ errorf ( fc , "cramfs: wrong endianness" );
548550 else if (!silent )
549- pr_err ( " wrong magic\n " );
551+ errorf ( fc , "cramfs: wrong magic" );
550552 return - EINVAL ;
551553 }
552554 }
553555
554556 /* get feature flags first */
555557 if (super -> flags & ~CRAMFS_SUPPORTED_FLAGS ) {
556- pr_err ( " unsupported filesystem features\n " );
558+ errorf ( fc , "cramfs: unsupported filesystem features" );
557559 return - EINVAL ;
558560 }
559561
560562 /* Check that the root inode is in a sane state */
561563 if (!S_ISDIR (super -> root .mode )) {
562- pr_err ( " root is not a directory\n " );
564+ errorf ( fc , "cramfs: root is not a directory" );
563565 return - EINVAL ;
564566 }
565567 /* correct strange, hard-coded permissions of mkcramfs */
@@ -578,12 +580,12 @@ static int cramfs_read_super(struct super_block *sb,
578580 sbi -> magic = super -> magic ;
579581 sbi -> flags = super -> flags ;
580582 if (root_offset == 0 )
581- pr_info ( " empty filesystem" );
583+ infof ( fc , "cramfs: empty filesystem" );
582584 else if (!(super -> flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET ) &&
583585 ((root_offset != sizeof (struct cramfs_super )) &&
584586 (root_offset != 512 + sizeof (struct cramfs_super ))))
585587 {
586- pr_err ( " bad root offset %lu\n " , root_offset );
588+ errorf ( fc , "cramfs: bad root offset %lu" , root_offset );
587589 return - EINVAL ;
588590 }
589591
@@ -607,8 +609,7 @@ static int cramfs_finalize_super(struct super_block *sb,
607609 return 0 ;
608610}
609611
610- static int cramfs_blkdev_fill_super (struct super_block * sb , void * data ,
611- int silent )
612+ static int cramfs_blkdev_fill_super (struct super_block * sb , struct fs_context * fc )
612613{
613614 struct cramfs_sb_info * sbi ;
614615 struct cramfs_super super ;
@@ -623,14 +624,13 @@ static int cramfs_blkdev_fill_super(struct super_block *sb, void *data,
623624 for (i = 0 ; i < READ_BUFFERS ; i ++ )
624625 buffer_blocknr [i ] = -1 ;
625626
626- err = cramfs_read_super (sb , & super , silent );
627+ err = cramfs_read_super (sb , fc , & super );
627628 if (err )
628629 return err ;
629630 return cramfs_finalize_super (sb , & super .root );
630631}
631632
632- static int cramfs_mtd_fill_super (struct super_block * sb , void * data ,
633- int silent )
633+ static int cramfs_mtd_fill_super (struct super_block * sb , struct fs_context * fc )
634634{
635635 struct cramfs_sb_info * sbi ;
636636 struct cramfs_super super ;
@@ -652,7 +652,7 @@ static int cramfs_mtd_fill_super(struct super_block *sb, void *data,
652652
653653 pr_info ("checking physical address %pap for linear cramfs image\n" ,
654654 & sbi -> linear_phys_addr );
655- err = cramfs_read_super (sb , & super , silent );
655+ err = cramfs_read_super (sb , fc , & super );
656656 if (err )
657657 return err ;
658658
@@ -947,32 +947,41 @@ static const struct inode_operations cramfs_dir_inode_operations = {
947947};
948948
949949static const struct super_operations cramfs_ops = {
950- .remount_fs = cramfs_remount ,
951950 .statfs = cramfs_statfs ,
952951};
953952
954- static struct dentry * cramfs_mount (struct file_system_type * fs_type , int flags ,
955- const char * dev_name , void * data )
953+ static int cramfs_get_tree (struct fs_context * fc )
956954{
957- struct dentry * ret = ERR_PTR ( - ENOPROTOOPT ) ;
955+ int ret = - ENOPROTOOPT ;
958956
959957 if (IS_ENABLED (CONFIG_CRAMFS_MTD )) {
960- ret = mount_mtd (fs_type , flags , dev_name , data ,
961- cramfs_mtd_fill_super );
962- if (!IS_ERR (ret ))
958+ ret = get_tree_mtd (fc , cramfs_mtd_fill_super );
959+ if (ret < 0 )
963960 return ret ;
964961 }
965- if (IS_ENABLED (CONFIG_CRAMFS_BLOCKDEV )) {
966- ret = mount_bdev (fs_type , flags , dev_name , data ,
967- cramfs_blkdev_fill_super );
968- }
962+ if (IS_ENABLED (CONFIG_CRAMFS_BLOCKDEV ))
963+ ret = get_tree_bdev (fc , cramfs_blkdev_fill_super );
969964 return ret ;
970965}
971966
967+ static const struct fs_context_operations cramfs_context_ops = {
968+ .get_tree = cramfs_get_tree ,
969+ .reconfigure = cramfs_reconfigure ,
970+ };
971+
972+ /*
973+ * Set up the filesystem mount context.
974+ */
975+ static int cramfs_init_fs_context (struct fs_context * fc )
976+ {
977+ fc -> ops = & cramfs_context_ops ;
978+ return 0 ;
979+ }
980+
972981static struct file_system_type cramfs_fs_type = {
973982 .owner = THIS_MODULE ,
974983 .name = "cramfs" ,
975- .mount = cramfs_mount ,
984+ .init_fs_context = cramfs_init_fs_context ,
976985 .kill_sb = cramfs_kill_sb ,
977986 .fs_flags = FS_REQUIRES_DEV ,
978987};
0 commit comments