๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป CS/์šด์˜์ฒด์ œ

[์šด์˜์ฒด์ œ] 10. File Systems

by nitronium102 2023. 1. 22.

File and File System

1) File 

- ์ด๋ฆ„์„ ํ†ตํ•ด ์ €์žฅํ•˜๋Š” collection : a named collection of related information

- ๋น„ํœ˜๋ฐœ์„ฑ์˜ ๋ณด์กฐ๊ธฐ์–ต์žฅ์น˜์— ์ €์žฅ

- ๋™์ผํ•œ ๋…ผ๋ฆฌ์  ๋‹จ์œ„๋กœ๋„ ์‚ฌ์šฉ๋จ (device special file)

- create, read, write, reposition(lseek - ์–ด๋””๊นŒ์ง€ ์ฝ์—ˆ๋Š”์ง€ ํ‘œ์‹œํ•˜๋Š” ํฌ์ธํ„ฐ), delete, open, close

* open : file์˜ ๋‚ด์šฉ์ด ์•„๋‹Œ metadata๋ฅผ disk์— ์˜ฌ๋ ค๋†“๋Š” ๊ฒƒ

 

2) File attribute(metadata)

ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ์ข… ์ •๋ณด๋“ค

- ํŒŒ์ผ ์ด๋ฆ„, ์œ ํ˜•, ์ €์žฅ๋œ ์œ„์น˜, ํŒŒ์ผ ์‚ฌ์ด์ฆˆ

- ์ ‘๊ทผ ๊ถŒํ•œ(r/w/x), ์‹œ๊ฐ„(์ƒ์„ฑ, ๋ณ€๊ฒฝ, ์‚ฌ์šฉ), ์†Œ์œ ์ž ๋“ฑ

 

3) File system

- OS์—์„œ ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„

- ํŒŒ์ผ ๋ฐ ํŒŒ์ผ์˜ metadata, ๋””๋ ‰ํ† ๋ฆฌ ์ •๋ณด ๋“ฑ์„ ๊ด€๋ฆฌ

- ํŒŒ์ผ์˜ ์ €์žฅ ๋ฐฉ๋ฒ• ๊ฒฐ์ •

- ํŒŒ์ผ์˜ ๋ณดํ˜ธ ๋“ฑ

 

Directory and Logical Disk

1) Directory

ํŒŒ์ผ์˜ metadata ์ค‘ ์ผ๋ถ€๋ฅผ ๋ณด๊ด€ํ•˜๊ณ  ์žˆ๋Š” ์ผ์ข…์˜ ํŠน๋ณ„ํ•œ ํŒŒ์ผ

- ๊ทธ ๋””๋ ‰ํ† ๋ฆฌ์— ์†ํ•œ ํŒŒ์ผ ์ด๋ฆ„ ๋ฐ ํŒŒ์ผ attribute

- search for, create, delete a file

- list a directory, rename a file, traverse a file system

 

2) Partition(Logical Disk)

- OS๊ฐ€ ๋ณด๋Š” DISK = Logical Disk

- ํ•˜๋‚˜์˜ (๋ฌผ๋ฆฌ์ ) ๋””์Šคํฌ ์•ˆ์— ์—ฌ๋Ÿฌ ํŒŒํ‹ฐ์…˜์„ ๋‘๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ 

- ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฌผ๋ฆฌ์ ์ธ ๋””์Šคํฌ๋ฅผ ํ•˜๋‚˜์˜ ํŒŒํ‹ฐ์…˜์œผ๋กœ ๊ตฌ์„ฑํ•˜๊ธฐ๋„ ํ•จ

- (๋ฌผ๋ฆฌ์ ) ๋””์Šคํฌ๋ฅผ ํŒŒํ‹ฐ์…˜์œผ๋กœ ๊ตฌ์„ฑํ•œ ํ›„ ๊ฐ๊ฐ์˜ ํŒŒํ‹ฐ์…˜์— file system์„ ๊น”๊ฑฐ๋‚˜ swap area๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ

 

open()

๋””์Šคํฌ๋กœ๋ถ€ํ„ฐ file์˜ metadata๋ฅผ ๋ฉ”๋ชจ๋ฆฌ๋กœ ๊ฐ€์ง€๊ณ  ์˜ด

directory path์˜ search์— ๋„ˆ๋ฌด ๋งŽ์€ ์‹œ๊ฐ„์ด ์†Œ์š”๋˜๊ธฐ ๋•Œ๋ฌธ์— open์„ read/write์™€ ๋ณ„๊ฐœ๋กœ ๋‘ 

-> ํ•œ ๋ฒˆ openํ•œ file์€ read/write ์‹œ directory search ๋ถˆํ•„์š”

open file table

ํ˜„์žฌ open๋œ ํŒŒ์ผ๋“ค์˜ metadata ๋ณด๊ด€์†Œ(in memory)
system-wideํ•˜๊ฒŒ ํ•˜๋‚˜๋งŒ ์กด์žฌ

๋””์Šคํฌ์˜ metadata๋ณด๋‹ค ๋ช‡ ๊ฐ€์ง€ ์ •๋ณด๊ฐ€ ์ถ”๊ฐ€

- openํ•œ process ์ˆ˜

- file offset : ํŒŒ์ผ์˜ ์–ด๋Š ์œ„์น˜์— ์ ‘๊ทผ ์ค‘์ธ์ง€ ํ‘œ์‹œ(๋ณ„๋„ ํ…Œ์ด๋ธ” ํ•„์š”)

 

file descriptor(file handle, file control block)

process๋งˆ๋‹ค ๊ฐ€์ง€๊ณ  ์žˆ์Œ (per-process)

- open file table์— ๋Œ€ํ•œ ์œ„์น˜ ์ •๋ณด(ํ”„๋กœ์„ธ์Šค ๋ณ„)

* buffer cache

- ์š”์ฒญํ•œ ๋‚ด์šฉ์ด buffer cache์— ์žˆ๋˜ ์—†๋˜ system call์„ ํ†ตํ•ด ๊ฒฐ์ •๊ถŒ์ด OSํ•œํ…Œ๋กœ ๋„˜์–ด๊ฐ

- OS๊ฐ€ cache๋ฅผ ๋ณธ ํ›„ ํ–‰๋™์„ ๊ฒฐ์ •

 

File Protection

๊ฐ file์— ๋Œ€ํ•ด ๋ˆ„๊ตฌ์—๊ฒŒ, ์–ด๋–ค ์œ ํ˜•์˜ ์ ‘๊ทผ(read / write / execution)์„ ํ—ˆ๋ฝํ•  ๊ฒƒ์ธ๊ฐ€?

Access control matrix

1) ํ–‰๋ ฌ ํ˜•ํƒœ : ์‚ฌ์šฉ์ž์™€ ํŒŒ์ผ ์ด๋ฆ„ ๋‚˜์—ด ํ›„ ๊ถŒํ•œ ํ‘œ์‹œ -> ํŠน์ • ์‚ฌ์šฉ์ž๋งŒ ์‚ฌ์šฉํ•˜๋Š” ํŒŒ์ผ์ด ๋งŽ๊ธฐ ๋•Œ๋ฌธ์— ๊ณต๊ฐ„ ๋‚ญ๋น„๊ฐ€ ์‹ฌํ•˜๋‹ค (sparse matrix)

 

2) ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ

๋ชจ๋“  ์‚ฌ์šฉ์ž์— ๋Œ€ํ•ด ๋ชจ๋“  ํŒŒ์ผ์˜ ์ ‘๊ทผ ๊ถŒํ•œ ์ œ์–ด ๊ฐ€๋Šฅ
(-) high overhead

- access control list : ํŒŒ์ผ๋ณ„๋กœ ๋ˆ„๊ตฌ์—๊ฒŒ ์ ‘๊ทผ ๊ถŒํ•œ์ด ์žˆ๋Š”์ง€ ํ‘œ์‹œ

- capability : ์‚ฌ์šฉ์ž๋ณ„๋กœ ์ž์‹ ์ด ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ฐ€์ง„ ํŒŒ์ผ ๋ฐ ํ•ด๋‹น ๊ถŒํ•œ ํ‘œ์‹œ

 

Grouping

์ผ๋ฐ˜์ ์ธ OS์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹ / ๊ต‰์žฅํžˆ ํšจ์œจ์ 

์ „์ฒด user๋ฅผ owner, group, public์˜ ์„ธ ๊ทธ๋ฃน์œผ๋กœ ๊ตฌ๋ถ„

๊ฐ ํŒŒ์ผ์— ๋Œ€ํ•ด ์„ธ ๊ทธ๋ฃน์˜ ์ ‘๊ทผ ๊ถŒํ•œ(rwx)๋ฅผ 3 bit์”ฉ ํ‘œ์‹œ (์ด 9 bit)

 

Password

ํŒŒ์ผ๋งˆ๋‹ค password๋ฅผ ๋‘๋Š” ๋ฐฉ๋ฒ•(directory file์— ๋‘๋Š” ๋ฐฉ๋ฒ•๋„ ๊ฐ€๋Šฅ)

- ๋ชจ๋“  ์ ‘๊ทผ ๊ถŒํ•œ์— ๋Œ€ํ•ด ํ•˜๋‚˜์˜ password๋ฅผ ๋‘๋Š” ๊ฒฝ์šฐ : all or nothing 

- ์ ‘๊ทผ ๊ถŒํ•œ ๋ณ„๋กœ password๋ฅผ ์ฃผ๋Š” ๊ฒฝ์šฐ: ์•”๊ธฐ / ๊ด€๋ฆฌ ๋ฌธ์ œ ๋ฐœ์ƒ

 

File System์˜ Mounting

root file system์—์„œ ๋‹ค๋ฅธ partition์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š” file system์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ•

๊ธฐ๋ณธ์ ์œผ๋กœ ํ•˜๋‚˜์˜ physical disk๋ฅผ logical disk๋กœ partition (๊ฐ logical disk์— file system ์„ค์น˜ ๊ฐ€๋Šฅ)

root file system์˜ ํŠน์ • ๋””๋ ‰ํ† ๋ฆฌ ์ด๋ฆ„์— [๋‹ค๋ฅธ partition์— ์žˆ๋Š” file system / root]์„ mountํ•ด์ค€๋‹ค

-> ๋‹ค๋ฅธ file system์˜ root directory์— ๋ฐ”๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅ

 

File Access Method

1) ์ˆœ์ฐจ์ ‘๊ทผ(sequential access)

- ์นด์„ธํŠธ ํ…Œ์ดํ”„๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ฒ˜๋Ÿผ ์ ‘๊ทผ

- ์ฝ๊ฑฐ๋‚˜ ์“ฐ๋ฉด offset์€ ์ž๋™์ ์œผ๋กœ ์ฆ๊ฐ€

2) ์ง์ ‘์ ‘๊ทผ(direct access, random access)

- ์ž„์˜ ์ ‘๊ทผ

- ํŒŒ์ผ์„ ๊ตฌ์„ฑํ•˜๋Š” ๋ ˆ์ฝ”๋“œ๋ฅผ ์ž„์˜์˜ ์ˆœ์„œ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Œ

๋Œ“๊ธ€