Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / fs / proc.c
bloba03469ec65b25ca7cb4710c881cc15c390bf2543
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2013 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/procfs.h>
20 #include <grub/disk.h>
21 #include <grub/fs.h>
22 #include <grub/file.h>
23 #include <grub/mm.h>
24 #include <grub/dl.h>
26 GRUB_MOD_LICENSE ("GPLv3+");
28 struct grub_procfs_entry *grub_procfs_entries;
30 static int
31 grub_procdev_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
32 grub_disk_pull_t pull)
34 if (pull != GRUB_DISK_PULL_NONE)
35 return 0;
37 return hook ("proc", hook_data);
40 static grub_err_t
41 grub_procdev_open (const char *name, grub_disk_t disk)
43 if (grub_strcmp (name, "proc"))
44 return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a procfs disk");
46 disk->total_sectors = 0;
47 disk->id = 0;
49 disk->data = 0;
51 return GRUB_ERR_NONE;
54 static void
55 grub_procdev_close (grub_disk_t disk __attribute((unused)))
59 static grub_err_t
60 grub_procdev_read (grub_disk_t disk __attribute((unused)),
61 grub_disk_addr_t sector __attribute((unused)),
62 grub_size_t size __attribute((unused)),
63 char *buf __attribute((unused)))
65 return GRUB_ERR_OUT_OF_RANGE;
68 static grub_err_t
69 grub_procdev_write (grub_disk_t disk __attribute ((unused)),
70 grub_disk_addr_t sector __attribute ((unused)),
71 grub_size_t size __attribute ((unused)),
72 const char *buf __attribute ((unused)))
74 return GRUB_ERR_OUT_OF_RANGE;
77 static grub_ssize_t
78 grub_procfs_read (grub_file_t file, char *buf, grub_size_t len)
80 char *data = file->data;
82 grub_memcpy (buf, data + file->offset, len);
84 return len;
87 static grub_err_t
88 grub_procfs_close (grub_file_t file)
90 char *data;
92 data = file->data;
93 grub_free (data);
95 return GRUB_ERR_NONE;
98 static grub_err_t
99 grub_procfs_dir (grub_device_t device, const char *path,
100 grub_fs_dir_hook_t hook, void *hook_data)
102 const char *ptr;
103 struct grub_dirhook_info info;
104 struct grub_procfs_entry *entry;
106 grub_memset (&info, 0, sizeof (info));
108 /* Check if the disk is our dummy disk. */
109 if (grub_strcmp (device->disk->name, "proc"))
110 return grub_error (GRUB_ERR_BAD_FS, "not a procfs");
111 for (ptr = path; *ptr == '/'; ptr++);
112 if (*ptr)
113 return 0;
114 FOR_LIST_ELEMENTS((entry), (grub_procfs_entries))
115 if (hook (entry->name, &info, hook_data))
116 return 0;
117 return 0;
120 static grub_err_t
121 grub_procfs_open (struct grub_file *file, const char *path)
123 const char *pathptr;
124 struct grub_procfs_entry *entry;
126 for (pathptr = path; *pathptr == '/'; pathptr++);
128 FOR_LIST_ELEMENTS((entry), (grub_procfs_entries))
129 if (grub_strcmp (pathptr, entry->name) == 0)
131 grub_size_t sz;
132 file->data = entry->get_contents (&sz);
133 if (!file->data)
134 return grub_errno;
135 file->size = sz;
136 return GRUB_ERR_NONE;
139 return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), path);
142 static struct grub_disk_dev grub_procfs_dev = {
143 .name = "proc",
144 .id = GRUB_DISK_DEVICE_PROCFS_ID,
145 .iterate = grub_procdev_iterate,
146 .open = grub_procdev_open,
147 .close = grub_procdev_close,
148 .read = grub_procdev_read,
149 .write = grub_procdev_write,
150 .next = 0
153 static struct grub_fs grub_procfs_fs =
155 .name = "procfs",
156 .dir = grub_procfs_dir,
157 .open = grub_procfs_open,
158 .read = grub_procfs_read,
159 .close = grub_procfs_close,
160 .next = 0
163 GRUB_MOD_INIT (procfs)
165 grub_disk_dev_register (&grub_procfs_dev);
166 grub_fs_register (&grub_procfs_fs);
169 GRUB_MOD_FINI (procfs)
171 grub_disk_dev_unregister (&grub_procfs_dev);
172 grub_fs_unregister (&grub_procfs_fs);