a5bd9f6
From a613c3ea1106ce4dc1e44f88665d14259b659da8 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Sun, 24 Mar 2013 13:05:59 +0100
a5bd9f6
Subject: [PATCH 226/364] 	Add new 'proc' filesystem framework and put
a5bd9f6
 luks_script into it.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog                   |   4 ++
a5bd9f6
 Makefile.util.def           |   1 +
a5bd9f6
 grub-core/Makefile.core.def |   5 ++
a5bd9f6
 grub-core/disk/cryptodisk.c | 113 +++++++++++++++++++++++++++++
a5bd9f6
 grub-core/disk/geli.c       |   2 -
a5bd9f6
 grub-core/disk/luks.c       |   2 -
a5bd9f6
 grub-core/fs/proc.c         | 172 ++++++++++++++++++++++++++++++++++++++++++++
a5bd9f6
 include/grub/cryptodisk.h   |   5 +-
a5bd9f6
 include/grub/disk.h         |   1 +
a5bd9f6
 include/grub/procfs.h       |  50 +++++++++++++
a5bd9f6
 10 files changed, 350 insertions(+), 5 deletions(-)
a5bd9f6
 create mode 100644 grub-core/fs/proc.c
a5bd9f6
 create mode 100644 include/grub/procfs.h
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 9841659..8f3878d 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,3 +1,7 @@
a5bd9f6
+2013-03-24  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
+	Add new 'proc' filesystem framework and put luks_script into it.
a5bd9f6
+
a5bd9f6
 2013-03-23  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
 
a5bd9f6
 	* grub-core/term/at_keyboard.c: Increase robustness on coreboot
a5bd9f6
diff --git a/Makefile.util.def b/Makefile.util.def
a5bd9f6
index 1ccf390..62bcf2d 100644
a5bd9f6
--- a/Makefile.util.def
a5bd9f6
+++ b/Makefile.util.def
a5bd9f6
@@ -33,6 +33,7 @@ library = {
a5bd9f6
   common = grub-core/disk/diskfilter.c;
a5bd9f6
   common = grub-core/partmap/gpt.c;
a5bd9f6
   common = grub-core/partmap/msdos.c;
a5bd9f6
+  common = grub-core/fs/proc.c;
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
 library = {
a5bd9f6
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
a5bd9f6
index a614b22..b1c1ab9 100644
a5bd9f6
--- a/grub-core/Makefile.core.def
a5bd9f6
+++ b/grub-core/Makefile.core.def
a5bd9f6
@@ -1068,6 +1068,11 @@ module = {
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
 module = {
a5bd9f6
+  name = procfs;
a5bd9f6
+  common = fs/proc.c;
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
+module = {
a5bd9f6
   name = affs;
a5bd9f6
   common = fs/affs.c;
a5bd9f6
 };
a5bd9f6
diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
a5bd9f6
index f39c1ab..374edd1 100644
a5bd9f6
--- a/grub-core/disk/cryptodisk.c
a5bd9f6
+++ b/grub-core/disk/cryptodisk.c
a5bd9f6
@@ -22,6 +22,9 @@
a5bd9f6
 #include <grub/dl.h>
a5bd9f6
 #include <grub/extcmd.h>
a5bd9f6
 #include <grub/i18n.h>
a5bd9f6
+#include <grub/fs.h>
a5bd9f6
+#include <grub/file.h>
a5bd9f6
+#include <grub/procfs.h>
a5bd9f6
 
a5bd9f6
 #ifdef GRUB_UTIL
a5bd9f6
 #include <errno.h>
a5bd9f6
@@ -403,6 +406,8 @@ grub_cryptodisk_setkey (grub_cryptodisk_t dev, grub_uint8_t *key, grub_size_t ke
a5bd9f6
   err = grub_crypto_cipher_set_key (dev->cipher, key, real_keysize);
a5bd9f6
   if (err)
a5bd9f6
     return err;
a5bd9f6
+  grub_memcpy (dev->key, key, keysize);
a5bd9f6
+  dev->keysize = keysize;
a5bd9f6
 
a5bd9f6
   /* Configure ESSIV if necessary.  */
a5bd9f6
   if (dev->mode_iv == GRUB_CRYPTODISK_MODE_IV_ESSIV)
a5bd9f6
@@ -979,6 +984,112 @@ static struct grub_disk_dev grub_cryptodisk_dev = {
a5bd9f6
   .next = 0
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
+static char
a5bd9f6
+hex (grub_uint8_t val)
a5bd9f6
+{
a5bd9f6
+  if (val < 10)
a5bd9f6
+    return '0' + val;
a5bd9f6
+  return 'a' + val - 10;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+/* Open a file named NAME and initialize FILE.  */
a5bd9f6
+static char *
a5bd9f6
+luks_script_get (void)
a5bd9f6
+{
a5bd9f6
+  grub_cryptodisk_t i;
a5bd9f6
+  grub_size_t size = 0;
a5bd9f6
+  char *ptr, *ret;
a5bd9f6
+
a5bd9f6
+  for (i = cryptodisk_list; i != NULL; i = i->next)
a5bd9f6
+    if (grub_strcmp (i->modname, "luks") == 0)
a5bd9f6
+      {
a5bd9f6
+	size += sizeof ("luks_mount ");
a5bd9f6
+	size += grub_strlen (i->uuid);
a5bd9f6
+	size += grub_strlen (i->cipher->cipher->name);
a5bd9f6
+	size += 54;
a5bd9f6
+	if (i->essiv_hash)
a5bd9f6
+	  size += grub_strlen (i->essiv_hash->name);
a5bd9f6
+	size += i->keysize * 2;
a5bd9f6
+      }
a5bd9f6
+
a5bd9f6
+  ret = grub_malloc (size + 1);
a5bd9f6
+  if (!ret)
a5bd9f6
+    return 0;
a5bd9f6
+
a5bd9f6
+  ptr = ret;
a5bd9f6
+
a5bd9f6
+  for (i = cryptodisk_list; i != NULL; i = i->next)
a5bd9f6
+    if (grub_strcmp (i->modname, "luks") == 0)
a5bd9f6
+      {
a5bd9f6
+	unsigned j;
a5bd9f6
+	const char *iptr;
a5bd9f6
+	ptr = grub_stpcpy (ptr, "luks_mount ");
a5bd9f6
+	ptr = grub_stpcpy (ptr, i->uuid);
a5bd9f6
+	*ptr++ = ' ';
a5bd9f6
+	grub_snprintf (ptr, 21, "%" PRIuGRUB_UINT64_T " ", i->offset);
a5bd9f6
+	while (*ptr)
a5bd9f6
+	  ptr++;
a5bd9f6
+	for (iptr = i->cipher->cipher->name; *iptr; iptr++)
a5bd9f6
+	  *ptr++ = grub_tolower (*iptr);
a5bd9f6
+	switch (i->mode)
a5bd9f6
+	  {
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_ECB:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-ecb"); 
a5bd9f6
+	    break;
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_CBC:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-cbc");
a5bd9f6
+	    break;
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_PCBC:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-pcbc");
a5bd9f6
+	    break;
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_XTS:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-xts");
a5bd9f6
+	    break;
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_LRW:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-lrw");
a5bd9f6
+	    break;
a5bd9f6
+	  }
a5bd9f6
+
a5bd9f6
+	switch (i->mode_iv)
a5bd9f6
+	  {
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_IV_NULL:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-null"); 
a5bd9f6
+	    break;
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_IV_PLAIN:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-plain"); 
a5bd9f6
+	    break;
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_IV_PLAIN64:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-plain64"); 
a5bd9f6
+	    break;
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_IV_BENBI:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-benbi"); 
a5bd9f6
+	    break;
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_IV_ESSIV:
a5bd9f6
+	    ptr = grub_stpcpy (ptr, "-essiv:"); 
a5bd9f6
+	    ptr = grub_stpcpy (ptr, i->essiv_hash->name);
a5bd9f6
+	    break;
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64:
a5bd9f6
+	  case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH:
a5bd9f6
+	    break;
a5bd9f6
+	  }
a5bd9f6
+	*ptr++ = ' ';
a5bd9f6
+	for (j = 0; j < i->keysize; j++)
a5bd9f6
+	  {
a5bd9f6
+	    *ptr++ = hex (i->key[j] >> 4);
a5bd9f6
+	    *ptr++ = hex (i->key[j] & 0xf);
a5bd9f6
+	  }
a5bd9f6
+	*ptr++ = '\n';
a5bd9f6
+      }
a5bd9f6
+  *ptr = '\0';
a5bd9f6
+  return ret;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+struct grub_procfs_entry luks_script =
a5bd9f6
+{
a5bd9f6
+  .name = "luks_script",
a5bd9f6
+  .get_contents = luks_script_get
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
 static grub_extcmd_t cmd;
a5bd9f6
 
a5bd9f6
 GRUB_MOD_INIT (cryptodisk)
a5bd9f6
@@ -987,10 +1098,12 @@ GRUB_MOD_INIT (cryptodisk)
a5bd9f6
   cmd = grub_register_extcmd ("cryptomount", grub_cmd_cryptomount, 0,
a5bd9f6
 			      N_("SOURCE|-u UUID|-a|-b"),
a5bd9f6
 			      N_("Mount a crypto device."), options);
a5bd9f6
+  grub_procfs_register ("luks_script", &luks_script);
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 GRUB_MOD_FINI (cryptodisk)
a5bd9f6
 {
a5bd9f6
   grub_disk_dev_unregister (&grub_cryptodisk_dev);
a5bd9f6
   cryptodisk_cleanup ();
a5bd9f6
+  grub_procfs_unregister (&luks_script);
a5bd9f6
 }
a5bd9f6
diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c
a5bd9f6
index f9315df..0b94414 100644
a5bd9f6
--- a/grub-core/disk/geli.c
a5bd9f6
+++ b/grub-core/disk/geli.c
a5bd9f6
@@ -381,9 +381,7 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid,
a5bd9f6
       newdev->rekey_shift = 20;
a5bd9f6
     }
a5bd9f6
 
a5bd9f6
-#ifdef GRUB_UTIL
a5bd9f6
   newdev->modname = "geli";
a5bd9f6
-#endif
a5bd9f6
 
a5bd9f6
   newdev->total_length = grub_disk_get_size (disk) - 1;
a5bd9f6
   grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid));
a5bd9f6
diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c
a5bd9f6
index 44f3cac..afcb7e4 100644
a5bd9f6
--- a/grub-core/disk/luks.c
a5bd9f6
+++ b/grub-core/disk/luks.c
a5bd9f6
@@ -290,9 +290,7 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid,
a5bd9f6
   newdev->log_sector_size = 9;
a5bd9f6
   newdev->total_length = grub_disk_get_size (disk) - newdev->offset;
a5bd9f6
   grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid));
a5bd9f6
-#ifdef GRUB_UTIL
a5bd9f6
   newdev->modname = "luks";
a5bd9f6
-#endif
a5bd9f6
   COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >= sizeof (uuid));
a5bd9f6
   return newdev;
a5bd9f6
 }
a5bd9f6
diff --git a/grub-core/fs/proc.c b/grub-core/fs/proc.c
a5bd9f6
new file mode 100644
a5bd9f6
index 0000000..8f27682
a5bd9f6
--- /dev/null
a5bd9f6
+++ b/grub-core/fs/proc.c
a5bd9f6
@@ -0,0 +1,172 @@
a5bd9f6
+/*
a5bd9f6
+ *  GRUB  --  GRand Unified Bootloader
a5bd9f6
+ *  Copyright (C) 2013  Free Software Foundation, Inc.
a5bd9f6
+ *
a5bd9f6
+ *  GRUB is free software: you can redistribute it and/or modify
a5bd9f6
+ *  it under the terms of the GNU General Public License as published by
a5bd9f6
+ *  the Free Software Foundation, either version 3 of the License, or
a5bd9f6
+ *  (at your option) any later version.
a5bd9f6
+ *
a5bd9f6
+ *  GRUB is distributed in the hope that it will be useful,
a5bd9f6
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
a5bd9f6
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a5bd9f6
+ *  GNU General Public License for more details.
a5bd9f6
+ *
a5bd9f6
+ *  You should have received a copy of the GNU General Public License
a5bd9f6
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
a5bd9f6
+ */
a5bd9f6
+
a5bd9f6
+#include <grub/procfs.h>
a5bd9f6
+#include <grub/disk.h>
a5bd9f6
+#include <grub/fs.h>
a5bd9f6
+#include <grub/file.h>
a5bd9f6
+#include <grub/mm.h>
a5bd9f6
+#include <grub/dl.h>
a5bd9f6
+
a5bd9f6
+GRUB_MOD_LICENSE ("GPLv3+");
a5bd9f6
+
a5bd9f6
+struct grub_procfs_entry *grub_procfs_entries;
a5bd9f6
+
a5bd9f6
+static int
a5bd9f6
+grub_procdev_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
a5bd9f6
+			 grub_disk_pull_t pull)
a5bd9f6
+{
a5bd9f6
+  if (pull != GRUB_DISK_PULL_NONE)
a5bd9f6
+    return 0;
a5bd9f6
+
a5bd9f6
+  return hook ("proc", hook_data);
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_procdev_open (const char *name, grub_disk_t disk)
a5bd9f6
+{
a5bd9f6
+  if (grub_strcmp (name, "proc"))
a5bd9f6
+      return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a procfs disk");
a5bd9f6
+
a5bd9f6
+  disk->total_sectors = 0;
a5bd9f6
+  disk->id = (unsigned long) "proc";
a5bd9f6
+
a5bd9f6
+  disk->data = 0;
a5bd9f6
+
a5bd9f6
+  return GRUB_ERR_NONE;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static void
a5bd9f6
+grub_procdev_close (grub_disk_t disk __attribute((unused)))
a5bd9f6
+{
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_procdev_read (grub_disk_t disk __attribute((unused)),
a5bd9f6
+		grub_disk_addr_t sector __attribute((unused)),
a5bd9f6
+		grub_size_t size __attribute((unused)),
a5bd9f6
+		char *buf __attribute((unused)))
a5bd9f6
+{
a5bd9f6
+  return GRUB_ERR_OUT_OF_RANGE;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_procdev_write (grub_disk_t disk __attribute ((unused)),
a5bd9f6
+		       grub_disk_addr_t sector __attribute ((unused)),
a5bd9f6
+		       grub_size_t size __attribute ((unused)),
a5bd9f6
+		       const char *buf __attribute ((unused)))
a5bd9f6
+{
a5bd9f6
+  return GRUB_ERR_OUT_OF_RANGE;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static grub_ssize_t
a5bd9f6
+grub_procfs_read (grub_file_t file, char *buf, grub_size_t len)
a5bd9f6
+{
a5bd9f6
+  char *data = file->data;
a5bd9f6
+
a5bd9f6
+  grub_memcpy (buf, data + file->offset, len);
a5bd9f6
+
a5bd9f6
+  return len;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_procfs_close (grub_file_t file)
a5bd9f6
+{
a5bd9f6
+  char *data;
a5bd9f6
+
a5bd9f6
+  data = file->data;
a5bd9f6
+  grub_free (data);
a5bd9f6
+
a5bd9f6
+  return GRUB_ERR_NONE;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_procfs_dir (grub_device_t device, const char *path,
a5bd9f6
+		 grub_fs_dir_hook_t hook, void *hook_data)
a5bd9f6
+{
a5bd9f6
+  const char *ptr;
a5bd9f6
+  struct grub_dirhook_info info;
a5bd9f6
+  struct grub_procfs_entry *entry;
a5bd9f6
+
a5bd9f6
+  grub_memset (&info, 0, sizeof (info));
a5bd9f6
+
a5bd9f6
+  /* Check if the disk is our dummy disk.  */
a5bd9f6
+  if (grub_strcmp (device->disk->name, "proc"))
a5bd9f6
+    return grub_error (GRUB_ERR_BAD_FS, "not a procfs");
a5bd9f6
+  for (ptr = path; *ptr == '/'; ptr++);
a5bd9f6
+  if (*ptr)
a5bd9f6
+    return 0;
a5bd9f6
+  FOR_LIST_ELEMENTS((entry), (grub_procfs_entries))
a5bd9f6
+    if (hook (entry->name, &info, hook_data))
a5bd9f6
+      return 0;
a5bd9f6
+  return 0;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_procfs_open (struct grub_file *file, const char *path)
a5bd9f6
+{
a5bd9f6
+  const char *pathptr;
a5bd9f6
+  struct grub_procfs_entry *entry;
a5bd9f6
+
a5bd9f6
+  for (pathptr = path; *pathptr == '/'; pathptr++);
a5bd9f6
+
a5bd9f6
+  FOR_LIST_ELEMENTS((entry), (grub_procfs_entries))
a5bd9f6
+    if (grub_strcmp (pathptr, entry->name) == 0)
a5bd9f6
+    {
a5bd9f6
+      file->data = entry->get_contents ();
a5bd9f6
+      if (!file->data)
a5bd9f6
+	return grub_errno;
a5bd9f6
+      file->size = grub_strlen (file->data);
a5bd9f6
+      return GRUB_ERR_NONE;
a5bd9f6
+    }
a5bd9f6
+
a5bd9f6
+  return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), path);
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static struct grub_disk_dev grub_procfs_dev = {
a5bd9f6
+  .name = "proc",
a5bd9f6
+  .id = GRUB_DISK_DEVICE_PROCFS_ID,
a5bd9f6
+  .iterate = grub_procdev_iterate,
a5bd9f6
+  .open = grub_procdev_open,
a5bd9f6
+  .close = grub_procdev_close,
a5bd9f6
+  .read = grub_procdev_read,
a5bd9f6
+  .write = grub_procdev_write,
a5bd9f6
+  .next = 0
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
+static struct grub_fs grub_procfs_fs =
a5bd9f6
+  {
a5bd9f6
+    .name = "procfs",
a5bd9f6
+    .dir = grub_procfs_dir,
a5bd9f6
+    .open = grub_procfs_open,
a5bd9f6
+    .read = grub_procfs_read,
a5bd9f6
+    .close = grub_procfs_close,
a5bd9f6
+    .next = 0
a5bd9f6
+  };
a5bd9f6
+
a5bd9f6
+GRUB_MOD_INIT (procfs)
a5bd9f6
+{
a5bd9f6
+  grub_disk_dev_register (&grub_procfs_dev);
a5bd9f6
+  grub_fs_register (&grub_procfs_fs);
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+GRUB_MOD_FINI (procfs)
a5bd9f6
+{
a5bd9f6
+  grub_disk_dev_unregister (&grub_procfs_dev);
a5bd9f6
+  grub_fs_unregister (&grub_procfs_fs);
a5bd9f6
+}
a5bd9f6
diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h
a5bd9f6
index 0bb5d44..c3ee820 100644
a5bd9f6
--- a/include/grub/cryptodisk.h
a5bd9f6
+++ b/include/grub/cryptodisk.h
a5bd9f6
@@ -49,6 +49,7 @@ typedef enum
a5bd9f6
 #define GRUB_CRYPTODISK_GF_SIZE (1U << GRUB_CRYPTODISK_GF_LOG_SIZE)
a5bd9f6
 #define GRUB_CRYPTODISK_GF_LOG_BYTES (GRUB_CRYPTODISK_GF_LOG_SIZE - 3)
a5bd9f6
 #define GRUB_CRYPTODISK_GF_BYTES (1U << GRUB_CRYPTODISK_GF_LOG_BYTES)
a5bd9f6
+#define GRUB_CRYPTODISK_MAX_KEYLEN 128
a5bd9f6
 
a5bd9f6
 struct grub_cryptodisk;
a5bd9f6
 
a5bd9f6
@@ -80,11 +81,13 @@ struct grub_cryptodisk
a5bd9f6
   grub_uint8_t *lrw_precalc;
a5bd9f6
   grub_uint8_t iv_prefix[64];
a5bd9f6
   grub_size_t iv_prefix_len;
a5bd9f6
+  grub_uint8_t key[GRUB_CRYPTODISK_MAX_KEYLEN];
a5bd9f6
+  grub_size_t keysize;
a5bd9f6
 #ifdef GRUB_UTIL
a5bd9f6
   char *cheat;
a5bd9f6
-  const char *modname;
a5bd9f6
   int cheat_fd;
a5bd9f6
 #endif
a5bd9f6
+  const char *modname;
a5bd9f6
   int log_sector_size;
a5bd9f6
   grub_cryptodisk_rekey_func_t rekey;
a5bd9f6
   int rekey_shift;
a5bd9f6
diff --git a/include/grub/disk.h b/include/grub/disk.h
a5bd9f6
index f0e3df3..d19b1ac 100644
a5bd9f6
--- a/include/grub/disk.h
a5bd9f6
+++ b/include/grub/disk.h
a5bd9f6
@@ -43,6 +43,7 @@ enum grub_disk_dev_id
a5bd9f6
     GRUB_DISK_DEVICE_CRYPTODISK_ID,
a5bd9f6
     GRUB_DISK_DEVICE_ARCDISK_ID,
a5bd9f6
     GRUB_DISK_DEVICE_HOSTDISK_ID,
a5bd9f6
+    GRUB_DISK_DEVICE_PROCFS_ID,
a5bd9f6
   };
a5bd9f6
 
a5bd9f6
 struct grub_disk;
a5bd9f6
diff --git a/include/grub/procfs.h b/include/grub/procfs.h
a5bd9f6
new file mode 100644
a5bd9f6
index 0000000..55cbb21
a5bd9f6
--- /dev/null
a5bd9f6
+++ b/include/grub/procfs.h
a5bd9f6
@@ -0,0 +1,50 @@
a5bd9f6
+/*
a5bd9f6
+ *  GRUB  --  GRand Unified Bootloader
a5bd9f6
+ *  Copyright (C) 2013  Free Software Foundation, Inc.
a5bd9f6
+ *
a5bd9f6
+ *  GRUB is free software: you can redistribute it and/or modify
a5bd9f6
+ *  it under the terms of the GNU General Public License as published by
a5bd9f6
+ *  the Free Software Foundation, either version 3 of the License, or
a5bd9f6
+ *  (at your option) any later version.
a5bd9f6
+ *
a5bd9f6
+ *  GRUB is distributed in the hope that it will be useful,
a5bd9f6
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
a5bd9f6
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a5bd9f6
+ *  GNU General Public License for more details.
a5bd9f6
+ *
a5bd9f6
+ *  You should have received a copy of the GNU General Public License
a5bd9f6
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
a5bd9f6
+ */
a5bd9f6
+
a5bd9f6
+#ifndef GRUB_PROCFS_HEADER
a5bd9f6
+#define GRUB_PROCFS_HEADER	1
a5bd9f6
+
a5bd9f6
+#include <grub/list.h>
a5bd9f6
+
a5bd9f6
+struct grub_procfs_entry
a5bd9f6
+{
a5bd9f6
+  struct grub_procfs_entry *next;
a5bd9f6
+  struct grub_procfs_entry **prev;
a5bd9f6
+
a5bd9f6
+  const char *name;
a5bd9f6
+  char * (*get_contents) (void);
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
+extern struct grub_procfs_entry *grub_procfs_entries;
a5bd9f6
+
a5bd9f6
+static inline void
a5bd9f6
+grub_procfs_register (const char *name __attribute__ ((unused)),
a5bd9f6
+		      struct grub_procfs_entry *entry)
a5bd9f6
+{
a5bd9f6
+  grub_list_push (GRUB_AS_LIST_P (&grub_procfs_entries),
a5bd9f6
+		  GRUB_AS_LIST (entry));
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static inline void
a5bd9f6
+grub_procfs_unregister (struct grub_procfs_entry *entry)
a5bd9f6
+{
a5bd9f6
+  grub_list_remove (GRUB_AS_LIST (entry));
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+
a5bd9f6
+#endif
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6