^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2012 Red Hat, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2012 Jeremy Kerr <jeremy.kerr@canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/fs_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/ucs2_string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/magic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) LIST_HEAD(efivarfs_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static void efivarfs_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static const struct super_operations efivarfs_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .statfs = simple_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .drop_inode = generic_delete_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .evict_inode = efivarfs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * Compare two efivarfs file names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * An efivarfs filename is composed of two parts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * 1. A case-sensitive variable name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * 2. A case-insensitive GUID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * So we need to perform a case-sensitive match on part 1 and a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * case-insensitive match on part 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int efivarfs_d_compare(const struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned int len, const char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) const struct qstr *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int guid = len - EFI_VARIABLE_GUID_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (name->len != len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* Case-sensitive compare for the variable name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (memcmp(str, name->name, guid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* Case-insensitive compare for the GUID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return strncasecmp(name->name + guid, str + guid, EFI_VARIABLE_GUID_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static int efivarfs_d_hash(const struct dentry *dentry, struct qstr *qstr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) unsigned long hash = init_name_hash(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) const unsigned char *s = qstr->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) unsigned int len = qstr->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!efivarfs_valid_name(s, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) while (len-- > EFI_VARIABLE_GUID_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) hash = partial_name_hash(*s++, hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* GUID is case-insensitive. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) while (len--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) hash = partial_name_hash(tolower(*s++), hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) qstr->hash = end_name_hash(hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static const struct dentry_operations efivarfs_d_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .d_compare = efivarfs_d_compare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .d_hash = efivarfs_d_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .d_delete = always_delete_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static struct dentry *efivarfs_alloc_dentry(struct dentry *parent, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct qstr q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) q.name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) q.len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) err = efivarfs_d_hash(parent, &q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) d = d_alloc(parent, &q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned long name_size, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct super_block *sb = (struct super_block *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct efivar_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct dentry *dentry, *root = sb->s_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) unsigned long size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) bool is_removable = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) entry = kzalloc(sizeof(*entry), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) memcpy(entry->var.VariableName, name16, name_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) memcpy(&(entry->var.VendorGuid), &vendor, sizeof(efi_guid_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) len = ucs2_utf8size(entry->var.VariableName);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* name, plus '-', plus GUID, plus NUL*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) name = kmalloc(len + 1 + EFI_VARIABLE_GUID_LEN + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ucs2_as_utf8(name, entry->var.VariableName, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (efivar_variable_is_removable(entry->var.VendorGuid, name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) is_removable = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) name[len] = '-';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) efi_guid_to_str(&entry->var.VendorGuid, name + len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) name[len + EFI_VARIABLE_GUID_LEN+1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* replace invalid slashes like kobject_set_name_vargs does for /sys/firmware/efi/vars. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) strreplace(name, '/', '!');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) inode = efivarfs_get_inode(sb, d_inode(root), S_IFREG | 0644, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) is_removable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) goto fail_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) dentry = efivarfs_alloc_dentry(root, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) err = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto fail_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) efivar_entry_size(entry, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) err = efivar_entry_add(entry, &efivarfs_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) goto fail_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* copied by the above to local storage in the dentry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) inode->i_private = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) i_size_write(inode, size + sizeof(entry->var.Attributes));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) d_add(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) fail_inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) fail_name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static int efivarfs_destroy(struct efivar_entry *entry, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) int err = efivar_entry_remove(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int efivarfs_fill_super(struct super_block *sb, struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct dentry *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) sb->s_maxbytes = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) sb->s_blocksize = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) sb->s_blocksize_bits = PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) sb->s_magic = EFIVARFS_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) sb->s_op = &efivarfs_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) sb->s_d_op = &efivarfs_d_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (!efivar_supports_writes())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) inode = efivarfs_get_inode(sb, NULL, S_IFDIR | 0755, 0, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) inode->i_op = &efivarfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) root = d_make_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) sb->s_root = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (!root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) INIT_LIST_HEAD(&efivarfs_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) err = efivar_init(efivarfs_callback, (void *)sb, true, &efivarfs_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) __efivar_entry_iter(efivarfs_destroy, &efivarfs_list, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int efivarfs_get_tree(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return get_tree_single(fc, efivarfs_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static const struct fs_context_operations efivarfs_context_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .get_tree = efivarfs_get_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int efivarfs_init_fs_context(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) fc->ops = &efivarfs_context_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static void efivarfs_kill_sb(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) kill_litter_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* Remove all entries and destroy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) __efivar_entry_iter(efivarfs_destroy, &efivarfs_list, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static struct file_system_type efivarfs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .name = "efivarfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .init_fs_context = efivarfs_init_fs_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .kill_sb = efivarfs_kill_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static __init int efivarfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (!efivars_kobject())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return register_filesystem(&efivarfs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static __exit void efivarfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) unregister_filesystem(&efivarfs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) MODULE_AUTHOR("Matthew Garrett, Jeremy Kerr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) MODULE_DESCRIPTION("EFI Variable Filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) MODULE_ALIAS_FS("efivarfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) module_init(efivarfs_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) module_exit(efivarfs_exit);