Organization: File Systems التنظيم: أنظمة الملفات (File Systems)

The logical view of storage. Files, Directories, Mounting, and Allocation Methods (Contiguous vs Linked vs Indexed). العرض المنطقي للتخزين. الملفات، الأدلة (Directories)، التركيب (Mounting)، وطرق التخصيص (المتجاور مقابل المتصل مقابل المفهرس).

File Attributes سمات الملف (Attributes) Directories (Single/Two-Level/Tree) الأدلة (أحادي/ثنائي المستوى/شجري) FCB (Inode) FCB (Inode) Allocation Methods طرق التخصيص Free Space Mgmt إدارة المساحة الحرة

File Concepts مفاهيم الملفات (File Concepts)

A file is a named collection of related information recorded on secondary storage.
Abstraction: The OS maps files to physical devices (blocks), hiding complexity.
الملف هو مجموعة مسماة من المعلومات المترابطة المسجلة على التخزين الثانوي.
تجريد (Abstraction): يقوم نظام التشغيل بربط الملفات بالأجهزة المادية (الكتل)، مخفياً التعقيد.

Attributes (Metadata) السمات (Attributes/Metadata)
  • Name (Human readable) الاسم (مقروء للبشر)
  • Identifier (Unique tag, Inode number) المعرف (علامة فريدة، رقم Inode)
  • Type, Location, Size النوع، الموقع، الحجم
  • Protection (Access control) الحماية (التحكم في الوصول)
  • Time/Date (Creation, Modification) الوقت/التاريخ (الإنشاء، التعديل)
Operations العمليات (Operations)
  • Create, Write, Read, Reposition (Seek) إنشاء، كتابة، قراءة، إعادة تموضع (Seek)
  • Delete, Truncate حذف، اقتطاع (Truncate)
  • Open ($F_i$): move attributes to memory. فتح ($F_i$): نقل السمات إلى الذاكرة.
  • Close ($F_i$): flush buffers to disk. إغلاق ($F_i$): تفريغ المخازن المؤقتة إلى القرص.

Directory Structure هيكل الدليل (Directory Structure)

Evolution of Directories تطور الأدلة

  • Single-Level: All files in one directory. Name collisions, hard to manage. مستوى واحد (Single-Level): كل الملفات في دليل واحد. تضارب الأسماء، وصعوبة الإدارة.
  • Two-Level: Master File Directory + User File Directory. Solves name collision between users. مستويان (Two-Level): دليل ملف رئيسي + دليل ملف مستخدم. يحل تضارب الأسماء بين المستخدمين.
  • Tree-Structured: Arbitrary depth. Standard today. Efficient searching and grouping. هيكل شجري (Tree-Structured): عمق عشوائي. المعيار اليوم. كفاءة في البحث والتجميع.
  • Acyclic Graph: Allows shared subdirectories/files (Aliasing/Links). Danger of dangling pointers. رسم بياني لا دوري (Acyclic Graph): يسمح بمشاركة الأدلة الفرعية/الملفات (Aliasing/Links). خطر المؤشرات المعلقة.

Mounting التركيب (Mounting)

A file system must be Mounted before it can be accessed.
The OS is given the name of the device and the Mount Point (location within the existing directory structure where the FS attaches).
يجب أن يتم تركيب (Mount) نظام الملفات قبل الوصول إليه.
يتم إعطاء نظام التشغيل اسم الجهاز و نقطة التركيب (Mount Point) (موقع داخل هيكل الدليل الحالي حيث يتصل نظام الملفات).

Implementation Details تفاصيل التنفيذ

File Control Block (FCB) كتلة تحكم الملف (FCB)

Also known as an Inode in UNIX.
Contains all details about a file: Permissions, dates, owner, size, and pointers to data blocks.
يعرف أيضاً بـ Inode في نظام UNIX.
يحتوي على كافة تفاصيل الملف: الأذونات، التواريخ، المالك، الحجم، ومؤشرات لكتل البيانات.

On-Disk Structures: هياكل على القرص: Boot Control Block (Bootloader) Boot Control Block (محمل الإقلاع)
Volume Control Block (Total blocks, free block count) Volume Control Block (الكتل الكلية، عدد الكتل الحرة)
Directory Structure (File names -> Inodes) هيكل الدليل (أسماء الملفات -> Inodes)
FCBs (Inodes) FCBs (Inodes)

Allocation Methods طرق التخصيص (Allocation Methods)

How do we allocate disk blocks to files? كيف نخصص كتل القرص للملفات؟

Contiguous متجاور (Contiguous)

Each file occupies a set of contiguous blocks.
Simple (Start, Length).
Excellent read performance.
يشغل كل ملف مجموعة من الكتل المتجاورة.
بسيط (البداية، الطول).
أداء قراءة ممتاز.

Problems: External fragmentation, hard to grow files. مشاكل: تجزئة خارجية (External fragmentation)، صعوبة تكبير الملفات.

Linked متصل (Linked)

Each file is a linked list of blocks.
No external fragmentation.
Easy to grow.
كل ملف هو قائمة متصلة من الكتل.
لا توجد تجزئة خارجية.
سهل التكبير.

Problems: Slow random access (must traverse list), reliability (lost pointer = lost file). مشاكل: وصول عشوائي بطيء (يجب اجتياز القائمة)، الموثوقية (مؤشر مفقود = ملف مفقود).

Indexed مفهرس (Indexed)

Bring all pointers together into an Index Block.
Supports direct access without external fragmentation.
Standard in modern systems (e.g., Inodes).
تجميع كل المؤشرات في كتلة فهرس (Index Block).
يدعم الوصول المباشر بدون تجزئة خارجية.
معياري في الأنظمة الحديثة (مثل Inodes).

Free Space Management إدارة المساحة الحرة (Free Space Management)

Bit Vector (Bit Map) متجه البت (Bit Vector)

1 bit per block. (1 = free, 0 = occupied).
Easy to find first free block.
Efficient if kept in memory.
بت واحد لكل كتلة. (1 = حر، 0 = مشغول).
من السهل العثور على أول كتلة حرة.
فعال إذا حفظ في الذاكرة.

Linked List قائمة متصلة (Linked List)

Link together all free blocks.
No waste of space (store pointer in free block itself).
Inefficient to traverse.
ربط كل الكتل الحرة معاً.
لا هدر للمساحة (تخزين المؤشر في الكتلة الحرة نفسها).
غير فعال للاجتياز.

The Exam Vault خزنة الاختبار (Exam Vault)

Professor's Secrets & Trap Avoidance أسرار البروفيسور وتجنب الفخاخ

TRAP: Hard vs Soft Links فخ: الروابط الصلبة مقابل اللينة

Hard Link: Another directory entry pointing to the same Inode. Deleting the original filename does NOT delete the file data (until link count = 0).
Soft (Symbolic) Link: A file containing the path to another file. If the original is deleted, the link becomes broken (dangling).
Hard Link: إدخال دليل آخر يشير إلى نفس الـ Inode. حذف اسم الملف الأصلي لا يحذف بيانات الملف (حتى يصبح عدد الروابط = 0).
Soft (Symbolic) Link: ملف يحتوي على المسار لملف آخر. إذا حذف الأصلي، يصبح الرابط مكسوراً (dangling).

TRAP: VFS فخ: VFS

Virtual File System (VFS): An abstraction layer. It allows different file systems (NTFS, FAT32, NFS) to coexist. The OS talks to VFS, VFS talks to specific FS drivers. It separates generic operations from implementation details. Virtual File System (VFS): طبقة تجريد. تسمح لأنظمة ملفات مختلفة (NTFS, FAT32, NFS) بالتعايش. يتحدث نظام التشغيل مع VFS، ويتحدث VFS مع مشغلات FS المحددة. يفصل العمليات العامة عن تفاصيل التنفيذ.

SECRET: Buffer Cache سر: Buffer Cache

Modern OSs integrate the Virtual Memory system with the File System Buffer Cache. This is called Unified Buffer Cache. Memory-mapped I/O uses the same page cache as standard file I/O, preventing double caching (storing data twice in memory). تدمج أنظمة التشغيل الحديثة نظام الذاكرة الافتراضية مع كاش نظام الملفات. يسمى هذا Unified Buffer Cache. يستخدم الـ Memory-mapped I/O نفس كاش الصفحة مثل الـ File I/O القياسي، مما يمنع التخزين المؤقت المزدوج (تخزين البيانات مرتين في الذاكرة).

KEY CONCEPT: ZFS & Copy-on-Write مفهوم مفتاحي: ZFS و Copy-on-Write

Advanced file systems like ZFS never overwrite blocks in place. They write new data to a new block and then update the pointer. This makes the file system consistent at all times (no corruption on power loss) and enables instant snapshots. أنظمة الملفات المتقدمة مثل ZFS لا تكتب فوق الكتل في مكانها أبداً. تكتب بيانات جديدة في كتلة جديدة ثم تحدث المؤشر. هذا يجعل نظام الملفات متسقاً في جميع الأوقات (لا فساد عند انقطاع الطاقة) ويمكن من أخذ لقطات (Snapshots) فورية.