1 /* GRUB compatibility header
3 * taken from filo and grub.
7 * GRUB -- GRand Unified Bootloader
8 * Copyright (C) 1999,2000,2001,2003 Free Software Foundation, Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
26 /* This disables some portion of code */
29 #if defined CONFIG_X86
31 * ffz = Find First Zero in word. Undefined if no zero exists,
32 * so code should check against ~0UL first..
34 static __inline__ unsigned int
35 ffz (unsigned int word)
43 static __inline__ unsigned int
44 log2 (unsigned int word)
52 #elif defined (CONFIG_PPC)
53 static __inline__ unsigned long
54 __ilog2(unsigned long x)
58 asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
62 static __inline__ unsigned long
68 return __ilog2(x & -x);
71 #define log2(n) ffz(~(n))
75 static __inline__ unsigned int log2(unsigned int word)
77 /* assume 8 bits per byte. */
78 unsigned int i = 1 << (sizeof(word)*8 - 1);
79 unsigned int pow = sizeof(word) * 8 - 1;
82 /* invalid parameter */
85 for(; i > word; i >>= 1, pow--) ;
90 #define ffz(n) log2(~(n))
95 substring (const char *s1, const char *s2)
99 /* The strings match exactly. */
105 /* S1 is a substring of S2. */
109 /* S1 isn't a substring. */
113 #define grub_memmove memmove
114 #define grub_strcmp strcmp
116 #define MAXINT 0x7fffffff
118 /* This is only used by fsys_* to determine if it's hard disk. If it is,
119 * they try to guess filesystem type by partition type. I guess it is
120 * not necessory, so hardcoded to 0 (first floppy) --ts1 */
121 #define current_drive 0
122 #define current_slice 0
123 #define current_partition 0
125 /* we fake this for now, assuming that the filesystem is not corrupt */
126 #define part_length -1
131 /* Error codes (descriptions are in common.c) */
174 extern grub_error_t errnum;
176 #define grub_open file_open
177 #define grub_read file_read
178 #define grub_seek file_seek
179 #define grub_close file_close
181 /* instrumentation variables */
182 /* (Not used in FILO) */
183 extern void (*disk_read_hook) (int, int, int);
184 extern void (*disk_read_func) (int, int, int);
186 #define FSYS_BUFLEN 0x8000
187 extern char FSYS_BUF[FSYS_BUFLEN];
189 #define print_possibilities 0
191 #define SECTOR_SIZE 512
192 #define SECTOR_BITS 9
194 #ifdef CONFIG_FSYS_FAT
195 int fat_mount (void);
196 int fat_read (char *buf, int len);
197 int fat_dir (char *dirname);
200 #ifdef CONFIG_FSYS_EXT2FS
201 int ext2fs_mount (void);
202 int ext2fs_read (char *buf, int len);
203 int ext2fs_dir (char *dirname);
206 #ifdef CONFIG_FSYS_MINIX
207 int minix_mount (void);
208 int minix_read (char *buf, int len);
209 int minix_dir (char *dirname);
212 #ifdef CONFIG_FSYS_REISERFS
213 int reiserfs_mount (void);
214 int reiserfs_read (char *buf, int len);
215 int reiserfs_dir (char *dirname);
216 int reiserfs_embed (int *start_sector, int needed_sectors);
219 #ifdef CONFIG_FSYS_JFS
220 int jfs_mount (void);
221 int jfs_read (char *buf, int len);
222 int jfs_dir (char *dirname);
223 int jfs_embed (int *start_sector, int needed_sectors);
226 #ifdef CONFIG_FSYS_XFS
227 int xfs_mount (void);
228 int xfs_read (char *buf, int len);
229 int xfs_dir (char *dirname);
232 #ifdef CONFIG_FSYS_UFS
233 int ufs_mount (void);
234 int ufs_read (char *buf, int len);
235 int ufs_dir (char *dirname);
236 int ufs_embed (int *start_sector, int needed_sectors);
239 #ifdef CONFIG_FSYS_ISO9660
240 int iso9660_mount (void);
241 int iso9660_read (char *buf, int len);
242 int iso9660_dir (char *dirname);
245 /* This is not a flag actually, but used as if it were a flag. */
246 #define PC_SLICE_TYPE_HIDDEN_FLAG 0x10
248 #define PC_SLICE_TYPE_NONE 0
249 #define PC_SLICE_TYPE_FAT12 1
250 #define PC_SLICE_TYPE_FAT16_LT32M 4
251 #define PC_SLICE_TYPE_EXTENDED 5
252 #define PC_SLICE_TYPE_FAT16_GT32M 6
253 #define PC_SLICE_TYPE_FAT32 0xb
254 #define PC_SLICE_TYPE_FAT32_LBA 0xc
255 #define PC_SLICE_TYPE_FAT16_LBA 0xe
256 #define PC_SLICE_TYPE_WIN95_EXTENDED 0xf
257 #define PC_SLICE_TYPE_EZD 0x55
258 #define PC_SLICE_TYPE_MINIX 0x80
259 #define PC_SLICE_TYPE_LINUX_MINIX 0x81
260 #define PC_SLICE_TYPE_EXT2FS 0x83
261 #define PC_SLICE_TYPE_LINUX_EXTENDED 0x85
262 #define PC_SLICE_TYPE_VSTAFS 0x9e
263 #define PC_SLICE_TYPE_DELL_UTIL 0xde
264 #define PC_SLICE_TYPE_LINUX_RAID 0xfd
266 /* For convinience. */
267 /* Check if TYPE is a FAT partition type. Clear the hidden flag before
268 the check, to allow the user to mount a hidden partition in GRUB. */
269 #define IS_PC_SLICE_TYPE_FAT(type) \
270 ({ int _type = (type) & ~PC_SLICE_TYPE_HIDDEN_FLAG; \
271 _type == PC_SLICE_TYPE_FAT12 \
272 || _type == PC_SLICE_TYPE_FAT16_LT32M \
273 || _type == PC_SLICE_TYPE_FAT16_GT32M \
274 || _type == PC_SLICE_TYPE_FAT16_LBA \
275 || _type == PC_SLICE_TYPE_FAT32 \
276 || _type == PC_SLICE_TYPE_FAT32_LBA \
277 || _type == PC_SLICE_TYPE_DELL_UTIL; })
279 #define IS_PC_SLICE_TYPE_MINIX(type) \
280 (((type) == PC_SLICE_TYPE_MINIX) \
281 || ((type) == PC_SLICE_TYPE_LINUX_MINIX))
283 #define IS_PC_SLICE_TYPE_BSD_WITH_FS(type,fs) 0
285 /* possible values for the *BSD-style partition type */
286 #define FS_UNUSED 0 /* unused */
287 #define FS_SWAP 1 /* swap */
288 #define FS_V6 2 /* Sixth Edition */
289 #define FS_V7 3 /* Seventh Edition */
290 #define FS_SYSV 4 /* System V */
291 #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
292 #define FS_V8 6 /* Eighth Edition, 4K blocks */
293 #define FS_BSDFFS 7 /* 4.2BSD fast file system */
294 #define FS_MSDOS 8 /* MSDOS file system */
295 #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
296 #define FS_OTHER 10 /* in use, but unknown/unsupported */
297 #define FS_HPFS 11 /* OS/2 high-performance file system */
298 #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
299 #define FS_BOOT 13 /* partition contains bootstrap */
300 #define FS_ADOS 14 /* AmigaDOS fast file system */
301 #define FS_HFS 15 /* Macintosh HFS */
302 #define FS_FILECORE 16 /* Acorn Filecore Filing System */
303 #define FS_EXT2FS 17 /* Linux Extended 2 file system */