• day14-文件系统工作流程分析


    1.内核启动文件系统后,文件系统的工作流程

            1.参数的接收

            2.参数的解析

            3.参数的应用

    问题:

    1.        UBOOT 传给 KERNEL 的参数是以tagglist进行的

               KERNEL 传给 文件系统(busybox)的参数是以什么进行的? 

    2.        在整个文件系统中都需要什么组件?

    文件系统初始化流程

    parse_inittab()

            file = fopen(INITTAB, "r");        //#define INITTAB      "/etc/inittab"

            if (file == NULL) {

                    /* Reboot on Ctrl-Alt-Del */

                    new_init_action(CTRLALTDEL, "reboot", "");

                    /* Umount all filesystems on halt/reboot */

                    new_init_action(SHUTDOWN, "umount -a -r", "");

                    /* Swapoff on halt/reboot */

                    if (ENABLE_SWAPONOFF) new_init_action(SHUTDOWN, "swapoff -a", "");

                    /* Prepare to restart init when a HUP is received */

                    new_init_action(RESTART, "init", "");

                    /* Askfirst shell on tty1-4 */

                    new_init_action(ASKFIRST, bb_default_login_shell, "");

                    new_init_action(ASKFIRST, bb_default_login_shell, VC_2);

                    new_init_action(ASKFIRST, bb_default_login_shell, VC_3);

                    new_init_action(ASKFIRST, bb_default_login_shell, VC_4);

                    /* sysinit */

                    new_init_action(SYSINIT, INIT_SCRIPT, "");

    inittab的格式:

                    Format for each entry: :::

    文件系统默认的参数解析:

    1. static void new_init_action(int action, const char *command, const char *cons)
    2. {
    3. struct init_action *new_action, *a, *last;
    4. if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
    5. return;
    6. /* Append to the end of the list */
    7. for (a = last = init_action_list; a; a = a->next) {
    8. /* don't enter action if it's already in the list,
    9. * but do overwrite existing actions */
    10. if ((strcmp(a->command, command) == 0)
    11. && (strcmp(a->terminal, cons) == 0)
    12. ) {
    13. a->action = action;
    14. return;
    15. }
    16. last = a;
    17. }
    18. new_action = xzalloc(sizeof(struct init_action));
    19. if (last) {
    20. last->next = new_action;
    21. } else {
    22. init_action_list = new_action;
    23. }
    24. strcpy(new_action->command, command);
    25. new_action->action = action;
    26. strcpy(new_action->terminal, cons);
    27. messageD(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n",
    28. new_action->command, new_action->action, new_action->terminal);
    29. }
    30. struct init_action {
    31. struct init_action *next;
    32. int action;
    33. pid_t pid;
    34. char command[INIT_BUFFS_SIZE];
    35. char terminal[CONSOLE_NAME_SIZE];
    36. };

    默认的inittab:   

    ::ctrlaltdel:/sbin/reboot

    ::shutdown:/sbin/swapoff -a

    ::shutdown:/bin/umount -a -r

    ::restart:/sbin/init

    ::askfirst:/bin/sh

    tty2::askfirst:/bin/sh

    tty3::askfirst:/bin/sh

    tty4::askfirst:/bin/sh

    ::SYSINIT:/etc/init.d/rcS

    参数使用流程

            run_actions(SYSINIT);

                    waitfor(a, 0);  //运行该action对应的命令函数,并且等待其退出

    启动流程:

              run_actions(SYSINIT);  //运行::SYSINIT:/etc/init.d/rcS脚本,并且等待退出

              run_actions(WAIT);

              run_actions(ONCE);

    1. while (1) {
    2. /* run the respawn stuff */
    3. run_actions(RESPAWN);
    4. /* run the askfirst stuff */
    5. run_actions(ASKFIRST);//:/bin/sh
    6. /* Don't consume all CPU time -- sleep a bit */
    7. sleep(1);
    8. /* Wait for a child process to exit */
    9. wpid = wait(NULL);
    10. while (wpid > 0) {
    11. /* Find out who died and clean up their corpse */
    12. for (a = init_action_list; a; a = a->next) {
    13. if (a->pid == wpid) {
    14. /* Set the pid to 0 so that the process gets
    15. * restarted by run_actions() */
    16. a->pid = 0;
    17. message(L_LOG, "process '%s' (pid %d) exited. "
    18. "Scheduling it for restart.",
    19. a->command, wpid);
    20. }
    21. }
    22. /* see if anyone else is waiting to be reaped */
    23. wpid = waitpid(-1, NULL, WNOHANG);
    24. }
    25. }

    一个文件系统都需要什么?

            1./dev/console        

            2.init_main函数---->busybox

            3./etc/init.d/rcS--脚本

            4.因为需要运行shell命令,所以要有shell命令的支持函数--->busybox

            5.标准库函数,包含glibc

  • 相关阅读:
    MySQL--MySQL索引事务
    程序员的七夕怎么过?不会是写代码吧
    利用go多态实现一个简单工厂模式
    基于PHP+MySQL企业网站的设计与开发
    Windows使用ssh协议远程连接ubuntu linux子系统
    python中使用缓存技术
    基于PLC的自动售货机设计
    PON网络是什么
    Android Glide 3.8 常见方法总结 【圆角、下载、回调】
    [免费专栏] Android安全之Xposed插件开发【从零手把手带】教程
  • 原文地址:https://blog.csdn.net/weixin_66218530/article/details/134325463