0% found this document useful (0 votes)
2 views102 pages

C5 File System

Chapter 5 of the document discusses file management systems, defining files and their types, including temporary and permanent files. It outlines the functions of a file management system, including file operations such as creation, opening, closing, and deletion, as well as file organization methods. The chapter also covers logical and physical organization, data access modes, and provides practical examples of file operations in both Windows and Linux environments.

Uploaded by

nmbougheloum
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views102 pages

C5 File System

Chapter 5 of the document discusses file management systems, defining files and their types, including temporary and permanent files. It outlines the functions of a file management system, including file operations such as creation, opening, closing, and deletion, as well as file organization methods. The chapter also covers logical and physical organization, data access modes, and provides practical examples of file operations in both Windows and Linux environments.

Uploaded by

nmbougheloum
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Centralized Operating System

Chapter 5

FILE MANAGEMENT SYSTEM

© 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

There are mainly two major visions of a file's structure:

1) The "Record-oriented" Vision for structured Files


This is the more common vision. The file is explicitly divided into logical
units called records or articles relating to the same subjects.
▪ Each record has a fixed or variable size.
▪ It is composed of fields, each field is defined by : a name, a type, and
potentially a length (for variable size record).

Example: A « Student file » where each « record" contains:


[Student Number, Last Name , First Name , Address].

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).

The operating system sees a File as an organization of data


stored in blocks on disk.

4
A file can be temporary or permanent :

❖ Temporary file: This is a working file that disappears once the

execution of the program that created it ends.


✓ Lifespan of a temporary file ≤ execution duration of the program
that created it.
✓ A temporary file is identified by a name chosen by the software.
Examples
▪ Windows Systems: \temp directory; the names of some
temporary files are followed by the .tmp extension.
▪ Unix Systems: Temporary files directory: /tmp.

❖ 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.

𝑩𝒍𝒐𝒄𝒌 𝒔𝒊𝒛𝒆
𝑩𝒍𝒐𝒄𝒌𝒊𝒏𝒈 𝒇𝒂𝒄𝒕𝒐𝒓 =
𝒓𝒆𝒄𝒐𝒓𝒅 𝒔𝒊𝒛𝒆

➢ For variable-sized records, the maximum record length will be used

Advantages of the grouping factor


✓ Better utilization of external storage media
✓ Reduction in the number of physical input/output operations.

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

▪ A file is defined in the system using a descriptor (table) that is


stored on the external storage media.
▪ The descriptor contains all the file attributes:
✓ Name, extension (PC-DOS), [version number],
✓ Address of the first block on disk, Address of the last block,
✓ File size (number of blocks or characters),
✓ Creation and modification dates, etc.
✓ Protection,
✓ File organization (sequential, direct, indexed sequential, etc.),
✓ Block length, Record format (fixed, variable), record length, logical
deletion, etc.

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.

2.1.1 Creating a File


This operation involves:
➢ Defining the file and assigning it a unique name to identify it.
➢ Checking whether the file already exists.
➢ Adding the file descriptor to the file directory.

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

a. Logical Organization b. Physical Organization (Disk


(User/Program View) View)
Logical organization defines how records Method for assigning a physical location
(also called items or entries) are structured on the external storage media to any
relative to one another within a file: logical record (item): Contiguous block
Sequential Organization, Indexed Allocation, linked block Allocation,
Sequential Organization (ISAM), Direct Indexed block Allocation (e.g., Unix
Organization, etc. Inodes) (see further: Linux EXT).

2) Data Access Modes :


This refers to the methods used by a system to retrieve or write information.
➢ Sequential Access: Accessing records in a consecutive order (one after another).
➢ Direct Access (or Random Access): Accessing a specific record immediately by its
address or position, without reading the preceding data.

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° Block : the physical pointer indicates which block should be loaded.

➢ 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° Block : the physical pointer indicates which block should be loaded.

➢ 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

3.3 Using physical disks


• A disk is a peripheral on which read/write operations can be performed without
taking the file system into account.
• a) Windows
• Physical disk name: \\.\PhysicalDriveN
➢ N : the number of the physical disk= 0, 1, 2, ….
➢ The first disk: N=0.
➢ Example : Open the second physical disk for reading:
✓ FILE *disk;
✓ disk = fopen("\\\\.\\PhysicalDrive1", "rb");
• Partition name: \\.\X:
➢ X: = C: , D: , E: , …
➢ X: Letter[a…z] followed by : - Refers to a hard drive partition, a CD-ROM
drive, a flash disk, or a floppy disk."

- 21 -
b) Linux

• Physical disk name :


➢ ATA : hdN
➢ SCSI, SATA, SSD, carte SD et USB : sdN
➢ N : the number of the physical disk: a, b, c, d, ….
➢ Disks are devices that are located in the directory /dev
➢ Exemples:
✓ /dev/sda /* First physical disk*/
✓ /dev/sdb /* Second physical disk */
FILE *disk;
disk = fopen(“/dev/sdb”, "rb"); /* Opening the second disk*/

• "The partitions of a disk are designated (named) by numbers: the


1st one bears the number 1, the 2nd one bears the number 2,
..."Examples :
✓ /dev/sda1 /* First partition of the first disk*/
✓ /dev/sda2 /* Second partition of the first disk */
- 22 -
/* Sequential reading and character-by-character writing to the file lireseq.c on drive
G: or “G:\lireseq.c” */
Note: In this example, a file is read from a partition
#include <stdio.h>
main()
{ int n;
char buffer; /* article de taille = 1 octet */
FILE *fichier=NULL;
fichier = fopen("G:\\lireseq.c","r"); /* Windows */
if(fichier == NULL) printf("\n The file is not open : %d\n", fichier);
else{
n=fread(&buffer, 1, 1, fichier);
while(n>0){
printf("%c",buffer);
n=fread(&buffer, 1, 1, fichier);
}
}
fclose(fichier);
return;
}
- 23 -
/* Sequentially read and print the first 10 sectors of the first physical disk */
#include <stdio.h>
main()
{ int n,s,i,j;
unsigned char buffer[512]; /* bloc = 512 octets*/
FILE *disk=NULL;
disk = fopen("\\\\.\\PhysicalDrive0", "rb"); /* Windows */
/*disk = fopen("/dev/sda", "rb"); */ /* Linux */
if(disk == NULL) printf("\n disk not open\n");
else{
for( i=0; i<10; i++){
n=fread(buffer, 512, 1, disk); /*reading a record or block od 512 bytes*/
if(n<=0) printf("\n Error of fread = %d ",n);
else{
printf("\n Sector%d: Number of items read = %d\n",i,n);
for(j=0; j<512; j++) printf("%02x", buffer[j]);
}
}
}
fclose(disk);
return;
}
- 24 -
/* Direct-access read from sector 10 (LBA 10) of the second physical disk */
#include <stdio.h>
main()
{ int n,s;
unsigned char buffer[512];
long int a=512*10; /* secteur 10 */
FILE *disk=NULL;
disk = fopen("\\\\.\\PhysicalDrive1", "rb"); /* Windows */
disk = fopen("/dev/sdb", "rb"); /* Linux */
if(disk == NULL) printf("\n Error the disk is not open\n" );
else{ s=fseek(disk, a, SEEK_SET); /*seek relative to the beginning of the file:0 */
if(s!=0) printf("\n Error of fseek : s= %d",s);
else{ n=fread(buffer,512, 1, disk);
if(n<=0) printf("\n Erreur de fread = %d ",n);
else printf("\n Lecture du secteur 10; Number of items read = %d\n",n);
}
}
fclose(disk);
return;
}
- 25 -
4. FILE SYSTEMS AND DIRECTORIES
File management systems store and manage a very large number of files.
→ Organize storage media to facilitate file management and access to
stored data.

The organization of external storage media such as disks is carried out in


two steps:

1) Partition the disks.

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:

➢ Sector 0 (LBA) or cylinder 0, head 0, sector 1 (HDD/CHS). This first


sector of the disk is called the Master Boot Record (MBR);

• After partitioning, each partition must be logically formatted


to install the file system (FAT, NTFS, ext4, …).

- 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.

b) The latest partitioning scheme (1999), known as GPT partitioning


(Globally Unique Identifier Partition Table), is based on UEFI (Unified
Extensible Firmware Interface). It overcomes the limitations imposed by
MBR partitioning, such as:

➢ The number of primary partitions ≤ 4,


➢ The size of a partition ≤ 2 TB (2,048,000,000 bytes),
➢ The partition table is not protected…

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, …).

• Note: Linux can be installed on an extended partition, whereas Windows


systems must be installed on a primary partition.

❖ The MBR is not protected (Pas de copie, pas de checksum)

- 32 -
1. General Structure of partitioned disk

MBR (Master Boot Record) : 512 bytes


NTFS Partition NTFS Partition FAT32 Partition Extended Partition

NTFS Boot Secteur NTFS Boot Secteur FAT Boot Secteur EBR

MFT MFT Reserved Zone

Clusters Clusters FAT1 Logical drive


partition
FAT2
Files and Files and
Clusters
directories directories

Copie MFT Copie MFT

Clusters Clusters Files and Other exteded


partitions
directories
Files and Files and
directories directories

- 33 -
2. The Master Boot Record : MBR

- MBR (Master Boot Record) :

- LBA : Sector 0;
- CHS : cylinder 0, head 0, sector 1; (HDD)
- Size = 1 sector = 512 bytes

- Bootstrap program: 440 bytess - disk signature: 4 bytes 0000

- partition Table: 4*16 = 64 bytes

Partition1 Partition2 Partition3 Partition4

- Signature (55AA) : 2 bytess

Note: MBR sector is not static on SSD drive (Wear Leveling, Garbage Collector)
- 34 -
3. Partition Table

Entry: Partition1 Ent2 Ent3 Ent4


Adr Size Content
Partition state:
446 1 - 00 : Inactive
- 80 : Active
447 1* N° head of partition (starting head N°): 8bits (0 à 255)

Starting Sector N° of partition : 6bits(1à 63)


448 2*
Starting Cylinder N° of partition :10bits(0 à 1023)

Type of partition (0B: FAT32 ; 05 : extended


450 1
partition 07: NTFS; 83: linux, 82: swap linux, …)
451 1* Ending head N° of partition (0 à 255)
Ending Sector N° of partition : 6bits (1à 63)
452 2*
Ending Cylindrer : 10bits (0 à 1023)
Distance, in sectors, between the partition table and the
454 4 first sector of this partition (aligned to 2048 sectors=1Mb
in SSD) (is the LBA of the first sector)

458 4 Partition size (in sectors)


- 35 -
N° Cylinder on 10 bits N° Sector : 6 bits
7 6 5 4 3 2 1 0 9 8 5 4 3 2 1 0
byte2 byte1

• 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

Boot sector NTFS EBR : 512 bytes(*)

- 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.

▪ Advanced Format (Aligned):


Standard for SSDs and modern HDDs. Aligned to 1 MB (2048 sectors:
alignment 0) to match NAND flash page boundaries

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.

Note: Values that are multiples of 8 can be used.


- 42 -
[Link] Partitionnement GPT-EFI
GPT : Guid Partition Table; GUID : Global Unique IDentifier;
EFI : Extensible Firmware Interface
• The limitations imposed by MBR partitioning are too restrictive for today’s
high-capacity disks.
• Intel has developed a new partitioning format based on UEFI (Unified
Extensible Firmware Interface), designed to replace BIOS (Basic Input/Output
System).
• GPT partitioning allows for a very large number of partitions: theoretically
2³².
• LBA address of a 64-bit partition = Maximum partition size = 2⁶⁴ sectors (or
2⁷³ bytes = 8 ZB).
• GPT partitioning uses only LBA addressing.
• GPT also provides redundancy by writing the header and partition table at
both the beginning and end of the disk.

- 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)

Protective Master Boot Record : Secteur 0

GPT partition table header: Sector 1

GPT partition table : Secteur2-Secteur33


Partition1 Partition2 Partition3 ... partition127 Partition128

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.

Backing up the GPT Partition Table:


Sector n-33
GPT Header Backup
Sector n-1 (last sector) - 47 -
Zone du disque GPT Secteurs Rôle
Compatibilité avec anciens
Protective MBR Secteur 0 systèmes MBR et protection du
disque GPT
Contient les informations principales
GPT (signature, taille disque,
GPT Header principal Secteur 1
positions des tables,
CRC/checksum…)
Contient les 128 entrées de
GPT Partition Table Secteurs 2 → 33
partitions GPT
Espace laissé vide pour alignement
Zone d’alignement Secteurs 34 → 2047
moderne 1 MB

Début des partitions utilisateur


Première partition réelle Généralement secteur 2048
(Windows, Linux, données…)

Partitions utilisateur Après LBA 2048 Contiennent OS, fichiers, données

Backup GPT Partition Copie de sauvegarde de la table


Secteurs n-33 → n-2
Table GPT
Secteur n-1 (dernier Copie de sauvegarde du GPT
Backup GPT Header
secteur) Header
48
• Protective Master Boot Record Partition Table
In Protected MBR (MBR Protective), only one primary partition is created.

Entry1: Partition1 Ent2 Ent3 Ent4


Adr size Content

446 1 00 : inactive partition 0 0 0

447 3 0 0 0 0

Type of partition : 0xEE ; ➔


450 1 0 0 0
The MBR is followed by an EFI header.
451 3 0 0 0 0

454 4 Starting LBA address of the partition: 1 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, …

56 72 Partition name (36 caracters Unicode(UTF-16LE)


- 51 -
4.1.3 Boot Process (MBR Partitioning)
Once the computer is powered on,
The processor starts executing the BIOS (Basic Input Output System) from the
ROM.
The role of the BIOS consists of:
1) Analyzing the hardware configuration (testing memory, checking
for the presence of peripherals: hard disks, CD players, USB drives,
keyboard, mouse, ...).
2) Locating the operating system to load by following the BIOS
configuration (hard disk, CD, USB drive, network, ...).
3) Reading the first sector (Sector 0: MBR) of the chosen boot device
and loading it into the main memory at the address: 0x7C00, then
launching its execution.
The MBR contains a "small program" of 440 bytes called the
"bootloader" and the partition table ($4 \times 16$ bytes).
The last two bytes of the MBR contain the hexadecimal values "55AA" ('55' in
byte 510 and 'AA' in byte 511).

- 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.

2. Lilo stored on the Linux partition


➢ The first part of the Lilo program (less than 512 bytes) is stored in
the first sector (boot sector) of the Linux partition.
➢ In this case, this first part of Lilo is loaded by the MBR bootloader.
➢ This first part will then load the rest of the Lilo program.

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)

4.2.1 Definition of a Directory (Catalog or Folder)


➢ It is a set of file descriptors that contain all the information
(attributes) defining the files on a disk.

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.

Example: The first version of PC-DOS used a single-level directory.

- 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

▪ Disks allow for the storage of a large number of files.


▪ The main challenge is determining how to allocate space to these
files so that disk space is used efficiently and files can be accessed
quickly.
▪ There are two strategies for storing a file of n bytes on a disk:
1) Allocating n consecutive bytes on the disk; this is known as
contiguous allocation.
2) Allocating multiple fixed-size blocks that are not necessarily
contiguous; this is known as non-contiguous allocation.

Most current file systems use non-contiguous 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

How to represent free space or free blocks?


▪ The file system must maintain all free blocks in an appropriate data
structure.
▪ This data structure is used during the creation and destruction of files.
▪ It can be implemented using a bit table (bit vectors) or a linked list.
a) Bit Tables
▪ Disk space is represented using a bit table, with one bit per block.
➢ bit = 0 ➔ free block
➢ bit = 1 ➔ occupied block

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.

[Link] Representation of a File's Disk Space (Blocks)

How to represent the disk space or blocks allocated to a file?


▪ Main techniques used:
✓ Linked blocks,
✓ Allocation index block,
✓ Allocation files (Mapping).

- 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.

4.4.1 Structure of a Directory Entry in the Linux Ext2/Ext3 File


System
• Each entry contains :
✓ The inode number (node index) ,
✓ The total length of the entry (or offset to the next entry),
✓ The length of the file name,
✓ The file type (not present in all versions),
✓ The file name.

- 69 -
• When a directory is created, two entries «.» et «..» are also created.
✓ «.» : refers to the current directory,
✓ «..» : refers to the parent directory.

• The user references a file using a name,


• The system uses the inode number to access the file.
- 70 -
• In the Unix system, several directories are created during the installation
of the system, such as : usr, sbin, etc, dev, home, ...

• Example of a File System

- 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

Double Allocation Allocation


12 Date
Indirections index block index block

Triple Allocation Allocation Allocation


13 index block Data
Indirections index block index block

- 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

Block bitmap Super bloc


tables

Inode Table of
bitmap Super bloc descriptors
tables

Inode table Super bloc Table of


descriptors

Data blocks Table of


descriptors

- 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

4.5.1 Structure of a FAT32 File System


A FAT32 partition is composed of:
• A boot sector,
• A reserved area,
• A FAT allocation table (two copies),
• The space reserved for directories and files: This space is
divided into blocks called clusters. The cluster is the unit of disk
space allocation.

90
FAT32 partition structure

MBR(Master Record Boot): 512 bytes

FAT32 partition Partition2 Partiton3 Partition4

- 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).

Structure of a FAT32 Partition Boot Sector


offset Content Taille
00 Jump Instruction : JMP; (EBxx90) 3

03 Manufacturer name and version no. 8

11-35 BIOS parameter block 25

36-89 File System informations (section FAT32) 54

xx-509 Remainder of the startup program or bootstrap 420

510-511 Signature hexa : AA55 (Little Endian : 55AA) 2


92
2. BIOS Parameters Block
Position Content Taille
11 Number of bytes per sector 2
13 Number of sector per cluster 1
14 Number of reserved sectors 2
16 Number of FAT 1
17 Number of entries for the root dir «\» (FAT 12 et 16) 2
19-20 Number of sectors per partition (small capacity partition< 32Mb) 2
21 Media descriptor (hexadecimal value, hard disk: F8) 1
22 Number of sectors per FAT(FAT12 et 16; for FAT32 bytes 36 à 39) 2
24 Number of sectors per piste 2
26 Number of read/write heads 2
28 Number of sectors before the partition(0 if disk is not partitioned ) 4
32 Number of sectors of the la partition (if position 19,20 = 0) 4

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)"

48 Sector number in the reserved area (sector 1) of the system 2


information file: (Fsinfo sector)
50 Boot sector copy (sector 6 of the reserved area) 2
52 12 reserved sector (12*0) 12
64 BIOS driver : hexa value : 8x (example : 80) 1
65 Reserved : (used by Windows NT) 1

66 Extension of the boot signature (0x29) : This means that the 1


following 3 fields exist in the boot sector
67 Volume serial number 4
71 Volume Label(name given during partition formatting) 11
82 File System : ‘FAT32 ‘ 8
94
4.5.2 Directories
• The root directory‘\’
It is created during logiccal disk formating (partition)

[Link] Directory entries


• A directory entry can be:
✓ A file ,
✓ A directory

• 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.

Example: [Link], prog.c.


Note that the dot separating the name from the extension is not
represented in the actual directory entry storage.

Note: The deletion of an entry (file descriptor) from the directory


is performed by assigning the value 0xE5 to the first byte of the
entry: this is a logical deletion.

97
offset size Content
00 8 Name: ASCII characters
08 3 Extension : ASCII characters

Attributes: (Bit0: read-only, Bit1: hidden, Bit2: system, Bit3: volume


11 1
label, Bit4: directory, Bit5: archive, 2 bits unused)
12 1 Reserved for Windows NT
13 1 "Millisecond" part of the creation time
14 2 Creation time: seconds (0 to 29), minute (0 to 59), hour (0 to 23)
16 2 Creation date: (date calculated starting from 01/01/1980)
18 2 Last access date
20 2 First cluster number in the FAT (High word for FAT32:poids fort)
22 2 Last modification time
24 2 Last modification date
26 2 First cluster number in the FAT (Low word: poids faible)
28 4 File size in bytes (max size = 4 Gigabytes)
98
Directory
1st Cluster
File1 …
0100

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

Last long-format entry in a file f

The second-to-last long-format entry in a file f (avant dernière entrée)



Second long-format entry in a file f

First long-format entry in a file f

Short-format entry in a file f

101
• Content of a Long-format entry:

Offset Size Content

00 1 Entry number; bit 6 (from 0) from the last entry = 1

01 10 Name : Characters 1-5 (UNICODE : UTF16)

11 1 Attribute LFN = ‘0F ‘ : Name in long format

12 1 Reserved

13 1 Control character : checksum

14 12 Rest of the name : characters 6-11 (UNICODE)

26 2 0000

28 4 Rest of the name : characters 12-13 (UNICODE)

• The attribute LFN=0F ➔ Entry of a name in long format.

- 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)
)

• A single entry in short format:


- For file/directory names written in uppercase letters or lowercase letters
and whose length is less than or equal to 8 characters;
- For the directories . and ..
• The root directory \ does not contain the directories . and ..

- 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 (k0).
• 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:

Disk capacity Cluster size


513 Mo-8 Go 4 Ko
8 Go - 16 Go 8 Ko
16 Go - 32 Go 16 Ko
32 Go and above 32 Ko

==============================================

- 107 -

You might also like