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 |
@@ -64,6 +80,7 @@ static const struct super_operations efivarfs_ops = {
64
80
.statfs = efivarfs_statfs ,
65
81
.drop_inode = generic_delete_inode ,
66
82
.evict_inode = efivarfs_evict_inode ,
83
+ .show_options = efivarfs_show_options ,
67
84
};
68
85
69
86
/*
@@ -225,6 +242,45 @@ static int efivarfs_destroy(struct efivar_entry *entry, void *data)
225
242
return 0 ;
226
243
}
227
244
245
+ enum {
246
+ Opt_uid , Opt_gid ,
247
+ };
248
+
249
+ static const struct fs_parameter_spec efivarfs_parameters [] = {
250
+ fsparam_u32 ("uid" , Opt_uid ),
251
+ fsparam_u32 ("gid" , Opt_gid ),
252
+ {},
253
+ };
254
+
255
+ static int efivarfs_parse_param (struct fs_context * fc , struct fs_parameter * param )
256
+ {
257
+ struct efivarfs_fs_info * sbi = fc -> s_fs_info ;
258
+ struct efivarfs_mount_opts * opts = & sbi -> mount_opts ;
259
+ struct fs_parse_result result ;
260
+ int opt ;
261
+
262
+ opt = fs_parse (fc , efivarfs_parameters , param , & result );
263
+ if (opt < 0 )
264
+ return opt ;
265
+
266
+ switch (opt ) {
267
+ case Opt_uid :
268
+ opts -> uid = make_kuid (current_user_ns (), result .uint_32 );
269
+ if (!uid_valid (opts -> uid ))
270
+ return - EINVAL ;
271
+ break ;
272
+ case Opt_gid :
273
+ opts -> gid = make_kgid (current_user_ns (), result .uint_32 );
274
+ if (!gid_valid (opts -> gid ))
275
+ return - EINVAL ;
276
+ break ;
277
+ default :
278
+ return - EINVAL ;
279
+ }
280
+
281
+ return 0 ;
282
+ }
283
+
228
284
static int efivarfs_fill_super (struct super_block * sb , struct fs_context * fc )
229
285
{
230
286
struct inode * inode = NULL ;
@@ -271,10 +327,21 @@ static int efivarfs_get_tree(struct fs_context *fc)
271
327
272
328
static const struct fs_context_operations efivarfs_context_ops = {
273
329
.get_tree = efivarfs_get_tree ,
330
+ .parse_param = efivarfs_parse_param ,
274
331
};
275
332
276
333
static int efivarfs_init_fs_context (struct fs_context * fc )
277
334
{
335
+ struct efivarfs_fs_info * sfi ;
336
+
337
+ sfi = kzalloc (sizeof (* sfi ), GFP_KERNEL );
338
+ if (!sfi )
339
+ return - ENOMEM ;
340
+
341
+ sfi -> mount_opts .uid = GLOBAL_ROOT_UID ;
342
+ sfi -> mount_opts .gid = GLOBAL_ROOT_GID ;
343
+
344
+ fc -> s_fs_info = sfi ;
278
345
fc -> ops = & efivarfs_context_ops ;
279
346
return 0 ;
280
347
}
@@ -295,6 +362,7 @@ static struct file_system_type efivarfs_type = {
295
362
.name = "efivarfs" ,
296
363
.init_fs_context = efivarfs_init_fs_context ,
297
364
.kill_sb = efivarfs_kill_sb ,
365
+ .parameters = efivarfs_parameters ,
298
366
};
299
367
300
368
static __init int efivarfs_init (void )
0 commit comments