summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/Kconfig15
-rw-r--r--fs/Makefile2
-rw-r--r--fs/efi.c563
-rw-r--r--fs/efivarfs.c340
-rw-r--r--fs/fat/fat.c4
5 files changed, 922 insertions, 2 deletions
diff --git a/fs/Kconfig b/fs/Kconfig
index 3724b34f9a..64fc1176a6 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -41,6 +41,21 @@ config FS_NFS
bool
prompt "nfs support"
+config FS_EFI
+ depends on ARCH_EFI
+ bool
+ prompt "EFI filesystem support"
+ help
+ This filesystem driver provides access to the filesystems provided
+ by the EFI Firmware via the EFI Simple File System Protocol.
+
+config FS_EFIVARFS
+ depends on ARCH_EFI
+ bool
+ prompt "EFI variable filesystem support (efivarfs)"
+ help
+ This filesystem driver provides access to EFI variables.
+
source fs/fat/Kconfig
source fs/ubifs/Kconfig
diff --git a/fs/Makefile b/fs/Makefile
index d3465edfa5..f5aae91a60 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -11,3 +11,5 @@ obj-$(CONFIG_FS_OMAP4_USBBOOT) += omap4_usbbootfs.o
obj-$(CONFIG_FS_NFS) += nfs.o parseopt.o
obj-$(CONFIG_FS_BPKFS) += bpkfs.o
obj-$(CONFIG_FS_UIMAGEFS) += uimagefs.o
+obj-$(CONFIG_FS_EFI) += efi.o
+obj-$(CONFIG_FS_EFIVARFS) += efivarfs.o
diff --git a/fs/efi.c b/fs/efi.c
new file mode 100644
index 0000000000..f096f91f58
--- /dev/null
+++ b/fs/efi.c
@@ -0,0 +1,563 @@
+/*
+ * efi.c - EFI filesystem mirror driver
+ *
+ * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <common.h>
+#include <driver.h>
+#include <init.h>
+#include <malloc.h>
+#include <fs.h>
+#include <string.h>
+#include <command.h>
+#include <errno.h>
+#include <linux/stat.h>
+#include <xfuncs.h>
+#include <fcntl.h>
+#include <wchar.h>
+#include <efi.h>
+#include <mach/efi.h>
+#include <mach/efi-device.h>
+
+/* Open modes */
+#define EFI_FILE_MODE_READ 0x0000000000000001
+#define EFI_FILE_MODE_WRITE 0x0000000000000002
+#define EFI_FILE_MODE_CREATE 0x8000000000000000
+
+/* File attributes */
+#define EFI_FILE_READ_ONLY 0x0000000000000001
+#define EFI_FILE_HIDDEN 0x0000000000000002
+#define EFI_FILE_SYSTEM 0x0000000000000004
+#define EFI_FILE_RESERVIED 0x0000000000000008
+#define EFI_FILE_DIRECTORY 0x0000000000000010
+#define EFI_FILE_ARCHIVE 0x0000000000000020
+#define EFI_FILE_VALID_ATTR 0x0000000000000037
+
+#define EFI_FILE_HANDLE_REVISION 0x00010000
+struct efi_file_handle {
+ uint64_t Revision;
+ efi_status_t(EFIAPI *open)(struct efi_file_handle *File,
+ struct efi_file_handle **NewHandle, s16 *FileName,
+ uint64_t OpenMode, uint64_t Attributes);
+ efi_status_t(EFIAPI *close)(struct efi_file_handle *File);
+ efi_status_t(EFIAPI *delete)(struct efi_file_handle *File);
+ efi_status_t(EFIAPI *read)(struct efi_file_handle *File, unsigned long *BufferSize,
+ void *Buffer);
+ efi_status_t(EFIAPI *write)(struct efi_file_handle *File,
+ unsigned long *BufferSize, void *Buffer);
+ efi_status_t(EFIAPI *get_position)(struct efi_file_handle *File,
+ uint64_t *Position);
+ efi_status_t(EFIAPI *set_position)(struct efi_file_handle *File,
+ uint64_t Position);
+ efi_status_t(EFIAPI *get_info)(struct efi_file_handle *File,
+ efi_guid_t *InformationType, unsigned long *BufferSize,
+ void *Buffer);
+ efi_status_t(EFIAPI *set_info)(struct efi_file_handle *File,
+ efi_guid_t *InformationType, unsigned long BufferSize,
+ void *Buffer);
+ efi_status_t(EFIAPI *flush)(struct efi_file_handle *File);
+};
+
+#define EFI_FILE_IO_INTERFACE_REVISION 0x00010000
+
+struct efi_file_io_interface {
+ uint64_t Revision;
+ efi_status_t(EFIAPI *open_volume)(
+ struct efi_file_io_interface *This,
+ struct efi_file_handle **Root);
+};
+
+struct efi_file_info {
+ uint64_t Size;
+ uint64_t FileSize;
+ uint64_t PhysicalSize;
+ efi_time_t CreateTime;
+ efi_time_t LastAccessTime;
+ efi_time_t ModificationTime;
+ uint64_t Attribute;
+ s16 FileName[1];
+};
+
+typedef unsigned short wchar_t;
+
+struct efifs_priv {
+ struct efi_file_handle *root_dir;
+ struct efi_file_io_interface *protocol;
+};
+
+struct efifs_file {
+ struct efi_file_handle *entry;
+};
+
+struct efifs_dir {
+ DIR dir;
+ struct efi_file_handle *entries;
+};
+
+static wchar_t *path_to_efi(const char *path)
+{
+ wchar_t *dst;
+ wchar_t *ret;
+
+ if (!*path)
+ return strdup_char_to_wchar("\\");
+
+ dst = strdup_char_to_wchar(path);
+ if (!dst)
+ return NULL;
+
+ ret = dst;
+
+ while (*dst) {
+ if (*dst == '/')
+ *dst = '\\';
+ dst++;
+ }
+
+ return ret;
+}
+
+static int efifs_create(struct device_d *dev, const char *pathname, mode_t mode)
+{
+ struct efifs_priv *priv = dev->priv;
+ wchar_t *efi_path = path_to_efi(pathname);
+ struct efi_file_handle *entry;
+ efi_status_t efiret;
+
+ efiret = priv->root_dir->open(priv->root_dir, &entry, efi_path,
+ EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
+ 0ULL);
+
+ free(efi_path);
+
+ if (EFI_ERROR(efiret)) {
+ printf("%s %s: %s\n", __func__, pathname, efi_strerror(efiret));
+ return -efi_errno(efiret);
+ }
+
+ entry->close(entry);
+
+ return 0;
+}
+
+static int efifs_unlink(struct device_d *dev, const char *pathname)
+{
+ struct efifs_priv *priv = dev->priv;
+ wchar_t *efi_path = path_to_efi(pathname);
+ struct efi_file_handle *entry;
+ efi_status_t efiret;
+
+ efiret = priv->root_dir->open(priv->root_dir, &entry, efi_path,
+ EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0ULL);
+
+ free(efi_path);
+
+ if (EFI_ERROR(efiret))
+ return -efi_errno(efiret);
+
+ efiret = entry->delete(entry);
+ if (EFI_ERROR(efiret))
+ return -efi_errno(efiret);
+
+ return 0;
+}
+
+static int efifs_mkdir(struct device_d *dev, const char *pathname)
+{
+ struct efifs_priv *priv = dev->priv;
+ wchar_t *efi_path = path_to_efi(pathname);
+ struct efi_file_handle *entry;
+ efi_status_t efiret;
+
+ efiret = priv->root_dir->open(priv->root_dir, &entry, efi_path,
+ EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
+ EFI_FILE_DIRECTORY);
+
+ free(efi_path);
+
+ if (EFI_ERROR(efiret)) {
+ printf("%s %s: %s\n", __func__, pathname, efi_strerror(efiret));
+ return -efi_errno(efiret);
+ }
+
+ entry->close(entry);
+
+ return 0;
+}
+
+static int efifs_rmdir(struct device_d *dev, const char *pathname)
+{
+ return efifs_unlink(dev, pathname);
+}
+
+static int efifs_open(struct device_d *dev, FILE *f, const char *filename)
+{
+ struct efifs_priv *priv = dev->priv;
+ efi_status_t efiret;
+ struct efifs_file *ufile;
+ wchar_t *efi_path = path_to_efi(filename);
+ struct efi_file_info *info;
+ unsigned long bufsize = 1024;
+ uint64_t efimode = EFI_FILE_MODE_READ;
+ int ret;
+
+ ufile = xzalloc(sizeof(*ufile));
+
+ if (f->flags & O_ACCMODE)
+ efimode |= EFI_FILE_MODE_WRITE;
+
+ efiret = priv->root_dir->open(priv->root_dir, &ufile->entry, efi_path,
+ efimode, 0ULL);
+ if (EFI_ERROR(efiret)) {
+ pr_err("%s: unable to Open %s: %s\n", __func__,
+ filename, efi_strerror(efiret));
+ free(ufile);
+ return -efi_errno(efiret);
+ }
+
+ free(efi_path);
+
+ info = xzalloc(1024);
+ efiret = ufile->entry->get_info(ufile->entry, &efi_file_info_id, &bufsize, info);
+ if (EFI_ERROR(efiret)) {
+ pr_err("%s: unable to GetInfo %s: %s\n", __func__,
+ filename, efi_strerror(efiret));
+ ret = -efi_errno(efiret);
+ goto out;
+ }
+
+ f->size = info->FileSize;
+
+ free(info);
+ f->inode = ufile;
+
+ return 0;
+out:
+ free(info);
+ free(ufile);
+ return ret;
+}
+
+static int efifs_close(struct device_d *dev, FILE *f)
+{
+ struct efifs_file *ufile = f->inode;
+
+ ufile->entry->close(ufile->entry);
+
+ free(ufile);
+
+ return 0;
+}
+
+static int efifs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
+{
+ struct efifs_file *ufile = f->inode;
+ efi_status_t efiret;
+ unsigned long bufsize = insize;
+
+ efiret = ufile->entry->read(ufile->entry, &bufsize, buf);
+ if (EFI_ERROR(efiret)) {
+ return -efi_errno(efiret);
+ }
+
+ return bufsize;
+}
+
+static int efifs_write(struct device_d *_dev, FILE *f, const void *buf, size_t insize)
+{
+ struct efifs_file *ufile = f->inode;
+ efi_status_t efiret;
+ unsigned long bufsize = insize;
+
+ efiret = ufile->entry->write(ufile->entry, &bufsize, (void *)buf);
+ if (EFI_ERROR(efiret)) {
+ pr_err("%s: unable to write: %s\n", __func__, efi_strerror(efiret));
+ return -efi_errno(efiret);
+ }
+
+ return bufsize;
+}
+
+static loff_t efifs_lseek(struct device_d *dev, FILE *f, loff_t pos)
+{
+ struct efifs_file *ufile = f->inode;
+ efi_status_t efiret;
+
+ f->pos = pos;
+
+ efiret = ufile->entry->set_position(ufile->entry, pos);
+ if (EFI_ERROR(efiret)) {
+ return -efi_errno(efiret);
+ }
+
+ return f->pos;
+}
+
+static int efifs_truncate(struct device_d *dev, FILE *f, unsigned long size)
+{
+ struct efifs_file *ufile = f->inode;
+ efi_status_t efiret;
+ struct efi_file_info *info;
+ unsigned long bufsize = 1024;
+ int ret;
+
+ info = xzalloc(1024);
+
+ efiret = ufile->entry->get_info(ufile->entry, &efi_file_info_id, &bufsize, info);
+ if (EFI_ERROR(efiret)) {
+ pr_err("%s: unable to GetInfo: %s\n", __func__, efi_strerror(efiret));
+ ret = -efi_errno(efiret);
+ goto out;
+ }
+
+ if (size > info->FileSize)
+ return 0;
+
+ info->FileSize = size;
+
+ efiret = ufile->entry->set_info(ufile->entry, &efi_file_info_id, bufsize, info);
+ if (EFI_ERROR(efiret)) {
+ pr_err("%s: unable to SetInfo: %s\n", __func__, efi_strerror(efiret));
+ ret = -efi_errno(efiret);
+ goto out;
+ }
+
+ return 0;
+out:
+ return ret;
+}
+
+static DIR *efifs_opendir(struct device_d *dev, const char *pathname)
+{
+ struct efifs_priv *priv = dev->priv;
+ efi_status_t efiret;
+ struct efifs_dir *udir;
+ wchar_t *efi_path = path_to_efi(pathname);
+
+ udir = xzalloc(sizeof(*udir));
+
+ efiret = priv->root_dir->open(priv->root_dir, &udir->entries, efi_path, EFI_FILE_MODE_READ, 0ULL);
+ if (EFI_ERROR(efiret)) {
+ free(udir);
+ return NULL;
+ }
+
+ free(efi_path);
+
+ return &udir->dir;
+}
+
+static struct dirent *efifs_readdir(struct device_d *dev, DIR *dir)
+{
+ struct efifs_dir *udir = container_of(dir, struct efifs_dir, dir);
+ efi_status_t efiret;
+ unsigned long bufsize = 256;
+ s16 buf[256];
+ struct efi_file_info *f;
+
+ efiret = udir->entries->read(udir->entries, &bufsize, buf);
+ if (EFI_ERROR(efiret) || bufsize == 0)
+ return NULL;
+
+ f = (struct efi_file_info *)buf;
+
+ strcpy_wchar_to_char(dir->d.d_name, f->FileName);
+
+ return &dir->d;
+}
+
+static int efifs_closedir(struct device_d *dev, DIR *dir)
+{
+ struct efifs_dir *udir = container_of(dir, struct efifs_dir, dir);
+
+ udir->entries->close(udir->entries);
+
+ free(dir);
+
+ return 0;
+}
+
+static int efifs_stat(struct device_d *dev, const char *filename, struct stat *s)
+{
+ struct efifs_priv *priv = dev->priv;
+ wchar_t *efi_path;
+ efi_status_t efiret;
+ struct efi_file_handle *entry;
+ struct efi_file_info *info;
+ unsigned long bufsize = 1024;
+ int ret;
+
+ info = xzalloc(1024);
+
+ efi_path = path_to_efi(filename);
+
+ efiret = priv->root_dir->open(priv->root_dir, &entry, efi_path, EFI_FILE_MODE_READ, 0ULL);
+ if (EFI_ERROR(efiret)) {
+ pr_err("%s: unable to Open %s: %s\n", __func__, filename,
+ efi_strerror(efiret));
+ ret = -efi_errno(efiret);
+ goto out_free;
+ }
+
+ efiret = entry->get_info(entry, &efi_file_info_id, &bufsize, info);
+ if (EFI_ERROR(efiret)) {
+ pr_err("%s: unable to GetInfo %s: %s\n", __func__, filename,
+ efi_strerror(efiret));
+ ret = -efi_errno(efiret);
+ goto out;
+ }
+
+ s->st_size = info->FileSize;
+ s->st_mode = 00555;
+
+ if (!info->Attribute & EFI_FILE_READ_ONLY)
+ s->st_mode |= 00222;
+
+ if (info->Attribute & EFI_FILE_DIRECTORY)
+ s->st_mode |= S_IFDIR;
+ else
+ s->st_mode |= S_IFREG;
+
+ ret = 0;
+out:
+ entry->close(entry);
+out_free:
+ free(efi_path);
+ free(info);
+
+ return ret;
+}
+
+static int efifs_symlink(struct device_d *dev, const char *pathname,
+ const char *newpath)
+{
+ return -EROFS;
+}
+
+static int efifs_readlink(struct device_d *dev, const char *pathname,
+ char *buf, size_t bufsiz)
+{
+ return -ENOENT;
+}
+
+static int efifs_probe(struct device_d *dev)
+{
+ struct fs_device_d *fsdev = dev_to_fs_device(dev);
+ struct efifs_priv *priv;
+ efi_status_t efiret;
+ struct efi_file_handle *file;
+ struct device_d *efi = get_device_by_name(fsdev->backingstore);
+ struct efi_device *udev = container_of(efi, struct efi_device, dev);
+
+ priv = xzalloc(sizeof(struct efifs_priv));
+ priv->protocol = udev->protocol;
+ dev->priv = priv;
+ dev->parent = &udev->dev;
+
+ efiret = priv->protocol->open_volume(priv->protocol, &file);
+ if (EFI_ERROR(efiret)) {
+ dev_err(dev, "failed to open volume: %s\n", efi_strerror(efiret));
+ return -efi_errno(efiret);
+ }
+
+ priv->root_dir = file;
+
+ return 0;
+}
+
+static void efifs_remove(struct device_d *dev)
+{
+ free(dev->priv);
+}
+
+static struct fs_driver_d efifs_driver = {
+ .create = efifs_create,
+ .unlink = efifs_unlink,
+ .open = efifs_open,
+ .close = efifs_close,
+ .truncate = efifs_truncate,
+ .read = efifs_read,
+ .write = efifs_write,
+ .lseek = efifs_lseek,
+ .mkdir = efifs_mkdir,
+ .rmdir = efifs_rmdir,
+ .opendir = efifs_opendir,
+ .readdir = efifs_readdir,
+ .closedir = efifs_closedir,
+ .stat = efifs_stat,
+ .symlink = efifs_symlink,
+ .readlink = efifs_readlink,
+ .drv = {
+ .probe = efifs_probe,
+ .remove = efifs_remove,
+ .name = "efifs",
+ }
+};
+
+static int efifs_init(void)
+{
+ return register_fs_driver(&efifs_driver);
+}
+
+coredevice_initcall(efifs_init);
+
+static int index;
+
+int efi_fs_probe(struct efi_device *efidev)
+{
+ char *path, *device;
+ int ret;
+ struct efi_file_io_interface *volume;
+
+ if (efi_loaded_image)
+ BS->handle_protocol(efi_loaded_image->device_handle,
+ &efi_simple_file_system_protocol_guid, (void*)&volume);
+
+ if (efidev->protocol == volume)
+ path = xstrdup("/boot");
+ else
+ path = asprintf("/efi%d", index);
+ device = asprintf("%s", dev_name(&efidev->dev));
+
+ ret = make_directory(path);
+ if (ret)
+ goto out;
+
+ ret = mount(device, "efifs", path, NULL);
+ if (ret)
+ goto out;
+
+ index++;
+
+ dev_info(&efidev->dev, "mounted on %s\n", path);
+
+ ret = 0;
+out:
+ free(path);
+ free(device);
+
+ return ret;
+}
+
+static struct efi_driver efi_fs_driver = {
+ .driver = {
+ .name = "efi-fs",
+ },
+ .probe = efi_fs_probe,
+ .guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID,
+};
+device_efi_driver(efi_fs_driver);
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
new file mode 100644
index 0000000000..58c637ef19
--- /dev/null
+++ b/fs/efivarfs.c
@@ -0,0 +1,340 @@
+/*
+ * ramfs.c - a malloc based filesystem
+ *
+ * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <common.h>
+#include <driver.h>
+#include <init.h>
+#include <malloc.h>
+#include <fs.h>
+#include <string.h>
+#include <errno.h>
+#include <linux/stat.h>
+#include <xfuncs.h>
+#include <fcntl.h>
+#include <efi.h>
+#include <wchar.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+#include <mach/efi.h>
+#include <mach/efi-device.h>
+
+struct efivarfs_priv {
+ struct efi_file_handle *root_dir;
+ struct efi_file_io_interface *protocol;
+};
+
+static int char_to_nibble(char c)
+{
+ int ret = tolower(c);
+
+ return ret <= '9' ? ret - '0' : ret - 'a' + 10;
+}
+
+static int read_byte_str(const char *str, u8 *out)
+{
+ if (!isxdigit(*str) || !isxdigit(*(str + 1)))
+ return -EINVAL;
+
+ *out = (char_to_nibble(*str) << 4) | char_to_nibble(*(str + 1));
+
+ return 0;
+}
+
+int efi_guid_parse(const char *str, efi_guid_t *guid)
+{
+ int i, ret;
+ u8 idx[] = { 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15 };
+
+ for (i = 0; i < 16; i++) {
+ ret = read_byte_str(str, &guid->b[idx[i]]);
+ if (ret)
+ return ret;
+ str += 2;
+
+ switch (i) {
+ case 3:
+ case 5:
+ case 7:
+ case 9:
+ if (*str != '-')
+ return -EINVAL;
+ str++;
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static int efivarfs_parse_filename(const char *filename, efi_guid_t *vendor, s16 **name)
+{
+ int len, ret;
+ const char *guidstr;
+ s16 *varname;
+ int i;
+
+ if (*filename == '/')
+ filename++;
+
+ len = strlen(filename);
+
+ if (len < sizeof("-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"))
+ return -EINVAL;
+
+ guidstr = filename + len - sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
+ if (*guidstr != '-')
+ return -EINVAL;
+
+ guidstr++;
+
+ ret = efi_guid_parse(guidstr, vendor);
+
+ varname = xzalloc((guidstr - filename) * sizeof(s16));
+
+ for (i = 0; i < guidstr - filename - 1; i++)
+ varname[i] = filename[i];
+
+ *name = varname;
+
+ return 0;
+}
+
+struct efivars_file {
+ void *buf;
+ unsigned long size;
+ efi_guid_t vendor;
+ s16 *name;
+};
+
+static int efivarfs_open(struct device_d *dev, FILE *f, const char *filename)
+{
+ struct efivars_file *efile;
+ efi_status_t efiret;
+ int ret;
+ uint32_t attributes;
+
+ efile = xzalloc(sizeof(*efile));
+
+ ret = efivarfs_parse_filename(filename, &efile->vendor, &efile->name);
+ if (ret)
+ return -ENOENT;
+
+ efiret = RT->get_variable(efile->name, &efile->vendor, &attributes, &efile->size, NULL);
+ if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL) {
+ ret = -efi_errno(efiret);
+ goto out;
+ }
+
+ efile->buf = malloc(efile->size + sizeof(uint32_t));
+ if (!efile->buf) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ efiret = RT->get_variable(efile->name, &efile->vendor, NULL, &efile->size,
+ efile->buf + sizeof(uint32_t));
+ if (EFI_ERROR(efiret)) {
+ ret = -efi_errno(efiret);
+ goto out;
+ }
+
+ *(uint32_t *)efile->buf = attributes;
+
+ f->size = efile->size + sizeof(uint32_t);
+ f->inode = efile;
+
+ return 0;
+
+out:
+ free(efile->buf);
+ free(efile);
+
+ return ret;
+}
+
+static int efivarfs_close(struct device_d *dev, FILE *f)
+{
+ struct efivars_file *efile = f->inode;
+
+ free(efile->buf);
+ free(efile);
+
+ return 0;
+}
+
+static int efivarfs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
+{
+ struct efivars_file *efile = f->inode;
+
+ memcpy(buf, efile->buf + f->pos, insize);
+
+ return insize;
+}
+
+static loff_t efivarfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
+{
+ f->pos = pos;
+
+ return f->pos;
+}
+
+struct efivarfs_dir_entry {
+ char *name;
+ struct efivarfs_dir_entry *next;
+};
+
+struct efivarfs_dir {
+ struct efivarfs_dir_entry *first;
+ struct efivarfs_dir_entry *current;
+ DIR dir;
+};
+
+static DIR *efivarfs_opendir(struct device_d *dev, const char *pathname)
+{
+ efi_status_t efiret;
+ efi_guid_t vendor;
+ s16 name[1024];
+ struct efivarfs_dir *edir;
+ unsigned long size;
+ unsigned char *name8;
+
+ name[0] = 0;
+
+ edir = xzalloc(sizeof(*edir));
+
+ while (1) {
+ struct efivarfs_dir_entry *entry;
+
+ size = sizeof(name);
+ efiret = RT->get_next_variable(&size, name, &vendor);
+ if (EFI_ERROR(efiret))
+ break;
+
+ entry = xzalloc(sizeof(*entry));
+ name8 = strdup_wchar_to_char(name);
+
+ entry->name = asprintf("%s-%pUl", name8, &vendor);
+
+ free(name8);
+
+ if (!edir->first)
+ edir->first = entry;
+
+ if (edir->current)
+ edir->current->next = entry;
+
+ edir->current = entry;
+ }
+
+ edir->current = edir->first;
+
+ return &edir->dir;
+}
+
+static struct dirent *efivarfs_readdir(struct device_d *dev, DIR *dir)
+{
+ struct efivarfs_dir *edir = container_of(dir, struct efivarfs_dir, dir);
+
+ if (!edir->current)
+ return NULL;
+
+ strcpy(dir->d.d_name, edir->current->name);
+
+ edir->current = edir->current->next;
+
+ return &dir->d;
+}
+
+static int efivarfs_closedir(struct device_d *dev, DIR *dir)
+{
+ struct efivarfs_dir *edir = container_of(dir, struct efivarfs_dir, dir);
+ struct efivarfs_dir_entry *entry;
+
+ entry = edir->first;
+
+ while (entry) {
+ struct efivarfs_dir_entry *tmp;
+ free(entry->name);
+ tmp = entry->next;
+ free(entry);
+ entry = tmp;
+ }
+
+ free(edir);
+
+ return 0;
+}
+
+static int efivarfs_stat(struct device_d *dev, const char *filename, struct stat *s)
+{
+ efi_guid_t vendor;
+ s16 *name;
+ efi_status_t efiret;
+ unsigned long size = 0;
+ int ret;
+
+ ret = efivarfs_parse_filename(filename, &vendor, &name);
+ if (ret)
+ return -ENOENT;
+
+ efiret = RT->get_variable(name, &vendor, NULL, &size, NULL);
+
+ free(name);
+
+ if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL)
+ return -efi_errno(efiret);
+
+ s->st_mode = 00666 | S_IFREG;
+ s->st_size = size;
+
+ return 0;
+}
+
+static int efivarfs_probe(struct device_d *dev)
+{
+ return 0;
+}
+
+static void efivarfs_remove(struct device_d *dev)
+{
+ free(dev->priv);
+}
+
+static struct fs_driver_d efivarfs_driver = {
+ .open = efivarfs_open,
+ .close = efivarfs_close,
+ .read = efivarfs_read,
+ .lseek = efivarfs_lseek,
+ .opendir = efivarfs_opendir,
+ .readdir = efivarfs_readdir,
+ .closedir = efivarfs_closedir,
+ .stat = efivarfs_stat,
+ .drv = {
+ .probe = efivarfs_probe,
+ .remove = efivarfs_remove,
+ .name = "efivarfs",
+ }
+};
+
+static int efivarfs_init(void)
+{
+ return register_fs_driver(&efivarfs_driver);
+}
+
+coredevice_initcall(efivarfs_init);
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index e65ef585a2..f8094d0608 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -167,7 +167,7 @@ static int fat_write(struct device_d *_dev, FILE *f, const void *buf, size_t ins
ret = f_write(f_file, buf, insize, &outsize);
- debug("%s: %d %d %d %p\n", __func__, ret, insize, outsize, f_file);
+ debug("%s: %d %zd %d %p\n", __func__, ret, insize, outsize, f_file);
if (ret)
return ret;
@@ -260,7 +260,7 @@ static int fat_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
ret = f_read(f_file, buf, insize, &outsize);
- debug("%s: %d %d %d %p\n", __func__, ret, insize, outsize, f_file);
+ debug("%s: %d %zd %d %p\n", __func__, ret, insize, outsize, f_file);
if (ret)
return ret;