OS PyramidTechnion 234123 · Operating Systemsbasics → exam
Stage 10: Storage & Filesystems
Winter2022-examAQuestion 2core25 pts

סעיף זה הוא על מערכת הקבצים VSFS שראינו בתרגולים. בסעיפים הבאים הניחו את ההנחות הבאות: • כל סעיף הינו המשך של הסעיף הקודם. • הניחו שהקבצים המופיעים בקטע הקוד אינם קיימים, התיקיות (a,d) קיימת. • הניחו שלינקים רכים שומרים את הpath בinode של הקובץ. • הניחו שIn, echo יוצרות קובץ חדש אם הוא לא קיים. • הניחו שהתיקייה בה מתחילים היא תיקיית השורש. • הניחו שקיים inode cache שבו נשמרים כל הinodes האחרונים אליהם ניגשים, והם נשארים בו במהלך כל ריצת הקוד. כך שקריאה של inode מתבצעת ישירות מהcache, וכתיבה אליו מתבצעת גם לcache וגם לדיסק. • תזכורת: מבנה פקודת In הוא In src dst, כאשר היא ללא דגל היא יוצרת hard link, ועם דגל -s היא יוצרת soft link.

Full original question text (raw OCR)

שאלה 2 - מערכות קבצים (25 נק')

  1. 1· short_answer· 4 ptsStorage & Filesystems

    (4 נק') מני יתרון אחד וחסרון אחד של מערכת הקבצים FAT לעומת VSFS.

    libc syscall wrapper caching pitfalls
  2. 2· short_answer· 3 ptsStorage & Filesystems

    (3 נק') האם מערכת הקבצים FAT תומכת בלינקים קשים? במידה וכן, הסבירי כיצד. במידה ולא, הסבירי מדוע.

    libc syscall wrapper caching pitfalls
  3. 3a· trace· 7 ptsStorage & Filesystems

    (7 נק') סעיף א: מה יהיה פלט הקוד? נמקי. 1. echo "Hello World!" > /a/b 2. In /a/b c 4. cat c ו. הקוד יצליח, הפלט יהיה ריק. ii. הקוד יצליח, הפלט יהיה "Hello World" iii. הקוד יצליח, הפלט יהיה "!Goodbye World" iv. הקוד ייכשל, תהיה שגיאה. כמה פעמים ניגש הקוד לדיסק? השלימי את הטבלה הבאה (שורות ועמודות חסרות) ונמקי.

    libc syscall wrapper caching pitfallsPer-process file descriptor tableHard link vs symlink inode behavior
  4. 3b· trace· 8 ptsStorage & Filesystems

    (8 נק') סעיף ב: מה יהיה פלט הקוד? נמקי. In -s /a/b /d/e echo "Goodbye World!" > /d/e cat c ו. הקוד יצליח, הפלט יהיה ריק. ii. הקוד יצליח, הפלט יהיה "Hello World" iii. הקוד יצליח, הפלט יהיה "!Goodbye World" iv. הקוד ייכשל, תהיה שגיאה. כמה פעמים ניגש הקוד לדיסק? השלימי את הטבלה הבאה (שורות ועמודות חסרות) ונמקי.

    libc syscall wrapper caching pitfallsPer-process file descriptor tableHard link vs symlink inode behavior
  5. 3c· trace· 3 ptsStorage & Filesystems

    (3 נק') סעיף ג: מה יהיה פלט הקוד? נמקי. rm /a/b cat /d/e ו. הקוד יצליח, הפלט יהיה ריק. ii. הקוד יצליח, הפלט יהיה "Hello World!". iii. הקוד יצליח, הפלט יהיה "!Goodbye World" iv. הקוד ייכשל, תהיה שגיאה.

    libc syscall wrapper caching pitfallsPer-process file descriptor tableHard link vs symlink inode behavior

The exam question — original PDF

pages 5, 6, 7, 8

Exactly as it appears on the exam paper.

loading page 5
loading page 6
loading page 7
loading page 8

Built from these components

Ordered basic → advanced. Master the earlier ones first.

L2System call trap and kernel entryL3libc syscall wrapper caching pitfallsL3Per-process file descriptor tableL3Hard link vs symlink inode behavior

Review the material

Read these before you answer — each verified slide teaches a component this question tests, and nothing from an unrelated topic is included. Tutorial slides show the actual slide image.

Lecture 11–12slide 9POSIX file descriptors (FDs)

POSIX file descriptors (FDs) • A successful open<“file name”> of a file returns a FD rpt – A nonnegative integer – An index to a per-process array called the “file descriptor table” – Each entry in the array saves, e.g., the current offset – Threads share the array (and hence the offset) – C’s FILE structure encapsulates a FD • FD or filename? – Some file-related POSIX system calls operate on FDs • read, write, fchmod, fchown, fchdir, fstat, ftruncate… – Others operate on file names • chmod, chown, chdir, stat, truncate – Has security implications: FD versions are more secure in some sense • Because association of FD to underlying file is immutable – Once an FD exists, it will always point to the same file • Whereas association between file & its name is mutable – So they can lead to TOCTTOU (time of check to time of use) races OS (234123) - files 9

Lecture slide — text above is the material (no raster available).
Lecture 11–12slide 26Hard links – when is a file deleted?

Hard links – when is a file deleted? • Every file has a “reference count” associated with it – link()  ref_count++ – unlink()  ref_count-- • if( ref_count == 0 ) – The file has no more names – It isn’t pointed to from any node within the file hierarchy – So it can finally be deleted • What if an open file is deleted? (its ref_count==0) – Can we still access the file through the open FD(s)? • Yes – If >=1 processes have the file open when the last link is removed • The link shall be removed before unlink() returns • But the removal of the file contents shall be postponed until all references (file descriptors) to the file are close()-ed • Have you seen files names that begin with “.nfs”? OS (234123) - files 26

Lecture slide — text above is the material (no raster available).
Lecture 11–12slide 34inodes & *stat syscalls

inodes & *stat syscalls • lstat(2) – Exactly the same as stat(2) if applied to a hard link – But if applied to a symlink, would return the information of this symlink (not to the target of the symlink) – In this case, POSIX says that the only fields within the stat structure that you can portably use are: • st_mode which will specify that the file is a symlink • st_size symlink content length (= length of target filepath) – The value of the rest of the fields could be valid, but it is not specified by POSIX – Notably, it is not specified if a symlink has a corresponding inode • Will be discussed shortly OS (234123) - files 34

Lecture slide — text above is the material (no raster available).
Tutorial 2slide 16קריאת המערכת waitpid()pid_t waitpid(pid_t pid, int *wstatus, int options);פעולה: המתנה לסיום בן ספציפי שמספרו pid

קריאת המערכת waitpid()pid_t waitpid(pid_t pid, int *wstatus, int options);פעולה: המתנה לסיום בן ספציפי שמספרו pid.wait(), waitpid() הן קריאות מערכת חוסמות.כלומר חוסמות את התקדמות התהליך עד להתרחשות תנאי מסוים.באנגלית: blocking system calls.הארגומנט options מאפשר לשנות את ההתנהגות של waitpid() לקריאת מערכת לא חוסמת.אם options==WNOHANG קריאת המערכת תחזור מיד, כאשר ערך חזרה 0 משמעותו שאף תהליך בן עוד לא סיים, ואילו ערך חזרה חיובי הוא ה-pid של תהליך בן שסיים ונמצא עדיין במצב zombie.מערכות הפעלה - תרגול 216

Tutorial 2slide 18קריאת המערכת exit()שאלה: למה בכלל לקרוא ל-exit(status) , אם אפשר פשוט לרשום return status בסוף פונקציית ה-main?תשובה:...

קריאת המערכת exit()שאלה: למה בכלל לקרוא ל-exit(status) , אם אפשר פשוט לרשום return status בסוף פונקציית ה-main?תשובה: main היא לא באמת הפונקציה הראשית של התכנית...main() נקראת ע"י __libc_start_main() שאוספת את ערך החזרה של main() וקוראת ל-exit().int __libc_start_main(…) { …… exit(main(…));}מסקנה: הפונקציה exit תמיד נקראת לסיום סטנדרטי של התוכנית.מערכות הפעלה - תרגול 218

Tutorial 2slide 22קריאות המערכת getpid(), getppid()pid_t getpid();קריאת מערכת המחזירה לתהליך הקורא את ה-pid של עצמו

קריאות המערכת getpid(), getppid()pid_t getpid();קריאת מערכת המחזירה לתהליך הקורא את ה-pid של עצמו.pid_t getppid();קריאת מערכת המחזירה את ה-PID של תהליך האב של התהליך הקורא.שאלה: מה המשמעות של getppid() == 1 עבור תהליך משתמש טיפוסי?תשובה: תהליך האב הוא init. קורה למשל אם תהליך הבן יתום.מערכות הפעלה - תרגול 222

Tutorial 2slide 24דוגמת קודמסכמתprintf("pid = %d\n", getpid());pid_t pid = fork();if (pid == 0) { printf("child pid = %d\n", getpid());...

דוגמת קודמסכמתprintf("pid = %d\n", getpid());pid_t pid = fork();if (pid == 0) { printf("child pid = %d\n", getpid()); char* args[] = {"/bin/date", NULL}; execv(args[0], args); printf("This should not be printed\n");} else { wait(NULL); printf("parent pid = %d\n", getpid());}פלט לדוגמה:pid = 8919child pid = 8920Sun Oct 29 00:31:32 IDT 2017parent pid = 8919מערכות הפעלה - תרגול 224

Tutorial 2slide 25אתחול תהליכים בלינוקסמשתמשים מתחברים לעבודה בלינוקס דרך מסופים (terminal)

אתחול תהליכים בלינוקסמשתמשים מתחברים לעבודה בלינוקס דרך מסופים (terminal).מסוף = מסך + מקלדת (מקומי או מרוחק).התהליך init יוצר תהליך בן עבור כל מסוף, אשר טוען ומבצע את המשימות הבאות לפי הסדר:איתחול של המסוף.התחברות של המשתמש עם שם משתמש וסיסמא באמצעות תכנית login.אם אושרה כניסת המשתמש: קריאה לתוכנית shell(כמו tcsh או bash) המאפשרת למשתמש להעביר פקודות למערכת ההפעלה.מערכות הפעלה - תרגול 225

Tutorial 2slide 26דוגמה לשימוש בתהליכים - shellממשק שורת פקודה (command line)

דוגמה לשימוש בתהליכים - shellממשק שורת פקודה (command line).ייעוד עיקרי: לקבל פקודות ולבצע אותן באופן סדרתי.ה-shell מייצר תהליך בן עבור כל פקודה על-מנת לבצע אותה.כל פקודה ניתן להריץ בחזית (foreground) או ברקע (background).הרצה בחזית: האב (shell) ממתין לסיום הבן לפני קריאת הפקודה הבאה.הרצה ברקע: האב (shell) עובר מיד לקריאת הפקודה הבאה.ייעוד נוסף: להציג קבצים ותיקיות על-מנת לסייר במערכת.דוגמה חיה:https://www.tutorialspoint.com/unix_terminal_online.phpמערכות הפעלה - תרגול 226

Tutorial 13slide 13בלינוקס יש שני סוגי קישורים (links)soft / symbolic linkln -s src dstקישור סימבולי הוא קובץ חדש עם inode נפרד מזה של ה...

בלינוקס יש שני סוגי קישורים (links)soft / symbolic linkln -s src dstקישור סימבולי הוא קובץ חדש עם inode נפרד מזה של הקובץ המקורי.כתיבה דרך הקישור כותבת לקובץ אליו הוא מצביע.מחיקת הקישור (באמצעות הפקודה rm) לא תמחק את הקובץ המוצבע.אפשר ליצור קישורים סימבוליים גם לקובץ שלא קיים.hard linkln src dstקישור קשיח הוא שם נרדף לקובץ המקורי כי הוא מצביע ישירות ל-inode של הקובץ המקורי.כתיבה דרך הקישור כותבת לקובץ אליו הוא מצביע.מחיקת הקישור תקטין את מונה הקישורים של הקובץ (כפי שנשמר ב-inode).הקובץ יימחק מהדיסק רק כאשר כל ה-hard links אליו יימחקו.מערכות הפעלה - תרגול 1213

Tutorial 13slide 19>> rm /A/helloמערכות הפעלה - תרגול 1219inode #2type=dirdatanameinode #A5B7inode #5type=dirdatanameinode #…………inode #1...

>> rm /A/helloמערכות הפעלה - תרגול 1219inode #2type=dirdatanameinode #A5B7inode #5type=dirdatanameinode #…………inode #13type=soft_linkdatainode #7type=dirdatanameinode #soft13……data block/A/helloקישור "שבור"!dangling link

Ask Gemini
Winter2022-examA · Q2 — question + its material already loaded
Pick a shortcut above or ask anything about this question.
The exam text, the skills it tests, and the exact slides are already in context.