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>
24 #include <grub/device.h>
26 #include <grub/disk.h>
28 /* File description. */
34 /* The underlying device. */
37 /* The underlying filesystem. */
40 /* The current offset. */
42 grub_off_t progress_offset
;
45 grub_uint64_t last_progress_time
;
46 grub_off_t last_progress_offset
;
47 grub_uint64_t estimated_speed
;
52 /* If file is not easily seekable. Should be set by underlying layer. */
53 int not_easily_seekable
;
55 /* Filesystem-specific 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. */
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
,
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
];
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
;
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;
100 grub_file_filter_disable (grub_file_filter_id_t id
)
102 grub_file_filters_enabled
[id
] = 0;
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;
116 grub_file_filter_disable_all (void)
118 grub_file_filter_id_t id
;
121 id
< GRUB_FILE_FILTER_MAX
; id
++)
122 grub_file_filters_enabled
[id
] = 0;
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
,
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
)
149 static inline grub_off_t
150 grub_file_tell (const grub_file_t file
)
156 grub_file_seekable (const grub_file_t file
)
158 return !file
->not_easily_seekable
;
162 grub_file_offset_open (grub_file_t parent
, grub_off_t start
,
165 grub_file_offset_close (grub_file_t file
);
167 #endif /* ! GRUB_FILE_HEADER */