๊ด€๋ฆฌ ๋ฉ”๋‰ด

๋ง๊ฐ๋กœ๊ทธ

ํฌ๋ž˜ํ”„ํ†ค ์ •๊ธ€ WEEK09 DAY71 - PintOS Project2 open, process_add_file ๋ณธ๋ฌธ

Krafton jungle

ํฌ๋ž˜ํ”„ํ†ค ์ •๊ธ€ WEEK09 DAY71 - PintOS Project2 open, process_add_file

habbn 2024. 3. 18. 23:48
728x90
๐Ÿ“†2024.3.18

1. system call - open(), process_add_file() ๊ตฌํ˜„

 

System Call 

 

1. open()

file ์„ ์—ด๊ธฐ ์œ„ํ•ด์„œ๋Š” ์‹œ์Šคํ…œ ์ฝœ open() ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค.

open์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” 

1. file์ด ์œ ํšจํ•œ ์ฃผ์†Œ๊ฐ’์ธ์ง€๋ฅผ ๊ฒ€์ฆํ•ด์•ผ ํ•œ๋‹ค.

2. filesys_open๋ฅผ ํ˜ธ์ถœํ•ด์„œ ํŒŒ์ผ์„ openํ•œ๋‹ค.

3. process_add_file ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด์„œ ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ ํ…Œ์ด๋ธ”์— ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•˜๊ณ  fd๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

4. ํŒŒ์ผ๋””์Šคํฌ๋ฆฝํ„ฐ ํ…Œ์ด๋ธ”์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ(fd == -1)์ธ ๊ฒฝ์šฐ์—” ํŒŒ์ผ์„ ๋‹ซ๊ณ  -1์„ ๋ฆฌํ„ดํ•œ๋‹ค.

5. ์˜คํ”ˆํ•œ ํŒŒ์ผ์˜ fd๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

int open (const char *file)
{
	check_address(file);
	struct file *f = filesys_open(file);	

	if(f != NULL)
	{
		int fd = process_add_file(f);
		return fd;
	}
	else
		return -1;
}

 

1-2 process_add_file()

 

ํ˜„์žฌ ์Šค๋ ˆ๋“œ์˜ ํŒŒ์ผ๋””์Šคํฌ๋ฆฝํ„ฐ์— ํ˜„์žฌ ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

ํ•ด๋‹น ํŒŒ์ผ์˜ ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ ๋ฒˆํ˜ธ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

int process_add_file(struct file *file)
{
	struct thread *curr = thread_current();
	struct file_discrpitor *cur_fd = malloc(sizeof(struct file_discrpitor));
	struct list *fd_list = &thread_current()->fd_list;
	
	cur_fd->file = file;
	cur_fd->fd_num = (curr->last_create_fd)++;	
	
	list_push_back(fd_list, &cur_fd->fd_elem);

	return cur_fd->fd_num; 
}

 

 

 

728x90