Lines Matching +full:num +full:- +full:ids

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
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()
95 unsigned long num; in squashfs_parse_param_threads_num() local
97 ret = kstrtoul(str, 0, &num); in squashfs_parse_param_threads_num()
99 return -EINVAL; in squashfs_parse_param_threads_num()
100 if (num > 1) { 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()
108 if (num == 1) { 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()
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()
170 if (!decompressor->supported) { in supported_squashfs_filesystem()
172 decompressor->name); in supported_squashfs_filesystem()
182 struct squashfs_mount_opts *opts = fc->fs_private; 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()
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 err = -ENOMEM; in squashfs_fill_super()
319 msblk->block_cache = squashfs_cache_init("metadata", in squashfs_fill_super()
321 if (msblk->block_cache == NULL) in squashfs_fill_super()
325 msblk->read_page = squashfs_cache_init("data", in squashfs_fill_super()
326 msblk->max_thread_num, msblk->block_size); in squashfs_fill_super()
327 if (msblk->read_page == NULL) { in squashfs_fill_super()
332 if (msblk->devblksize == PAGE_SIZE) { in squashfs_fill_super()
339 cache->i_size = OFFSET_MAX; in squashfs_fill_super()
340 mapping_set_gfp_mask(cache->i_mapping, GFP_NOFS); in squashfs_fill_super()
342 msblk->cache_mapping = cache->i_mapping; in squashfs_fill_super()
345 msblk->stream = squashfs_decompressor_setup(sb, flags); in squashfs_fill_super()
346 if (IS_ERR(msblk->stream)) { in squashfs_fill_super()
347 err = PTR_ERR(msblk->stream); in squashfs_fill_super()
348 msblk->stream = NULL; in squashfs_fill_super()
353 sb->s_xattr = squashfs_xattr_handlers; in squashfs_fill_super()
354 xattr_id_table_start = le64_to_cpu(sblk->xattr_id_table_start); in squashfs_fill_super()
356 next_table = msblk->bytes_used; in squashfs_fill_super()
361 msblk->xattr_id_table = squashfs_read_xattr_id_table(sb, in squashfs_fill_super()
362 xattr_id_table_start, &msblk->xattr_table, &msblk->xattr_ids); in squashfs_fill_super()
363 if (IS_ERR(msblk->xattr_id_table)) { in squashfs_fill_super()
365 err = PTR_ERR(msblk->xattr_id_table); in squashfs_fill_super()
366 msblk->xattr_id_table = NULL; in squashfs_fill_super()
367 if (err != -ENOTSUPP) in squashfs_fill_super()
370 next_table = msblk->xattr_table; in squashfs_fill_super()
374 msblk->id_table = squashfs_read_id_index_table(sb, in squashfs_fill_super()
375 le64_to_cpu(sblk->id_table_start), next_table, msblk->ids); in squashfs_fill_super()
376 if (IS_ERR(msblk->id_table)) { in squashfs_fill_super()
378 err = PTR_ERR(msblk->id_table); in squashfs_fill_super()
379 msblk->id_table = NULL; in squashfs_fill_super()
382 next_table = le64_to_cpu(msblk->id_table[0]); in squashfs_fill_super()
385 lookup_table_start = le64_to_cpu(sblk->lookup_table_start); in squashfs_fill_super()
390 msblk->inode_lookup_table = squashfs_read_inode_lookup_table(sb, in squashfs_fill_super()
391 lookup_table_start, next_table, msblk->inodes); in squashfs_fill_super()
392 if (IS_ERR(msblk->inode_lookup_table)) { in squashfs_fill_super()
394 err = PTR_ERR(msblk->inode_lookup_table); in squashfs_fill_super()
395 msblk->inode_lookup_table = NULL; in squashfs_fill_super()
398 next_table = le64_to_cpu(msblk->inode_lookup_table[0]); in squashfs_fill_super()
400 sb->s_export_op = &squashfs_export_ops; in squashfs_fill_super()
403 fragments = msblk->fragments; in squashfs_fill_super()
407 msblk->fragment_cache = squashfs_cache_init("fragment", in squashfs_fill_super()
408 SQUASHFS_CACHED_FRAGMENTS, msblk->block_size); in squashfs_fill_super()
409 if (msblk->fragment_cache == NULL) { in squashfs_fill_super()
410 err = -ENOMEM; in squashfs_fill_super()
415 msblk->fragment_index = squashfs_read_fragment_index_table(sb, in squashfs_fill_super()
416 le64_to_cpu(sblk->fragment_table_start), next_table, fragments); in squashfs_fill_super()
417 if (IS_ERR(msblk->fragment_index)) { in squashfs_fill_super()
419 err = PTR_ERR(msblk->fragment_index); in squashfs_fill_super()
420 msblk->fragment_index = NULL; in squashfs_fill_super()
423 next_table = le64_to_cpu(msblk->fragment_index[0]); in squashfs_fill_super()
427 if (msblk->directory_table > next_table) { in squashfs_fill_super()
428 err = -EINVAL; in squashfs_fill_super()
433 if (msblk->inode_table >= msblk->directory_table) { in squashfs_fill_super()
434 err = -EINVAL; in squashfs_fill_super()
441 err = -ENOMEM; in squashfs_fill_super()
453 sb->s_root = d_make_root(root); in squashfs_fill_super()
454 if (sb->s_root == NULL) { in squashfs_fill_super()
456 err = -ENOMEM; in squashfs_fill_super()
467 squashfs_cache_delete(msblk->block_cache); in squashfs_fill_super()
468 squashfs_cache_delete(msblk->fragment_cache); in squashfs_fill_super()
469 squashfs_cache_delete(msblk->read_page); in squashfs_fill_super()
470 if (msblk->cache_mapping) in squashfs_fill_super()
471 iput(msblk->cache_mapping->host); in squashfs_fill_super()
472 msblk->thread_ops->destroy(msblk); in squashfs_fill_super()
473 kfree(msblk->inode_lookup_table); in squashfs_fill_super()
474 kfree(msblk->fragment_index); in squashfs_fill_super()
475 kfree(msblk->id_table); in squashfs_fill_super()
476 kfree(msblk->xattr_id_table); in squashfs_fill_super()
477 kfree(sb->s_fs_info); in squashfs_fill_super()
478 sb->s_fs_info = NULL; in squashfs_fill_super()
490 struct super_block *sb = fc->root->d_sb; in squashfs_reconfigure()
491 struct squashfs_sb_info *msblk = sb->s_fs_info; in squashfs_reconfigure()
492 struct squashfs_mount_opts *opts = fc->fs_private; in squashfs_reconfigure()
494 sync_filesystem(fc->root->d_sb); in squashfs_reconfigure()
495 fc->sb_flags |= SB_RDONLY; in squashfs_reconfigure()
497 msblk->panic_on_errors = (opts->errors == Opt_errors_panic); in squashfs_reconfigure()
504 kfree(fc->fs_private); in squashfs_free_fs_context()
516 struct super_block *sb = root->d_sb; in squashfs_show_options()
517 struct squashfs_sb_info *msblk = sb->s_fs_info; in squashfs_show_options()
519 if (msblk->panic_on_errors) in squashfs_show_options()
525 if (msblk->thread_ops == &squashfs_decompressor_single) { in squashfs_show_options()
529 if (msblk->thread_ops == &squashfs_decompressor_percpu) { in squashfs_show_options()
535 seq_printf(s, ",threads=%d", msblk->max_thread_num); in squashfs_show_options()
546 return -ENOMEM; in squashfs_init_fs_context()
549 opts->thread_ops = &squashfs_decompressor_single; in squashfs_init_fs_context()
551 opts->thread_ops = &squashfs_decompressor_multi; in squashfs_init_fs_context()
553 opts->thread_ops = &squashfs_decompressor_percpu; in squashfs_init_fs_context()
557 opts->thread_num = 0; in squashfs_init_fs_context()
558 fc->fs_private = opts; in squashfs_init_fs_context()
559 fc->ops = &squashfs_context_ops; in squashfs_init_fs_context()
565 struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info; in squashfs_statfs()
566 u64 id = huge_encode_dev(dentry->d_sb->s_bdev->bd_dev); in squashfs_statfs()
570 buf->f_type = SQUASHFS_MAGIC; in squashfs_statfs()
571 buf->f_bsize = msblk->block_size; in squashfs_statfs()
572 buf->f_blocks = ((msblk->bytes_used - 1) >> msblk->block_log) + 1; in squashfs_statfs()
573 buf->f_bfree = buf->f_bavail = 0; in squashfs_statfs()
574 buf->f_files = msblk->inodes; in squashfs_statfs()
575 buf->f_ffree = 0; in squashfs_statfs()
576 buf->f_namelen = SQUASHFS_NAME_LEN; in squashfs_statfs()
577 buf->f_fsid = u64_to_fsid(id); in squashfs_statfs()
585 if (sb->s_fs_info) { in squashfs_put_super()
586 struct squashfs_sb_info *sbi = sb->s_fs_info; in squashfs_put_super()
587 squashfs_cache_delete(sbi->block_cache); in squashfs_put_super()
588 squashfs_cache_delete(sbi->fragment_cache); in squashfs_put_super()
589 squashfs_cache_delete(sbi->read_page); in squashfs_put_super()
590 if (sbi->cache_mapping) in squashfs_put_super()
591 iput(sbi->cache_mapping->host); in squashfs_put_super()
592 sbi->thread_ops->destroy(sbi); in squashfs_put_super()
593 kfree(sbi->id_table); in squashfs_put_super()
594 kfree(sbi->fragment_index); in squashfs_put_super()
595 kfree(sbi->meta_index); in squashfs_put_super()
596 kfree(sbi->inode_lookup_table); in squashfs_put_super()
597 kfree(sbi->xattr_id_table); in squashfs_put_super()
598 kfree(sb->s_fs_info); in squashfs_put_super()
599 sb->s_fs_info = NULL; in squashfs_put_super()
610 inode_init_once(&ei->vfs_inode); in init_once()
621 return squashfs_inode_cachep ? 0 : -ENOMEM; in init_inodecache()
667 return ei ? &ei->vfs_inode : NULL; in squashfs_alloc_inode()
696 MODULE_DESCRIPTION("squashfs 4.0, a compressed read-only filesystem");