From 33421955afb21c5e89a85f0b8f19c3644b18c8ae Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Sat, 2 Mar 2019 15:27:29 -0800 Subject: ACPI tables translator Exposes x86 ACPI tables as a netfs on a mount point * acpi: New directory. * Makefile (prog-subdirs): Add acpi. * hurd/hurd_types.h (FSTYPE_ACPI): New macro. --- acpi/acpifs.h | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 acpi/acpifs.h (limited to 'acpi/acpifs.h') diff --git a/acpi/acpifs.h b/acpi/acpifs.h new file mode 100644 index 00000000..2e9063cc --- /dev/null +++ b/acpi/acpifs.h @@ -0,0 +1,147 @@ +/* + Copyright (C) 2018 Free Software Foundation, Inc. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd 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. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* ACPI Filesystem header */ + +#ifndef ACPIFS_H +#define ACPIFS_H + +#include +#include +#include + +#include +#include + +/* Size of a directory entry name */ +#ifndef NAME_SIZE +#define NAME_SIZE 8 +#endif + +/* Node cache defaults size */ +#define NODE_CACHE_MAX 16 + +/* + * User and group ids to grant permission to acpi + */ +struct acpifs_perm +{ + int32_t uid; + int32_t gid; +}; + +/* + * Directory entry. + * + * All directory entries are created on startup and used to generate the + * fs tree and create or retrieve libnetfs node objects. + * + * From libnetfs' point of view, these are the light nodes. + */ +struct acpifs_dirent +{ + char name[NAME_SIZE]; + struct acpifs_dirent *parent; + io_statbuf_t stat; + + /* + * We only need two kind of nodes: files and directories. + * When `dir' is null, this is a file; when not null, it's a directory. + */ + struct acpifs_dir *dir; + + /* Active node on this entry */ + struct node *node; + + /* ACPI table related to an entry */ + struct acpi_table *acpitable; +}; + +/* + * A directory, it only contains a list of directory entries + */ +struct acpifs_dir +{ + /* Number of directory entries */ + uint16_t num_entries; + + /* Array of directory entries */ + struct acpifs_dirent **entries; +}; + +/* A particular ACPI filesystem. */ +struct acpifs +{ + /* Root of filesystem. */ + struct node *root; + + /* A cache that holds a reference to recently used nodes. */ + struct node *node_cache_mru, *node_cache_lru; + size_t node_cache_len; /* Number of entries in it. */ + size_t node_cache_max; + pthread_mutex_t node_cache_lock; + + struct acpifs_perm perm; + + struct acpifs_dirent *entries; + size_t num_entries; +}; + +/* Main FS pointer */ +struct acpifs *fs; + +/* Global mapped time */ +volatile struct mapped_time_value *acpifs_maptime; + +/* Update entry and node times */ +#define UPDATE_TIMES(e, what) (\ + {\ + fshelp_touch (&e->stat, what, acpifs_maptime);\ + if(e->node)\ + fshelp_touch (&e->node->nn_stat, what, acpifs_maptime);\ + }\ +) + +/* Update entry and node owner */ +#define UPDATE_OWNER(e, uid) (\ + {\ + e->stat.st_uid = uid;\ + if(e->node)\ + e->node->nn_stat.st_uid = uid;\ + }\ +) + +/* Update entry and node group */ +#define UPDATE_GROUP(e, gid) (\ + {\ + e->stat.st_gid = gid;\ + if(e->node)\ + e->node->nn_stat.st_gid = gid;\ + }\ +) + +/* FS manipulation functions */ +error_t alloc_file_system (struct acpifs **fs); +error_t init_file_system (file_t underlying_node, struct acpifs *fs); +error_t create_fs_tree (struct acpifs *fs); +error_t fs_set_permissions (struct acpifs *fs); +error_t entry_check_perms (struct iouser *user, struct acpifs_dirent *e, + int flags); + +#endif /* ACPIFS_H */ -- cgit v1.2.3