无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 3418|回复: 7
打印 上一主题 下一主题

[求助] 求fat外部命令的源码以及一些写g4d外部命令需要了解的东西。。。

[复制链接]
跳转到指定楼层
1#
发表于 2014-12-3 20:38:16 来自手机 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如题,我想写一个ntfs的外部命令来,准备照葫芦画瓢,参考文献是那份nt4泄露的源码(我前几天在这发过)。。。谢谢

还有啥基础知识没,比如C标准库对应的g4d函数啥的以及调试方法等等。。。谢谢
2#
发表于 2014-12-3 20:40:44 | 只看该作者
**** Running User Programs(外部命令,供开发人员参考) ****
从0.4.5起,用户可以自行编写程序以在GRUB4DOS中运行。
该可执行程序文件必须以8字节grub4dos EXEC签名结尾。
0x05, 0x18, 0x05, 0x03, 0xBA, 0xA7, 0xBA, 0xBC
程序的入口点在文件头,和DOS的.com文件很像(但我们是32位的程序)。
注:因为使用了linux gcc的特性,所以程序只能在linux下使用gcc进行编译。
附上一个简单的echo.c源码,供参考。
/*================ begin echo.c ================*/
/*
* 编译:
gcc -Wl,--build-id=none -m32 -mno-sse -nostdlib -fno-zero-initialized-in-bss -fno-function-cse -fno-jump-tables -Wl,-N -fPIE echo.c -o echo.o
* disassemble:              objdump -d echo.o
* confirm no relocation:    readelf -r echo.o
* generate executable:      objcopy -O binary echo.o echo
* 经过这一步之后生成的echo文件就是可以在grub4dos中运行的程序。
* and then the resultant echo will be grub4dos executable.
*/
/*
* This is a simple ECHO command, running under grub4dos.
*/
#define sprintf ((int (*)(char *, const char *, ...))((*(int **)0x8300)[0]))
#define printf(...) sprintf(NULL, __VA_ARGS__)
int i = 0x66666666; /* 这是必要的,看下面的注释。*/
/* gcc treat the following as data only if a global initialization like the
* above line occurs.
*/
/* GRUB4DOS可执行程序结尾必须有以下8个字节(EXEC签名) */
asm(".long 0x03051805");
asm(".long 0xBCBAA7BA")
;
/* 感谢上帝, gcc 会把上面的8个字按兵不动放在最终程序的最后面。
* 不要在这里插入其它任何代码.
*/
int main(char *arg,int flags)
{
return printf("%s\n",arg);
}
/*================ end echo.c ================*/
0x8300 是 grub4dos 系统函数(API)的入口点. 你可以在 asm.S 源码中找到它的定义.
目前可以使用的函数和变量:
http://grubutils.googlecode.com/svn/trunk/src/include/grub4dos.h

点评

首先,google挂了。。。 其次。main的第二个参数flag是什么鬼  详情 回复 发表于 2014-12-3 20:50
回复

使用道具 举报

3#
 楼主| 发表于 2014-12-3 20:50:43 来自手机 | 只看该作者
sratlf 发表于 2014-12-3 20:40
**** Running User Programs(外部命令,供开发人员参考) ****
从0.4.5起,用户可以自行编写程序以在GRUB ...

首先,google挂了。。。
其次。main的第二个参数flag是什么鬼

点评

google的问题可以用vpn出去 天朝必备技能 至于main参数 我也不知道。。。这段是readme里的  详情 回复 发表于 2014-12-3 21:37
回复

使用道具 举报

4#
发表于 2014-12-3 21:37:12 | 只看该作者
sunsea 发表于 2014-12-3 20:50
首先,google挂了。。。
其次。main的第二个参数flag是什么鬼

google的问题可以用vpn出去  天朝必备技能  至于main参数  我也不知道。。。这段是readme里的
回复

使用道具 举报

5#
发表于 2014-12-4 08:35:50 | 只看该作者
不要使用C自带的函数.直接调用grub4dos提供的函数

flags可以不用管它,这个是用于判断当前命令运行的环境 ,比如是从菜单运行,还是从命令行运行的,或是通过批处理调用的.

  1. /*
  2. * The C code for a grub4dos executable may have defines as follows:
  3. * 用于编写外部命令的函数定义。
  4. */
  5. #ifndef GRUB4DOS_2011_12_13
  6. #define GRUB4DOS_2011_12_13
  7. #undef NULL
  8. #define NULL         ((void *) 0)

  9. /* Error codes (descriptions are in common.c) */
  10. typedef enum
  11. {
  12.   ERR_NONE = 0,
  13.   ERR_BAD_FILENAME,
  14.   ERR_BAD_FILETYPE,
  15.   ERR_BAD_GZIP_DATA,
  16.   ERR_BAD_GZIP_HEADER,
  17.   ERR_BAD_PART_TABLE,
  18.   ERR_BAD_VERSION,
  19.   ERR_BELOW_1MB,
  20.   ERR_BOOT_COMMAND,
  21.   ERR_BOOT_FAILURE,
  22.   ERR_BOOT_FEATURES,
  23.   ERR_DEV_FORMAT,
  24.   ERR_DEV_VALUES,
  25.   ERR_EXEC_FORMAT,
  26.   ERR_FILELENGTH,
  27.   ERR_FILE_NOT_FOUND,
  28.   ERR_FSYS_CORRUPT,
  29.   ERR_FSYS_MOUNT,
  30.   ERR_GEOM,
  31.   ERR_NEED_LX_KERNEL,
  32.   ERR_NEED_MB_KERNEL,
  33.   ERR_NO_DISK,
  34.   ERR_NO_PART,
  35.   ERR_NUMBER_PARSING,
  36.   ERR_OUTSIDE_PART,
  37.   ERR_READ,
  38.   ERR_SYMLINK_LOOP,
  39.   ERR_UNRECOGNIZED,
  40.   ERR_WONT_FIT,
  41.   ERR_WRITE,
  42.   ERR_BAD_ARGUMENT,
  43.   ERR_UNALIGNED,
  44.   ERR_PRIVILEGED,
  45.   ERR_DEV_NEED_INIT,
  46.   ERR_NO_DISK_SPACE,
  47.   ERR_NUMBER_OVERFLOW,

  48.   ERR_DEFAULT_FILE,
  49.   ERR_DEL_MEM_DRIVE,
  50.   ERR_DISABLE_A20,
  51.   ERR_DOS_BACKUP,
  52.   ERR_ENABLE_A20,
  53.   ERR_EXTENDED_PARTITION,
  54.   ERR_FILENAME_FORMAT,
  55.   ERR_HD_VOL_START_0,
  56.   ERR_INT13_ON_HOOK,
  57.   ERR_INT13_OFF_HOOK,
  58.   ERR_INVALID_BOOT_CS,
  59.   ERR_INVALID_BOOT_IP,
  60.   ERR_INVALID_FLOPPIES,
  61.   ERR_INVALID_HARDDRIVES,
  62.   ERR_INVALID_HEADS,
  63.   ERR_INVALID_LOAD_LENGTH,
  64.   ERR_INVALID_LOAD_OFFSET,
  65.   ERR_INVALID_LOAD_SEGMENT,
  66.   ERR_INVALID_SECTORS,
  67.   ERR_INVALID_SKIP_LENGTH,
  68.   ERR_INVALID_RAM_DRIVE,
  69.   ERR_IN_SITU_FLOPPY,
  70.   ERR_IN_SITU_MEM,
  71.   ERR_MD_BASE,
  72.   ERR_NON_CONTIGUOUS,
  73.   ERR_NO_DRIVE_MAPPED,
  74.   ERR_NO_HEADS,
  75.   ERR_NO_SECTORS,
  76.   ERR_PARTITION_TABLE_FULL,
  77.   ERR_RD_BASE,
  78.   ERR_SPECIFY_GEOM,
  79.   ERR_SPECIFY_MEM,
  80.   ERR_SPECIFY_RESTRICTION,
  81. //  ERR_INVALID_RD_BASE,
  82. //  ERR_INVALID_RD_SIZE,
  83.   ERR_MD5_FORMAT,
  84.   ERR_WRITE_GZIP_FILE,
  85.   ERR_FUNC_CALL,
  86. //  ERR_WRITE_TO_NON_MEM_DRIVE,
  87.   ERR_INTERNAL_CHECK,
  88.   ERR_KERNEL_WITH_PROGRAM,
  89.   ERR_HALT,
  90.   ERR_PARTITION_LOOP,
  91.   ERR_NOT_ENOUGH_MEMORY,
  92.   ERR_BAT_GOTO,
  93.   ERR_BAT_CALL,

  94.   MAX_ERR_NUM
  95. } grub_error_t;

  96. #define install_partition (*(unsigned long long *)0x8208)
  97. #define boot_drive (*(unsigned long long *)0x8280)
  98. #define pxe_yip (*(unsigned long *)0x8284)
  99. #define pxe_sip (*(unsigned long *)0x8288)
  100. #define pxe_gip (*(unsigned long *)0x828C)
  101. #define filesize (*(unsigned long long *)0x8290)
  102. #define saved_mem_upper (*(unsigned long *)0x8298)
  103. #define saved_partition (*(unsigned long *)0x829C)
  104. #define saved_drive (*(unsigned long *)0x82A0)
  105. #define no_decompression (*(unsigned long *)0x82A4)
  106. #define part_start (*(unsigned long long *)0x82A8)
  107. #define part_length (*(unsigned long long *)0x82B0)
  108. #define fb_status (*(unsigned long *)0x82B8)
  109. #define is64bit (*(unsigned long *)0x82BC)
  110. #define saved_mem_higher (*(unsigned long long *)0x82C0)
  111. #define cdrom_drive (*(unsigned long *)0x82C8)
  112. #define ram_drive (*(unsigned long *)0x82CC)
  113. #define rd_base (*(unsigned long long *)0x82D0)
  114. #define rd_size (*(unsigned long long *)0x82D8)
  115. #define addr_system_functions (*(unsigned long *)0x8300)
  116. #define next_partition_drive                ((*(unsigned long **)0x8304)[0])
  117. #define next_partition_dest                ((*(unsigned long **)0x8304)[1])
  118. #define next_partition_partition        ((*(unsigned long ***)0x8304)[2])
  119. #define next_partition_type                ((*(unsigned long ***)0x8304)[3])
  120. #define next_partition_start                ((*(unsigned long ***)0x8304)[4])
  121. #define next_partition_len                ((*(unsigned long ***)0x8304)[5])
  122. #define next_partition_offset                ((*(unsigned long ***)0x8304)[6])
  123. #define next_partition_entry                ((*(unsigned long ***)0x8304)[7])
  124. #define next_partition_ext_offset        ((*(unsigned long ***)0x8304)[8])
  125. #define next_partition_buf                ((*(char ***)0x8304)[9])
  126. #define quit_print                ((*(int **)0x8304)[10])
  127. #define filesystem_type ((*(int **)0x8304)[13])
  128. //#define query_block_entries ((*(long **)0x8304)[14])
  129. //#define map_start_sector ((*(unsigned long **)0x8304)[15])
  130. #define buf_geom ((*(struct geometry ***)0x8304)[16])
  131. #define tmp_geom ((*(struct geometry ***)0x8304)[17])
  132. #define term_table ((*(struct term_entry ***)0x8304)[18])
  133. #define current_term ((*(struct term_entry ***)0x8304)[19])
  134. #define fsys_table ((*(struct fsys_entry ***)0x8304)[20])
  135. //#define fsys_type ((*(int **)0x8304)[21])
  136. //#define NUM_FSYS ((*(const int **)0x8304)[22])

  137. #define graphics_inited ((*(const int **)0x8304)[23])
  138. #define VARIABLE_GRAPHICS ((char *)(*(int ***)0x8304)[24])
  139. #define font8x16 ((*(char ***)0x8304)[25])
  140. #define fontx ((*(int **)0x8304)[26])
  141. #define fonty ((*(int **)0x8304)[27])
  142. #define graphics_CURSOR ((*(int **)0x8304)[28])
  143. #define menu_border ((*(struct border ***)0x8304)[29])
  144. #define current_color ((*(int **)0x8304)[42])
  145. #define foreground ((*(int **)0x8304)[43])
  146. #define background ((*(int **)0x8304)[44])
  147. #define p_get_cmdline_str ((*(int **)0x8304)[45])
  148. #define splashimage_loaded ((*(unsigned long **)0x8304)[46])
  149. #define putchar_hooked ((*(unsigned long **)0x8304)[47])
  150. #define init_free_mem_start ((*(unsigned long **)0x8304)[48])
  151. #define cursorX (*(short *)(VARIABLE_GRAPHICS))
  152. #define cursorY (*(short *)(VARIABLE_GRAPHICS + 2))
  153. #define cursorBuf ((char *)(VARIABLE_GRAPHICS + 6))

  154. #define free_mem_start (*(unsigned long *)0x82F0)
  155. #define free_mem_end (*(unsigned long *)0x82F4)
  156. #define saved_mmap_addr (*(unsigned long *)0x82F8)
  157. #define saved_mmap_length (*(unsigned long *)0x82FB)

  158. #define DRIVE_MAP_SIZE        8
  159. #define PXE_DRIVE                0x21
  160. #define INITRD_DRIVE        0x22
  161. #define FB_DRIVE                0x23
  162. #define SECTOR_SIZE                0x200
  163. #define SECTOR_BITS                9
  164. #define BIOSDISK_FLAG_BIFURCATE                0x4
  165. #define MB_ARD_MEMORY        1
  166. #define MB_INFO_MEM_MAP        0x00000040

  167. #define errnum (*(grub_error_t *)0x8314)
  168. #define current_drive (*(unsigned long *)0x8318)
  169. #define current_partition (*(unsigned long *)0x831C)
  170. #define filemax (*(unsigned long long *)0x8320)
  171. #define filepos (*(unsigned long long *)0x8328)
  172. #define debug (*(int *)0x8330)
  173. #define current_slice (*(unsigned long *)0x8334)
  174. #define buf_track        (*(unsigned long long *)0x8340)
  175. #define buf_drive        (*(int *)0x8348)

  176. #define GRUB_READ 0xedde0d90
  177. #define GRUB_WRITE 0x900ddeed

  178. #define sprintf ((int (*)(char *, const char *, ...))((*(int **)0x8300)[0]))
  179. #define printf(...) sprintf(NULL, __VA_ARGS__)
  180. #define putstr ((void (*)(const char *))((*(int **)0x8300)[1]))
  181. #define putchar ((void (*)(int))((*(int **)0x8300)[2]))
  182. #define get_cmdline_obsolete ((int (*)(struct get_cmdline_arg cmdline))((*(int **)0x8300)[3]))
  183. #define getxy ((int (*)(void))((*(int **)0x8300)[4]))
  184. #define gotoxy ((void (*)(int, int))((*(int **)0x8300)[5]))
  185. #define cls ((void (*)(void))((*(int **)0x8300)[6]))
  186. #define wee_skip_to ((char *(*)(char *, int))((*(int **)0x8300)[7]))
  187. #define nul_terminate ((int (*)(char *))((*(int **)0x8300)[8]))
  188. #define safe_parse_maxint_with_suffix ((int (*)(char **str_ptr, unsigned long long *myint_ptr, int unitshift))((*(int **)0x8300)[9]))
  189. #define safe_parse_maxint(str_ptr, myint_ptr) safe_parse_maxint_with_suffix(str_ptr, myint_ptr, 0)
  190. #define substring ((int (*)(const char *s1, const char *s2, int case_insensitive))((*(int **)0x8300)[10]))
  191. #define strstr ((char *(*)(const char *s1, const char *s2))((*(int **)0x8300)[11]))
  192. #define strlen ((int (*)(const char *str))((*(int **)0x8300)[12]))
  193. #define strtok ((char *(*)(char *s, const char *delim))((*(int **)0x8300)[13]))
  194. #define strncat ((int (*)(char *s1, const char *s2, int n))((*(int **)0x8300)[14]))
  195. //#define strcmp ((int (*)(const char *s1, const char *s2))((*(int **)0x8300)[15]))
  196. #define strcpy ((char *(*)(char *dest, const char *src))((*(int **)0x8300)[16]))
  197. #define getkey ((int (*)(void))((*(int **)0x8300)[19]))
  198. #define checkkey ((int (*)(void))((*(int **)0x8300)[20]))
  199. #define memcmp ((int (*)(const char *s1, const char *s2, int n))((*(int **)0x8300)[22]))
  200. #define memmove ((void *(*)(void *to, const void *from, int len))((*(int **)0x8300)[23]))
  201. #define memset ((void *(*)(void *start, int c, int len))((*(int **)0x8300)[24]))
  202. #define open ((int (*)(char *))((*(int **)0x8300)[26]))
  203. #define read ((unsigned long long (*)(unsigned long long, unsigned long long, unsigned long))((*(int **)0x8300)[27]))
  204. #define close ((void (*)(void))((*(int **)0x8300)[28]))
  205. #define devread ((int (*)(unsigned long long sector, unsigned long byte_offset, unsigned long long byte_len, unsigned long long buf, unsigned long write))((*(int **)0x8300)[32]))
  206. /*
  207. * int
  208. * devwrite (unsigned long sector, unsigned long sector_count, char *buf)
  209. */
  210. #define devwrite ((int (*)(unsigned long, unsigned long, char *))((*(int **)0x8300)[33]))
  211. #define next_partition ((int (*)(void))((*(int **)0x8300)[34]))
  212. #define open_device ((int (*)(void))((*(int **)0x8300)[35]))
  213. #define real_open_partition ((int (*)(int))((*(int **)0x8300)[36]))
  214. #define set_device ((char *(*)(char *))((*(int **)0x8300)[37]))
  215. #define parse_string ((int (*)(char *))((*(int **)0x8300)[41]))
  216. #define hexdump ((void (*)(unsigned long long, char *, int))((*(int **)0x8300)[42]))
  217. #define skip_to ((char *(*)(int after_equal, char *cmdline))((*(int **)0x8300)[43]))
  218. #define builtin_cmd ((int (*)(char *cmd, char *arg, int flags))((*(int **)0x8300)[44]))
  219. #define get_datetime ((void (*)(unsigned long *date, unsigned long *time))((*(int **)0x8300)[45]))
  220. #define find_command ((struct builtin *(*)(char *))((*(int **)0x8300)[46]))
  221. #define get_mmap_entry ((int (*)(char *,int))((*(int **)0x8300)[49]))
  222. #define malloc ((void *(*)(int size))((*(int **)0x8300)[50]))
  223. #define free ((void (*)(void *ptr))((*(int **)0x8300)[51]))
  224. #define realmode_run ((int (*)(long regs_ptr))((*(int **)0x8300)[53]))

  225. #define SKIP_LINE                0x100
  226. #define SKIP_NONE                0
  227. #define SKIP_WITH_TERMINATE        0x200

  228. /*
  229. int
  230. devread (unsigned long drive, unsigned long sector, unsigned long byte_offset, unsigned long long byte_len, unsigned long long buf, unsigned long write)
  231. */
  232. #define grub_dir ((int (*)(char *))((*(int **)0x8300)[61]))
  233. #define print_a_completion ((void (*)(char *, int))((*(int **)0x8300)[62]))
  234. #define print_completions ((int (*)(int, int))((*(int **)0x8300)[63]))
  235. #define lba_to_chs ((void (*)(unsigned long lba, unsigned long *cl, unsigned long *ch, unsigned long *dh))((*(int **)0x8300)[64]))
  236. #define probe_bpb ((int (*)(struct master_and_dos_boot_sector *BS))((*(int **)0x8300)[65]))
  237. #define probe_mbr ((int (*)(struct master_and_dos_boot_sector *BS, unsigned long start_sector1, unsigned long sector_count1, unsigned long part_start1))((*(int **)0x8300)[66]))
  238. #define unicode_to_utf8 ((unsigned long (*)(unsigned short *, unsigned char *, unsigned long))((*(int **)0x8300)[67]))
  239. /*
  240. int
  241. rawread (unsigned long drive, unsigned long long sector, unsigned long byte_offset, unsigned long byte_len, unsigned long long buf, unsigned long write)
  242. */
  243. #define rawread ((int (*)(unsigned long, unsigned long long, unsigned long, unsigned long long, unsigned long long, unsigned long))((*(int **)0x8300)[68]))
  244. /*
  245. int
  246. rawwrite (unsigned long drive, unsigned long sector, char *buf)
  247. */
  248. #define rawwrite ((int (*)(unsigned long, unsigned long, char *))((*(int **)0x8300)[69]))

  249. #define setcursor ((int (*)(int))((*(int **)0x8300)[70]))
  250. #define tolower ((int (*)(int))((*(int **)0x8300)[71]))
  251. #define isspace ((int (*)(int))((*(int **)0x8300)[72]))
  252. #define sleep ((unsigned int (*)(unsigned int))((*(int **)0x8300)[73]))
  253. #define mem64 ((int (*)(int, unsigned long long, unsigned long long, unsigned long long))((*(int **)0x8300)[74]))
  254. //int envi_cmd(const char *var,char * const env,int flags);
  255. #define envi_cmd ((int (*)(const char*, char *const, int))((*(int **)0x8300)[75]))

  256. /* strncmpx 增强型字符串比较函数 by chenall 2011-12-13
  257.         int strncmpx(const char *s1,const char *s2, unsigned long n, int case_insensitive)
  258.         比较两个字符串s1,s2.长度: n,
  259.         如果n等于0,则只比较到字符串结束位置。否则比较指定长度n.不管字符串是否结束。
  260.         如果case_insensitive非0,比较字母时不区分大小写。
  261.         可以替换strcmp/memcmp等字符串比较函数
  262.         返回值: s1-s2
  263.                 当s1<s2时,返回值<0
  264.                 当s1=s2时,返回值=0
  265.                 当s1>s2时,返回值>0
  266. */
  267. #define strncmpx ((int (*)(const char*, const char*, unsigned long,int))((*(int **)0x8300)[76]))
  268. /*
  269.         以下几个字符串比较都是使用strncmpx来实现
  270. */
  271. //比较字符串s1和s2。
  272. #define strcmp(s1,s2) strncmpx(s1,s2,0,0)
  273. //比较字符串s1和s2。不区分大小写
  274. #define stricmp(s1,s2) strncmpx(s1,s2,0,1)
  275. #define strcmpi stricmp
  276. //比较字符串s1和s2的前n个字符。
  277. #define strncmp(s1,s2,n) strncmpx(s1,s2,n,0)
  278. //比较字符串s1和s2的前n个字符但不区分大小写。
  279. #define strnicmp(s1,s2,n) strncmpx(s1,s2,n,1)
  280. #define strncmpi strnicmp

  281. //void rectangle(int left, int top, int length, int width, int line);
  282. #define rectangle ((void (*)(int,int,int,int,int))((*(int **)0x8300)[77]))

  283. #define get_cmdline ((int (*)(void))((*(int **)0x8300)[78]))

  284. #define RAW_ADDR(x) (x)
  285. #define SCRATCHADDR  RAW_ADDR (0x37e00)
  286. #define MBR ((char *)0x8000)
  287. //#define grub_memcmp memcmp
  288. struct get_cmdline_arg
  289. {
  290.         char *cmdline;
  291.         char *prompt;
  292.         int maxlen;
  293.         int echo_char;
  294.         int readline;
  295. } __attribute__ ((packed));

  296. struct geometry
  297. {
  298.   /* The number of cylinders */
  299.   unsigned long cylinders;
  300.   /* The number of heads */
  301.   unsigned long heads;
  302.   /* The number of sectors */
  303.   unsigned long sectors;
  304.   /* The total number of sectors */
  305.   unsigned long long total_sectors;
  306.   /* Device sector size */
  307.   unsigned long sector_size;
  308.   /* Flags */
  309.   unsigned long flags;
  310. };

  311. /* fsys.h */
  312. struct fsys_entry
  313. {
  314.   char *name;
  315.   int (*mount_func) (void);
  316.   unsigned long (*read_func) (unsigned long long buf, unsigned long long len, unsigned long write);
  317.   int (*dir_func) (char *dirname);
  318.   void (*close_func) (void);
  319.   unsigned long (*embed_func) (unsigned long *start_sector, unsigned long needed_sectors);
  320. };
  321. /* fsys.h */

  322. /* shared.h */
  323. struct master_and_dos_boot_sector {
  324. /* 00 */ char dummy1[0x0b]; /* at offset 0, normally there is a short JMP instuction(opcode is 0xEB) */
  325. /* 0B */ unsigned short bytes_per_sector __attribute__ ((packed));/* seems always to be 512, so we just use 512 */
  326. /* 0D */ unsigned char sectors_per_cluster;/* non-zero, the power of 2, i.e., 2^n */
  327. /* 0E */ unsigned short reserved_sectors __attribute__ ((packed));/* FAT=non-zero, NTFS=0? */
  328. /* 10 */ unsigned char number_of_fats;/* NTFS=0; FAT=1 or 2  */
  329. /* 11 */ unsigned short root_dir_entries __attribute__ ((packed));/* FAT32=0, NTFS=0, FAT12/16=non-zero */
  330. /* 13 */ unsigned short total_sectors_short __attribute__ ((packed));/* FAT32=0, NTFS=0, FAT12/16=any */
  331. /* 15 */ unsigned char media_descriptor;/* range from 0xf0 to 0xff */
  332. /* 16 */ unsigned short sectors_per_fat __attribute__ ((packed));/* FAT32=0, NTFS=0, FAT12/16=non-zero */
  333. /* 18 */ unsigned short sectors_per_track __attribute__ ((packed));/* range from 1 to 63 */
  334. /* 1A */ unsigned short total_heads __attribute__ ((packed));/* range from 1 to 256 */
  335. /* 1C */ unsigned long hidden_sectors __attribute__ ((packed));/* any value */
  336. /* 20 */ unsigned long total_sectors_long __attribute__ ((packed));/* FAT32=non-zero, NTFS=0, FAT12/16=any */
  337. /* 24 */ unsigned long sectors_per_fat32 __attribute__ ((packed));/* FAT32=non-zero, NTFS=any, FAT12/16=any */
  338. /* 28 */ unsigned long long total_sectors_long_long __attribute__ ((packed));/* NTFS=non-zero, FAT12/16/32=any */
  339. /* 30 */ char dummy2[0x18e];

  340.     /* Partition Table, starting at offset 0x1BE */
  341. /* 1BE */ struct {
  342.         /* +00 */ unsigned char boot_indicator;
  343.         /* +01 */ unsigned char start_head;
  344.         /* +02 */ unsigned short start_sector_cylinder __attribute__ ((packed));
  345.         /* +04 */ unsigned char system_indicator;
  346.         /* +05 */ unsigned char end_head;
  347.         /* +06 */ unsigned short end_sector_cylinder __attribute__ ((packed));
  348.         /* +08 */ unsigned long start_lba __attribute__ ((packed));
  349.         /* +0C */ unsigned long total_sectors __attribute__ ((packed));
  350.         /* +10 */
  351.     } P[4];
  352. /* 1FE */ unsigned short boot_signature __attribute__ ((packed));/* 0xAA55 */
  353. #if 0
  354.          /* This starts at offset 0x200 */
  355. /* 200 */ unsigned long probed_total_sectors __attribute__ ((packed));
  356. /* 204 */ unsigned long probed_heads __attribute__ ((packed));
  357. /* 208 */ unsigned long probed_sectors_per_track __attribute__ ((packed));
  358. /* 20C */ unsigned long probed_cylinders __attribute__ ((packed));
  359. /* 210 */ unsigned long sectors_per_cylinder __attribute__ ((packed));
  360. /* 214 */ char dummy3[0x0c] __attribute__ ((packed));

  361.     /* matrix of coefficients of linear equations
  362.      *
  363.      *   C[n] * (H_count * S_count) + H[n] * S_count = LBA[n] - S[n] + 1
  364.      *
  365.      * where n = 1, 2, 3, 4, 5, 6, 7, 8
  366.      */
  367.          /* This starts at offset 0x130 */
  368. /* 220 */ long long L[9] __attribute__ ((packed)); /* L[n] == LBA[n] - S[n] + 1 */
  369. /* 268 */ long H[9] __attribute__ ((packed));
  370. /* 28C */ short C[9] __attribute__ ((packed));
  371. /* 29E */ short X __attribute__ ((packed));
  372. /* 2A0 */ short Y __attribute__ ((packed));
  373. /* 2A2 */ short Cmax __attribute__ ((packed));
  374. /* 2A4 */ long Hmax __attribute__ ((packed));
  375. /* 2A8 */ unsigned long Z __attribute__ ((packed));
  376. /* 2AC */ short Smax __attribute__ ((packed));
  377. /* 2AE */
  378. #endif
  379.   };

  380. struct drive_map_slot
  381. {
  382.         /* Remember to update DRIVE_MAP_SLOT_SIZE once this is modified.
  383.          * The struct size must be a multiple of 4.
  384.          */

  385.           /* X=max_sector bit 7: read only or fake write */
  386.           /* Y=to_sector  bit 6: safe boot or fake write */
  387.           /* ------------------------------------------- */
  388.           /* X Y: meaning of restrictions imposed on map */
  389.           /* ------------------------------------------- */
  390.           /* 1 1: read only=0, fake write=1, safe boot=0 */
  391.           /* 1 0: read only=1, fake write=0, safe boot=0 */
  392.           /* 0 1: read only=0, fake write=0, safe boot=1 */
  393.           /* 0 0: read only=0, fake write=0, safe boot=0 */

  394.         unsigned char from_drive;
  395.         unsigned char to_drive;                /* 0xFF indicates a memdrive */
  396.         unsigned char max_head;
  397.         unsigned char max_sector;        /* bit 7: read only */
  398.                                         /* bit 6: disable lba */

  399.         unsigned short to_cylinder;        /* max cylinder of the TO drive */
  400.                                         /* bit 15:  TO  drive support LBA */
  401.                                         /* bit 14:  TO  drive is CDROM(with big 2048-byte sector) */
  402.                                         /* bit 13: FROM drive is CDROM(with big 2048-byte sector) */

  403.         unsigned char to_head;                /* max head of the TO drive */
  404.         unsigned char to_sector;        /* max sector of the TO drive */
  405.                                         /* bit 7: in-situ */
  406.                                         /* bit 6: fake-write or safe-boot */

  407.         unsigned long long start_sector;
  408.         //unsigned long start_sector_hi;        /* hi dword of the 64-bit value */
  409.         unsigned long long sector_count;
  410.         //unsigned long sector_count_hi;        /* hi dword of the 64-bit value */
  411. };


  412. /* shared.h */

  413. typedef enum
  414. {
  415.         COLOR_STATE_STANDARD,
  416.         /* represents the user defined colors for normal text */
  417.         COLOR_STATE_NORMAL,
  418.         /* represents the user defined colors for highlighted text */
  419.         COLOR_STATE_HIGHLIGHT,
  420.         /* represents the user defined colors for help text */
  421.         COLOR_STATE_HELPTEXT,
  422.         /* represents the user defined colors for heading line */
  423.         COLOR_STATE_HEADING
  424. } color_state;

  425. struct term_entry
  426. {
  427.   /* The name of a terminal.  */
  428.   const char *name;
  429.   /* The feature flags defined above.  */
  430.   unsigned long flags;
  431.   unsigned short chars_per_line;
  432.   /* Default for maximum number of lines if not specified */
  433.   unsigned short max_lines;
  434.   /* Put a character.  */
  435.   void (*PUTCHAR) (int c);
  436.   /* Check if any input character is available.  */
  437.   int (*CHECKKEY) (void);
  438.   /* Get a character.  */
  439.   int (*GETKEY) (void);
  440.   /* Get the cursor position. The return value is ((X << 8) | Y).  */
  441.   int (*GETXY) (void);
  442.   /* Go to the position (X, Y).  */
  443.   void (*GOTOXY) (int x, int y);
  444.   /* Clear the screen.  */
  445.   void (*CLS) (void);
  446.   /* Set the current color to be used */
  447.   void (*SETCOLORSTATE) (color_state state);
  448.   /* Set the normal color and the highlight color. The format of each
  449.      color is VGA's.  */
  450.   void (*SETCOLOR) (unsigned long state,unsigned long long color[]);
  451.   /* Turn on/off the cursor.  */
  452.   int (*SETCURSOR) (int on);

  453.   /* function to start a terminal */
  454.   int (*STARTUP) (void);
  455.   /* function to use to shutdown a terminal */
  456.   void (*SHUTDOWN) (void);
  457. };

  458. /* The table for a builtin.  */
  459. struct builtin
  460. {
  461.   /* The command name.  */
  462.   char *name;
  463.   /* The callback function.  */
  464.   int (*func) (char *, int);
  465.   /* The combination of the flags defined above.  */
  466.   int flags;
  467.   /* The short version of the documentation.  */
  468.   char *short_doc;
  469.   /* The long version of the documentation.  */
  470.   char *long_doc;
  471. };

  472. #endif
复制代码

点评

谢谢,还有fat外部命令的源码哪边能搞到  详情 回复 发表于 2014-12-4 12:25
谢了,看来我得先实现一套C标准库的功能了  详情 回复 发表于 2014-12-4 11:51
回复

使用道具 举报

6#
 楼主| 发表于 2014-12-4 11:51:07 来自手机 | 只看该作者
chenall 发表于 2014-12-4 08:35
不要使用C自带的函数.直接调用grub4dos提供的函数

flags可以不用管它,这个是用于判断当前命令运行的环境 ...

谢了,看来我得先实现一套C标准库的功能了
回复

使用道具 举报

7#
 楼主| 发表于 2014-12-4 12:25:37 来自手机 | 只看该作者
chenall 发表于 2014-12-4 08:35
不要使用C自带的函数.直接调用grub4dos提供的函数

flags可以不用管它,这个是用于判断当前命令运行的环境 ...

谢谢,还有fat外部命令的源码哪边能搞到
回复

使用道具 举报

8#
发表于 2014-12-5 09:36:25 | 只看该作者
要学会翻Q,很多好的东西都在外面的世界呢,,
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-12-2 16:55

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表