Fix cross compilation (e.g. on Darwin). Following changes to make.tmpl,
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / file.h
blob739488cbe59aaa044b37611d00fb2c6c615e2c31
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2007 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 #ifndef GRUB_FILE_HEADER
20 #define GRUB_FILE_HEADER 1
22 #include <grub/types.h>
23 #include <grub/err.h>
24 #include <grub/device.h>
25 #include <grub/fs.h>
26 #include <grub/disk.h>
28 /* File description. */
29 struct grub_file
31 /* File name. */
32 char *name;
34 /* The underlying device. */
35 grub_device_t device;
37 /* The underlying filesystem. */
38 grub_fs_t fs;
40 /* The current offset. */
41 grub_off_t offset;
42 grub_off_t progress_offset;
44 /* Progress info. */
45 grub_uint64_t last_progress_time;
46 grub_off_t last_progress_offset;
47 grub_uint64_t estimated_speed;
49 /* The file size. */
50 grub_off_t size;
52 /* If file is not easily seekable. Should be set by underlying layer. */
53 int not_easily_seekable;
55 /* Filesystem-specific data. */
56 void *data;
58 /* This is called when a sector is read. Used only for a disk device. */
59 grub_disk_read_hook_t read_hook;
61 /* Caller-specific data passed to the read hook. */
62 void *read_hook_data;
64 typedef struct grub_file *grub_file_t;
66 extern grub_disk_read_hook_t EXPORT_VAR(grub_file_progress_hook);
68 /* Filters with lower ID are executed first. */
69 typedef enum grub_file_filter_id
71 GRUB_FILE_FILTER_PUBKEY,
72 GRUB_FILE_FILTER_GZIO,
73 GRUB_FILE_FILTER_XZIO,
74 GRUB_FILE_FILTER_LZOPIO,
75 GRUB_FILE_FILTER_MAX,
76 GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
77 GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
78 } grub_file_filter_id_t;
80 typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, const char *filename);
82 extern grub_file_filter_t EXPORT_VAR(grub_file_filters_all)[GRUB_FILE_FILTER_MAX];
83 extern grub_file_filter_t EXPORT_VAR(grub_file_filters_enabled)[GRUB_FILE_FILTER_MAX];
85 static inline void
86 grub_file_filter_register (grub_file_filter_id_t id, grub_file_filter_t filter)
88 grub_file_filters_all[id] = filter;
89 grub_file_filters_enabled[id] = filter;
92 static inline void
93 grub_file_filter_unregister (grub_file_filter_id_t id)
95 grub_file_filters_all[id] = 0;
96 grub_file_filters_enabled[id] = 0;
99 static inline void
100 grub_file_filter_disable (grub_file_filter_id_t id)
102 grub_file_filters_enabled[id] = 0;
105 static inline void
106 grub_file_filter_disable_compression (void)
108 grub_file_filter_id_t id;
110 for (id = GRUB_FILE_FILTER_COMPRESSION_FIRST;
111 id <= GRUB_FILE_FILTER_COMPRESSION_LAST; id++)
112 grub_file_filters_enabled[id] = 0;
115 static inline void
116 grub_file_filter_disable_all (void)
118 grub_file_filter_id_t id;
120 for (id = 0;
121 id < GRUB_FILE_FILTER_MAX; id++)
122 grub_file_filters_enabled[id] = 0;
125 static inline void
126 grub_file_filter_disable_pubkey (void)
128 grub_file_filters_enabled[GRUB_FILE_FILTER_PUBKEY] = 0;
131 /* Get a device name from NAME. */
132 char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
134 grub_file_t EXPORT_FUNC(grub_file_open) (const char *name);
135 grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
136 grub_size_t len);
137 grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
138 grub_err_t EXPORT_FUNC(grub_file_close) (grub_file_t file);
140 /* Return value of grub_file_size() in case file size is unknown. */
141 #define GRUB_FILE_SIZE_UNKNOWN 0xffffffffffffffffULL
143 static inline grub_off_t
144 grub_file_size (const grub_file_t file)
146 return file->size;
149 static inline grub_off_t
150 grub_file_tell (const grub_file_t file)
152 return file->offset;
155 static inline int
156 grub_file_seekable (const grub_file_t file)
158 return !file->not_easily_seekable;
161 grub_file_t
162 grub_file_offset_open (grub_file_t parent, grub_off_t start,
163 grub_off_t size);
164 void
165 grub_file_offset_close (grub_file_t file);
167 #endif /* ! GRUB_FILE_HEADER */