40
Operating Systems, 142 Practical Session 12 File Systems, part 2 1

Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

  • Upload
    others

  • View
    10

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Operating Systems, 142

Practical Session 12

File Systems, part 2

1

Page 2: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

File system layout (Tanenbaum)

2

Page 3: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Quick recap: i-Nodes

• An i-node (index node) is a data structure containing pointers to the disk blocks that contain the actual file contents.

• Every i-node object represents a single file.

• An i-node needs to be in Main Memory only if the correspondent file is open.

3

Page 4: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Quick recap: FAT

• A FAT (File allocation table) contains the chains of disk blocks. Each chain defines a different file.

• Every entry in the FAT points to the next disk block of the file.

• Chains of blocks are terminated by a special marker – end_of_file character.

• Directory entry points to first block in a file (i.e. specifies the block number).

• The FAT is held in Main Memory and its size is proportional to the disk size.

Page 5: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Recap: MS-DOS directory entry • Tree structure (no links)

• directories provide information about location of file blocks (directly or indirectly..)

• Both names and attributes are IN the directory

MS-DOS uses fixed size 32-byte directory entries

•read-only

• hidden

• system

• archive

An index into the 64K –entry FAT

5

Page 6: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

NTFS

• Each file is represented by a record in a special file called the master file table (MFT).

• Directories are also files. • The first 16 records of the table are reserved for special

information and the first record of this table describes the master file table itself, followed by a MFT mirror record.

• The seventeenth and following records of the master file table are for user files and directories.

• The master file table allocates a certain amount of space for each file record (for attributes and initial data).

• Small files can be entirely contained within the master file table record in this case file access is very fast.

Page 7: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

MFT records

Page 8: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

The MFT record of a long file

A file that requires three MFT records to store its runs

Ben-Gurion University Operating Systems, Semester B 2008, Danny Hendler 8

Page 9: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

NFS – Network File System

• Allows sharing of file Systems.

• A server exports part of its file system.

• A client can mount an exported file system.

• A stateless protocol. The server remembers nothing about previous requests from a client.

Page 10: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

10

EXT4 NTFS 6 FAT32

Allocation method

Indexed Indexed, by “runs” Linked

File representation

i-node (default size 256KB)

MFT record (default size 1Kb)

Chain of clusters pointed from a Directory entry

Location of filename

Directory entry Directory entry,

MFT record Directory entry

Location of attributes

i-node MFT record Directory entry

Data access i-node contain pointers with different levels of

indirection

For small files- the contents inside the MFT

record, for larger- organized as 'runs'

which may span multiple MFT records

Directory entry Points to 1st link in

chain

Location of index table

i-nodes table immediately after the

superblock

MFT anywhere, pointed by MBR

FAT anywhere, pointed by MBR

Design compare

Page 11: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

11

EXT4 NTFS 6 FAT32

Built in security Yes Yes No

Recoverability Yes, via data and

metadata journaling Yes, via metadata

journaling No

Efficient disk usage

Yes, via sparse files Yes, via compression,

sparse files No

Fragmentation problem

No Some, tries to store

files sequentially Yes

Max file size 16TB

(for 4k block) 16EB by design, 16TB

by implementation 4GB

Max volume size 1EB

(1EB=1,000,000TB) 16EB 2TB

Max filename length

255 chars (case sensitive)

255 chars (case sensitive)

Originally 8+3, extended to 255

(not case sensitive)

Hard links Yes Yes No

Soft links Yes Yes No

Features compare

Page 12: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

12

EXT4 NTFS 6 FAT32

Pros

• Supports large volumes and files

• Built in security and permissions

• Recoverability • Unicode file names • Extended file attributes • No fragmentation

problems, no maintenance needed

• Small memory footprint

• Modern • Supports large volumes

and files • Built in security and

permissions • Recoverability • Unicode file names • Extended file attributes • High performance on

large directories and files

• Simple • Widely supported • Efficient for small

files on small volumes and sequential access

Cons

• Compatibility issues with other OS

• Larger disk footprint than NTFS

• Fragmentation problem • Inefficient on small

volumes • Performance degrades

when disk is almost full • Size of MFT grows with

usage

• Obsolete • Not suitable for

large volumes and files

• No recoverability • No security • No user permissions • Fragmentation

reduce performance

Pros & Cons

Page 13: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 1: FAT

A FAT starts with the following values:

Assuming that slots with -1 indicates an end of file and slots with 0 indicates a free slot: 1. If the directory containing a certain file has 7 as

the starting block, how many blocks does that file contain?

2. The owner of the file has written two more blocks to the file. Adjust the FAT to the change.

Page 14: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 1: FAT

1. 4

2. 14 , 19 , 8 , -1 , -1 , 9 , 3 , 2 , 5 , 10 , -1 0 X

1 X

2 EOF

3 13

4 2

5 9

6 8

7 Free

8 Y

9 12

10 3

11 FREE

12 EOF

13 EOF

14 FREE

15 BAD

Not allocated

End of file

Marked as a

bad block

6 8 4 2

5 9 12

10 3 13

File A:

File B:

File C:

Page 15: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 2: FAT (2007a)

במבני הנתונים )בשאלה זו עליכם להציע שינויים על מנת MS-DOSשל מערכת הקבצים של ( ובקוד

תתמוך , לאחר השינוי. links-להוסיף לה תמיכה בMS-DOS בשתי הפקודות החדשות הבאות:

:הפקודה– soft-link old-path new-path .old-pathאל new-path-חדש מ soft linkיוצרת

:הפקודה– hard-link old-path new-path .old-pathאל new-path-חדש מ hard linkיוצרת

Page 16: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 2: FAT (2007a)

MS-DOSאנו רוצים להוסיף למערכת הקבצים של ( נקודות 13) .א FAT-ה מבלי לבצע שינוי כלשהוא בטבלת, soft links-תמיכה ב

.ומבלי להוסיף מבני נתונים חדשים

(a תארו בפירוט אילו מבני נתונים שלMS-DOS ישתנו וכיצד.

המציין , directory entry-ב flagהשינוי היחיד הנדרש הינו תוספת במידה . או לא symbolic linkהינו entry-י ה"האם הקובץ המוצבע ע

link-הינו ה entry-תוכנו של הקובץ ששמו מופיע ב, מורם flag-וה (.old-path, כלומר)

Page 17: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 2: FAT (2007a)

(bקוד המתאר את פעולתה של פרוצדורה-כתבו פסאודו

soft-link(old-path, new-path)

. soft-linkהמממשת את הפקודה

Procedure soft-link(old-path, new-path) } // get directory-name and entry-name

Convert new-path to <dirName, entryName> // allocate a new directory entry in directory dirName

new-entry ← allocate-new-entry(dirName) new-entry.filename ← entryName new-entry.link ← true // indicate that this is a symbolic link allocate a single block, initialize with old-path, set it as new-entry's single block new-entry.data ← old-path {

Page 18: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 2: FAT (2007a)

c ) האם נדרשים שינויים נוספים בקוד שלMS-DOS ?ציינו אותם בקצרה, אם כן.

אם ישנם )שבו directories-עוברים על ה pathname-ל parsingכאשר מבצעים בתלות אם ) current directory-או ה root directoryהחל מן ה , על פי הסדר( כאלה

יש לבדוק אם הוא , בו נתקלים nameעבור כל שם (. relative pathאו absoluteזהו nameיש לקרוא את תוכן הקובץ , אם כן. שהוספנו flag-י בדיקת ה"ע, linkמיצג

החל parsing-ולהמשיך את פעולת ה, link-ב nameלהחליף את , linkלמשתנה .linkמתחילת

יש למנוע לולאה אינסופית . link-ל linkמרשה הצבעות של . bהמימוש שלנו בסעיף י ספירה של מספר הפעמים בהן התהליך נתקל "למשל ע, parsing-במהלך פעולת ה

ויציאה עם הודעת שגיאה מתאימה במידה והמונה מגיע לערך סף שנקבע link-ב .אפשרות נוספת היא למנוע מראש הצבעות בין לינקים. מראש

.false-ל linkיש לאתחל את דגל , כאשר יוצרים קובץ רגיל

Page 19: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 2: FAT (2007a)

MS-DOSכעת נוסיף למערכת הקבצים של ( נקודות 12) .בהניחו ) FAT-מבלי לבצע שינוי כלשהוא בטבלת ה, hard links-תמיכה ב

(.כי ניתן להיעזר במבני נתונים נוספים

a ) תארו בפירוט אילו מבני נתונים שלMS-DOS ואילו , ישתנו וכיצד .מבני נתונים יתווספו

. Unix-ב inodes -נוסיף טבלה הדומה מבחינות מסוימות לטבלת ה directoryשינוי נוסף הוא במבנה של . dnodesנקרא לה טבלת

entries . כלdirectory entry יצביע לכניסה בטבלת ה-dnodes במקום. בכל כניסה כזו יהיו שני שדות. להצביע לבלוק הראשון של הקובץ

והשדה dnode-השדה הראשון מונה את מספר ההצבעות לרשומת ה .נשאר ללא שינוי FAT-ה. השני מצביע לבלוק הראשון של הקובץ

Page 20: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 2: FAT (2007a)

Page 21: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 2: FAT (2007a)

b) קוד המתאר אל פעולתה של פרוצדורה -כתבו פסאודוhard-link(old-path, new-path) , .hard-linkהמממשת את הפקודה

Procedure hard-link(old-path, new-path) } // get directory-name and entry-name

Convert new-path to <dname, ename> // allocate a new directory entry in directory dname

new-entry ← allocate-new-entry(dname) new-entry.filename ← ename

// locate old-path dnote entry dnode-entry-num ← locate-dnote-entry(old-path)

// point from directory entry to dnode entry new-entry.dnode ← dnode-entry-num

// Increment links number dnodes[dnodes-entry-num].links++ {

Page 22: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 2: FAT (2007a)

c) האם נדרשים שינויים נוספים בקוד שלMS-DOS ? .ציינו אותם בקצרה, אם כן

מובן כי כעת כל הפרוצדורות הפועלות על קבצים כאשר . נדרשות לעבוד עם מבני הנתונים החדשים

יש לאתחל את מספר הלינקים של , נוצר קובץ חדשכאשר מוחקים קובץ יש . 1-החדש ל dnode-ה

שלו dnode-להפחית את מספר הלינקים של היש למחוק את , רק אם מספר זה מתאפס. באחד

.הקובץ עצמו

Page 23: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 3 (Moed b, 2007) .NFSנתון שרטוט של יישום שכבתי של לקוח ושרת במערכת

Page 24: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 3 (Moed b, 2007)

.a הוסיפו לשרטוטcache גם אצל השרת וגם אצל

. cache-ציינו איזה שכבה משתמשת ב. הלקוח

.cache-נמקו במדויק את בחירתכם למיקום ה

.b מה ההבדל במערכתNFS בין ה- cache של

הסבירו את ההבדל ביתרונות ? הלקוח והשרת

אצל הלקוח ואצל cache-ובחסרונות בשימוש ב

. השרת

Page 25: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 3a (Moed b, 2007) Client kernel Server kernel

System call layer

Virtual file system layer

v-nodes

Local FS1

Local FS2

NFS server

Buffer cache

Message to server

Virtual file system layer

Local FS1

Local FS2

NFS server

Buffer cache

Message from client

i-nodes

r-nodes

25

Page 26: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 3b (Moed b, 2007)

כל . ולכן לא נשמר שום מידע statelessהשרת הינו •

גישה לשרת היא חדשה והשרת ניגש למערכת

.הקבצים הרגילה

NFS-ולכן גם בקשות ה statelessהלקוח אינו •

.cache-יכולות לעבור דרך ה

Page 27: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 4 (Moed b 2006)

בהנחה שבתחילת א-התכנית הקובץ

dugma1.txt הוא ריק ,מה תוכנו לאחר סיום

.הסבירו? התכנית

החלף את השורה ב-האדומה על מנת

לקבל תוצאה אחרת , והסבר את השוני

בהתייחס למימוש מערכת הקבצים של

UNIX .

:נתונה התוכנית

int main(char ** argv, int argc){

int fd=open("dugma1.txt",O_WRONLY,0666);

if (fork()==0){

int fd2=dup(fd);

sleep(10);

write (fd2,"I was here second",17);

}//if

else{

write (fd,"I was here first",16);

}

}

Page 28: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 4 (Moed b 2006)

1. I was here firstI was here second

2. int fd2=open (“dugma1.txt”,O_WRONLY,0666);

output is : I was here second

Why?

Page 29: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Open File Description Table & File Descriptor Table

Parent’s file

descriptors table

Child’s file descriptors

table

Unrelated process’s

file descriptors

table

File position RW

pointer to i-node

File position RW

pointer to i-node

File position RW

pointer to i-node

i-nodes table

Open files description table

29

Page 30: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Locking Files

• Two or more processes accessing a file together can cause race conditions.

• Ability to lock any number of bytes of a file.

• Two kinds of locks shared locks, exclusive locks

• C Function is int flock(int fd, int operation);

• flock is an advisory lock

Page 31: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Locking Files

• flock doesn’t work over NFS

• Locking a whole file is wasteful.

• lockf(int fd, int cmd, off_t len) – Allows locking over NFS by implementing another

protocol (Network Lock Manager)

– No shared locking

– Also an advisory lock

– Commands: F_ULOCK (unlock), F_LOCK (lock [blocking]), F_TLOCK (test & lock [non-blocking]), F_TEST (test)

Page 32: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 4 (Moed b 2006) [revised]

int main(char ** argv, int argc){

int stat;

int fd=open("dugma1.txt",O_WRONLY,0666);

if (fork()==0){

int fd2=open("dugma1.txt",O_WRONLY,0666);

sleep(10);

if (lockf(fd2,F_TLOCK,17)>=0){

write (fd2,"I was here second",17);

}

}//if

else{

lockf(fd,F_TLOCK,16);

write (fd,"I was here first",16);

wait(&stat);

}

}

.שינו את הקוד

?מה יהיה הפלט עכשיו

.הסבר

Page 33: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 4 (Moed b 2006)

השתמשנו ) non-blockingבשורה שהוספנו הוספנו מנעול :הקובץ יכיל שורה אחת בלבד(. F_TLOCKבארגומנט

I was here first אם . הסיבה לכך היא מכיוון שלא מתבצעת סגירה של הקובץ

כלומר כשבודקים את המנעול ) F_LOCKנשנה את הארגומנט ל .deadlockנקבל , (נמתין עד שישתחרר

:ניתן לפתור זאת באחת משתי דרכים (סגנון רע) waitלוותר על 1.

!(.באופן כללי תמיד נדאג לסגור קבצים שפתחנו) closeלהוסיף 2.

:במקרה זה תודפס שורה אחת ובה

I was here second

? DUP -ומה יקרה כשנשתמש ב

Page 34: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 5 (Moed a 2009)

(.NFS)נתונה מערכת קבצים של לינוקס אשר תומכת בשיתוף קבצים

הסבירו את . i-node, v-node, r-node: במערכת קיימים שלושה סוגי מבני נתונים. א .תפקידו של כל אחד ממבני הנתונים הללו ואת הקשרים ביניהם

. ב

.נתון קטע הקוד הבא

int fd=open("data.txt",O_RDONLY,0666);

lseek(fd,50,SEEK_SET); // Sets the offset to 50

write(fd,buf,150); // Write 150 bytes from buf

lseek(fd,50,SEEK_SET); // Sets the offset to 50

read(fd,buf,150); // Read 150 bytes into buf (. ולא במערכת הקבצים המקומית)יושב על גבי שרת חיצוני data.txtידוע שהקובץ

נמקו תשובתכם בקצרה . הסבירו אילו מן הפקודות שבקוד נשלחות לשרת ואילו לא .('נק 6)

Page 35: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 5 (Moed a 2009)

. א

i-node :מבנה נתונים המתאר קובץ במערכת הקבצים המקומית

r-node : מבנה נתונים אשר נמצא אצל הקליינט ומתאר קובץ במערכת קבצים

מרוחקת

v-node :נמצא בשכבת ה- VFS ומצביע או ל- i-node או ל- r-node

עם קבצים יתבצע " דיבור"ה, כלומר. v-nodeרק מול " עובדת" System Call Layer -ה

י שכבה זו "הממשק המוחצן ע)בלי קשר אם הקובץ מקומי או מרוחק " שפה"באותה יתרגם את הפקודות v-nodeאליו מצביע r-node(. אינו מתייחס למיקום הקבצים

אשר אליו מצביע i-nodeואילו . להודעות עבור שרת מרוחק שעליו יושב הקובץ

יתרגם את הפקודות להודעות למערכת הקבצים המקומית של v-nodeאיזשהו

.מערכת ההפעלה

Page 36: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 5 (Moed a 2009) .ב

אשר תחזיר לקליינט lookupאלה פקודות , לשרת openלא תשלח פקודת :1שורה filehandle .לאחר קבלת ה- filehandle הקליינט ייצרv-node וr-node כאשר ה-

v-node מצביע ל- r-node וה- r-node מחזיק את ה- filehandle. 1לשורה FDנשלח והשרת מחזיר open -התקבלו גם התשובות שבהן הנבחן רשם שה

לא נשלח בגלל שהשרת הוא open -וגם התשובות שבהן הנבחן רשם שהstateless

של הקובץ נמצא אצל offsetולכן מידע כגון ה statelessהשרת הוא :2שורה .תמיד תתבצע בצד של הקליינט בלבד lseekכלומר פקודת . הקליינט

קריאה של הקובץ /ולכן מידע כגון הרשאות כתיבה statelessהשרת הוא :3שורה הקליינט יזהה שאסור RD_ONLY -מכיוון שהקובץ נפתח כ. נמצאות אצל הקליינט

.לא תשלח לשרת write -ולכן פקודת ה. לבצע פעולת כתיבה לקובץ

.2ראה הסבר לשורה :4שורה

-פקודת ה( ולא אצל הקליינט)מכיוון שהתוכן של הקובץ יושב אצל השרת :5שורה read הביטים מ 150תשלח לשרת ותבקש את- offset 100.

Page 37: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 5 (Moed a 2009)

.נתון קטע הקוד הבא. ג

int fd=open("data.txt",O_RDONLY,0666);

lseek(fd,0,SEEK_SET); // Sets the offset to 0

read(fd,buf,500);

read(fd,buf,500);

read(fd,buf,1000);

והשרת שולח לקליינט בלוקים בגודל NFS cachingנתון גם כי לקליינט יש שכבת

. KB 1קבוע של

נמקו תשובתכם . הסבירו אילו מן הפקודות בקוד שלמעלה נשלחות לשרת ואילו לא

.('נק 6) בקצרה

Page 38: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 5 (Moed a 2009)

כאשר . יכולה להחזיר יותר מידע ממה שהקליינט ביקש read -בשאלה זו פקודת ה: הערההיא שסביר להניח שבאיזשהו שלב הקליינט , "נוסף"המוטיבציה מאחורי קבלת מידע

אשר בה יאוחסן המידע יכולה cache -שכבת ה. ירצה לקרוא את המידע הנוסף הזה .לחסוך גישות לשרת

('בסעיף ב 1ראה הסבר לשורה ): 1שורה

('בסעיף ב 2ראה הסבר לשורה ): 2שורה

פקודת . ריק ולכן עליו לקבל את תוכן הקובץ מהשרת cache -הקליינט יראה שה: 3שורה מכיוון שנתון שהשרת . אפסoffset -הביטים מ 500תשלח לשרת ותבקש את read -ה

עד 0 -הקליינט יקבל חזרה את תוכן הקובץ מ KB 1מחזיר תשובות בבלוקים של cache -בייט ויאכסן את המידע ב 1024

הפעם הקליינט . בייט 1000עד 500 -כעת הקליינט רוצה את תוכן הקובץ מ: 4שורה , לא תישלח לשרת read -ולכן פקודת ה cache -יגלה שהמידע שהוא צריך יושב ב

cache -אלה תילקח המידע ישירות מה

cache -אולם ל. בייט 2000עד 0001 –כעת הקליינט רוצה את תוכן הקובץ מ : 5שורה .תישלח לשרתread -ולכן הפעם פקודת ה 1024 -יש רק את המידע עד הבייט ה

Page 39: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 5 (Moed a 2009)

לכתיבה data.txtהתהליך הראשון פותח את הקובץ . נתונים שני תהליכים. ד

י התהליך "התהליך השני מנסה למחוק את הקובץ בעודו פתוח ע. ולקריאה

.הראשון

שני קליינטים שונים של השרת )בהנחה ששני התהליכים רצים על מחשבים שונים . 1

.נמקו בקצרה? האם המחיקה תצליח(. החיצוני

האם (. קליינט של השרת החיצוני)בהנחה ששני התהליכים רצים על אותו מחשב . 2

נמקו בקצרה? המחיקה תצליח

Page 40: Operating Systems, 142os142/wiki.files/Practical Session 12 - File... · Operating Systems, 142 Practical Session 12 File Systems, part 2 1 . File system layout (Tanenbaum) 2 . Quick

Question 5 (Moed a 2009) .ד

ולכן אין לו שום מידע לגבי איזה תהליכים פתחו את הקובץ statelessהשרת הוא 1.

data.txt .המחיקה תצליח, בהנחה שיש לקליינט הרשאות מתאימות.

מערכת , מכיוון ששני התהליכים רצים על אותה מערכת הפעלה באותו מחשב2.( statefullהקליינט הוא )ההפעלה של הקליינט יכולה לזהות שהקובץ פתוח

נבחן שהבין שהפעם המחיקה . תלוי במערכת ההפעלה? האם המחיקה תצליח

קיבל את מלוא , הסבר מספקוסטודנט שנתן ( ולא בשרת)תלויה בקליינט

.הנקודות