- 论坛徽章:
- 4
|
20可用积分
本帖最后由 chishanmingshen 于 2013-01-25 09:30 编辑
from 3.6.10
populate_rootfs()->unpack_to_rootfs() 做新的initramfs或者旧的initrd的文件拷贝操作。
1. 可是我不明白的是拷贝到哪里去?不用指定文件名字么?比如initrd方式(非cpio)时,内核会建好文件/initrd.image,然后写入。
2. 此时是实际根文件系统是哪里加载的?因为后续才会加载实际根文件系统.
3. header_buf symlink_buf name_buf : 这几个全局变量的作用是?
4. 请指点这个函数的具体机制.
谢谢!
- static char * __init unpack_to_rootfs(char *buf, unsigned len)
- {
- int written, res;
- decompress_fn decompress;
- const char *compress_name;
- static __initdata char msg_buf[64];
- header_buf = kmalloc(110, GFP_KERNEL);
- symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
- name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
- if (!header_buf || !symlink_buf || !name_buf)
- panic("can't allocate buffers");
- state = Start;
- this_header = 0;
- message = NULL;
- while (!message && len) {
- loff_t saved_offset = this_header;
- if (*buf == '0' && !(this_header & 3)) {
- state = Start;
- written = write_buffer(buf, len);<---(*actions[])将数据写到哪里去了?求详解。。
- buf += written;
- len -= written;
- continue;
- }
- if (!*buf) {
- buf++;
- len--;
- this_header++;
- continue;
- }
- this_header = 0;
- decompress = decompress_method(buf, len, &compress_name);
- if (decompress) {
- res = decompress(buf, len, NULL, flush_buffer, NULL,
- &my_inptr, error);
- if (res)
- error("decompressor failed");
- } else if (compress_name) {
- if (!message) {
- snprintf(msg_buf, sizeof msg_buf,
- "compression method %s not configured",
- compress_name);
- message = msg_buf;
- }
- } else
- error("junk in compressed archive");
- if (state != Reset)
- error("junk in compressed archive");
- this_header = saved_offset + my_inptr;
- buf += my_inptr;
- len -= my_inptr;
- }
- dir_utime();
- kfree(name_buf);
- kfree(symlink_buf);
- kfree(header_buf);
- return message;
- }
复制代码 |
最佳答案
查看完整内容
回复 3# chishanmingshen 就是这个"unpack_to_rootfs就是将initramfs或者initrd的内容释放到"/"那里", 我搞不明白其中的奥秘...任何文件系统的访问都要以来于建立在RAM中的文件系统相关的数据结构,这些最基本的数据结构就是位于RAM中的"/",当需要访问外部的存储器而不是在RAM中的该如何办呢?在RAM中的“/”留一个挂在点去mount,来搭建一条访问的路径。unpack_to_rootfs做的就是在RAM的“/”建立ramdisk中事先建立好的一些 ...
|