hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/fs/cramfs/inode.c
....@@ -24,6 +24,7 @@
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>
....@@ -419,9 +420,12 @@
419420 int i;
420421 vma->vm_flags |= VM_MIXEDMAP;
421422 for (i = 0; i < pages && !ret; i++) {
423
+ vm_fault_t vmf;
422424 unsigned long off = i * PAGE_SIZE;
423425 pfn_t pfn = phys_to_pfn_t(address + off, PFN_DEV);
424
- ret = vm_insert_mixed(vma, vma->vm_start + off, pfn);
426
+ vmf = vmf_insert_mixed(vma, vma->vm_start + off, pfn);
427
+ if (vmf & VM_FAULT_ERROR)
428
+ ret = vm_fault_to_errno(vmf, 0);
425429 }
426430 }
427431
....@@ -503,18 +507,19 @@
503507 kfree(sbi);
504508 }
505509
506
-static int cramfs_remount(struct super_block *sb, int *flags, char *data)
510
+static int cramfs_reconfigure(struct fs_context *fc)
507511 {
508
- sync_filesystem(sb);
509
- *flags |= SB_RDONLY;
512
+ sync_filesystem(fc->root->d_sb);
513
+ fc->sb_flags |= SB_RDONLY;
510514 return 0;
511515 }
512516
513
-static int cramfs_read_super(struct super_block *sb,
514
- 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)
515519 {
516520 struct cramfs_sb_info *sbi = CRAMFS_SB(sb);
517521 unsigned long root_offset;
522
+ bool silent = fc->sb_flags & SB_SILENT;
518523
519524 /* We don't know the real size yet */
520525 sbi->size = PAGE_SIZE;
....@@ -529,7 +534,7 @@
529534 /* check for wrong endianness */
530535 if (super->magic == CRAMFS_MAGIC_WEND) {
531536 if (!silent)
532
- pr_err("wrong endianness\n");
537
+ errorfc(fc, "wrong endianness");
533538 return -EINVAL;
534539 }
535540
....@@ -541,22 +546,22 @@
541546 mutex_unlock(&read_mutex);
542547 if (super->magic != CRAMFS_MAGIC) {
543548 if (super->magic == CRAMFS_MAGIC_WEND && !silent)
544
- pr_err("wrong endianness\n");
549
+ errorfc(fc, "wrong endianness");
545550 else if (!silent)
546
- pr_err("wrong magic\n");
551
+ errorfc(fc, "wrong magic");
547552 return -EINVAL;
548553 }
549554 }
550555
551556 /* get feature flags first */
552557 if (super->flags & ~CRAMFS_SUPPORTED_FLAGS) {
553
- pr_err("unsupported filesystem features\n");
558
+ errorfc(fc, "unsupported filesystem features");
554559 return -EINVAL;
555560 }
556561
557562 /* Check that the root inode is in a sane state */
558563 if (!S_ISDIR(super->root.mode)) {
559
- pr_err("root is not a directory\n");
564
+ errorfc(fc, "root is not a directory");
560565 return -EINVAL;
561566 }
562567 /* correct strange, hard-coded permissions of mkcramfs */
....@@ -575,12 +580,12 @@
575580 sbi->magic = super->magic;
576581 sbi->flags = super->flags;
577582 if (root_offset == 0)
578
- pr_info("empty filesystem");
583
+ infofc(fc, "empty filesystem");
579584 else if (!(super->flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) &&
580585 ((root_offset != sizeof(struct cramfs_super)) &&
581586 (root_offset != 512 + sizeof(struct cramfs_super))))
582587 {
583
- pr_err("bad root offset %lu\n", root_offset);
588
+ errorfc(fc, "bad root offset %lu", root_offset);
584589 return -EINVAL;
585590 }
586591
....@@ -594,6 +599,8 @@
594599
595600 /* Set it all up.. */
596601 sb->s_flags |= SB_RDONLY;
602
+ sb->s_time_min = 0;
603
+ sb->s_time_max = 0;
597604 sb->s_op = &cramfs_ops;
598605 root = get_cramfs_inode(sb, cramfs_root, 0);
599606 if (IS_ERR(root))
....@@ -604,8 +611,7 @@
604611 return 0;
605612 }
606613
607
-static int cramfs_blkdev_fill_super(struct super_block *sb, void *data,
608
- int silent)
614
+static int cramfs_blkdev_fill_super(struct super_block *sb, struct fs_context *fc)
609615 {
610616 struct cramfs_sb_info *sbi;
611617 struct cramfs_super super;
....@@ -620,14 +626,13 @@
620626 for (i = 0; i < READ_BUFFERS; i++)
621627 buffer_blocknr[i] = -1;
622628
623
- err = cramfs_read_super(sb, &super, silent);
629
+ err = cramfs_read_super(sb, fc, &super);
624630 if (err)
625631 return err;
626632 return cramfs_finalize_super(sb, &super.root);
627633 }
628634
629
-static int cramfs_mtd_fill_super(struct super_block *sb, void *data,
630
- int silent)
635
+static int cramfs_mtd_fill_super(struct super_block *sb, struct fs_context *fc)
631636 {
632637 struct cramfs_sb_info *sbi;
633638 struct cramfs_super super;
....@@ -649,7 +654,7 @@
649654
650655 pr_info("checking physical address %pap for linear cramfs image\n",
651656 &sbi->linear_phys_addr);
652
- err = cramfs_read_super(sb, &super, silent);
657
+ err = cramfs_read_super(sb, fc, &super);
653658 if (err)
654659 return err;
655660
....@@ -685,8 +690,7 @@
685690 buf->f_bavail = 0;
686691 buf->f_files = CRAMFS_SB(sb)->files;
687692 buf->f_ffree = 0;
688
- buf->f_fsid.val[0] = (u32)id;
689
- buf->f_fsid.val[1] = (u32)(id >> 32);
693
+ buf->f_fsid = u64_to_fsid(id);
690694 buf->f_namelen = CRAMFS_MAXPATHLEN;
691695 return 0;
692696 }
....@@ -870,8 +874,8 @@
870874 if (unlikely(block_start & CRAMFS_BLK_FLAG_DIRECT_PTR)) {
871875 /* See comments on earlier code. */
872876 u32 prev_start = block_start;
873
- block_start = prev_start & ~CRAMFS_BLK_FLAGS;
874
- block_start <<= CRAMFS_BLK_DIRECT_PTR_SHIFT;
877
+ block_start = prev_start & ~CRAMFS_BLK_FLAGS;
878
+ block_start <<= CRAMFS_BLK_DIRECT_PTR_SHIFT;
875879 if (prev_start & CRAMFS_BLK_FLAG_UNCOMPRESSED) {
876880 block_start += PAGE_SIZE;
877881 } else {
....@@ -944,32 +948,41 @@
944948 };
945949
946950 static const struct super_operations cramfs_ops = {
947
- .remount_fs = cramfs_remount,
948951 .statfs = cramfs_statfs,
949952 };
950953
951
-static struct dentry *cramfs_mount(struct file_system_type *fs_type, int flags,
952
- const char *dev_name, void *data)
954
+static int cramfs_get_tree(struct fs_context *fc)
953955 {
954
- struct dentry *ret = ERR_PTR(-ENOPROTOOPT);
956
+ int ret = -ENOPROTOOPT;
955957
956958 if (IS_ENABLED(CONFIG_CRAMFS_MTD)) {
957
- ret = mount_mtd(fs_type, flags, dev_name, data,
958
- cramfs_mtd_fill_super);
959
- if (!IS_ERR(ret))
960
- return ret;
959
+ ret = get_tree_mtd(fc, cramfs_mtd_fill_super);
960
+ if (!ret)
961
+ return 0;
961962 }
962
- if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV)) {
963
- ret = mount_bdev(fs_type, flags, dev_name, data,
964
- cramfs_blkdev_fill_super);
965
- }
963
+ if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV))
964
+ ret = get_tree_bdev(fc, cramfs_blkdev_fill_super);
966965 return ret;
966
+}
967
+
968
+static const struct fs_context_operations cramfs_context_ops = {
969
+ .get_tree = cramfs_get_tree,
970
+ .reconfigure = cramfs_reconfigure,
971
+};
972
+
973
+/*
974
+ * Set up the filesystem mount context.
975
+ */
976
+static int cramfs_init_fs_context(struct fs_context *fc)
977
+{
978
+ fc->ops = &cramfs_context_ops;
979
+ return 0;
967980 }
968981
969982 static struct file_system_type cramfs_fs_type = {
970983 .owner = THIS_MODULE,
971984 .name = "cramfs",
972
- .mount = cramfs_mount,
985
+ .init_fs_context = cramfs_init_fs_context,
973986 .kill_sb = cramfs_kill_sb,
974987 .fs_flags = FS_REQUIRES_DEV,
975988 };
....@@ -997,3 +1010,4 @@
9971010 module_init(init_cramfs_fs)
9981011 module_exit(exit_cramfs_fs)
9991012 MODULE_LICENSE("GPL");
1013
+MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);