Notice
Recent Posts
Recent Comments
Link
Β«   2025/10   Β»
일 μ›” ν™” 수 λͺ© 금 ν† 
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

JunHyeok

[PintOS - Userprog] Seek & Tell λ³Έλ¬Έ

PintOS

[PintOS - Userprog] Seek & Tell

junhyeok-log 2024. 5. 28. 19:35

tell μ‹œμŠ€ν…œ 콜 πŸ“ž

tell μ‹œμŠ€ν…œ μ½œμ€ μ—΄λ¦° 파일 λ‚΄μ—μ„œ ν˜„μž¬ 파일 μ˜€ν”„μ…‹(즉, 파일 λ‚΄μ—μ„œ ν˜„μž¬ μ½κ±°λ‚˜ μ“Έ μœ„μΉ˜)을 λ°˜ν™˜ν•©λ‹ˆλ‹€.

파일 μ˜€ν”„μ…‹μ€ 파일의 μ‹œμž‘λΆ€ν„°μ˜ λ°”μ΄νŠΈ 수λ₯Ό λ‚˜νƒ€λ‚΄λ©°, tell μ‹œμŠ€ν…œ μ½œμ„ μ‚¬μš©ν•˜μ—¬ 파일 ν¬μΈν„°μ˜ ν˜„μž¬ μœ„μΉ˜λ₯Ό μ•Œ 수 μžˆμŠ΅λ‹ˆλ‹€.

tell κ΅¬ν˜„

unsigned tell(int fd) {
    if (fd < 2 || fd > 128)
        return;
    struct file *tmp = process_get_file(fd);
    if (tmp)
        return file_tell(tmp);
    return NULL;
}
  • fd: μ—΄λ¦° 파일의 파일 λ””μŠ€ν¬λ¦½ν„°.
    이 ν•¨μˆ˜λŠ” 파일의 ν˜„μž¬ μœ„μΉ˜λ₯Ό λ‚˜νƒ€λ‚΄λŠ” μ˜€ν”„μ…‹μ„ λ°˜ν™˜ν•©λ‹ˆλ‹€.

seek μ‹œμŠ€ν…œ 콜 πŸ”

seek μ‹œμŠ€ν…œ μ½œμ€ μ—΄λ¦° 파일 λ‚΄μ—μ„œ 파일 포인터λ₯Ό νŠΉμ • μœ„μΉ˜λ‘œ μ΄λ™μ‹œν‚΅λ‹ˆλ‹€. 이 μœ„μΉ˜λŠ” 파일의 μ‹œμž‘λΆ€ν„°μ˜ λ°”μ΄νŠΈ 수둜 μ§€μ •λ©λ‹ˆλ‹€.

seek μ‹œμŠ€ν…œ μ½œμ„ μ‚¬μš©ν•˜μ—¬ 파일 λ‚΄μ˜ νŠΉμ • μœ„μΉ˜λ‘œ μ΄λ™ν•˜μ—¬ 읽기 λ˜λŠ” μ“°κΈ° μž‘μ—…μ„ μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Seek κ΅¬ν˜„

void seek(int fd, unsigned position) {
    if (fd < 2 || fd > 128) {
        return;
    }
    struct file *tmp = process_get_file(fd);
    if (tmp) {
        file_seek(tmp, position);
    }
}
  • fd: μ—΄λ¦° 파일의 파일 λ””μŠ€ν¬λ¦½ν„°.
  • position: 파일의 μ‹œμž‘λΆ€ν„°μ˜ λ°”μ΄νŠΈ μ˜€ν”„μ…‹μ„ λ‚˜νƒ€λ‚΄λŠ” μœ„μΉ˜.

이 ν•¨μˆ˜λŠ” μ§€μ •λœ μœ„μΉ˜λ‘œ 파일 포인터λ₯Ό μ΄λ™μ‹œν‚΅λ‹ˆλ‹€.

πŸ›‹οΈ μš”μ•½

  • tell : ν˜„μž¬ 파일 μ˜€ν”„μ…‹μ„ λ°˜ν™˜.
  • seek : 파일 포인터λ₯Ό νŠΉμ • μœ„μΉ˜λ‘œ 이동.

seek κ³Ό tell μ‹œμŠ€ν…œ μ½œμ„ 보자마자 read 와 write μ—μ„œ μš”κΈ΄ν•˜κ²Œ 쓰이겠닀고 μƒκ°ν–ˆλ‹€.

tell κ³Ό seek ν•¨μˆ˜λ₯Ό μ œλŒ€λ‘œ κ΅¬ν˜„ν•˜μ§€ μ•ŠμœΌλ©΄ νŒŒμΌμ—μ„œ μ½κ±°λ‚˜ μˆ˜μ •ν•΄μ•Όν•  μœ„μΉ˜λ₯Ό μ •ν™•νžˆ 찾을 수 없을 것이닀.

FAIL tests/filesys/base/lg-random
FAIL tests/filesys/base/sm-random

μœ„μ˜ ν…ŒμŠ€νŠΈ κ²°κ³ΌλŠ” seekκ³Ό tell ν•¨μˆ˜λ₯Ό μ œλŒ€λ‘œ κ΅¬ν˜„ν•˜μ§€ μ•Šμ•˜μ„ λ•Œ λ‚˜νƒ€λ‚œλ‹€. (λ¬Όλ‘  read 와writeλŠ” μ œλŒ€λ‘œ κ΅¬ν˜„ 됐닀고 κ°€μ •)

random μ΄λΌλŠ” ν…ŒμŠ€νŠΈ λͺ…μ—μ„œ μ•Œ 수 μžˆλ“―, νŒŒμΌμ„ μ—΄κ³  λžœλ€ν•œ μœ„μΉ˜μ— μ ‘κ·Όν•˜μ—¬ μˆ˜μ •μ„ ν•˜λŠ”λ° μ—λŸ¬κ°€ λ‚œ 것이닀!

μ•žμœΌλ‘œλŠ” κΌΌκΌΌνžˆμ’€ μ²΄ν¬ν•˜μž! πŸ₯²

'PintOS' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

[PintOS - Userprog] Fork, Exec, Wait 에 λ“€μ–΄κ°€κΈ° μ•žμ„œ...  (0) 2024.05.29
[PintOS - Userprog] Write  (0) 2024.05.28
[PintOS - Userprog] Create & Remove  (0) 2024.05.28
[PintOS - Userprog] Read  (0) 2024.05.28
[PintOS - Userprog] Open & Close  (0) 2024.05.27