You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* GRUB compatibility header */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 1999,2000,2001,2003 Free Software Foundation, Inc.
  5. *
  6. * This program 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 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program 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 this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. //#include <lib.h>
  21. #include <etherboot.h>
  22. #include <fs.h>
  23. /* This disables some portion of code */
  24. #define STAGE1_5 1
  25. static inline int
  26. substring (const char *s1, const char *s2)
  27. {
  28. while (*s1 == *s2)
  29. {
  30. /* The strings match exactly. */
  31. if (! *(s1++))
  32. return 0;
  33. s2 ++;
  34. }
  35. /* S1 is a substring of S2. */
  36. if (*s1 == 0)
  37. return -1;
  38. /* S1 isn't a substring. */
  39. return 1;
  40. }
  41. #define grub_memmove memmove
  42. #define grub_strcmp strcmp
  43. #define MAXINT 0x7fffffff
  44. /* This is only used by fsys_* to determine if it's hard disk. If it is,
  45. * they try to guess filesystem type by partition type. I guess it is
  46. * not necessory, so hardcoded to 0 (first floppy) --ts1 */
  47. #define current_drive 0
  48. /* Ditto */
  49. #define current_slice 0
  50. extern unsigned long part_start;
  51. extern unsigned long part_length;
  52. extern int filepos;
  53. extern int filemax;
  54. extern int fsmax;
  55. /* Error codes (descriptions are in common.c) */
  56. typedef enum
  57. {
  58. ERR_NONE = 0,
  59. ERR_BAD_FILENAME,
  60. ERR_BAD_FILETYPE,
  61. ERR_BAD_GZIP_DATA,
  62. ERR_BAD_GZIP_HEADER,
  63. ERR_BAD_PART_TABLE,
  64. ERR_BAD_VERSION,
  65. ERR_BELOW_1MB,
  66. ERR_BOOT_COMMAND,
  67. ERR_BOOT_FAILURE,
  68. ERR_BOOT_FEATURES,
  69. ERR_DEV_FORMAT,
  70. ERR_DEV_VALUES,
  71. ERR_EXEC_FORMAT,
  72. ERR_FILELENGTH,
  73. ERR_FILE_NOT_FOUND,
  74. ERR_FSYS_CORRUPT,
  75. ERR_FSYS_MOUNT,
  76. ERR_GEOM,
  77. ERR_NEED_LX_KERNEL,
  78. ERR_NEED_MB_KERNEL,
  79. ERR_NO_DISK,
  80. ERR_NO_PART,
  81. ERR_NUMBER_PARSING,
  82. ERR_OUTSIDE_PART,
  83. ERR_READ,
  84. ERR_SYMLINK_LOOP,
  85. ERR_UNRECOGNIZED,
  86. ERR_WONT_FIT,
  87. ERR_WRITE,
  88. ERR_BAD_ARGUMENT,
  89. ERR_UNALIGNED,
  90. ERR_PRIVILEGED,
  91. ERR_DEV_NEED_INIT,
  92. ERR_NO_DISK_SPACE,
  93. ERR_NUMBER_OVERFLOW,
  94. MAX_ERR_NUM
  95. } grub_error_t;
  96. extern grub_error_t errnum;
  97. #define grub_open file_open
  98. #define grub_read file_read
  99. #define grub_seek file_seek
  100. #define grub_close file_close
  101. /* instrumentation variables */
  102. /* (Not used in FILO) */
  103. extern void (*disk_read_hook) (int, int, int);
  104. extern void (*disk_read_func) (int, int, int);
  105. #define FSYS_BUFLEN 0x8000
  106. extern char FSYS_BUF[FSYS_BUFLEN];
  107. #define print_possibilities 0
  108. #define SECTOR_SIZE 512
  109. #define SECTOR_BITS 9
  110. #ifdef FSYS_FAT
  111. int fat_mount (void);
  112. int fat_read (char *buf, int len);
  113. int fat_dir (char *dirname);
  114. #endif
  115. #ifdef FSYS_EXT2FS
  116. int ext2fs_mount (void);
  117. int ext2fs_read (char *buf, int len);
  118. int ext2fs_dir (char *dirname);
  119. #endif
  120. #ifdef FSYS_MINIX
  121. int minix_mount (void);
  122. int minix_read (char *buf, int len);
  123. int minix_dir (char *dirname);
  124. #endif
  125. #ifdef FSYS_REISERFS
  126. int reiserfs_mount (void);
  127. int reiserfs_read (char *buf, int len);
  128. int reiserfs_dir (char *dirname);
  129. int reiserfs_embed (int *start_sector, int needed_sectors);
  130. #endif
  131. #ifdef FSYS_JFS
  132. int jfs_mount (void);
  133. int jfs_read (char *buf, int len);
  134. int jfs_dir (char *dirname);
  135. int jfs_embed (int *start_sector, int needed_sectors);
  136. #endif
  137. #ifdef FSYS_XFS
  138. int xfs_mount (void);
  139. int xfs_read (char *buf, int len);
  140. int xfs_dir (char *dirname);
  141. #endif
  142. #ifdef FSYS_ISO9660
  143. int iso9660_mount (void);
  144. int iso9660_read (char *buf, int len);
  145. int iso9660_dir (char *dirname);
  146. #endif
  147. /* This is not a flag actually, but used as if it were a flag. */
  148. #define PC_SLICE_TYPE_HIDDEN_FLAG 0x10
  149. #define PC_SLICE_TYPE_NONE 0
  150. #define PC_SLICE_TYPE_FAT12 1
  151. #define PC_SLICE_TYPE_FAT16_LT32M 4
  152. #define PC_SLICE_TYPE_EXTENDED 5
  153. #define PC_SLICE_TYPE_FAT16_GT32M 6
  154. #define PC_SLICE_TYPE_FAT32 0xb
  155. #define PC_SLICE_TYPE_FAT32_LBA 0xc
  156. #define PC_SLICE_TYPE_FAT16_LBA 0xe
  157. #define PC_SLICE_TYPE_WIN95_EXTENDED 0xf
  158. #define PC_SLICE_TYPE_EZD 0x55
  159. #define PC_SLICE_TYPE_MINIX 0x80
  160. #define PC_SLICE_TYPE_LINUX_MINIX 0x81
  161. #define PC_SLICE_TYPE_EXT2FS 0x83
  162. #define PC_SLICE_TYPE_LINUX_EXTENDED 0x85
  163. #define PC_SLICE_TYPE_VSTAFS 0x9e
  164. #define PC_SLICE_TYPE_DELL_UTIL 0xde
  165. #define PC_SLICE_TYPE_LINUX_RAID 0xfd
  166. /* For convinience. */
  167. /* Check if TYPE is a FAT partition type. Clear the hidden flag before
  168. the check, to allow the user to mount a hidden partition in GRUB. */
  169. #define IS_PC_SLICE_TYPE_FAT(type) \
  170. ({ int _type = (type) & ~PC_SLICE_TYPE_HIDDEN_FLAG; \
  171. _type == PC_SLICE_TYPE_FAT12 \
  172. || _type == PC_SLICE_TYPE_FAT16_LT32M \
  173. || _type == PC_SLICE_TYPE_FAT16_GT32M \
  174. || _type == PC_SLICE_TYPE_FAT16_LBA \
  175. || _type == PC_SLICE_TYPE_FAT32 \
  176. || _type == PC_SLICE_TYPE_FAT32_LBA \
  177. || _type == PC_SLICE_TYPE_DELL_UTIL; })
  178. #define IS_PC_SLICE_TYPE_MINIX(type) \
  179. (((type) == PC_SLICE_TYPE_MINIX) \
  180. || ((type) == PC_SLICE_TYPE_LINUX_MINIX))
  181. #define IS_PC_SLICE_TYPE_BSD_WITH_FS(type,fs) 0
  182. /* possible values for the *BSD-style partition type */
  183. #define FS_UNUSED 0 /* unused */
  184. #define FS_SWAP 1 /* swap */
  185. #define FS_V6 2 /* Sixth Edition */
  186. #define FS_V7 3 /* Seventh Edition */
  187. #define FS_SYSV 4 /* System V */
  188. #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
  189. #define FS_V8 6 /* Eighth Edition, 4K blocks */
  190. #define FS_BSDFFS 7 /* 4.2BSD fast file system */
  191. #define FS_MSDOS 8 /* MSDOS file system */
  192. #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
  193. #define FS_OTHER 10 /* in use, but unknown/unsupported */
  194. #define FS_HPFS 11 /* OS/2 high-performance file system */
  195. #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
  196. #define FS_BOOT 13 /* partition contains bootstrap */
  197. #define FS_ADOS 14 /* AmigaDOS fast file system */
  198. #define FS_HFS 15 /* Macintosh HFS */
  199. #define FS_FILECORE 16 /* Acorn Filecore Filing System */
  200. #define FS_EXT2FS 17 /* Linux Extended 2 file system */