8
8
#include <linux/efi.h>
9
9
#include <linux/fs.h>
10
10
#include <linux/fs_context.h>
11
+ #include <linux/fs_parser.h>
11
12
#include <linux/module.h>
12
13
#include <linux/pagemap.h>
13
14
#include <linux/ucs2_string.h>
@@ -24,6 +25,21 @@ static void efivarfs_evict_inode(struct inode *inode)
24
25
clear_inode (inode );
25
26
}
26
27
28
+ static int efivarfs_show_options (struct seq_file * m , struct dentry * root )
29
+ {
30
+ struct super_block * sb = root -> d_sb ;
31
+ struct efivarfs_fs_info * sbi = sb -> s_fs_info ;
32
+ struct efivarfs_mount_opts * opts = & sbi -> mount_opts ;
33
+
34
+ if (!uid_eq (opts -> uid , GLOBAL_ROOT_UID ))
35
+ seq_printf (m , ",uid=%u" ,
36
+ from_kuid_munged (& init_user_ns , opts -> uid ));
37
+ if (!gid_eq (opts -> gid , GLOBAL_ROOT_GID ))
38
+ seq_printf (m , ",gid=%u" ,
39
+ from_kgid_munged (& init_user_ns , opts -> gid ));
40
+ return 0 ;
41
+ }
42
+
27
43
static int efivarfs_statfs (struct dentry * dentry , struct kstatfs * buf )
28
44
{
29
45
const u32 attr = EFI_VARIABLE_NON_VOLATILE |
@@ -72,6 +88,7 @@ static const struct super_operations efivarfs_ops = {
72
88
.statfs = efivarfs_statfs ,
73
89
.drop_inode = generic_delete_inode ,
74
90
.evict_inode = efivarfs_evict_inode ,
91
+ .show_options = efivarfs_show_options ,
75
92
};
76
93
77
94
/*
@@ -233,6 +250,45 @@ static int efivarfs_destroy(struct efivar_entry *entry, void *data)
233
250
return 0 ;
234
251
}
235
252
253
+ enum {
254
+ Opt_uid , Opt_gid ,
255
+ };
256
+
257
+ static const struct fs_parameter_spec efivarfs_parameters [] = {
258
+ fsparam_u32 ("uid" , Opt_uid ),
259
+ fsparam_u32 ("gid" , Opt_gid ),
260
+ {},
261
+ };
262
+
263
+ static int efivarfs_parse_param (struct fs_context * fc , struct fs_parameter * param )
264
+ {
265
+ struct efivarfs_fs_info * sbi = fc -> s_fs_info ;
266
+ struct efivarfs_mount_opts * opts = & sbi -> mount_opts ;
267
+ struct fs_parse_result result ;
268
+ int opt ;
269
+
270
+ opt = fs_parse (fc , efivarfs_parameters , param , & result );
271
+ if (opt < 0 )
272
+ return opt ;
273
+
274
+ switch (opt ) {
275
+ case Opt_uid :
276
+ opts -> uid = make_kuid (current_user_ns (), result .uint_32 );
277
+ if (!uid_valid (opts -> uid ))
278
+ return - EINVAL ;
279
+ break ;
280
+ case Opt_gid :
281
+ opts -> gid = make_kgid (current_user_ns (), result .uint_32 );
282
+ if (!gid_valid (opts -> gid ))
283
+ return - EINVAL ;
284
+ break ;
285
+ default :
286
+ return - EINVAL ;
287
+ }
288
+
289
+ return 0 ;
290
+ }
291
+
236
292
static int efivarfs_fill_super (struct super_block * sb , struct fs_context * fc )
237
293
{
238
294
struct inode * inode = NULL ;
@@ -279,10 +335,21 @@ static int efivarfs_get_tree(struct fs_context *fc)
279
335
280
336
static const struct fs_context_operations efivarfs_context_ops = {
281
337
.get_tree = efivarfs_get_tree ,
338
+ .parse_param = efivarfs_parse_param ,
282
339
};
283
340
284
341
static int efivarfs_init_fs_context (struct fs_context * fc )
285
342
{
343
+ struct efivarfs_fs_info * sfi ;
344
+
345
+ sfi = kzalloc (sizeof (* sfi ), GFP_KERNEL );
346
+ if (!sfi )
347
+ return - ENOMEM ;
348
+
349
+ sfi -> mount_opts .uid = GLOBAL_ROOT_UID ;
350
+ sfi -> mount_opts .gid = GLOBAL_ROOT_GID ;
351
+
352
+ fc -> s_fs_info = sfi ;
286
353
fc -> ops = & efivarfs_context_ops ;
287
354
return 0 ;
288
355
}
@@ -303,6 +370,7 @@ static struct file_system_type efivarfs_type = {
303
370
.name = "efivarfs" ,
304
371
.init_fs_context = efivarfs_init_fs_context ,
305
372
.kill_sb = efivarfs_kill_sb ,
373
+ .parameters = efivarfs_parameters ,
306
374
};
307
375
308
376
static __init int efivarfs_init (void )
0 commit comments