λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

μΉ΄ν…Œκ³ λ¦¬ μ—†μŒ

λ¦¬λˆ…μŠ€ 컀널 μ„œλΈŒμ‹œμŠ€ν…œ - 가상 파일 μ‹œμŠ€ν…œ(Virtual File System)

λ°˜μ‘ν˜•

Parent Content: λ¦¬λˆ…μŠ€ OS와 μ„œλΈŒμ‹œμŠ€ν…œ(λ…Όλ¬Έ: Conceptual Architecture of the Linux Kernel)

 

가상 파일 μ‹œμŠ€ν…œ(VFS-Virtual File System)은 λ¦¬λˆ…μŠ€ μ»€λ„μ˜ 5가지 μ£Όμš” μ„œλΈŒμ‹œμŠ€ν…œ 쀑 ν•˜λ‚˜λ‘œ, λͺ¨λ“  λ””λ°”μ΄μŠ€μ— 곡톡 파일 μΈν„°νŽ˜μ΄μŠ€(open, stat, read, write, chmod λ“±)λ₯Ό μ œκ³΅ν•˜μ—¬ λ‹€μ–‘ν•œ ν•˜λ“œμ›¨μ–΄ λ””λ°”μ΄μŠ€μ˜ μ„ΈλΆ€ 정보λ₯Ό μΆ”μƒν™”ν•˜λ©° ν΄λΌμ΄μ–ΈνŠΈ μ‘μš© ν”„λ‘œκ·Έλž¨μ΄ μ—¬λŸ¬ 파일 μ‹œμŠ€ν…œμ— 같은 λ°©λ²•μœΌλ‘œ μ ‘κ·Όν•  수 있게 ν•΄ μ£ΌλŠ” μ†Œν”„νŠΈμ›¨μ–΄ λ ˆμ΄μ–΄μž…λ‹ˆλ‹€: [1]

 

예λ₯Ό λ“€μ–΄ νŒŒμΌμ„ μ—¬λŠ” open() ν•¨μˆ˜κ°€ μ‹€μ œ 파일 μ‹œμŠ€ν…œ μœ ν˜•(예:ext2, ext4...)에 상관없이 λ™μΌν•˜κ²Œ μž‘λ™ν•  수 μžˆλŠ” μ΄μœ λŠ” μš”μ²­μ΄ VFS λ ˆμ΄μ–΄λ₯Ό 거쳐 μ‹€μ œ 파일 μ‹œμŠ€ν…œμ— μ „λ‹¬λ˜κΈ° λ•Œλ¬Έμž…λ‹ˆλ‹€. VFSλŠ” 각 파일 μ‹œμŠ€ν…œ μœ ν˜•μ— λŒ€ν•œ ν•¨μˆ˜ 포인터 ν…Œμ΄λΈ”μ„ 가지고 있으며, 이 ν…Œμ΄λΈ”μ€ ν•΄λ‹Ή 파일 μ‹œμŠ€ν…œμ˜ λ™μž‘μ„ μ •μ˜ν•˜λŠ” ν•¨μˆ˜λ₯Ό κ°€λ¦¬ν‚€λŠ” ν¬μΈν„°λ‘œ κ΅¬μ„±λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

 

예λ₯Ό λ“€μ–΄ ext4 파일 μ‹œμŠ€ν…œμ΄ VFS에 등둝될 λ•Œ, ν•΄λ‹Ή 파일 μ‹œμŠ€ν…œ μœ ν˜•μ— λŒ€ν•œ open() ν•¨μˆ˜μ™€ 같은 λ™μž‘μ„ μˆ˜ν–‰ν•˜λŠ” ν•¨μˆ˜ 포인터가 VFS ν…Œμ΄λΈ”μ— μΆ”κ°€λ©λ‹ˆλ‹€. λ”°λΌμ„œ ν•΄λ‹Ή ν•¨μˆ˜λ“€μ€ 각각의 파일 μ‹œμŠ€ν…œ μœ ν˜•λ³„λ‘œ 파일 μ‹œμŠ€ν…œ λͺ¨λ“ˆ 내에 ν•¨μˆ˜ λ™μž‘μ΄ ν¬ν•¨λœ ꡬ쑰체가 κ΅¬ν˜„λ˜μ–΄ μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. open() ν•¨μˆ˜κ°€ 호좜될 λ•Œ, VFSλŠ” ν•΄λ‹Ή 파일 μ‹œμŠ€ν…œμ˜ ν•¨μˆ˜ 포인터λ₯Ό μ‚¬μš©ν•˜μ—¬ μ‹€μ œ λ™μž‘μ„ μˆ˜ν–‰ν•©λ‹ˆλ‹€.

 

 

Figure 1.1: [4]

 

μš”μ•½ν•˜λ©΄, 각 파일 μ‹œμŠ€ν…œ λ‚΄μ—λŠ” VFS와 μƒν˜Έμž‘μš© ν•˜κΈ° μœ„ν•œ ν•¨μˆ˜μ™€ ꡬ쑰체가 κ΅¬ν˜„λ˜μ–΄ 있으며, μ΄λŸ¬ν•œ ν•¨μˆ˜λ“€μ€ VFS ν…Œμ΄λΈ”μ— λ“±λ‘λ˜μ–΄ VFSκ°€ 파일 μ‹œμŠ€ν…œ μœ ν˜•μ„ μΈμ‹ν•˜κ³  ν•΄λ‹Ή ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•  수 있게 λ©λ‹ˆλ‹€. VFSλŠ” 이런 λ°©μ‹μœΌλ‘œ λ‹€μ–‘ν•œ 파일 μ‹œμŠ€ν…œ μœ ν˜•μ„ μ§€μ›ν•˜κ³ , 각 파일 μ‹œμŠ€ν…œμ€ ν•΄λ‹Ή λ™μž‘μ„ μ²˜λ¦¬ν•˜κΈ° μœ„ν•œ ν•¨μˆ˜λ₯Ό 자체 파일 μ‹œμŠ€ν…œ λͺ¨λ“ˆμ— κ΅¬ν˜„ν•©λ‹ˆλ‹€. 이둜 인해 파일 μ‹œμŠ€ν…œμ˜ 처리λ₯Ό μ‘μš© ν”„λ‘œκ·Έλž¨μ— λ…ΈμΆœμ‹œν‚€μ§€ μ•Šμ„ 수 있으며, μ΄λŠ” λ¦¬λˆ…μŠ€ μ‹œμŠ€ν…œμ„ 보닀 μœ μ—°ν•˜κ²Œ λ§Œλ“€μ–΄μ£Όκ³  ν™•μž₯성을 μ œκ³΅ν•©λ‹ˆλ‹€.

 


더 읽어보기: VFS Operations - File Open

- Given a file path, an open mode and a file permissions mask

Entry function: sys_open, in fs/open.c.
Underlying open function: filp_open, in fs/open.c.

 

- Allocate a free file descriptor.
- Try to open the file.
- On success, put the new 'struct file' in the fd table of the process.
- On error, free the allocated file descriptor. 

 

Actually Opening The File

Entry function: open_namei, in fs/namei.c.

Case (1): Create modeκ°€ μ•„λ‹Œ μƒνƒœμ—μ„œ 파일 open (file already exists, no O_CREAT flag given)
    If not opening in create mode (no O_CREAT flag given):
    lookup the file via the dentry cache (path_lookup -> path_walk -> link_path_walk).

 

Case (2): Create mode μƒνƒœμ—μ„œ 파일 open(open with create)
    Otherwise (it is an open in create mode):
        Lookup the parent directory (path_lookup again). If it does not exist, or is not a directory - fail the operation.
        Lookup the file in the parent directory. If it does not exist, create it (see vfs_create later on).
        Handle special cases (flags mismatch, file is a directory, file is a link...). 

 

Case (1),(2) 곡톡사항:
        Perform sanity checks.
        Check permissions.
        Check various mode limitations (e.g. file is read-only and trying to open for write, trying to open a device file on a 'no_dev' file-system mount, etc.).
        Handle truncation. 

 

 

References:

[1] https://ko.wikipedia.org/wiki/%EA%B0%80%EC%83%81_%ED%8C%8C%EC%9D%BC_%EC%8B%9C%EC%8A%A4%ED%85%9C

 

가상 파일 μ‹œμŠ€ν…œ - μœ„ν‚€λ°±κ³Ό, 우리 λͺ¨λ‘μ˜ 백과사전

μœ„ν‚€λ°±κ³Ό, 우리 λͺ¨λ‘μ˜ 백과사전.

ko.wikipedia.org

 

[2] https://hyeyoo.com/84

 

[Linux Kernel] 가상 νŒŒμΌμ‹œμŠ€ν…œμ΄λž€ (VFS, Virtual Filesystem Switch)

Virtual Filesystemμ΄λž€ λ¦¬λˆ…μŠ€λ₯Ό μ‚¬μš©ν•˜λ©΄ λ‹€μ–‘ν•œ ν˜•μ‹μœΌλ‘œ 포맷된 λ””μŠ€ν¬λ₯Ό μ‚¬μš©ν•  수 μžˆλ‹€. 보톡 λ¦¬λˆ…μŠ€μ–΄μ„ΈλŠ” ext2, ext3, ext4λ₯Ό μ‚¬μš©ν•˜μ§€λ§Œ μœˆλ„μš°μ—μ„œ μ‚¬μš©ν•˜λŠ” NTFSλ‚˜ FAT같은 λ””μŠ€ν¬λ„ μ‚¬μš©ν•  수

hyeyoo.com

 

[3] https://www.kernel.org/doc/html/latest/filesystems/vfs.html

 

Overview of the Linux Virtual File System — The Linux Kernel documentation

The Virtual File System (also known as the Virtual Filesystem Switch) is the software layer in the kernel that provides the filesystem interface to userspace programs. It also provides an abstraction within the kernel which allows different filesystem impl

www.kernel.org

[4] http://haifux.org/lectures/119/linux-2.4-vfs/linux-2.4-vfs.html

 

The VFS (Virtual File System) in Linux Kernel V2.4

The VFS (Virtual File System) in Linux Kernel V2.4 A Play In 5 Acts Act I - The Linux Kernel's VFS - exposition Is the component in the kernel that handles file-systems, directory and file access. It abstracts common tasks of many file-systems. And present

haifux.org

 

λ°˜μ‘ν˜•
Archives
Notice
Link
Visits
Today
Yesterday