C5 File System
C5 File System
Chapter 5
© 2025-2026
-1-
1. INTRODUCTION
1.1 Definition
A File is a collection of information organized for storage and use iof a
File A n a computer system.
Examples
Text file: Document, source code, ...
Binary file: Executable file, image file, ...
Structured file: Student file, bank account file,
a) System and user perspectives
• From the system’s perspective:
“A file is an object possessing a name that allows it to be designated,
and it is provided with access functions that allow consulting or
modifying the information it contains."
-2-
• User perspective
3
2. The "Stream of Bytes" Vision for unstructured Files
A File is seen as a simple linear sequence of bytes. There are no records
(articles) imposed by the system. It is the application using the file that
decides how to interpret the data. For example for simple text File,
sometimes it is seen as lines (= records).
4
A file can be temporary or permanent :
❖ Permanent file
✓ Lifespan of a permanent file execution duration of the program
that created it.
✓ The name of a permanent file is chosen by the user.
5
1.3 Blocking Factor
❑ For structured Files, records can be grouped into blocks.
▪ This operation is called blocking or grouping of records.
▪ The number of items per block is called the blocking factor;
▪ The blocking factor is defined or by the file system or by the user based on
the user’s applications and the machine’s constraints.
𝑩𝒍𝒐𝒄𝒌 𝒔𝒊𝒛𝒆
𝑩𝒍𝒐𝒄𝒌𝒊𝒏𝒈 𝒇𝒂𝒄𝒕𝒐𝒓 =
𝒓𝒆𝒄𝒐𝒓𝒅 𝒔𝒊𝒛𝒆
6
❑ For an unstructured file (such as a .txt file, a .jpg image, or an executable):
➢ without a logical structure “records”, physical management “blocks”
becomes the only unit of measure, making the Blocking factor ratio non-
significant (read/write X records per block).
➢ the Operating System does not see "boundaries" between records. To the
OS, the file is simply one long continuous sequence of bytes.
➢ We often consider that the record is the block itself (Blocking factor =1). The
system reads one block, and that block contains a continuous portion of the
data stream.
7
1.4 Logical bloc vs Physical bloc
• A physical block: It is the amount of information that can be transferred
between secondary memory (storage) and central memory (RAM) in block
mode.“ (The block is the unit of transfer)
On Disk:
A block consists of one or several sectors and must start on a sector
boundary. The maximum size of a block depends on the hardware:
Block size ≤ one track.
-8-
At the logical level:
▪ A file is a set of blocks numbered from 0 to n-1 (the logical addresses of
the file's blocks: this is relative addressing).
• To access the block, the system converts the block's logical address (a
relative number from the beginning of the file) into a physical address
(LBA/CHS)
Practical example:
Consider a file that starts at LBA 1000.
A physical block consists of 8 sectors.
We want to read logical block N° 2 (logical address):
The OS calculates: 2 * 8 + 1000 = 1016 (physical address).
It requests from the disk: “Read the block starting at LBA address 1016 (the 8
sectors starting from LBA 1016).”
-9-
2. FUNCTIONS OF FILE MANAGEMENT SYSTEM (FMS)
The file management system is a module of the operating system that enables:
• Storing data on external media,
• performing data access functions (files),
• and managing user data.
Functions of a FMS :
➢ Create, view, edit, and delete files,
➢ Control access to files,
➢ Organize files and allocate space on external storage devices,
➢ Back up and restore files,
➢ Protect files,
➢ Share files, …
- 10 -
❖ File descriptor
11
2.1 File Operations
There are two types of operations:
1) Operations involving the file as a whole, such as creation, deletion,
opening, closing, copying, saving, restoring, etc.
2) Operations on individual entries, such as reading, writing, and
deleting.
12
2.1.2 Opening a File (File Opening Process)
Opening a file consists of the following operations:
▪ Locate the file on external storage: verify if the file exists.
▪ Check access rights: does the user have permission to open the file in
the specified mode?
▪ Allocate memory for buffers and the file descriptor.
▪ Establish the link between the program (logical file) and the physical
file on external storage.
▪ Complete the file descriptor using information from the file directory.
▪ Define the processing mode: Read-only, Write-only (at the beginning
or end of the file), or Read/Write (update).
▪ Define the access mode: Sequential or Direct.
▪ Initialize pointers: Current block number and current record (article)
number.
13
2.1.3 Closing a file
Closing a file consists of:
▪ If the file was opened in write or update mode → Write all buffers
(tampons) to the external storage.
▪ Update the file descriptor in the directory if it has been modified.
▪ Release the file: Break the link between the program and the file.
▪ Free the memory space occupied by the file descriptor and the buffers.
Note: At the end of a program, the system automatically closes all files
used by that program.
- 14 -
2.1.4 Deleting a File (destruction)
The destruction of a file consists of:
▪ Locate the file: Verify if the file exists.
▪ Check access rights (permissions).
▪ Verify that the file is not currently in use.
▪ Free the disk space occupied by the file.
▪ Delete its descriptor in the directory (logical deletion).
In Unix systems:
✓ Decrement the link count.
✓ Destroy the file if the link count equals zero (links = 0).
15
3. FILE ORGANISATIONS
1) Two main types of organization
16
3.1 Sequential Organization
• The simplest and most widely used.
• In this organization, records are placed one after another in their order of
arrival. A record can only be inserted at the end (logical end) of the file.
Logical Physical
EOF EOF
record1 record2 record3 … record1 record2 record3 record1
block0 … blockn-2 blockn-1
b) On disk:
✓ Contiguous allocation: Sequential locations,
✓ Block-based allocation (or cluster-based allocation): Any location → The
physical location does not correspond to the logical location.
- 17 -
1) Deleting a record
• The deletion of a record is achieved by setting an indicator called a "deletion
character". This indicator is part of the record itself.
• The deletion is referred to as "logical" because the space occupied by the
record on the external storage medium (disk) is not freed (the record will be
ignored by the OS).
2) Access to Records
• If the file is structured into records, access to these records is only possible
through sequential access.
3) Access to Blocks
• Access to a block within a sequentially organized file can be performed either
sequentially or directly by using the block's relative number.
- 18 -
4) Record Reading operation
• read_article(f, article)`: the function that allows the user to read an
article from a file `f
➢ N° Record : his is the logical pointer. It indicates which specific record within the buffer
the user wants to read (here, it points to record1).
- 19 -
5) Record Writing Operation
• Write_record(f, record) the function that allows the user to write a record
(an article) to a file named f.
➢ N° Record : his is the logical pointer. It indicates which specific record within the buffer
the user wants to write (here, it points to record1).
- 20 -
Annexe
- 21 -
b) Linux
2) Install a file system and organize the partitions into directories (logical
formatting).
26
4.1 Disk Partitioning (Step 1)
• A physical disk is divided into one or more partitions (or logical disks).
• This operation is performed after physical formatting → Each partition is
treated as a physical disk.
• Information regarding the partitioning of a hard disk is stored in its first
sector:
- 27 -
• Each partition contains a description of the logical disk:
✓ Total partition space,
✓ Free space, used space,
✓ Block size (or cluster size): the unit of disk space allocation.
✓…
• Each partition (or logical disk) contains information about the files it holds:
➢ This information is stored in directories (catalogs or folders) within that
partition.
➢ One piece of information contained in a directory: the file’s address on the
disk (its location on the disk).
- 28 -
4.1.1 Advantages of Partitioning a disk
• We can have multiple operating systems on the same disk: one system per
partition.
Note: Windows operating systems can only be installed on primary partitions.
• We can limit disk fragmentation by assigning a specific partition to: Temporary
files, system logs (log files), “Internet” files, Disk space reserved for paging
(Windows’ [Link] or Linux’s swap file or partition).
• System security and/or the security of certain important applications can be
improved by separating the system and/or these applications from other tasks
(programs and files).
• Sharing programs and data is more secure: You can share one partition while
restricting access to the others.
• Disk performance can be improved by assigning a partition to frequently used
software (programs and files), thereby reducing the movement of the read/write
heads.
- 29 -
4.1.2 Partitioning Techniques
There are two main partitioning techniques:
a) The older method, known as MBR Partitioning (Master Boot Record)
✓ Based on the BIOS (Basic Input/Output System),
✓ Used on machines with Intel x86 processors.
Note: This partitioning scheme replaces the MBR partitioning scheme. EFI was developed by
Intel in 1999 alongside the Itanium processor. 30
[Link] MBR Partitioning– BIOS
MBR partitioning dates back to the early 1980s.
A hard drive can be divided into partitions.
The number of primary partitions per hard drive is limited to four:
➢ 1 to 4 primary partitions, or
➢ 1 to 3 primary partitions and a single extended partition, or
➢ a single extended partition.
▪ The extended partition can contain one or more logical drives (theoretically
an unlimited number).
▪ Each of the primary partitions can contain an operating system (Windows,
Linux, etc.) or data (without an operating system).
▪ Thanks to partitioning, multiple operating systems can coexist on the same
disk.
- 31 -
• At any given time, only one partition is active, so the operating system on
that partition will be loaded.
• Partitions can be created, modified, or deleted using commands such as:
diskpart (Windows), fdisk (Linux), … or with other equivalent software
(Partition Magic, EaseUS Partition Master, GParted, …).
- 32 -
1. General Structure of partitioned disk
NTFS Boot Secteur NTFS Boot Secteur FAT Boot Secteur EBR
- 33 -
2. The Master Boot Record : MBR
- LBA : Sector 0;
- CHS : cylinder 0, head 0, sector 1; (HDD)
- Size = 1 sector = 512 bytes
Note: MBR sector is not static on SSD drive (Wear Leveling, Garbage Collector)
- 34 -
3. Partition Table
• Bits 6-7 of byte1 are the most significant Bits of Cylinder N° (bits 8 et 9)
• Note: The maximum capacity of a disk using CHS addressing is 256 × 63
× 1024 × 512 = 7.875 GB.
• *: Fields not used for disks with a capacity exceeding 7.875 GB and SSDs.
• Partition size on 4 bytes ➔
Max size of a partition = 232*29=241 bytes ou 2To.
- 36 -
• Types of partition :
✓ 01 : FAT12 (<10 Mo),
✓ 04 : FAT16 (<32 Mo),
✓ 05 : Extended Partition,
✓ 06 : FAT16,
✓ 07 : NTFS,
✓ 0B : FAT32,
✓ 0C : FAT32 (0B + LBA)*,
✓ …,
✓ 82 : Swap linux,
✓ 83 : Linux, …
* : The BIOS 13h interrupt extensions (functions 41h, 42h, 43h, 49h,
4Eh, and 50h) must be available to support LBA mode.
- 37 -
4. Extended Partition The number of primary partitions you can create is
limited to 4.
• How can you work around this limitation? Use an extended partition.
• A disk can have 1 to 3 primary partitions and only one extended partition.
• An extended partition can contain one or more logical drives.
Extended Partition structure
An extended partition always begins with an EBR (Extended Boot Record),
which occupies one sector (like the MBR):
✓ 446 bytes : 0,
✓ Extended partition Table : 4*16 bytes,
✓ Signature « 55AA » : 2 bytes.
➢ Extended partition Table includes :
✓ One logical drive and
✓ One extended partition.
Or
✓ Only one logical drive.
➢ 1 or 2 entries of the extended partition table are used.
- 38 -
Extended Partition
EBR : 512 bytes (the first sector of the extended partiton*)
- 446 ‘0’
- The extended partition table (64 b) : 2 entries are used
- 55AA (2 b)
Logical drive NTFS Extended Partition
- 446 ‘0’
Master File Table - Partition Table (64 b) : 1 entry is used
- 55AA (2b)
Logical drive: FAT32
Boot Sector
Reserved Zone
FAT1
Clusters : FAT2
Files and directories
Clusters :
Files and directories
- 39 -
5. The starting addresses of the partitions
▪ Classic Format (Legacy / Non-aligned):
Typically used on older HDDs with Windows XP or software that does not
support Advanced Format.
40
5.1. Non-aligned Partitions (legacy)
➢ Disks partitioned and formatted using Windows XP software or other software that
does not support the extended format.
• MBR: 0,0,1; → The first track of the disk contains only the MBR.
• Primary partition of the disk (partition following the MBR): 0,1,1. LBA address: 63
• Other primary partitions: x, 0, 1 (Start address of a cylinder).
• Extended partition: Always starts at address x,0,1 ➔
➢ EBR: x, 0, 1➔ The first track of the extended partition contains only the EBR
➢ Logical drive : x, 1, 1.
LBA address 63 relative to the start of the extended partition (EBR)
➢ Notes: If the first partition on the disk is an extended partition, one cylinder is lost
(-1 sector) → Lost Space = (63*256-1)*512= 8257024 = 7.875 MB.
❖ Cylinder 0 contains only the MBR.
❖ The extended partition is on the next cylinder.
- 41 -
5.2. Aligned Partitions (SSD/HDD with advanced format)
The LBA address (start address) of a partition is aligned with the start address of a
4K-byte sector: The partition's start address (LBA) is a multiple of 8.
The default Windows value is 2048 sectors of 512 bytes → Partitions start at the
beginning of a 4K-byte sector.
If all partitions start at an LBA address that is a multiple of 8 sectors of 512 bytes:
→This is Alignment 0.
Disks (HDD or SSD) partitioned and formatted with Windows starting from "Vista
SP1" or utilities supporting Advanced Format
▪ MBR: LBA 0; → The first track/page of the disk contains only the MBR.
The size of a primary partition must be a multiple of 2048 sectors (Alignment 0).
▪ First primary partition following the MBR: LBA 2048 address.
▪ Other primary partitions: Start address is a multiple of 2048 sectors.
▪ Extended Partition: Start address is a multiple of 2048 sectors.
- 43 -
• The partition table is better protected: The header and partition table are
stored at the end of the hard drive.
• In addition, a 32-bit CRC (Cyclic Redundancy Code) is used for the header
and another for the partition table.
• GPT partitioning has retained MBR partitioning for a single primary
partition.
1) Microsoft's implementation of GPT partitioning
• Number of partitions: 128.
• Partition size = 256 TB (248).
• 4 reserved partitions (3 for Windows 7; 4 for Windows 8).
• Users have only 124 partitions available (system and data).
- 44 -
• Microsoft Configuration
• Three partitions are required and must be located before the Windows
partition:
1) A “recovery” partition (WinRE) for Windows Recovery Environment tools:
NTFS, size ≥ 300 MB (specific to Windows 8).
2) An ‘ESP’ (EFI System Partition), a UEFI partition containing the NTLDR, HAL,
[Link], and other files necessary for system startup, such as drivers: FAT32,
Size ≥ 100MB.
3) An ‘MSR’ (Microsoft® Reserved Partition): Unformatted, Size = 32MB if disk <
16GB; Size = 128MB if disk > 16GB.
4) Windows 7 / Windows 8 partition: NTFS ≥ 20GB.
Recommended Partition
In addition to the first three partitions listed above, Microsoft recommends
a fourth partition for the manufacturer’s recovery image ([Link]),
which would be used to restore the factory settings: NTFS. This partition
must be located after the user partitions (Windows and data partitions).
- 45 -
Partition GPT
Rôle principal Visible utilisateur ? Taille typique
Windows
Contient les fichiers de
EFI System Partition démarrage UEFI (.efi)
Généralement cachée 100–300 MB
(ESP) et le boot manager
Windows
Réservée par
Microsoft Reserved Windows pour gestion 16 MB (Windows
Cachée
Partition (MSR) interne GPT et futures récents)
opérations disque
Contient Windows,
Windows Partition (C:) programmes et fichiers ✅ Oui Variable
utilisateur
Contient les outils de
Recovery Partition
récupération et Généralement cachée 500 MB – 1 GB
(WinRE)
réparation Windows
Partition ajoutée par le
OEM Recovery fabricant (HP, Dell,
Souvent cachée 1–20 GB
Partition Lenovo…) pour
restauration usine
46
2) Disk structure with GPT partitioning (n sectors)
Partitions :
➢ Theoretically, partitions start at sector 34.
➢ The first partition starts at LBA 2048.
➢ The size of a partition must be a multiple of 1 MB or 2048 sectors.
447 3 0 0 0 0
Disk size
458 4 If size 241 sectors (2To) ➔ 0 0 0
Maximal size = 2Tb, The remainder is ignored
- 49 -
GPT Partition Table Header
offset Long Content
0 8 Signature ("EFI PART")
8 4 Version
12 4 Header size(Little Endian)
16 4 CRC32 header
20 4 Reserved: initialized to zero
24 8 LBA GPT header: 1
32 8 LBA of the header copy (last sector of the disk)
40 8 First LBA address of the data area (start of partitions)
48 8 Last LBA address in the data area (end of partitions)
GUID(Globally Unique Identifier) of the disk (equivalent to UUID
56 16
Universally Unique Identifier de Linux voir /etc/fstab and command blkid)
72 8 LBA address of the partition table (2 for GPT)
80 4 Number of entries in the partition table
84 4 Entry size : 128 bytes
88 4 CRC32 of the partition table
92 420 Reserved : initialized to zero
- 50 -
Partition table entry: 128 bytes
offset Lenght Content
Partition GUID type: Examples :
Unused partition : 00000000-0000-0000-0000-000000000000
0 16
Partition (GPT-EFI) : C12A7328-F81F-11D2-BA4B-00A0C93EC93B
MBR Partition: 024DEE41-33E7-11D3-9D69-0008C781F39F
Unique partition GUID Exemple: A81C2DB8-E808-4853-A67B-
16 16
3982C65C23C2
32 8 First LBA (little-endian) address of the partition
40 8 Last LBA address of the partition
Attributs:
00: System partition
02: BIOS-bootable
48 8
60: Only read
62: hidden
63: Do not automatically mount, …
- 53 -
The MBR bootloader (boot program):
• Locates the active partition,
• Loads the Boot sector of this partition into the main memory at address
0x7C00 (16-bit addressing), and
• Starts the execution of the boot sector of the chosen partition.
It is the boot sector that loads the operating system (Windows 7, Linux, ...)
of the chosen partition into the main memory.
Example: Linux with Lilo
• Linux uses its own bootloader (Lilo or GRUB).
• Lilo (Linux Loader) can be stored on the MBR or on the Linux partition.
1. Lilo stored on the MBR
The size of Lilo 5 KB → 10 times the size of the MBR;
Since Lilo cannot fit on a single sector → One part (less than 512 bytes) of Lilo
is stored in the MBR and the other part is stored in the Linux partition.
54
➢ The BIOS loads the first part of Lilo, which in turn will load the
rest of the program from the Linux partition.
➢ Lilo chooses the system to load from the file /boot/boot.b.
Note: On some current PCs, it is the EFI (and not the BIOS) that is
used to launch the bootloader (loader): The EFI reads the GPT table
of the disk (GUID Partition Table) to determine the location of the boot
routine.
55
4.2 Organizing Partitions into Directories (Step 2)
Use of Directories
A directory is used during the following operations:
➢ File Creation: This consists of adding an entry (file descriptor) into the
directory.
➢ File Destruction: This is a logical deletion (e.g., in FAT, placing 'E5'
in the 1st byte of the filename → the entry is marked as deleted).
➢ Opening/Closing a file: To read or write "articles" (data records).
➢ Listing the directory: For example, the "dir" command in DOS or "ls"
in UNIX/Linux.
➢ Backup, restoration, file copying, ...
▪ Therefore, a directory must be organized in a way that facilitates
all these operations.
56
4.2.1 Directory Structure
A directory can have one or more levels.
[Link] Single-level Directory
A disk (physical or partition) has only one directory; all file descriptors are
located in the same directory.
This structure is easy to implement; However, it does not allow two
different users to give the same name to their files.
- 57 -
[Link] Hierarchical or Multi-level Directory
A physical disk or partition has a root directory and potentially one or more
"subdirectories."An entry (descriptor) within a directory can identify either
a file or a directory (subdirectory).The number of levels and the number
of entries per directory depend on the file system.
- 58 -
4.3 Disk space allocation
59
4.3.1 Contiguous Allocation
• In this method, the space required for the file is requested upon creation;
if the system cannot satisfy this request, the file is not created.
• Free space is represented using a list of free zones.
• Initially, the disk consists of a single zone.
• Zones are created as files are created (space allocation) and destroyed
(space deallocation/release).
• Several strategies exist for selecting a zone; the most important ones are:
first-fit and best-fit, ...
- 60 -
4.3.2 Non-contiguous Allocation
▪ To solve the problem of disk space fragmentation (émiettement), this
space is considered as a set of blocks of the same size, where the block is
the unit of allocation.
[Link] Block Size
▪ CHS Addressing: A disk is composed of cylinders, tracks, and sectors.
▪ With LBA Addressing: A disk is considered as a set of sectors
numbered from 0 to n-1.
▪ The smallest amount of information that can be transferred in block
mode between the disk and main memory is the sector.
▪ Block size must be a multiple of the sector size.
▪ If the block size is well-chosen →
➢ Better disk space occupancy, and
➢ Reduced I/O (Input/Output) time in sequential processing.
61
[Link] Representation of Free Blocks
Exemple
The following blocks are free: 2, 3, 4, 5, 8, 9, 10, 11, 12, 20, 21.
1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 …
- 62 -
b) Free Block List (Linked Lists of Blocks)
Free blocks are linked together to form a list of free blocks.
The following blocks are free: 2, 3, 4, 5, 8, 9, 10, 11, 12, 20, 21.
- 63 -
a) Linked Blocks
▪ The file consists of a set of blocks linked together.
▪ A block is composed of two parts: A pointer and data.
▪ The file descriptor contains:
✓ The address of the first block of the file (head of the list),
✓ The address of the last block.
This allocation mode is well-suited for sequential access. However, it is very
costly for direct access.
64
b) Allocation Index Tables
▪ A file is composed of:
▪ Allocation index tables (blocks),
▪ A set of data blocks.
▪ The allocation index blocks are linked together and point to the data blocks.
▪ The file descriptor contains the address of the first allocation table.
- 65 -
c) The Allocation File (Mapping)
▪ Disk space is represented using an allocation table (file).
▪ One entry in this table (file) corresponds to a block.
▪ The table contains as many entries as there are data blocks on the disk.
▪ The blocks allocated to a file are linked together.
▪ The file descriptor contains the address (index) of the first block in the
allocation table (allocation file).
- 66 -
4.4 Unix File System
• The Unix file system is hierarchical: it is organized as a tree structure
whose nodes are directories and whose leaves are files.
• The tree is built from a unique root directory called the root, designated
by ‘/’
• Main file types :
✓Regular files (-),
✓Directories (d),
✓Symbolic links (l),
✓Special file : These are used to represent hardware devices. They are
generally located in the / dev directory..
❖ Character-mode devices (c ),
❖ Block-mode devices (b),
❖…
- 67 -
• A directory is a file whose content consists of a sequence of “pairs” made
up of a file name and an index (inode number).
• The index provides access to the file descriptor table called the inode
table.
• In the early versions of Unix, file names were limited to 14 characters.
• Therefore, one entry occupies 16 bytes:
✓ 2 bytes for the inode number,
✓ 14 bytes for the file name.
- 68 -
• BSD Versions (from BSD 4.2) and linux (ext2,ext3,...),
➢ File names have variable lengths, up to 255 bytes ➔Therefore,
directory entries also have variable lengths.
A directory is thus a file with a variable-length format.
- 69 -
• When a directory is created, two entries «.» et «..» are also created.
✓ «.» : refers to the current directory,
✓ «..» : refers to the parent directory.
- 71 -
4.4.2 File Naming
➢ A Unix file name is composed of a sequence of characters;
➢ Unix is case-sensitive, meaning it distinguishes between uppercase and
lowercase letters.
➢ The character « - » is discouraged at the beginning of a file name
because some commands may interpret it as an option.
➢ A file can be designated using either an absolute path or a relative
path.
• Absolute Path
➢ An absolute path starts from the root « / » of the file system and
contains all the directory names forming the path. These directory
names are separated by the character /.
➢ The last name in the path corresponds to the directory or file that we
want to access.
➢ Example1 : Absolute path of the file tpsys :
/home/1cs/Groupe3/b6/tpsys - 72 -
• Relative Path
➢ To access a directory or a file from the current directory, we use the
name of the desired file or directory.
➢ A relative path starts from the current directory.
➢ Example:
✓ Suppose the current directory is: /home/1cs/Groupe3/b6
✓ The relative path: tpsys is equivalent to the absolute
path:/home/1cs/Groupe3/b6/tpsys
- 73 -
[Link] Structure of a Logical Disk (Unix System V)
Boot
Super bloc
Inode table
Data blocks:
Directories
And
files
• Note: This structure does not correspond to BSD and Linux file systems
(ext2, …).
- 77 -
• The superblock contains the following information:
✓ File system size,
✓ File system name,
✓ Number of blocks,
✓ List of free blocks,
✓ Pointer to the first free block,
✓ Number of inodes,
✓ List of free inodes,
✓ Pointer to the first free inode,
✓ Disk characteristics.
- 78 -
• An inode is a structure containing all the information defining a file. It
includes:
➢ File type,
➢ Number of links,
➢ Owner identifier,
➢ Group identifier,
➢ File size in bytes,
➢ Creation date or last modification date,
➢ Date of last use (last access date),
➢ Last inode modification date,
➢ Protection or access rights (12 bits),
➢ File allocation index table (13 words of 4 bytes),
➢ Other information depending on the version,
- 79 -
4.4.4 Disk Space Allocation in Unix System V
• Disk space = a set of blocks.
• Allocation unit = block. Dynamic allocation is done per block.
• Block size varies depending on system versions: 512, 1024, 2048, ….etc.
• The most commonly used size is 1024 bytes.
• Free space is described using a list of free blocks stored in the superblock.
• The allocated disk space (allocated blocks) of a file is represented using
allocation index tables:
✓ The first allocation index table, composed of 13 entries, is stored in the
file’s inode.
✓ Depending on the file size, additional indexes (index blocks) may be
used; these indexes are part of the file itself.
✓ Size of an entry in the allocation index table or an allocation index
block = 4 bytes.
- 80 -
Inode1 Name 1 … Inode i Name i …
Inode1
… …
Inode i File type
Number of links
Owner ID
Group ID
File size in bytes
Dates : creation, modification,
last access, inode modification
Protection (12 bits)
File allocation index table
… …
INODE TABLE
- 81 -
INODE File
Data block
1 Data
address
2
3
…
Data block
10 Date
address
11 Indirection Allocation
index block Date
- 82 -
• The actual size of a file = allocation index blocks + data blocks.
• Example: Block size = 1024 bytes; Entry length= 4 bytes.
• The maximum number of data blocks in a file =
10 + 1024/4 + (1024/4)2 + (1024/4)3 = 10 + 256 + 2562 + 2563
= 16843018 blocks
• The maximum actual size =
10+(1+256)+(1+256+2562)+(1+256+2562+2563) = 16 909 069
blocks.
• Remarks :
➢ The access time to file blocks is not uniform:
the first 10 blocks are prioritized.
➢ This representation allows fast access to small files.
- 83 -
• Some differences between Unix System V and Unix BSD:
1. BSD disks are organized into cylinder groups.
Each group has the same organization as System V logical disks ➔ this
helps reduce head movement.
2. Data blocks are larger (4 KB or 8 KB).
3. The file allocation index table contains:
✓ 12 direct addresses,
✓ 1 indirect address,
✓ 1 double indirect address,
✓ 1 triple indirect address (this one is not used, because with 4 KB
block sizes the file size exceeds the 2³² bytes limit).
4. File names range from 1 à 255 bytes ➔ directories are composed of
variable-length records.
- 84 -
[Link] Structure of a Logical Disk in the Linux ext2/ext3 File
System
• A logical disk or volume (partition or hard disk) in the Ext2/Ext3 file
system is divided into block groups (similar to BSD cylinder groups).
• Each block group contains:
✓ Super bloc,
✓ Descriptor table that locates the different group tables,
✓ Block bitmap table of the group,
✓ Inode bitmap table of the group,
✓ Table de bitmaps des inodes du groupe,
✓ Table des inodes du groupe,
✓ Data blocks containing directories and files.
• In each group, a copy of the superblock and a copy of the descriptor table
are found. ➔ this improves the reliability of the Linux file system (ext2/3).
- 85 -
SecteurBoot
Sector Boot
Group 1 of Group 2 of Group 3 of Group n of
blocks blocks blocks blocks
Super bloc
Table of
descriptors
Inode Table of
bitmap Super bloc descriptors
tables
- 86 -
SGF EXT 4 (Linux)
• Uses extents
- A set of contiguous blocks (e.g., 128 MB of 4 KB blocks).
- They do not require metadata (at inode level) for each block.
- Operations are faster.
- Supports larger files than previous systems. For example, with 1
KB blocks, the maximum file size increases from 16 GB to 16 TB.
The maximum partition size can reach 1 Exa byte.
• Journaling file system: All modifications to data and to the file
system itself are recorded sequentially in this file. This helps
prevent data loss after a system crash(bug or system error).
• Partitioned into blocks, like ext2.
• Uses 48 bits for each extent address.
87
4.4.6 Links
• A link allows a file to be referenced using multiple names.
• Two types of links are distinguished:
1. Physical link (or hard link),
2. Symbolic link).
[Link] Physical link (or hard link):
✓ Allows multiple names (links) to be associated with a file; the file must
be in the same file system.
✓ At the implementation level, there is only one inode : the inode of the
original file.
✓ All link names point to the same inode.
✓ Deleting the file ➔ Deleting a link.
The file is only removed when the number of links becomes zero.
✓ Command: ln original_file hard_link_file
88
[Link] Symbolic link: (raccourci)
✓ Introduced in version 4.2BSD,
✓ It allows one or more names (links) to be associated with a file or
directory located in the same file system or in another file system.
✓ It is a link-type file that has its own inode.
✓ The data of a symbolic link corresponds to the path of the original file.
✓ Deletion:
❖ Deleting a symbolic link has no effect on the original file it refers to.
❖ Deleting or moving the original file “breaks” the symbolic link:
The symbolic link still exists but can no longer access the file.
✓ Command:
ln -s original_file symbolic_link_file
89
4.5 FAT32 File System
90
FAT32 partition structure
- Boot sector
- Reserved Area (with sector boot):
bytes 14-15 of boot sector
- FAT1
- FAT2
Clusters
Files and Directories
91
1. Boot Sector
The first sector of a partition contains:
• The startup program called 'bootstrap' or boot sector,
• A table containing BIOS parameters and information regarding the file
system (FAT section).
On an SSD, entries 24 and 26 are passive. The file system writes them during formatting to comply with the FAT32
standard, but the SSD controller ignores them completely." 93
3. FAT Section (Boot Sector)
Position Content Taille
36 Number of sectors per FAT32 (replace positions 22-23) 4
40 Flags : used for « mirroring » of the FAT 2
42 File System Version 2
First cluster of the root directory (): cluster 2
44 4
(this value can change if cluster 2 is defective)"
• When a directory is created, teh system creates two entries ‘.’ and ‘..’
➢ ‘.’ : current directory,
➢ ‘..’ : parent directory.
- 95 -
Each entry consists of 32 bytes.
The maximum number of entries in FAT32 directories is equal to
65534. We distinguish two types of entries:
1) Entry for short format names (11 characters (8.3)): [Link];
2) Entry for long format names (255 characters).
In the area (implementation address) reserved for the first cluster number, we
find:
▪ The number of the first cluster of the current directory for the directory
'.'
▪ The number of the first cluster of the parent for the directory '..'; or
Zero if the parent directory is '' (root).
▪ The area reserved for the file size contains zero.
➢ These directories (. and ..) allow for navigating up the directory tree."
96
[Link] Structure of a short format entry (directory)
A file name is composed of two parts:
▪ The name, consisting of 1 to 8 ASCII characters.
▪ The extension, consisting of 0 to 3 ASCII characters.
97
offset size Content
00 8 Name: ASCII characters
08 3 Extension : ASCII characters
FAT32 table
0
File 1 of 3 1
clusters
2
…
…
00000101 100
00000102 101
0FFFFFFF 102
…
…
- 99 -
[Link] Structure of a long format entry (format long)
▪ The file name consists of 1 to 255 characters.
▪ A file is represented in the directory by means of:
➢ One to twenty long format entries:
• One entry = 32 bytes.
• Each entry can contain at most 13 characters of the name.
• The characters making up long format names are represented in
UNICODE (UTF16: 2 bytes per character).
➢ One short format entry:
• In the short format entry, the name consists of the first six characters
(letters or numbers) followed by the ~ character, which is followed by a
digit (number) and finally the extension (without the dot).
• The name is converted to Uppercase.
• The characters making up short format names are represented in ASCII
(1 byte per character).
100
Entries composing a long format name
…
…
…
101
• Content of a Long-format entry:
12 1 Reserved
26 2 0000
- 102 -
• Example of a file name:‘‘long format [Link]’’
✓ File name = 30 characters ➔ 3 entries in long format
✓ Short format name = NOMENF~1DOC (the dot ‘.’ is not represented)
)
- 103 -
4.5.3 Allocation in the FAT32 file system
• The disk space reserved for files and directories is divided into n clusters
numbered from 2 to n + 1.
• Each cluster is composed of 2k sectors (k0).
• The allocation unit is the cluster.
• The space is dynamically allocated to a file: one cluster at a time.
• Disk space is represented in an allocation file called the FAT(File Allocation
Table).
• Entry number i in the FAT corresponds to cluster number i in the disk
space.
• An entry may use 12 bits (FAT12), 16 bits (FAT16), or 32 bits (FAT32).
• The first two entries are reserved for the system:
The first byte contains the device descriptor code (ex. F8 for a hard
drive), the remaining bytes contain the value ‘FF’.
- 105 -
• An FAT32 entry can contain the following values:
value Meaning
0x00000000 Free cluster
0x0FFFFFF0 – 0x0FFFFFF6 Reserved cluster
0x0FFFFFF7 Defective cluster
0x0FFFFFF8 – 0x0FFFFFFF Last cluster of the file (EOF)
Other values greater than 2: The number of the next cluster in the
(28 rightmost bits) file. First cluster in the FAT = 2
• The entries corresponding to the clusters allocated to the files are linked together.
➢ FAT LBA address = Partition start LBA address + number of reserved sectors.
➢ First cluster LBA address = Partition start LBA address + number of reserved
sectors+ Number of FATs * Number of sectors per FAT
➢ LBA address of cluster i = LBA start address of the first cluster + (i - 2) * number
of sectors per cluster.
- 106 -
The size of a cluster depends on the disk capacity:
==============================================
- 107 -