summaryrefslogtreecommitdiffstats
path: root/fs/squashfs/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/squashfs/super.c')
-rw-r--r--fs/squashfs/super.c100
1 files changed, 55 insertions, 45 deletions
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index a9e9837617a9..0cc4ceec0562 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -17,6 +17,7 @@
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 18
19#include <linux/fs.h> 19#include <linux/fs.h>
20#include <linux/fs_context.h>
20#include <linux/vfs.h> 21#include <linux/vfs.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
22#include <linux/mutex.h> 23#include <linux/mutex.h>
@@ -36,26 +37,27 @@
36static struct file_system_type squashfs_fs_type; 37static struct file_system_type squashfs_fs_type;
37static const struct super_operations squashfs_super_ops; 38static const struct super_operations squashfs_super_ops;
38 39
39static const struct squashfs_decompressor *supported_squashfs_filesystem(short 40static const struct squashfs_decompressor *supported_squashfs_filesystem(
40 major, short minor, short id) 41 struct fs_context *fc,
42 short major, short minor, short id)
41{ 43{
42 const struct squashfs_decompressor *decompressor; 44 const struct squashfs_decompressor *decompressor;
43 45
44 if (major < SQUASHFS_MAJOR) { 46 if (major < SQUASHFS_MAJOR) {
45 ERROR("Major/Minor mismatch, older Squashfs %d.%d " 47 errorf(fc, "Major/Minor mismatch, older Squashfs %d.%d "
46 "filesystems are unsupported\n", major, minor); 48 "filesystems are unsupported", major, minor);
47 return NULL; 49 return NULL;
48 } else if (major > SQUASHFS_MAJOR || minor > SQUASHFS_MINOR) { 50 } else if (major > SQUASHFS_MAJOR || minor > SQUASHFS_MINOR) {
49 ERROR("Major/Minor mismatch, trying to mount newer " 51 errorf(fc, "Major/Minor mismatch, trying to mount newer "
50 "%d.%d filesystem\n", major, minor); 52 "%d.%d filesystem", major, minor);
51 ERROR("Please update your kernel\n"); 53 errorf(fc, "Please update your kernel");
52 return NULL; 54 return NULL;
53 } 55 }
54 56
55 decompressor = squashfs_lookup_decompressor(id); 57 decompressor = squashfs_lookup_decompressor(id);
56 if (!decompressor->supported) { 58 if (!decompressor->supported) {
57 ERROR("Filesystem uses \"%s\" compression. This is not " 59 errorf(fc, "Filesystem uses \"%s\" compression. This is not supported",
58 "supported\n", decompressor->name); 60 decompressor->name);
59 return NULL; 61 return NULL;
60 } 62 }
61 63
@@ -63,7 +65,7 @@ static const struct squashfs_decompressor *supported_squashfs_filesystem(short
63} 65}
64 66
65 67
66static int squashfs_fill_super(struct super_block *sb, void *data, int silent) 68static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
67{ 69{
68 struct squashfs_sb_info *msblk; 70 struct squashfs_sb_info *msblk;
69 struct squashfs_super_block *sblk = NULL; 71 struct squashfs_super_block *sblk = NULL;
@@ -98,7 +100,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
98 sblk = squashfs_read_table(sb, SQUASHFS_START, sizeof(*sblk)); 100 sblk = squashfs_read_table(sb, SQUASHFS_START, sizeof(*sblk));
99 101
100 if (IS_ERR(sblk)) { 102 if (IS_ERR(sblk)) {
101 ERROR("unable to read squashfs_super_block\n"); 103 errorf(fc, "unable to read squashfs_super_block");
102 err = PTR_ERR(sblk); 104 err = PTR_ERR(sblk);
103 sblk = NULL; 105 sblk = NULL;
104 goto failed_mount; 106 goto failed_mount;
@@ -109,14 +111,15 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
109 /* Check it is a SQUASHFS superblock */ 111 /* Check it is a SQUASHFS superblock */
110 sb->s_magic = le32_to_cpu(sblk->s_magic); 112 sb->s_magic = le32_to_cpu(sblk->s_magic);
111 if (sb->s_magic != SQUASHFS_MAGIC) { 113 if (sb->s_magic != SQUASHFS_MAGIC) {
112 if (!silent) 114 if (!(fc->sb_flags & SB_SILENT))
113 ERROR("Can't find a SQUASHFS superblock on %pg\n", 115 errorf(fc, "Can't find a SQUASHFS superblock on %pg",
114 sb->s_bdev); 116 sb->s_bdev);
115 goto failed_mount; 117 goto failed_mount;
116 } 118 }
117 119
118 /* Check the MAJOR & MINOR versions and lookup compression type */ 120 /* Check the MAJOR & MINOR versions and lookup compression type */
119 msblk->decompressor = supported_squashfs_filesystem( 121 msblk->decompressor = supported_squashfs_filesystem(
122 fc,
120 le16_to_cpu(sblk->s_major), 123 le16_to_cpu(sblk->s_major),
121 le16_to_cpu(sblk->s_minor), 124 le16_to_cpu(sblk->s_minor),
122 le16_to_cpu(sblk->compression)); 125 le16_to_cpu(sblk->compression));
@@ -133,15 +136,15 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
133 /* Check block size for sanity */ 136 /* Check block size for sanity */
134 msblk->block_size = le32_to_cpu(sblk->block_size); 137 msblk->block_size = le32_to_cpu(sblk->block_size);
135 if (msblk->block_size > SQUASHFS_FILE_MAX_SIZE) 138 if (msblk->block_size > SQUASHFS_FILE_MAX_SIZE)
136 goto failed_mount; 139 goto insanity;
137 140
138 /* 141 /*
139 * Check the system page size is not larger than the filesystem 142 * Check the system page size is not larger than the filesystem
140 * block size (by default 128K). This is currently not supported. 143 * block size (by default 128K). This is currently not supported.
141 */ 144 */
142 if (PAGE_SIZE > msblk->block_size) { 145 if (PAGE_SIZE > msblk->block_size) {
143 ERROR("Page size > filesystem block size (%d). This is " 146 errorf(fc, "Page size > filesystem block size (%d). This is "
144 "currently not supported!\n", msblk->block_size); 147 "currently not supported!", msblk->block_size);
145 goto failed_mount; 148 goto failed_mount;
146 } 149 }
147 150
@@ -152,12 +155,12 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
152 155
153 /* Check that block_size and block_log match */ 156 /* Check that block_size and block_log match */
154 if (msblk->block_size != (1 << msblk->block_log)) 157 if (msblk->block_size != (1 << msblk->block_log))
155 goto failed_mount; 158 goto insanity;
156 159
157 /* Check the root inode for sanity */ 160 /* Check the root inode for sanity */
158 root_inode = le64_to_cpu(sblk->root_inode); 161 root_inode = le64_to_cpu(sblk->root_inode);
159 if (SQUASHFS_INODE_OFFSET(root_inode) > SQUASHFS_METADATA_SIZE) 162 if (SQUASHFS_INODE_OFFSET(root_inode) > SQUASHFS_METADATA_SIZE)
160 goto failed_mount; 163 goto insanity;
161 164
162 msblk->inode_table = le64_to_cpu(sblk->inode_table_start); 165 msblk->inode_table = le64_to_cpu(sblk->inode_table_start);
163 msblk->directory_table = le64_to_cpu(sblk->directory_table_start); 166 msblk->directory_table = le64_to_cpu(sblk->directory_table_start);
@@ -199,7 +202,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
199 msblk->read_page = squashfs_cache_init("data", 202 msblk->read_page = squashfs_cache_init("data",
200 squashfs_max_decompressors(), msblk->block_size); 203 squashfs_max_decompressors(), msblk->block_size);
201 if (msblk->read_page == NULL) { 204 if (msblk->read_page == NULL) {
202 ERROR("Failed to allocate read_page block\n"); 205 errorf(fc, "Failed to allocate read_page block");
203 goto failed_mount; 206 goto failed_mount;
204 } 207 }
205 208
@@ -207,7 +210,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
207 if (IS_ERR(msblk->stream)) { 210 if (IS_ERR(msblk->stream)) {
208 err = PTR_ERR(msblk->stream); 211 err = PTR_ERR(msblk->stream);
209 msblk->stream = NULL; 212 msblk->stream = NULL;
210 goto failed_mount; 213 goto insanity;
211 } 214 }
212 215
213 /* Handle xattrs */ 216 /* Handle xattrs */
@@ -222,7 +225,7 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
222 msblk->xattr_id_table = squashfs_read_xattr_id_table(sb, 225 msblk->xattr_id_table = squashfs_read_xattr_id_table(sb,
223 xattr_id_table_start, &msblk->xattr_table, &msblk->xattr_ids); 226 xattr_id_table_start, &msblk->xattr_table, &msblk->xattr_ids);
224 if (IS_ERR(msblk->xattr_id_table)) { 227 if (IS_ERR(msblk->xattr_id_table)) {
225 ERROR("unable to read xattr id index table\n"); 228 errorf(fc, "unable to read xattr id index table");
226 err = PTR_ERR(msblk->xattr_id_table); 229 err = PTR_ERR(msblk->xattr_id_table);
227 msblk->xattr_id_table = NULL; 230 msblk->xattr_id_table = NULL;
228 if (err != -ENOTSUPP) 231 if (err != -ENOTSUPP)
@@ -236,7 +239,7 @@ allocate_id_index_table:
236 le64_to_cpu(sblk->id_table_start), next_table, 239 le64_to_cpu(sblk->id_table_start), next_table,
237 le16_to_cpu(sblk->no_ids)); 240 le16_to_cpu(sblk->no_ids));
238 if (IS_ERR(msblk->id_table)) { 241 if (IS_ERR(msblk->id_table)) {
239 ERROR("unable to read id index table\n"); 242 errorf(fc, "unable to read id index table");
240 err = PTR_ERR(msblk->id_table); 243 err = PTR_ERR(msblk->id_table);
241 msblk->id_table = NULL; 244 msblk->id_table = NULL;
242 goto failed_mount; 245 goto failed_mount;
@@ -252,7 +255,7 @@ allocate_id_index_table:
252 msblk->inode_lookup_table = squashfs_read_inode_lookup_table(sb, 255 msblk->inode_lookup_table = squashfs_read_inode_lookup_table(sb,
253 lookup_table_start, next_table, msblk->inodes); 256 lookup_table_start, next_table, msblk->inodes);
254 if (IS_ERR(msblk->inode_lookup_table)) { 257 if (IS_ERR(msblk->inode_lookup_table)) {
255 ERROR("unable to read inode lookup table\n"); 258 errorf(fc, "unable to read inode lookup table");
256 err = PTR_ERR(msblk->inode_lookup_table); 259 err = PTR_ERR(msblk->inode_lookup_table);
257 msblk->inode_lookup_table = NULL; 260 msblk->inode_lookup_table = NULL;
258 goto failed_mount; 261 goto failed_mount;
@@ -277,7 +280,7 @@ handle_fragments:
277 msblk->fragment_index = squashfs_read_fragment_index_table(sb, 280 msblk->fragment_index = squashfs_read_fragment_index_table(sb,
278 le64_to_cpu(sblk->fragment_table_start), next_table, fragments); 281 le64_to_cpu(sblk->fragment_table_start), next_table, fragments);
279 if (IS_ERR(msblk->fragment_index)) { 282 if (IS_ERR(msblk->fragment_index)) {
280 ERROR("unable to read fragment index table\n"); 283 errorf(fc, "unable to read fragment index table");
281 err = PTR_ERR(msblk->fragment_index); 284 err = PTR_ERR(msblk->fragment_index);
282 msblk->fragment_index = NULL; 285 msblk->fragment_index = NULL;
283 goto failed_mount; 286 goto failed_mount;
@@ -288,13 +291,13 @@ check_directory_table:
288 /* Sanity check directory_table */ 291 /* Sanity check directory_table */
289 if (msblk->directory_table > next_table) { 292 if (msblk->directory_table > next_table) {
290 err = -EINVAL; 293 err = -EINVAL;
291 goto failed_mount; 294 goto insanity;
292 } 295 }
293 296
294 /* Sanity check inode_table */ 297 /* Sanity check inode_table */
295 if (msblk->inode_table >= msblk->directory_table) { 298 if (msblk->inode_table >= msblk->directory_table) {
296 err = -EINVAL; 299 err = -EINVAL;
297 goto failed_mount; 300 goto insanity;
298 } 301 }
299 302
300 /* allocate root */ 303 /* allocate root */
@@ -323,6 +326,8 @@ check_directory_table:
323 kfree(sblk); 326 kfree(sblk);
324 return 0; 327 return 0;
325 328
329insanity:
330 errorf(fc, "squashfs image failed sanity check");
326failed_mount: 331failed_mount:
327 squashfs_cache_delete(msblk->block_cache); 332 squashfs_cache_delete(msblk->block_cache);
328 squashfs_cache_delete(msblk->fragment_cache); 333 squashfs_cache_delete(msblk->fragment_cache);
@@ -338,6 +343,28 @@ failed_mount:
338 return err; 343 return err;
339} 344}
340 345
346static int squashfs_get_tree(struct fs_context *fc)
347{
348 return get_tree_bdev(fc, squashfs_fill_super);
349}
350
351static int squashfs_reconfigure(struct fs_context *fc)
352{
353 sync_filesystem(fc->root->d_sb);
354 fc->sb_flags |= SB_RDONLY;
355 return 0;
356}
357
358static const struct fs_context_operations squashfs_context_ops = {
359 .get_tree = squashfs_get_tree,
360 .reconfigure = squashfs_reconfigure,
361};
362
363static int squashfs_init_fs_context(struct fs_context *fc)
364{
365 fc->ops = &squashfs_context_ops;
366 return 0;
367}
341 368
342static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf) 369static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
343{ 370{
@@ -360,14 +387,6 @@ static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
360} 387}
361 388
362 389
363static int squashfs_remount(struct super_block *sb, int *flags, char *data)
364{
365 sync_filesystem(sb);
366 *flags |= SB_RDONLY;
367 return 0;
368}
369
370
371static void squashfs_put_super(struct super_block *sb) 390static void squashfs_put_super(struct super_block *sb)
372{ 391{
373 if (sb->s_fs_info) { 392 if (sb->s_fs_info) {
@@ -386,14 +405,6 @@ static void squashfs_put_super(struct super_block *sb)
386 } 405 }
387} 406}
388 407
389
390static struct dentry *squashfs_mount(struct file_system_type *fs_type,
391 int flags, const char *dev_name, void *data)
392{
393 return mount_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);
394}
395
396
397static struct kmem_cache *squashfs_inode_cachep; 408static struct kmem_cache *squashfs_inode_cachep;
398 409
399 410
@@ -470,7 +481,7 @@ static void squashfs_free_inode(struct inode *inode)
470static struct file_system_type squashfs_fs_type = { 481static struct file_system_type squashfs_fs_type = {
471 .owner = THIS_MODULE, 482 .owner = THIS_MODULE,
472 .name = "squashfs", 483 .name = "squashfs",
473 .mount = squashfs_mount, 484 .init_fs_context = squashfs_init_fs_context,
474 .kill_sb = kill_block_super, 485 .kill_sb = kill_block_super,
475 .fs_flags = FS_REQUIRES_DEV 486 .fs_flags = FS_REQUIRES_DEV
476}; 487};
@@ -481,7 +492,6 @@ static const struct super_operations squashfs_super_ops = {
481 .free_inode = squashfs_free_inode, 492 .free_inode = squashfs_free_inode,
482 .statfs = squashfs_statfs, 493 .statfs = squashfs_statfs,
483 .put_super = squashfs_put_super, 494 .put_super = squashfs_put_super,
484 .remount_fs = squashfs_remount
485}; 495};
486 496
487module_init(init_squashfs_fs); 497module_init(init_squashfs_fs);