Chinaunix首页 | 论坛 | 博客
  • 博客访问: 952290
  • 博文数量: 113
  • 博客积分: 7235
  • 博客等级: 少将
  • 技术积分: 2101
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-14 11:24
文章分类

全部博文(113)

文章存档

2013年(7)

2012年(5)

2011年(6)

2010年(8)

2009年(15)

2008年(72)

分类: LINUX

2009-04-17 21:26:11

上节我们说到使用genromfs工具生成romfs映像,现在我们一一详细讲述genromfs的各个参数的含义及用法。
1. -f参数
   该参数指定要生成的romfs映像的名字,是一个必须参数,如果缺少,则无法生成映像。例如:

niutao@niutao:~/kernel/romfs$ ls
hello.c
niutao@niutao:~/kernel/romfs$ genromfs -f hello.img
niutao@niutao:~/kernel/romfs$ ls
hello.c hello.img

  可以看到生成了名为hello.img的romfs格式的映像。那么genromfs是将那个目录制作成了hello.img?将hello.img挂载之后,可以看到其内的文件为当前路径下的文件(hello.c和hello.img)。所以在没有指定源目录(要将那个目录制作成romfs映像)的时候,默认为当前目录。这一点也可以从genromfs的源代码中看到:

701 int main(int argc, char *argv[])
702 {
703 int c;
704 char *dir = ".";
705 char *outf = NULL;
706 char *volname = NULL;

注:代码摘自genromfs-0.5.2/genromfs.c。
可以看到其中的dir就是指定的源目录,默认为当前目录。那么如何指定源目录?通过使用-d参数指定。

2. -d参数
    该参数指定源目录,意思是要将那个目录及其下面的文件制作成romfs格式的映像。如果不使用-d参数指定,则默认为当前目录。例如:

niutao@niutao:~/kernel/romfs$ ls
hello
niutao@niutao:~/kernel/romfs$ ls hello/
hello.c
niutao@niutao:~/kernel/romfs$ genromfs -f hello.img -d hello/
niutao@niutao:~/kernel/romfs$ ls
hello hello.img
niutao@niutao:~/kernel/romfs$

3. -v参数
    -v表示显示romfs映像创建的详细过程。例如:

niutao@niutao:~/kernel/romfs$ ls
hello
niutao@niutao:~/kernel/romfs$ genromfs -f hello.img -d hello/ -v
0 rom 49e06097 [0xffffffff, 0xffffffff] 37777777777, sz 0, at 0x0
1 . [0x80e , 0x1e4204 ] 0040755, sz 0, at 0x20
1 .. [0x80e , 0x1e41ea ] 0040755, sz 0, at 0x40 [link to 0x20 ]
1 hello.c [0x80e , 0x1e4266 ] 0100644, sz 71, at 0x60
niutao@niutao:~/kernel/romfs$ ls
hello hello.img
niutao@niutao:~/kernel/romfs$

(1).第一列为目录深度(0为顶极目录),各项的含义具体见genromfs.c的shownode函数。
(2).第二列为文件或者目录名。
(3).第三列为前一个为文件或者目录所在设备的设备号,后一个为文件或者目录的节点号(这两个对应struct stat结构体的st_dev项和st_ino项)。
(4).第四列为文件或者目录的属性(对应struct stat结构体的st_mode项)。
(5).第五列为文件或者目录的大小,对于目录为0,文件则为文件以字节为单位的大小。
(6).第六列为文件或者目录在生成的romfs格式映像文件中的偏移。
(7).第七列表示该文件或者目录是一个硬链接,其指向的位置。这里需要注意一个细节:对于顶极目录下的目录,..目录是一个硬链接,除此之外,所有的目录都是目录(也就是说此第七列对于顶极目录下的目录就不存在)。而对于顶极目录下的子目录内的目录,则都是硬链接。这个在往后还会继续从代码的角度分析为什么会是这样(见对genromfs工具的分析)。

4. -V参数
    指定当前要生成的romfs格式映像的卷标,如果没有指定,则默认为字符串"rom "加当前的时间(16进制格式)。例如:

niutao@niutao:~/kernel/romfs$ genromfs -f hello.img -d hello/
niutao@niutao:~/kernel/romfs$ ls
hello hello.img
niutao@niutao:~/kernel/romfs$ file hello.img
hello.img: romfs filesystem, version 1 256 bytes, named rom 49e069d8.
niutao@niutao:~/kernel/romfs$ genromfs -f hello.img -d hello/ -V niutao
niutao@niutao:~/kernel/romfs$ file hello.img
hello.img: romfs filesystem, version 1 256 bytes, named niutao.
niutao@niutao:~/kernel/romfs$

5. -a参数
  指定普通文件的对齐边界(默认为16字节),目的是为了快速访问文件内容。给出的对齐边界值必须大于16并且为16的倍数。这里所说的对齐指的是普通文件的文件内容的对齐,而并非文件头(见内核include/linux/romfs_fs.h中结构体struct romfs_inode )的对齐。假如指定普通文件x的对齐边界为align,其在生成的romfs格式映像中的偏移为start,文件名长度为len,则文件内容在romfs映像中的偏移offset为:
offset = start + 16 + (len / 16) * 16 + len % 16 ? 16 : 0
其计算过程为文件头偏移加上文件头大小(struct romfs_inode),其文件头大小为16字节,再加上文件名以16字节对齐的长度。
例如:


niutao@niutao:~/kernel/romfs$ genromfs -f hello.img -d hello/ -V niutao -a 64 -v
0 niutao [0xffffffff, 0xffffffff] 37777777777, sz 0, at 0x0
1 . [0x80e , 0x1e4204 ] 0040755, sz 0, at 0x20
1 .. [0x80e , 0x1e41ea ] 0040755, sz 0, at 0x40 [link to 0x20 ]
1 hello.c [0x80e , 0x1e4266 ] 0100644, sz 71, at 0x60
niutao@niutao:~/kernel/romfs$

我们使用-a参数指定普通文件的对齐algin = 64。可以看到普通文件hello.c文件头(也叫节点)开始偏移为start = 0x60,文件名长度len = 7,则文件内容起始位置offset为:
offset = start + 16 + (len / 16) * 16 + len % 16 ? 16 : 0
        = 0x60 + 16 + (7 / 16) * 16 + 7 % 16 ? 16 : 0
       = 0x80
其正好对齐在64边界上。
注意:-a参数只对普通文件起作用,如果要对所有或者部分或者指定的文件起作用,则要使用-A或者-x参数。

6. -A参数

genromfs -A ALIGN,PATTERN

    匹配PATTERN的对象对齐在ALIGN边界上。给出的对齐边界值必须大于16并且为16的倍数。和-a不同的是,-A参数可以指定某个文件或者某些文件对其在ALIGN边界上。例如:
指定目录"."对齐在64字节边界上:

niutao@niutao:~/kernel/romfs$ genromfs -f hello.img -d hello/ -v -A 64,.
0 rom 49e08490 [0xffffffff, 0xffffffff] 37777777777, sz 0, at 0x0
1 . [0x80e , 0x1e4204 ] 0040755, sz 0, at 0x40
1 .. [0x80e , 0x1e41ea ] 0040755, sz 0, at 0x60 [link to 0x40 ]
1 hello.c [0x80e , 0x1e4266 ] 0100644, sz 71, at 0x80
niutao@niutao:~/kernel/romfs$


指定所有的.c文件对其在64字节边界上:

niutao@niutao:~/kernel/romfs$ genromfs -f hello.img -d hello/ -v -A 64,*.c
0 rom 49e08553 [0xffffffff, 0xffffffff] 37777777777, sz 0, at 0x0
1 . [0x80e , 0x1e4204 ] 0040755, sz 0, at 0x20
1 .. [0x80e , 0x1e41ea ] 0040755, sz 0, at 0x40 [link to 0x20 ]
1 hello.c [0x80e , 0x1e4266 ] 0100644, sz 71, at 0x60
niutao@niutao:~/kernel/romfs$

7. -x参数
    不包括匹配PATTERN的对象。也就是说在生成romfs格式映像的时候,不包括指定的源目录下的匹配PATTERN的文件或者目录。例如:

niutao@niutao:~/kernel/romfs$ ls -al hello
total 12
drwxr-xr-x 2 niutao niutao 4096 2009-04-11 20:02 .
drwxr-xr-x 3 niutao niutao 4096 2009-04-11 19:49 ..
-rw-r--r-- 1 niutao niutao 0 2009-04-11 20:02 aa.c
-rw-r--r-- 1 niutao niutao 71 2009-04-11 16:54 hello.c
niutao@niutao:~/kernel/romfs$ genromfs -f hello.img -d hello/ -v -x hello.c
0 rom 49e086ed [0xffffffff, 0xffffffff] 37777777777, sz 0, at 0x0
1 . [0x80e , 0x1e4204 ] 0040755, sz 0, at 0x20
1 .. [0x80e , 0x1e41ea ] 0040755, sz 0, at 0x40 [link to 0x20 ]
1 aa.c [0x80e , 0x1e4276 ] 0100644, sz 0, at 0x60

可以看出,我们使用-x参数将hello.c文件过滤掉了,在生成的romfs格式的映像中,没有hello.c。
阅读(5741) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~