1717#define pr_fmt (fmt ) KBUILD_MODNAME ": " fmt
1818
1919#include <linux/fs.h>
20+ #include <linux/fs_context.h>
2021#include <linux/vfs.h>
2122#include <linux/slab.h>
2223#include <linux/mutex.h>
3637static struct file_system_type squashfs_fs_type ;
3738static const struct super_operations squashfs_super_ops ;
3839
39- static const struct squashfs_decompressor * supported_squashfs_filesystem (short
40- major , short minor , short id )
40+ static const struct squashfs_decompressor * supported_squashfs_filesystem (
41+ struct fs_context * fc ,
42+ short major , short minor , short id )
4143{
4244 const struct squashfs_decompressor * decompressor ;
4345
4446 if (major < SQUASHFS_MAJOR ) {
45- ERROR ( "Major/Minor mismatch, older Squashfs %d.%d "
46- "filesystems are unsupported\n " , major , minor );
47+ errorf ( fc , "Major/Minor mismatch, older Squashfs %d.%d "
48+ "filesystems are unsupported" , major , minor );
4749 return NULL ;
4850 } else if (major > SQUASHFS_MAJOR || minor > SQUASHFS_MINOR ) {
49- ERROR ( "Major/Minor mismatch, trying to mount newer "
50- "%d.%d filesystem\n " , major , minor );
51- ERROR ( "Please update your kernel\n " );
51+ errorf ( fc , "Major/Minor mismatch, trying to mount newer "
52+ "%d.%d filesystem" , major , minor );
53+ errorf ( fc , "Please update your kernel" );
5254 return NULL ;
5355 }
5456
5557 decompressor = squashfs_lookup_decompressor (id );
5658 if (!decompressor -> supported ) {
57- ERROR ( "Filesystem uses \"%s\" compression. This is not "
58- "supported\n" , decompressor -> name );
59+ errorf ( fc , "Filesystem uses \"%s\" compression. This is not supported" ,
60+ decompressor -> name );
5961 return NULL ;
6062 }
6163
6264 return decompressor ;
6365}
6466
6567
66- static int squashfs_fill_super (struct super_block * sb , void * data , int silent )
68+ static int squashfs_fill_super (struct super_block * sb , struct fs_context * fc )
6769{
6870 struct squashfs_sb_info * msblk ;
6971 struct squashfs_super_block * sblk = NULL ;
@@ -98,7 +100,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
98100 sblk = squashfs_read_table (sb , SQUASHFS_START , sizeof (* sblk ));
99101
100102 if (IS_ERR (sblk )) {
101- ERROR ( "unable to read squashfs_super_block\n " );
103+ errorf ( fc , "unable to read squashfs_super_block" );
102104 err = PTR_ERR (sblk );
103105 sblk = NULL ;
104106 goto failed_mount ;
@@ -109,14 +111,15 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
109111 /* Check it is a SQUASHFS superblock */
110112 sb -> s_magic = le32_to_cpu (sblk -> s_magic );
111113 if (sb -> s_magic != SQUASHFS_MAGIC ) {
112- if (!silent )
113- ERROR ( "Can't find a SQUASHFS superblock on %pg\n " ,
114- sb -> s_bdev );
114+ if (!( fc -> sb_flags & SB_SILENT ) )
115+ errorf ( fc , "Can't find a SQUASHFS superblock on %pg" ,
116+ sb -> s_bdev );
115117 goto failed_mount ;
116118 }
117119
118120 /* Check the MAJOR & MINOR versions and lookup compression type */
119121 msblk -> decompressor = supported_squashfs_filesystem (
122+ fc ,
120123 le16_to_cpu (sblk -> s_major ),
121124 le16_to_cpu (sblk -> s_minor ),
122125 le16_to_cpu (sblk -> compression ));
@@ -133,15 +136,15 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
133136 /* Check block size for sanity */
134137 msblk -> block_size = le32_to_cpu (sblk -> block_size );
135138 if (msblk -> block_size > SQUASHFS_FILE_MAX_SIZE )
136- goto failed_mount ;
139+ goto insanity ;
137140
138141 /*
139142 * Check the system page size is not larger than the filesystem
140143 * block size (by default 128K). This is currently not supported.
141144 */
142145 if (PAGE_SIZE > msblk -> block_size ) {
143- ERROR ( "Page size > filesystem block size (%d). This is "
144- "currently not supported!\n " , msblk -> block_size );
146+ errorf ( fc , "Page size > filesystem block size (%d). This is "
147+ "currently not supported!" , msblk -> block_size );
145148 goto failed_mount ;
146149 }
147150
@@ -152,12 +155,12 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
152155
153156 /* Check that block_size and block_log match */
154157 if (msblk -> block_size != (1 << msblk -> block_log ))
155- goto failed_mount ;
158+ goto insanity ;
156159
157160 /* Check the root inode for sanity */
158161 root_inode = le64_to_cpu (sblk -> root_inode );
159162 if (SQUASHFS_INODE_OFFSET (root_inode ) > SQUASHFS_METADATA_SIZE )
160- goto failed_mount ;
163+ goto insanity ;
161164
162165 msblk -> inode_table = le64_to_cpu (sblk -> inode_table_start );
163166 msblk -> directory_table = le64_to_cpu (sblk -> directory_table_start );
@@ -197,15 +200,15 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
197200 msblk -> read_page = squashfs_cache_init ("data" ,
198201 squashfs_max_decompressors (), msblk -> block_size );
199202 if (msblk -> read_page == NULL ) {
200- ERROR ( "Failed to allocate read_page block\n " );
203+ errorf ( fc , "Failed to allocate read_page block" );
201204 goto failed_mount ;
202205 }
203206
204207 msblk -> stream = squashfs_decompressor_setup (sb , flags );
205208 if (IS_ERR (msblk -> stream )) {
206209 err = PTR_ERR (msblk -> stream );
207210 msblk -> stream = NULL ;
208- goto failed_mount ;
211+ goto insanity ;
209212 }
210213
211214 /* Handle xattrs */
@@ -220,7 +223,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
220223 msblk -> xattr_id_table = squashfs_read_xattr_id_table (sb ,
221224 xattr_id_table_start , & msblk -> xattr_table , & msblk -> xattr_ids );
222225 if (IS_ERR (msblk -> xattr_id_table )) {
223- ERROR ( "unable to read xattr id index table\n " );
226+ errorf ( fc , "unable to read xattr id index table" );
224227 err = PTR_ERR (msblk -> xattr_id_table );
225228 msblk -> xattr_id_table = NULL ;
226229 if (err != - ENOTSUPP )
@@ -234,7 +237,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
234237 le64_to_cpu (sblk -> id_table_start ), next_table ,
235238 le16_to_cpu (sblk -> no_ids ));
236239 if (IS_ERR (msblk -> id_table )) {
237- ERROR ( "unable to read id index table\n " );
240+ errorf ( fc , "unable to read id index table" );
238241 err = PTR_ERR (msblk -> id_table );
239242 msblk -> id_table = NULL ;
240243 goto failed_mount ;
@@ -250,7 +253,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
250253 msblk -> inode_lookup_table = squashfs_read_inode_lookup_table (sb ,
251254 lookup_table_start , next_table , msblk -> inodes );
252255 if (IS_ERR (msblk -> inode_lookup_table )) {
253- ERROR ( "unable to read inode lookup table\n " );
256+ errorf ( fc , "unable to read inode lookup table" );
254257 err = PTR_ERR (msblk -> inode_lookup_table );
255258 msblk -> inode_lookup_table = NULL ;
256259 goto failed_mount ;
@@ -275,7 +278,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
275278 msblk -> fragment_index = squashfs_read_fragment_index_table (sb ,
276279 le64_to_cpu (sblk -> fragment_table_start ), next_table , fragments );
277280 if (IS_ERR (msblk -> fragment_index )) {
278- ERROR ( "unable to read fragment index table\n " );
281+ errorf ( fc , "unable to read fragment index table" );
279282 err = PTR_ERR (msblk -> fragment_index );
280283 msblk -> fragment_index = NULL ;
281284 goto failed_mount ;
@@ -286,13 +289,13 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
286289 /* Sanity check directory_table */
287290 if (msblk -> directory_table > next_table ) {
288291 err = - EINVAL ;
289- goto failed_mount ;
292+ goto insanity ;
290293 }
291294
292295 /* Sanity check inode_table */
293296 if (msblk -> inode_table >= msblk -> directory_table ) {
294297 err = - EINVAL ;
295- goto failed_mount ;
298+ goto insanity ;
296299 }
297300
298301 /* allocate root */
@@ -321,6 +324,8 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
321324 kfree (sblk );
322325 return 0 ;
323326
327+ insanity :
328+ errorf (fc , "squashfs image failed sanity check" );
324329failed_mount :
325330 squashfs_cache_delete (msblk -> block_cache );
326331 squashfs_cache_delete (msblk -> fragment_cache );
@@ -336,6 +341,28 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
336341 return err ;
337342}
338343
344+ static int squashfs_get_tree (struct fs_context * fc )
345+ {
346+ return get_tree_bdev (fc , squashfs_fill_super );
347+ }
348+
349+ static int squashfs_reconfigure (struct fs_context * fc )
350+ {
351+ sync_filesystem (fc -> root -> d_sb );
352+ fc -> sb_flags |= SB_RDONLY ;
353+ return 0 ;
354+ }
355+
356+ static const struct fs_context_operations squashfs_context_ops = {
357+ .get_tree = squashfs_get_tree ,
358+ .reconfigure = squashfs_reconfigure ,
359+ };
360+
361+ static int squashfs_init_fs_context (struct fs_context * fc )
362+ {
363+ fc -> ops = & squashfs_context_ops ;
364+ return 0 ;
365+ }
339366
340367static int squashfs_statfs (struct dentry * dentry , struct kstatfs * buf )
341368{
@@ -358,14 +385,6 @@ static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
358385}
359386
360387
361- static int squashfs_remount (struct super_block * sb , int * flags , char * data )
362- {
363- sync_filesystem (sb );
364- * flags |= SB_RDONLY ;
365- return 0 ;
366- }
367-
368-
369388static void squashfs_put_super (struct super_block * sb )
370389{
371390 if (sb -> s_fs_info ) {
@@ -384,14 +403,6 @@ static void squashfs_put_super(struct super_block *sb)
384403 }
385404}
386405
387-
388- static struct dentry * squashfs_mount (struct file_system_type * fs_type ,
389- int flags , const char * dev_name , void * data )
390- {
391- return mount_bdev (fs_type , flags , dev_name , data , squashfs_fill_super );
392- }
393-
394-
395406static struct kmem_cache * squashfs_inode_cachep ;
396407
397408
@@ -468,7 +479,7 @@ static void squashfs_free_inode(struct inode *inode)
468479static struct file_system_type squashfs_fs_type = {
469480 .owner = THIS_MODULE ,
470481 .name = "squashfs" ,
471- .mount = squashfs_mount ,
482+ .init_fs_context = squashfs_init_fs_context ,
472483 .kill_sb = kill_block_super ,
473484 .fs_flags = FS_REQUIRES_DEV
474485};
@@ -479,7 +490,6 @@ static const struct super_operations squashfs_super_ops = {
479490 .free_inode = squashfs_free_inode ,
480491 .statfs = squashfs_statfs ,
481492 .put_super = squashfs_put_super ,
482- .remount_fs = squashfs_remount
483493};
484494
485495module_init (init_squashfs_fs );
0 commit comments