]> git.proxmox.com Git - grub2.git/blob - grub-core/include/grub/fs.h
merge with mainline
[grub2.git] / grub-core / include / grub / fs.h
1 /* fs.h - filesystem manager */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc.
5 *
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef GRUB_FS_HEADER
21 #define GRUB_FS_HEADER 1
22
23 #include <grub/device.h>
24 #include <grub/symbol.h>
25 #include <grub/types.h>
26
27 #include <grub/list.h>
28
29 /* Forward declaration is required, because of mutual reference. */
30 struct grub_file;
31
32 struct grub_dirhook_info
33 {
34 int dir:1;
35 int mtimeset:1;
36 int case_insensitive:1;
37 grub_int32_t mtime;
38 };
39
40 /* Filesystem descriptor. */
41 struct grub_fs
42 {
43 /* The next filesystem. */
44 struct grub_fs *next;
45
46 /* My name. */
47 const char *name;
48
49 /* Call HOOK with each file under DIR. */
50 grub_err_t (*dir) (grub_device_t device, const char *path,
51 int (*hook) (const char *filename,
52 const struct grub_dirhook_info *info));
53
54 /* Open a file named NAME and initialize FILE. */
55 grub_err_t (*open) (struct grub_file *file, const char *name);
56
57 /* Read LEN bytes data from FILE into BUF. */
58 grub_ssize_t (*read) (struct grub_file *file, char *buf, grub_size_t len);
59
60 /* Close the file FILE. */
61 grub_err_t (*close) (struct grub_file *file);
62
63 /* Return the label of the device DEVICE in LABEL. The label is
64 returned in a grub_malloc'ed buffer and should be freed by the
65 caller. */
66 grub_err_t (*label) (grub_device_t device, char **label);
67
68 /* Return the uuid of the device DEVICE in UUID. The uuid is
69 returned in a grub_malloc'ed buffer and should be freed by the
70 caller. */
71 grub_err_t (*uuid) (grub_device_t device, char **uuid);
72
73 /* Get writing time of filesystem. */
74 grub_err_t (*mtime) (grub_device_t device, grub_int32_t *timebuf);
75
76 #ifdef GRUB_UTIL
77 /* Whether this filesystem reserves first sector for DOS-style boot. */
78 int reserved_first_sector;
79 #endif
80 };
81 typedef struct grub_fs *grub_fs_t;
82
83 /* This is special, because block lists are not files in usual sense. */
84 extern struct grub_fs grub_fs_blocklist;
85
86 /* This hook is used to automatically load filesystem modules.
87 If this hook loads a module, return non-zero. Otherwise return zero.
88 The newly loaded filesystem is assumed to be inserted into the head of
89 the linked list GRUB_FS_LIST through the function grub_fs_register. */
90 typedef int (*grub_fs_autoload_hook_t) (void);
91 extern grub_fs_autoload_hook_t EXPORT_VAR(grub_fs_autoload_hook);
92 extern grub_fs_t EXPORT_VAR (grub_fs_list);
93
94 #ifndef GRUB_LST_GENERATOR
95 static inline void
96 grub_fs_register (grub_fs_t fs)
97 {
98 grub_list_push (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
99 }
100 #endif
101
102 static inline void
103 grub_fs_unregister (grub_fs_t fs)
104 {
105 grub_list_remove (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
106 }
107
108 #define FOR_FILESYSTEMS(var) FOR_LIST_ELEMENTS((var), (grub_fs_list))
109
110 grub_fs_t EXPORT_FUNC(grub_fs_probe) (grub_device_t device);
111
112 #endif /* ! GRUB_FS_HEADER */