• toc {:toc}

Basic Concept

  • OS λŠ” μ €μž₯된 정보에 λŒ€ν•΄ λ™μΌν•œ logical view λ₯Ό μ œκ³΅ν•œλ‹€.
    • μ €μž₯μž₯치의 물리적 νŠΉμ§•μ„ μΆ•μ•½ν•œλ‹€.
  • File : Logical storage unit (μ €μž₯ μž₯μΉ˜μ— μ €μž₯ν•˜λŠ” λ‹¨μœ„)
    • μ‚¬μš©μžμ™€ ν”„λ‘œκ·Έλž¨μ΄ 데이터λ₯Ό μ €μž₯ν•˜κ³  μž¬μ‚¬μš©ν•  수 μžˆλ‹€.
    • Nonvolatile
    • ν”„λ‘œκ·Έλž¨ (source, objects) κ³Ό 데이터 (numeric, character, binary) λ₯Ό λ‚˜νƒ€λ‚Έλ‹€.
  • File β†’ ν™•μž₯μžμ— μ˜ν•΄ λ‚΄μš© μ •μ˜λœλ‹€.

File Attributes

AttributeDescription
nameμ‚¬λžŒμ΄ 읽을 수 μžˆλŠ” ν˜•νƒœ 이름
identifierμ‹œμŠ€ν…œμ΄ ꡬ뢄할 수 μžˆλŠ” 속성
type파일 νƒ€μž…
locationμž₯치의 파일 μœ„μΉ˜
sizeν˜„μž¬ 파일 μ‚¬μ΄μ¦ˆ
protectionλˆ„κ°€ 읽고 μ“°κ³  μ‹€ν–‰ν•  수 μžˆλŠ”μ§€
timestamps and user identificationmonitoring, λ³΄μ•ˆμ— λŒ€ν•œ 데이터

File Operations

  • Create
  • Open
  • Write - write pointer μœ„μΉ˜μ—μ„œ write
  • Read - read pointer μœ„μΉ˜μ—μ„œ read
  • Reposition within a file
  • Delete
  • Truncate : 파일 λ‚΄μš©μ€ μ§€μš°κ³  속성은 μœ μ§€
  • Create, Open μ œμ™Έν•œ λͺ¨λ“  operation 은 open 을 λ¨Όμ € μ§„ν–‰ν•΄ file discripter λ₯Ό μ–»μ–΄μ•Ό ν•œλ‹€.
    • OS β†’ open-file table 을 μœ μ§€ (μ—΄λ € μžˆλŠ” 파일 좔적 λͺ©μ )
    • open count : 파일이 λͺ‡λ²ˆ μ—΄λ ΈλŠ”μ§€ μ €μž₯

File Locking

  • νŒŒμΌμ— λŒ€ν•΄ μ ‘κ·Ό μ–»μ§€ λͺ»ν•˜λ„둝 νŒŒμΌμ„ μž κ·ΈλŠ” 것
  • reader-writer lock κ³Ό λΉ„μŠ·ν•˜λ‹€.
  • Shared lock : reader lock κ³Ό λΉ„μŠ· β†’ μ—¬λŸ¬ ν”„λ‘œμ„ΈμŠ€λ“€μ΄ λ™μ‹œμ— lock νšλ“ κ°€λŠ₯
  • Exclusive lock : writer lock κ³Ό λΉ„μŠ· β†’ ν•œ λ²ˆμ— ν•œ ν”„λ‘œμ„ΈμŠ€λ§Œ νšλ“ κ°€λŠ₯
  • Mandatory : OS κ°€ locking ν†΅ν•©μ μœΌλ‘œ 보μž₯
  • Advisory : 개발자 (μ‚¬μš©μ£Όμ²΄) κ°€ lock 을 μ μ ˆν•˜κ²Œ 직접 μ„€μ •
    • int flock(int fd, int operation);
    • int fcntl(int fd, int cmd, …);

File Types

  • 파일 μ‹œμŠ€ν…œμ˜ 이해λ₯Ό μœ„ν•œ type
    • device, directory, symbolic link
  • OS, runtime library
    • executable, dll, source code, object code
  • ν”„λ‘œκ·Έλž¨
    • jpg, mpg, avi, mp3, …
  • 인코딩 파일 νƒ€μž…
    • μœˆλ„μš°λŠ” 이름 μ•ˆμ— νƒ€μž…μ΄ μžˆλ‹€.
      • .com, .exe, .bat, .dll, .jpg, …
    • μœ λ‹‰μŠ€λŠ” 파일 λ‚΄μš© μ•ˆμ— μžˆλ‹€.

Access Methods

image

  • Sequential access (순차 μ ‘κ·Ό) : λ‹€μŒ λ‚΄μš©μ„ 읽고 μ“΄λ‹€.
  • Direct access : number 에 ν•΄λ‹Ήν•˜λŠ” 뢀뢄을 직접 μ ‘κ·Ό (μˆœμ„œμ— 상관없이 λΉ λ₯΄κ²Œ 읽고 μ“Έ 수 μžˆλ‹€.)
  • Index access : μ±…μ˜ λͺ©μ°¨μ²˜λŸΌ μ‚¬μš©ν•΄ μ ‘κ·Ό

Directory Structure

  • λͺ¨λ“  νŒŒμΌμ— λŒ€ν•œ 정보λ₯Ό ν¬ν•¨ν•œ λ…Έλ“œλ“€μ˜ μ§‘ν•©
    • 디렉토리 ꡬ쑰와 파일 λͺ¨λ‘ λ””μŠ€ν¬μ— μœ„μΉ˜
  • Efficiency(νš¨μœ¨μ„±) : λΉ λ₯΄κ²Œ νŒŒμΌμ„ μœ„μΉ˜μ‹œν‚€κΈ° μœ„ν•΄ μ‚¬μš©
  • Naming(λͺ…μΉ­) : μ‚¬μš©μžμ˜ νŽΈμ˜μ„±μ„ μœ„ν•΄
    • μ„œλ‘œ λ‹€λ₯Έ μ‚¬μš©μžμ˜ 경우 λ‹€μ–‘ν•œ νŒŒμΌμ— λŒ€ν•΄ 같은 이름을 κ°€μ§ˆ 수 μžˆλ‹€.
    • 같은 νŒŒμΌμ— λŒ€ν•΄ λ‹€μ–‘ν•œ 이름을 κ°€μ§ˆ 수 μžˆλ‹€.
  • Grouping : 파일 logical grouping

Single-Level Directory

  • λͺ¨λ“  파일이 ν•œ 폴더에 λ“€μ–΄κ°€ μžˆλŠ” 경우
  • Naming problem(μ„œλ‘œ μœ μΌν•œ 이름 κ°–λŠ”λ‹€.), Grouping problem(λ‚˜λˆŒ 수 μ—†λ‹€.) λ°œμƒ.

image

Two-Level Directory

  • μ‚¬μš©μž 각각의 폴더가 λ‹€λ₯΄κ²Œ λΆ„λ¦¬ν•œλ‹€.
  • Path name : user_name/file_name
  • 효율적 탐색
  • Grouping 은 ν•  수 μ—†λ‹€.

image

Tree-Structured Directory

  • κ°€μž₯ ν”ν•œ directory ꡬ쑰
  • Root directory λ₯Ό κ°–λŠ”λ‹€.
  • λͺ¨λ“  파일이 κ³ μœ ν•œ 경둜λ₯Ό κ°–λŠ”λ‹€.

image

Acyclic-Graph Directory

  • μƒμœ„ 디렉토리가 ν•˜μœ„ 디렉토리와 νŒŒμΌμ„ κ³΅μœ ν•  수 μžˆλ„λ‘ ν—ˆμš©ν•œλ‹€.
  • 파일이 두 κ°€μ§€ λ‹€λ₯Έ 이름을 κ°€μ§ˆ 수 μžˆλ‹€.
  • ν•˜μ§€λ§Œ μˆœν™˜ ꡬ쑰가 생기면 μ•ˆλœλ‹€.
  • μœ λ‹‰μŠ€ = Symbolic link, Pointer

image

General Graph Directory

  • 디렉토리와 νŒŒμΌμ—μ„œ μˆœν™˜ ꡬ쑰가 λ°œμƒν•΄λ„ λœλ‹€.
    • Reference count κ°€ 0 이 λ˜μ§€ μ•ŠλŠ”λ‹€.
    • β‡’ root μ—μ„œ ν•΄λ‹Ή 파일둜 κ°€λŠ₯ κ²½λ‘œκ°€ 없어도 reference count = 1 이 λœλ‹€. (μˆœν™˜ κ΅¬μ‘°μ—μ„œ)
    • β‡’ μ ‘κ·Ό κ°€λŠ₯ν•˜λ €λ©΄ 0 이어야 ν•˜λŠ”λ°, 이λ₯Ό 확인할 수 μ—†λ‹€.
    • β‡’ Garbage collection 을 μ‚¬μš©ν•˜μ—¬ μ ‘κ·Όν•  수 μ—†μœΌλ©΄ μ‚­μ œν•œλ‹€.

image

Protection

  • 파일 μ œμž‘μž/μ†Œμœ μž β‡’ λˆ„κ΅¬μ— μ˜ν•΄ μ‹€ν–‰λ˜μ—ˆλŠ”μ§€ μ•Œμ•„μ•Ό ν•œλ‹€.
  • μ ‘κ·Ό κΆŒν•œ λΆ€μ—¬

Access List / Group in Unix

  • 3 κ°€μ§€ λͺ¨λ“œ : read (R), write (W), execute (X)

image

  • chmod λ₯Ό 톡해 ν•΄λ‹Ή μ ‘κ·Ό κΆŒν•œμ„ λΆ€μ—¬ν•  수 μžˆλ‹€.

Memory-Mapped Files

  • Virtual address 의 ν•œ 뢀뢄이 νŒŒμΌλ“€κ³Ό λ…Όλ¦¬μ μœΌλ‘œ 연결될 수 μžˆλ„λ‘ ν—ˆμš©ν•œλ‹€.
  • Disk Block 을 Page 와 μ—°κ²°ν•œλ‹€.
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
  • addr = mmap() 이후 addr 에 write λ₯Ό ν•  경우 λ©”λͺ¨λ¦¬μ— μ¨μ§€λŠ” 것이 μ•„λ‹Œ νŒŒμΌμ— μ¨μ§€λŠ” 것

image

  • Memory-mapped μƒν™©μ—μ„œ 3 번 frame 에 write κ³Όμ •
  1. Write μž…λ ₯
  2. 3 번 frame addr 에 μ ‘κ·Ό
  3. Page fault λ°œμƒ
  4. Disk μ—μ„œ ν•΄λ‹Ή file 뢀뢄을 3 번 physical memory 에 μ˜¬λ €μ€€λ‹€.
  5. Page κ°€ physical memory 에 μ˜¬λ €μ§„ disk block 에 μ ‘κ·Όν•΄ μž‘μ—…ν•œλ‹€.