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

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

1.参数的接收

2.参数的解析

3.参数的应用

问题:

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

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

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

文件系统初始化流程

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: <id>:<runlevels>:<action>:<process>

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

cs 复制代码
static void new_init_action(int action, const char *command, const char *cons)
{
	struct init_action *new_action, *a, *last;

	if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
		return;

	/* Append to the end of the list */
	for (a = last = init_action_list; a; a = a->next) {
		/* don't enter action if it's already in the list,
		 * but do overwrite existing actions */
		if ((strcmp(a->command, command) == 0)
		 && (strcmp(a->terminal, cons) == 0)
		) {
			a->action = action;
			return;
		}
		last = a;
	}

	new_action = xzalloc(sizeof(struct init_action));
	if (last) {
		last->next = new_action;
	} else {
		init_action_list = new_action;
	}
	strcpy(new_action->command, command);
	new_action->action = action;
	strcpy(new_action->terminal, cons);
	messageD(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n",
		new_action->command, new_action->action, new_action->terminal);
}

struct init_action {
	struct init_action *next;
	int action;
	pid_t pid;
	char command[INIT_BUFFS_SIZE];
	char terminal[CONSOLE_NAME_SIZE];
};

默认的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);

cs 复制代码
	while (1) {
		/* run the respawn stuff */
		run_actions(RESPAWN);

		/* run the askfirst stuff */
		run_actions(ASKFIRST);//:/bin/sh

		/* Don't consume all CPU time -- sleep a bit */
		sleep(1);

		/* Wait for a child process to exit */
		wpid = wait(NULL);
		while (wpid > 0) {
			/* Find out who died and clean up their corpse */
			for (a = init_action_list; a; a = a->next) {
				if (a->pid == wpid) {
					/* Set the pid to 0 so that the process gets
					 * restarted by run_actions() */
					a->pid = 0;
					message(L_LOG, "process '%s' (pid %d) exited. "
							"Scheduling it for restart.",
							a->command, wpid);
				}
			}
			/* see if anyone else is waiting to be reaped */
			wpid = waitpid(-1, NULL, WNOHANG);
		}
	}

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

1./dev/console

2.init_main函数---->busybox

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

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

5.标准库函数,包含glibc

相关推荐
IT 古月方源16 分钟前
ospf 的 状态机详解
运维·网络·tcp/ip·智能路由器
dog25020 分钟前
UDP 比 TCP 更快吗?
网络·tcp/ip·udp
hc_bmxxf27 分钟前
Linux应用软件编程-多任务处理(进程)
linux·运维·服务器
一勺汤36 分钟前
YOLO11改进-模块-引入星型运算Star Blocks
网络·yolo·目标检测·改进·魔改·yolov11·yolov11改进
ChennyWJS37 分钟前
03.HTTPS的实现原理-HTTPS的工作流程
网络·网络协议·http·https
M-C-B1 小时前
配置带外与更改密码
运维·服务器
Hacker_Oldv1 小时前
网络安全攻防学习平台 - 基础关
网络·学习·web安全
沐多1 小时前
波折重重:一个Linux实时系统Xenomai宕机问题的深度定位过程
linux·xenomai·实时linux·xenomai4
猿经验1 小时前
tar.gz压缩文件在linux上解压异常问题:gzip:stdin:invalid compressed data
linux·运维·服务器
木卫二号Coding1 小时前
宝塔-firefox(Docker应用)-构建自己的Web浏览器
linux·docker·开源