summaryrefslogtreecommitdiff
path: root/acpi/acpifs.h
blob: 8e359efb70ab9b2a6c0536b788691f9e14c77293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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 <<a rel="nofollow" href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>>.
*/

/* ACPI Filesystem header */

#ifndef ACPIFS_H
#define ACPIFS_H

#include <hurd/netfs.h>
#include <pthread.h>
#include <maptime.h>

#include <netfs_impl.h>
#include <acpi.h>

/* 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 */
extern struct acpifs *fs;

/* Global mapped time */
extern 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 */