hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/fs/efivarfs/super.c
....@@ -1,15 +1,13 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2012 Red Hat, Inc.
34 * Copyright (C) 2012 Jeremy Kerr <jeremy.kerr@canonical.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
85 */
96
107 #include <linux/ctype.h>
118 #include <linux/efi.h>
129 #include <linux/fs.h>
10
+#include <linux/fs_context.h>
1311 #include <linux/module.h>
1412 #include <linux/pagemap.h>
1513 #include <linux/ucs2_string.h>
....@@ -30,8 +28,6 @@
3028 .drop_inode = generic_delete_inode,
3129 .evict_inode = efivarfs_evict_inode,
3230 };
33
-
34
-static struct super_block *efivarfs_sb;
3531
3632 /*
3733 * Compare two efivarfs file names.
....@@ -194,13 +190,11 @@
194190 return 0;
195191 }
196192
197
-static int efivarfs_fill_super(struct super_block *sb, void *data, int silent)
193
+static int efivarfs_fill_super(struct super_block *sb, struct fs_context *fc)
198194 {
199195 struct inode *inode = NULL;
200196 struct dentry *root;
201197 int err;
202
-
203
- efivarfs_sb = sb;
204198
205199 sb->s_maxbytes = MAX_LFS_FILESIZE;
206200 sb->s_blocksize = PAGE_SIZE;
....@@ -209,6 +203,9 @@
209203 sb->s_op = &efivarfs_ops;
210204 sb->s_d_op = &efivarfs_d_ops;
211205 sb->s_time_gran = 1;
206
+
207
+ if (!efivar_supports_writes())
208
+ sb->s_flags |= SB_RDONLY;
212209
213210 inode = efivarfs_get_inode(sb, NULL, S_IFDIR | 0755, 0, true);
214211 if (!inode)
....@@ -229,16 +226,24 @@
229226 return err;
230227 }
231228
232
-static struct dentry *efivarfs_mount(struct file_system_type *fs_type,
233
- int flags, const char *dev_name, void *data)
229
+static int efivarfs_get_tree(struct fs_context *fc)
234230 {
235
- return mount_single(fs_type, flags, data, efivarfs_fill_super);
231
+ return get_tree_single(fc, efivarfs_fill_super);
232
+}
233
+
234
+static const struct fs_context_operations efivarfs_context_ops = {
235
+ .get_tree = efivarfs_get_tree,
236
+};
237
+
238
+static int efivarfs_init_fs_context(struct fs_context *fc)
239
+{
240
+ fc->ops = &efivarfs_context_ops;
241
+ return 0;
236242 }
237243
238244 static void efivarfs_kill_sb(struct super_block *sb)
239245 {
240246 kill_litter_super(sb);
241
- efivarfs_sb = NULL;
242247
243248 /* Remove all entries and destroy */
244249 __efivar_entry_iter(efivarfs_destroy, &efivarfs_list, NULL, NULL);
....@@ -247,15 +252,12 @@
247252 static struct file_system_type efivarfs_type = {
248253 .owner = THIS_MODULE,
249254 .name = "efivarfs",
250
- .mount = efivarfs_mount,
255
+ .init_fs_context = efivarfs_init_fs_context,
251256 .kill_sb = efivarfs_kill_sb,
252257 };
253258
254259 static __init int efivarfs_init(void)
255260 {
256
- if (!efi_enabled(EFI_RUNTIME_SERVICES))
257
- return -ENODEV;
258
-
259261 if (!efivars_kobject())
260262 return -ENODEV;
261263
....@@ -270,6 +272,7 @@
270272 MODULE_AUTHOR("Matthew Garrett, Jeremy Kerr");
271273 MODULE_DESCRIPTION("EFI Variable Filesystem");
272274 MODULE_LICENSE("GPL");
275
+MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
273276 MODULE_ALIAS_FS("efivarfs");
274277
275278 module_init(efivarfs_init);