i am not familiar with ide.c
1) if u want to get what add_gd_partition() get, for example, see extended_partition() in msdos.c. it call read_dev_sector() to get data from disk then call add_hd_partition with these info. but i am not sure what u can do while system is init. after system init, if u want this info, in kernel space u can read the genhd list. in user space, i believe fdisk use ioctl to get this info. u can check ide_ioctl in ide.c and see HDIO_GETGEO in hdreg.h. u can use 'strace fdisk' to see that fdisk call ioctl with 0x301. and 0x301 is defined as HDIO_GETGEO in hdreg.h.
2) i think read_dev_sector can do what u want. but it looks that it can only be used after system init. since it use page cache, page io. and go over block layer io.
are these right? u need check it by uself.
btw, u want to code user space code or kernel module? or both?
谢谢cheungming的提示!
我想直接修改IDE驱动达到目的,所以应该算 kernel module.
"after system init, if u want this info, in kernel space u can read the genhd list. "意思是否是可以做一个模块,来完成这个功能?我有一点不明白:怎样获得genhd list呢?请继续指教
i forget this in genhd.c
/*
* Global kernel list of partitioning information.
*
* XXX: you should _never_ access this directly.
* the o
so u had better not access gendisk_head or gendisk_array directly. i think u can use get_gendisk, walk_gendisk... in genhd.c to get the value stored by add_gd_partition.
u write to ide controller directly? i do not think this is a good idea. linux lldd already does this. so if u also do this, u may have conflict with it. u still need to use some high level functions to finish this. at least this is my thought. anyway, good luck