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 કરો!