find命令的使用方法:
"find [--set-root[=DIR]] [--devices=DEVLIST] [--ignore-floppies] [--ignore-cd] [FILENAME] [CONDITION]",
说明:
在所有设备的所有分区中搜索文件名“ FILENAME”(首先在当前启动设备上寻找),打印包含该文件并满足“ CONDITION”要求的设备列表。 “ CONDITION”是普通的grub命令,对于TRUE返回非零,对于FALSE返回零。
如果使用了--set-root选项,并且在设备上找到“ FILENAME”,则立即停止查找并将设备(如"(hdn,m)")设置为新的根目录,如果--set-root其后跟了一个路径,如--set-root=/123/456/则根目录需要加上这个路径(如"(hdn,m)/123/456/")。
如果存在--ignore-floppies选项,则搜索将绕过所有软盘,--ignore-cd将跳过CDROM。
“ DEVLIST”指定搜索设备和顺序,默认的“ DEVLIST”为“ upnhcf”。 “ DEVLIST”必须是这些字母(u,p,n,h,c,f)的组合。”u,p,n,h,c,f 分别对应 ud(udfs设备), pd(PXE设备),nd(网络驱动器,实际已废弃),hd(硬盘),cd(CDROM),fd(软盘)。
示例:
find --set-root --devices=h /BOOT/BOOT10PE
在所有的硬盘上的各个分区里寻找/BOOT/BOOT10PE文件,如果找到就将该分区作为根设备(root)。
find命令的实现如下:
/*
arg是一行命令,flags是正在执行的环境(menu/script)
注意find命令可以在Menu下执行,也可以在"title"下执行,详见下面"find"命令对应builtin中的flags。
*/
static int
find_func(char *arg, int flags)
{
struct builtin *builtin1 = 0;
// int ret;
char *filename;
unsigned long drive;
unsigned long tmp_drive = saved_drive;
unsigned long tmp_partition = saved_partition;
unsigned long got_file = 0;
char *set_root = 0;
unsigned long ignore_cd = 0;
unsigned long ignore_floppies = 0;
unsigned long ignore_oem = 0;
char find_devices[8] = "pnuhcf";//这是默认的寻找顺序:pd->nd->ud->hd->cd->fd
//char *in_drives = NULL; /* search in drive list */
// char root_found[16];
errnum = 0;
#ifdef FSYS_FB
if (saved_drive == FB_DRIVE && !(unsigned char)(fb_status >> 8))
{
*(unsigned long *)&find_devices[3] = 0x686366;
}
#endif
/*
解析各命令行参数,"--set-root"/"--ignore-cd"/"--ignore-floppies"/"--ignore-oem"/"--devices="
root的格式类似"(%d,%d)%s