Theory
अदृश्य Cabinet
जब आप अपने C program को हमारे साझा college server, LabOne, पर lab2.c के रूप में save करते हैं, आप इसे एक directory folder में बैठे एक अकेले, साफ़-सुथरे document के रूप में सोचते हैं। पर अगर आप server room के अंदर असली magnetic platter या electronic chips को देखते, आपका code बेतरतीब physical sectors में binary digits के रूप में बिखरा है। fragmented bits का एक विशाल संग्रह आपके compiler को एक अकेली निरंतर notebook कैसे दिखता है?
Theory
Library Catalog Card
एक file को एक printed library book की तरह सोचिए। student के लिए, यह एक title, author, और size वाली एक अकेली निरंतर कहानी है। पर physical building के लिए, वह किताब दूर shelves में store किए individual pages में टूटी है। operating system master librarian की तरह काम करता है: यह उन सारे बिखरे pages को एक साथ लपेटता है, उन पर एक logical title tag चिपकाता है, और कहता है, 'shelf numbers की चिंता मत करो, बस title पढ़ो।'
Theory
File Concept परिभाषित
औपचारिक रूप से, एक file संबंधित जानकारी का एक नामित संग्रह है जो secondary storage पर record किया जाता है। operating system के नज़रिए से, एक file सबसे छोटी logical storage unit है: data secondary storage पर तब तक नहीं लिखा जा सकता जब तक इसे एक file के अंदर लपेटा न जाए। यह एक निरंतर logical address space दर्शाता है जो system software द्वारा physical storage tracks और blocks पर map किया जाता है।
At a glance
हर logical file entry के लिए file system द्वारा बनाए रखे मूल attributes।
| File Attribute | उद्देश्य | LabOne Server उदाहरण |
|---|---|---|
| Name | user सुविधा के लिए मानव पठनीय identifier | lab2.c |
| Identifier | data track करता अनोखा system tag number | Inode 45219 |
| Type | भीतरी format extension निर्दिष्ट करता है | .c या .out |
| Location | physical disk block addresses की ओर pointer | Blocks 1024 से 1028 |
Follow along
छह मूल Lifecycle Operations
- Create OS ख़ाली disk space allocate करता है और directory structure में एक नया name pointer entry जोड़ता है।
- Write system file name और data निर्दिष्ट करता है, यह track करने के लिए एक सक्रिय write pointer रखते हुए कि अगला byte कहाँ जाता है।
- Read system मौजूदा read pointer position से data पढ़ता है और tracking pointer head आगे बढ़ाता है।
- Reposition एक file seek के रूप में भी जाना जाता है, यह data पढ़े या लिखे बिना मौजूदा position pointer बदलता है।
- Delete OS directory खोजता है, सारे allocated disk blocks release करता है, और directory entry मिटाता है।
- Truncate system file की सामग्री शून्य bytes तक साफ़ करता है पर इसके attributes और directory name बरक़रार रखता है।
Quiz
जब कई student sessions LabOne पर एक साझा textbook file एक साथ पढ़ते हैं, operating system हर एक individual program के लिए इसकी reading position track करने के लिए कौन सा भीतरी marker बनाए रखता है?
- एक physical hardware track address
- एक current file position pointer
- एक global disk sector index number
- एक file format extension string
Show the answer
एक current file position pointer
operating system हर open process के लिए एक स्वतंत्र current file position pointer बनाए रखता है। यह pointer track करता है कि अगला read या write operation कहाँ होगा, एक student की position को दूसरे से अलग करते हुए।
Watch out
Missing Close का जाल
university exams में एक classic ग़लती file lifecycles सूचीबद्ध करते समय close operation भूलना है। students सोचते हैं कि delete या create ही एकमात्र बड़े tasks हैं। पर अगर एक program स्पष्ट रूप से close call नहीं करता, सक्रिय file pointers और भीतरी system table buffers RAM में locked रहते हैं। यह LabOne पर memory resources बर्बाद करता है और अगर server अप्रत्याशित रूप से restart होता है तो स्थायी data corruption पैदा कर सकता है।
Think first
एक File Delete बनाम Truncate करना
मान लीजिए एक student एक अस्थायी file के अंदर सारे log messages साफ़ करना चाहता है पर भविष्य के automated scripts के लिए filename बरक़रार रखना चाहता है। क्या उन्हें file delete करनी चाहिए या truncate करनी चाहिए? tap करने से पहले logical फ़र्क़ का मन में विश्लेषण कीजिए।
Show the answer
उन्हें file truncate करनी होगी। Deleting file name, attributes, और entry pointer को directory structure से पूरी तरह हटाता है, एक recreation चरण की ज़रूरत रखते हुए। Truncating file name, permissions, और ownership बरक़रार रखता है, पर file size को शून्य पर reset करता है और इसके stored data blocks को वापस मुफ़्त disk pool में release करता है।
Theory
System Calls और बाद के Semesters
आप इन बिल्कुल operations को Unit 4 में raw programming commands इस्तेमाल करते हुए execute करेंगे। cat, rm, और touch जैसी utilities जादुई tools नहीं हैं: वे आज हमने पढ़े बुनियादी operating system algorithms के इर्द-गिर्द सीधे scripts हैं। अपने चौथे semester के data structures course में, आप memory index maps बनाएँगे जो बिल्कुल दर्पण की तरह दिखाते हैं कि ये logical file pointers physical storage sectors में कैसे अनुवादित होते हैं।
Summary
Key takeaways
- एक file सबसे छोटी नामित logical storage unit है जो physical secondary storage devices पर map की जाती है।
- operating system physical tracks, sectors, और sector सीमाओं को applications से पूरी तरह छुपाता है।
- name, identifier, type, और location जैसे file attributes directory records के अंदर सुरक्षित रूप से track किए जाते हैं।
- छह मूल system operations हैं create, write, read, reposition, delete, और truncate।
- System tables multi-user access states साफ़-सुथरे track करने के लिए current file pointers बनाए रखती हैं।
- Memory hook: इसे Create करो, open करो, seek करो, lock करो, close करो, और protect करो!