summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2018-11-21 05:16:37 -0500
committerDamien Zammit <damien@zamaudio.com>2018-11-24 01:20:08 -0500
commit82dbba62d3a021c749711677bd1fac6805aa4289 (patch)
tree9a6b2e6b8ba0b51588ef85a2c854b0c9baeed38d
parent542aa718a06c5ea30ea7cf2f85e20f101de8fd41 (diff)
Modify acpi translator to allow write to existing tables
-rw-r--r--acpi/acpifs.c6
-rw-r--r--acpi/func_files.c65
-rw-r--r--acpi/func_files.h13
-rw-r--r--acpi/netfs_impl.c15
4 files changed, 68 insertions, 31 deletions
diff --git a/acpi/acpifs.c b/acpi/acpifs.c
index e779e0f9..d572c5ac 100644
--- a/acpi/acpifs.c
+++ b/acpi/acpifs.c
@@ -166,9 +166,9 @@ create_fs_tree (struct acpifs *fs)
/* Remove all permissions to others */
e_stat.st_mode &= ~(S_IROTH | S_IWOTH | S_IXOTH);
- /* Change mode to a regular read-only file */
- e_stat.st_mode &= ~(S_IFDIR | S_IXUSR | S_IXGRP | S_IWUSR | S_IWGRP);
- e_stat.st_mode |= S_IFREG;
+ /* Change mode to a regular file */
+ e_stat.st_mode &= ~(S_IFDIR | S_IXUSR | S_IXGRP);
+ e_stat.st_mode |= S_IFREG | S_IWUSR | S_IWGRP;
/* Get all ACPI tables */
err = acpi_get_tables(&iter);
diff --git a/acpi/func_files.c b/acpi/func_files.c
index 371f989a..99f18036 100644
--- a/acpi/func_files.c
+++ b/acpi/func_files.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2017 Free Software Foundation, Inc.
+ Copyright (C) 2018 Free Software Foundation, Inc.
This file is part of the GNU Hurd.
@@ -17,18 +17,12 @@
along with the GNU Hurd. If not, see <<a rel="nofollow" href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>>.
*/
-/*
- * Per-function files implementation.
- *
- * Implementation of all files repeated for each function.
- */
-
#include <func_files.h>
#include <assert.h>
/* Read an acpi table */
error_t
-io_acpi_table (struct acpi_table *t, off_t offset, size_t *len, void *data)
+io_read_table (struct acpi_table *t, off_t offset, size_t *len, void *data)
{
error_t err;
size_t datalen;
@@ -49,28 +43,63 @@ io_acpi_table (struct acpi_table *t, off_t offset, size_t *len, void *data)
return err;
}
-/* Read from an acpi table file */
+/* Write values to an existing acpi table
+ * (dangerous, mainly for implementing power off)
+ */
error_t
-io_acpi_file (struct acpifs_dirent *e, off_t offset, size_t *len,
- void *data)
+io_write_table (struct acpi_table *t, off_t offset, size_t *len, void *data)
{
+ error_t err;
size_t datalen;
- struct acpi_table *table;
/* This should never happen */
- assert_backtrace (e->acpitable != 0);
+ assert_backtrace (t != 0);
- /* Get the table */
- table = e->acpitable;
+ datalen = t->datalen;
- datalen = table->datalen;
- /* Don't exceed the region size */
+ /* Don't exceed the size of the acpi table */
if (offset > datalen)
return EINVAL;
if ((offset + *len) > datalen)
*len = datalen - offset;
- memcpy (data, table->data + offset, *len);
+ memcpy (t->data + offset, data, *len);
+
+ return err;
+}
+
+/* Read from an acpi table file */
+error_t
+io_read_acpi_file (struct acpifs_dirent *e, off_t offset, size_t *len,
+ void *data)
+{
+ struct acpi_table *table;
+
+ /* This should never happen */
+ assert_backtrace (e->acpitable != 0);
+
+ /* Get the table */
+ table = e->acpitable;
+
+ io_read_table (table, offset, len, data);
+
+ return 0;
+}
+
+/* Write to an acpi table file */
+error_t
+io_write_acpi_file (struct acpifs_dirent *e, off_t offset, size_t *len,
+ void *data)
+{
+ struct acpi_table *table;
+
+ /* This should never happen */
+ assert_backtrace (e->acpitable != 0);
+
+ /* Get the table */
+ table = e->acpitable;
+
+ io_write_table (table, offset, len, data);
return 0;
}
diff --git a/acpi/func_files.h b/acpi/func_files.h
index 90d92cc3..c8e4bbdf 100644
--- a/acpi/func_files.h
+++ b/acpi/func_files.h
@@ -25,15 +25,12 @@
#include <acpifs.h>
#include <acpi.h>
-typedef int (*acpi_read_op_t) (struct acpi_table *t, void *data,
- off_t offset, size_t *len);
-
/* Tables */
-#define DIR_TABLES_NAME "tables"
+#define DIR_TABLES_NAME "acpi"
-error_t io_read_table (struct acpi_table *t, struct acpifs_dirent *e,
- off_t offset, size_t *len, void *data);
-error_t io_acpi_file (struct acpifs_dirent *e, off_t offset, size_t *len,
- void *data);
+error_t io_read_table (struct acpi_table *t, off_t offset, size_t *len, void *data);
+error_t io_write_table (struct acpi_table *t, off_t offset, size_t *len, void *data);
+error_t io_read_acpi_file (struct acpifs_dirent *e, off_t offset, size_t *len, void *data);
+error_t io_write_acpi_file (struct acpifs_dirent *e, off_t offset, size_t *len, void *data);
#endif /* FUNC_FILES_H */
diff --git a/acpi/netfs_impl.c b/acpi/netfs_impl.c
index 84f52c89..f9f8df9c 100644
--- a/acpi/netfs_impl.c
+++ b/acpi/netfs_impl.c
@@ -499,7 +499,7 @@ netfs_attempt_read (struct iouser * cred, struct node * node,
return EOPNOTSUPP;
else
{
- err = io_acpi_file (node->nn->ln, offset, len, data);
+ err = io_read_acpi_file (node->nn->ln, offset, len, data);
if (!err)
/* Update atime */
UPDATE_TIMES (node->nn->ln, TOUCH_ATIME);
@@ -514,7 +514,18 @@ error_t
netfs_attempt_write (struct iouser * cred, struct node * node,
off_t offset, size_t * len, void *data)
{
- return EOPNOTSUPP;
+ error_t err;
+
+ if (!strncmp (node->nn->ln->name, DIR_TABLES_NAME, NAME_SIZE))
+ return EOPNOTSUPP;
+ else
+ {
+ err = io_write_acpi_file (node->nn->ln, offset, len, data);
+ if (!err)
+ /* Update mtime */
+ UPDATE_TIMES (node->nn->ln, TOUCH_MTIME);
+ }
+ return err;
}
/* Node NP is all done; free all its associated storage. */