linux-0.11调试教程,fdisk for linux-0.11 by chenghao0511

来源:互联网 发布:网络电视看翡翠台 编辑:程序博客网 时间:2024/05/29 10:32

csdn下载:http://download.csdn.net/detail/sitelist/5065652

fdisk-by-chenghao0511 for linux-0.11

2014年1月11日更新,fdiskch,第二版,此版本可以使shoelace启动,第二可以以此制作一个把

Image放到硬盘分区前面,直接启动系统。

http://pan.baidu.com/s/13oTQ2  里面的fdiskch-inlinux.rar


百度网盘下载地址

http://pan.baidu.com/share/link?shareid=330227&uk=453348606

2013/2/16 by chenghao0511 # gmail.com

patch to:
/fs/ioctl.c
/include/linux/hdreg.h
/kernel/blk_drv/hd.c


打补丁的目的是获得hd_info[dev]的硬盘信息,既磁头数,磁道数,扇区数。

13年12月30日更新:把

+     dev = MINOR(dev) >> 6;

改为:

+     dev = MINOR(dev) >> 2;

fdisk-0.91编译的时候应该把/dev/hda改为/dev/hd0才会正常运行,也就是不犯错。





如何给内核打补丁:

diff -rc2N linux/fs/ioctl.c extra/fs/ioctl.c
*** linux-0.95a/fs/ioctl.c    Thu Feb 20 15:01:13 1992
--- linux/fs/ioctl.c    Tue Mar 31 10:09:50 1992
***************
*** 11,14 ****
--- 11,15 ----
  #include <linux/sched.h>
 
+ extern int hd_ioctl(int dev, int cmd, int arg);
  extern int tty_ioctl(int dev, int cmd, int arg);
  extern int pipe_ioctl(struct inode *pino, int cmd, int arg);
***************
*** 22,26 ****
      NULL,        /* /dev/mem */
      NULL,        /* /dev/fd */
!     NULL,        /* /dev/hd */
      tty_ioctl,    /* /dev/ttyx */
      tty_ioctl,    /* /dev/tty */
--- 23,27 ----
      NULL,        /* /dev/mem */
      NULL,        /* /dev/fd */
!     hd_ioctl,    /* /dev/hd */
      tty_ioctl,    /* /dev/ttyx */
      tty_ioctl,    /* /dev/tty */
diff -rc2N linux/include/linux/hdreg.h extra/include/linux/hdreg.h
*** linux-0.95a/include/linux/hdreg.h    Sat Feb  1 14:04:36 1992
--- linux/include/linux/hdreg.h    Sat Mar 28 19:57:00 1992
***************
*** 65,67 ****
--- 65,74 ----
  };
 
+ #define HDIO_REQ 0x301
+ struct hd_geometry {
+     unsigned char heads;
+     unsigned char sectors;
+     unsigned short cylinders;
+ };
+
  #endif
diff -rc2N linux/kernel/blk_drv/hd.c extra/kernel/blk_drv/hd.c
*** linux-0.95a/kernel/blk_drv/hd.c    Tue Mar 31 09:57:31 1992
--- linux/kernel/blk_drv/hd.c    Wed Mar 25 08:56:24 1992
***************
*** 26,29 ****
--- 26,30 ----
  #include <asm/io.h>
  #include <asm/segment.h>
+ #include <errno.h>
 
  #define MAJOR_NR 3
***************
*** 431,433 ****
--- 511,537 ----
      outb(inb_p(0xA1)&0xbf,0xA1);
      timer_table[HD_TIMER].fn = hd_times_out;
+ }
+
+ int hd_ioctl(int dev, int cmd, int arg)
+ {
+     struct hd_geometry *loc = (void *) arg;
+
+     if (!loc)
+         return -EINVAL;
+     dev = MINOR(dev) >> 6;
+     if (dev >= NR_HD)
+         return -EINVAL;
+
+     switch (cmd) {
+         case HDIO_REQ:
+             put_fs_byte(hd_info[dev].head,
+                 (unsigned char *) &loc->heads);
+             put_fs_byte(hd_info[dev].sect,
+                 (unsigned char *) &loc->sectors);
+             put_fs_word(hd_info[dev].cyl,
+                 (unsigned short *) &loc->cylinders);
+             return 0;
+         default:
+             return -EINVAL;
+     }
  }



原创粉丝点击