Lines Matching +full:static +full:- +full:trace +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Squashfs - a compressed read only filesystem for Linux
13 * in-memory structures at mount time, and all the VFS glue code to register
40 static struct file_system_type squashfs_fs_type;
41 static const struct super_operations squashfs_super_ops;
59 static const struct constant_table squashfs_param_errors[] = {
65 static const struct fs_parameter_spec squashfs_fs_parameters[] = {
72 static int squashfs_parse_param_threads_str(const char *str, struct squashfs_mount_opts *opts) in squashfs_parse_param_threads_str()
76 opts->thread_ops = &squashfs_decompressor_single; in squashfs_parse_param_threads_str()
80 opts->thread_ops = &squashfs_decompressor_multi; in squashfs_parse_param_threads_str()
84 opts->thread_ops = &squashfs_decompressor_percpu; in squashfs_parse_param_threads_str()
88 return -EINVAL; in squashfs_parse_param_threads_str()
91 static int squashfs_parse_param_threads_num(const char *str, struct squashfs_mount_opts *opts) in squashfs_parse_param_threads_num()
99 return -EINVAL; in squashfs_parse_param_threads_num()
101 opts->thread_ops = &squashfs_decompressor_multi; in squashfs_parse_param_threads_num()
102 if (num > opts->thread_ops->max_decompressors()) in squashfs_parse_param_threads_num()
103 return -EINVAL; in squashfs_parse_param_threads_num()
104 opts->thread_num = (int)num; in squashfs_parse_param_threads_num()
109 opts->thread_ops = &squashfs_decompressor_single; in squashfs_parse_param_threads_num()
110 opts->thread_num = 1; in squashfs_parse_param_threads_num()
115 return -EINVAL; in squashfs_parse_param_threads_num()
118 static int squashfs_parse_param_threads(const char *str, struct squashfs_mount_opts *opts) in squashfs_parse_param_threads()
127 static int squashfs_parse_param(struct fs_context *fc, struct fs_parameter *param) in squashfs_parse_param()
129 struct squashfs_mount_opts *opts = fc->fs_private; in squashfs_parse_param()
139 opts->errors = result.uint_32; in squashfs_parse_param()
142 if (squashfs_parse_param_threads(param->string, opts) != 0) in squashfs_parse_param()
143 return -EINVAL; in squashfs_parse_param()
146 return -EINVAL; in squashfs_parse_param()
152 static const struct squashfs_decompressor *supported_squashfs_filesystem( in supported_squashfs_filesystem()
154 short major, short minor, short id) in supported_squashfs_filesystem() argument
169 decompressor = squashfs_lookup_decompressor(id); in supported_squashfs_filesystem()
170 if (!decompressor->supported) { in supported_squashfs_filesystem()
172 decompressor->name); in supported_squashfs_filesystem()
180 static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc) in squashfs_fill_super()
182 struct squashfs_mount_opts *opts = fc->fs_private; in squashfs_fill_super()
192 TRACE("Entered squashfs_fill_superblock\n"); in squashfs_fill_super()
194 sb->s_fs_info = kzalloc(sizeof(*msblk), GFP_KERNEL); in squashfs_fill_super()
195 if (sb->s_fs_info == NULL) { in squashfs_fill_super()
197 return -ENOMEM; in squashfs_fill_super()
199 msblk = sb->s_fs_info; in squashfs_fill_super()
200 msblk->thread_ops = opts->thread_ops; in squashfs_fill_super()
202 msblk->panic_on_errors = (opts->errors == Opt_errors_panic); in squashfs_fill_super()
204 msblk->devblksize = sb_min_blocksize(sb, SQUASHFS_DEVBLK_SIZE); in squashfs_fill_super()
205 msblk->devblksize_log2 = ffz(~msblk->devblksize); in squashfs_fill_super()
207 mutex_init(&msblk->meta_index_mutex); in squashfs_fill_super()
210 * msblk->bytes_used is checked in squashfs_read_table to ensure reads in squashfs_fill_super()
215 msblk->bytes_used = sizeof(*sblk); in squashfs_fill_super()
225 err = -EINVAL; in squashfs_fill_super()
228 sb->s_magic = le32_to_cpu(sblk->s_magic); in squashfs_fill_super()
229 if (sb->s_magic != SQUASHFS_MAGIC) { in squashfs_fill_super()
230 if (!(fc->sb_flags & SB_SILENT)) in squashfs_fill_super()
232 sb->s_bdev); in squashfs_fill_super()
236 if (opts->thread_num == 0) { in squashfs_fill_super()
237 msblk->max_thread_num = msblk->thread_ops->max_decompressors(); in squashfs_fill_super()
239 msblk->max_thread_num = opts->thread_num; in squashfs_fill_super()
243 msblk->decompressor = supported_squashfs_filesystem( in squashfs_fill_super()
245 le16_to_cpu(sblk->s_major), in squashfs_fill_super()
246 le16_to_cpu(sblk->s_minor), in squashfs_fill_super()
247 le16_to_cpu(sblk->compression)); in squashfs_fill_super()
248 if (msblk->decompressor == NULL) in squashfs_fill_super()
253 msblk->bytes_used = le64_to_cpu(sblk->bytes_used); in squashfs_fill_super()
254 if (msblk->bytes_used < 0 || in squashfs_fill_super()
255 msblk->bytes_used > bdev_nr_bytes(sb->s_bdev)) in squashfs_fill_super()
259 msblk->block_size = le32_to_cpu(sblk->block_size); in squashfs_fill_super()
260 if (msblk->block_size > SQUASHFS_FILE_MAX_SIZE) in squashfs_fill_super()
267 if (PAGE_SIZE > msblk->block_size) { in squashfs_fill_super()
269 "currently not supported!", msblk->block_size); in squashfs_fill_super()
274 msblk->block_log = le16_to_cpu(sblk->block_log); in squashfs_fill_super()
275 if (msblk->block_log > SQUASHFS_FILE_MAX_LOG) in squashfs_fill_super()
279 if (msblk->block_size != (1 << msblk->block_log)) in squashfs_fill_super()
283 root_inode = le64_to_cpu(sblk->root_inode); in squashfs_fill_super()
287 msblk->inode_table = le64_to_cpu(sblk->inode_table_start); in squashfs_fill_super()
288 msblk->directory_table = le64_to_cpu(sblk->directory_table_start); in squashfs_fill_super()
289 msblk->inodes = le32_to_cpu(sblk->inodes); in squashfs_fill_super()
290 msblk->fragments = le32_to_cpu(sblk->fragments); in squashfs_fill_super()
291 msblk->ids = le16_to_cpu(sblk->no_ids); in squashfs_fill_super()
292 flags = le16_to_cpu(sblk->flags); in squashfs_fill_super()
294 TRACE("Found valid superblock on %pg\n", sb->s_bdev); in squashfs_fill_super()
295 TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(flags) in squashfs_fill_super()
297 TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(flags) in squashfs_fill_super()
299 TRACE("Filesystem size %lld bytes\n", msblk->bytes_used); in squashfs_fill_super()
300 TRACE("Block size %d\n", msblk->block_size); in squashfs_fill_super()
301 TRACE("Number of inodes %d\n", msblk->inodes); in squashfs_fill_super()
302 TRACE("Number of fragments %d\n", msblk->fragments); in squashfs_fill_super()
303 TRACE("Number of ids %d\n", msblk->ids); in squashfs_fill_super()
304 TRACE("sblk->inode_table_start %llx\n", msblk->inode_table); in squashfs_fill_super()
305 TRACE("sblk->directory_table_start %llx\n", msblk->directory_table); in squashfs_fill_super()
306 TRACE("sblk->fragment_table_start %llx\n", in squashfs_fill_super()
307 (u64) le64_to_cpu(sblk->fragment_table_start)); in squashfs_fill_super()
308 TRACE("sblk->id_table_start %llx\n", in squashfs_fill_super()
309 (u64) le64_to_cpu(sblk->id_table_start)); in squashfs_fill_super()
311 sb->s_maxbytes = MAX_LFS_FILESIZE; in squashfs_fill_super()
312 sb->s_time_min = 0; in squashfs_fill_super()
313 sb->s_time_max = U32_MAX; in squashfs_fill_super()
314 sb->s_flags |= SB_RDONLY; in squashfs_fill_super()
315 sb->s_op = &squashfs_super_ops; in squashfs_fill_super()
317 msblk->block_cache = squashfs_cache_init("metadata", in squashfs_fill_super()
319 if (IS_ERR(msblk->block_cache)) { in squashfs_fill_super()
320 err = PTR_ERR(msblk->block_cache); in squashfs_fill_super()
325 msblk->read_page = squashfs_cache_init("data", in squashfs_fill_super()
326 SQUASHFS_READ_PAGES, msblk->block_size); in squashfs_fill_super()
327 if (IS_ERR(msblk->read_page)) { in squashfs_fill_super()
329 err = PTR_ERR(msblk->read_page); in squashfs_fill_super()
333 if (msblk->devblksize == PAGE_SIZE) { in squashfs_fill_super()
337 err = -ENOMEM; in squashfs_fill_super()
342 cache->i_size = OFFSET_MAX; in squashfs_fill_super()
343 mapping_set_gfp_mask(cache->i_mapping, GFP_NOFS); in squashfs_fill_super()
345 msblk->cache_mapping = cache->i_mapping; in squashfs_fill_super()
348 msblk->stream = squashfs_decompressor_setup(sb, flags); in squashfs_fill_super()
349 if (IS_ERR(msblk->stream)) { in squashfs_fill_super()
350 err = PTR_ERR(msblk->stream); in squashfs_fill_super()
351 msblk->stream = NULL; in squashfs_fill_super()
356 sb->s_xattr = squashfs_xattr_handlers; in squashfs_fill_super()
357 xattr_id_table_start = le64_to_cpu(sblk->xattr_id_table_start); in squashfs_fill_super()
359 next_table = msblk->bytes_used; in squashfs_fill_super()
363 /* Allocate and read xattr id lookup table */ in squashfs_fill_super()
364 msblk->xattr_id_table = squashfs_read_xattr_id_table(sb, in squashfs_fill_super()
365 xattr_id_table_start, &msblk->xattr_table, &msblk->xattr_ids); in squashfs_fill_super()
366 if (IS_ERR(msblk->xattr_id_table)) { in squashfs_fill_super()
367 errorf(fc, "unable to read xattr id index table"); in squashfs_fill_super()
368 err = PTR_ERR(msblk->xattr_id_table); in squashfs_fill_super()
369 msblk->xattr_id_table = NULL; in squashfs_fill_super()
370 if (err != -ENOTSUPP) in squashfs_fill_super()
373 next_table = msblk->xattr_table; in squashfs_fill_super()
376 /* Allocate and read id index table */ in squashfs_fill_super()
377 msblk->id_table = squashfs_read_id_index_table(sb, in squashfs_fill_super()
378 le64_to_cpu(sblk->id_table_start), next_table, msblk->ids); in squashfs_fill_super()
379 if (IS_ERR(msblk->id_table)) { in squashfs_fill_super()
380 errorf(fc, "unable to read id index table"); in squashfs_fill_super()
381 err = PTR_ERR(msblk->id_table); in squashfs_fill_super()
382 msblk->id_table = NULL; in squashfs_fill_super()
385 next_table = le64_to_cpu(msblk->id_table[0]); in squashfs_fill_super()
388 lookup_table_start = le64_to_cpu(sblk->lookup_table_start); in squashfs_fill_super()
393 msblk->inode_lookup_table = squashfs_read_inode_lookup_table(sb, in squashfs_fill_super()
394 lookup_table_start, next_table, msblk->inodes); in squashfs_fill_super()
395 if (IS_ERR(msblk->inode_lookup_table)) { in squashfs_fill_super()
397 err = PTR_ERR(msblk->inode_lookup_table); in squashfs_fill_super()
398 msblk->inode_lookup_table = NULL; in squashfs_fill_super()
401 next_table = le64_to_cpu(msblk->inode_lookup_table[0]); in squashfs_fill_super()
403 sb->s_export_op = &squashfs_export_ops; in squashfs_fill_super()
406 fragments = msblk->fragments; in squashfs_fill_super()
410 msblk->fragment_cache = squashfs_cache_init("fragment", in squashfs_fill_super()
411 min(SQUASHFS_CACHED_FRAGMENTS, fragments), msblk->block_size); in squashfs_fill_super()
412 if (IS_ERR(msblk->fragment_cache)) { in squashfs_fill_super()
413 err = PTR_ERR(msblk->fragment_cache); in squashfs_fill_super()
418 msblk->fragment_index = squashfs_read_fragment_index_table(sb, in squashfs_fill_super()
419 le64_to_cpu(sblk->fragment_table_start), next_table, fragments); in squashfs_fill_super()
420 if (IS_ERR(msblk->fragment_index)) { in squashfs_fill_super()
422 err = PTR_ERR(msblk->fragment_index); in squashfs_fill_super()
423 msblk->fragment_index = NULL; in squashfs_fill_super()
426 next_table = le64_to_cpu(msblk->fragment_index[0]); in squashfs_fill_super()
430 if (msblk->directory_table > next_table) { in squashfs_fill_super()
431 err = -EINVAL; in squashfs_fill_super()
436 if (msblk->inode_table >= msblk->directory_table) { in squashfs_fill_super()
437 err = -EINVAL; in squashfs_fill_super()
444 err = -ENOMEM; in squashfs_fill_super()
456 sb->s_root = d_make_root(root); in squashfs_fill_super()
457 if (sb->s_root == NULL) { in squashfs_fill_super()
459 err = -ENOMEM; in squashfs_fill_super()
463 TRACE("Leaving squashfs_fill_super\n"); in squashfs_fill_super()
470 squashfs_cache_delete(msblk->block_cache); in squashfs_fill_super()
471 squashfs_cache_delete(msblk->fragment_cache); in squashfs_fill_super()
472 squashfs_cache_delete(msblk->read_page); in squashfs_fill_super()
473 if (msblk->cache_mapping) in squashfs_fill_super()
474 iput(msblk->cache_mapping->host); in squashfs_fill_super()
475 msblk->thread_ops->destroy(msblk); in squashfs_fill_super()
476 kfree(msblk->inode_lookup_table); in squashfs_fill_super()
477 kfree(msblk->fragment_index); in squashfs_fill_super()
478 kfree(msblk->id_table); in squashfs_fill_super()
479 kfree(msblk->xattr_id_table); in squashfs_fill_super()
480 kfree(sb->s_fs_info); in squashfs_fill_super()
481 sb->s_fs_info = NULL; in squashfs_fill_super()
486 static int squashfs_get_tree(struct fs_context *fc) in squashfs_get_tree()
491 static int squashfs_reconfigure(struct fs_context *fc) in squashfs_reconfigure()
493 struct super_block *sb = fc->root->d_sb; in squashfs_reconfigure()
494 struct squashfs_sb_info *msblk = sb->s_fs_info; in squashfs_reconfigure()
495 struct squashfs_mount_opts *opts = fc->fs_private; in squashfs_reconfigure()
497 sync_filesystem(fc->root->d_sb); in squashfs_reconfigure()
498 fc->sb_flags |= SB_RDONLY; in squashfs_reconfigure()
500 msblk->panic_on_errors = (opts->errors == Opt_errors_panic); in squashfs_reconfigure()
505 static void squashfs_free_fs_context(struct fs_context *fc) in squashfs_free_fs_context()
507 kfree(fc->fs_private); in squashfs_free_fs_context()
510 static const struct fs_context_operations squashfs_context_ops = {
517 static int squashfs_show_options(struct seq_file *s, struct dentry *root) in squashfs_show_options()
519 struct super_block *sb = root->d_sb; in squashfs_show_options()
520 struct squashfs_sb_info *msblk = sb->s_fs_info; in squashfs_show_options()
522 if (msblk->panic_on_errors) in squashfs_show_options()
528 if (msblk->thread_ops == &squashfs_decompressor_single) { in squashfs_show_options()
532 if (msblk->thread_ops == &squashfs_decompressor_percpu) { in squashfs_show_options()
538 seq_printf(s, ",threads=%d", msblk->max_thread_num); in squashfs_show_options()
543 static int squashfs_init_fs_context(struct fs_context *fc) in squashfs_init_fs_context()
549 return -ENOMEM; in squashfs_init_fs_context()
552 opts->thread_ops = &squashfs_decompressor_single; in squashfs_init_fs_context()
554 opts->thread_ops = &squashfs_decompressor_multi; in squashfs_init_fs_context()
556 opts->thread_ops = &squashfs_decompressor_percpu; in squashfs_init_fs_context()
560 opts->thread_num = 0; in squashfs_init_fs_context()
561 fc->fs_private = opts; in squashfs_init_fs_context()
562 fc->ops = &squashfs_context_ops; in squashfs_init_fs_context()
566 static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf) in squashfs_statfs()
568 struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info; in squashfs_statfs()
569 u64 id = huge_encode_dev(dentry->d_sb->s_bdev->bd_dev); in squashfs_statfs() local
571 TRACE("Entered squashfs_statfs\n"); in squashfs_statfs()
573 buf->f_type = SQUASHFS_MAGIC; in squashfs_statfs()
574 buf->f_bsize = msblk->block_size; in squashfs_statfs()
575 buf->f_blocks = ((msblk->bytes_used - 1) >> msblk->block_log) + 1; in squashfs_statfs()
576 buf->f_bfree = buf->f_bavail = 0; in squashfs_statfs()
577 buf->f_files = msblk->inodes; in squashfs_statfs()
578 buf->f_ffree = 0; in squashfs_statfs()
579 buf->f_namelen = SQUASHFS_NAME_LEN; in squashfs_statfs()
580 buf->f_fsid = u64_to_fsid(id); in squashfs_statfs()
586 static void squashfs_put_super(struct super_block *sb) in squashfs_put_super()
588 if (sb->s_fs_info) { in squashfs_put_super()
589 struct squashfs_sb_info *sbi = sb->s_fs_info; in squashfs_put_super()
590 squashfs_cache_delete(sbi->block_cache); in squashfs_put_super()
591 squashfs_cache_delete(sbi->fragment_cache); in squashfs_put_super()
592 squashfs_cache_delete(sbi->read_page); in squashfs_put_super()
593 if (sbi->cache_mapping) in squashfs_put_super()
594 iput(sbi->cache_mapping->host); in squashfs_put_super()
595 sbi->thread_ops->destroy(sbi); in squashfs_put_super()
596 kfree(sbi->id_table); in squashfs_put_super()
597 kfree(sbi->fragment_index); in squashfs_put_super()
598 kfree(sbi->meta_index); in squashfs_put_super()
599 kfree(sbi->inode_lookup_table); in squashfs_put_super()
600 kfree(sbi->xattr_id_table); in squashfs_put_super()
601 kfree(sb->s_fs_info); in squashfs_put_super()
602 sb->s_fs_info = NULL; in squashfs_put_super()
606 static struct kmem_cache *squashfs_inode_cachep;
609 static void init_once(void *foo) in init_once()
613 inode_init_once(&ei->vfs_inode); in init_once()
617 static int __init init_inodecache(void) in init_inodecache()
624 return squashfs_inode_cachep ? 0 : -ENOMEM; in init_inodecache()
628 static void destroy_inodecache(void) in destroy_inodecache()
639 static int __init init_squashfs_fs(void) in init_squashfs_fs()
658 static void __exit exit_squashfs_fs(void) in exit_squashfs_fs()
665 static struct inode *squashfs_alloc_inode(struct super_block *sb) in squashfs_alloc_inode()
670 return ei ? &ei->vfs_inode : NULL; in squashfs_alloc_inode()
674 static void squashfs_free_inode(struct inode *inode) in squashfs_free_inode()
679 static struct file_system_type squashfs_fs_type = {
689 static const struct super_operations squashfs_super_ops = {
699 MODULE_DESCRIPTION("squashfs 4.0, a compressed read-only filesystem");