0% found this document useful (0 votes)
23 views77 pages

File System

Uploaded by

Tien Anh Do
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)
23 views77 pages

File System

Uploaded by

Tien Anh Do
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
You are on page 1/ 77

POSTS AND TELECOMMUNICATIONS INSTITUTE OF TECHNOLOGY

OPERATING SYSTEM

Lecturer: Dr. Long Hoang Dang


Department: Information Technology 1
Email: [email protected]

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 1
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
CHAPTER 2: FILE SYSTEM

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 2
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
CONTENT

1. Concepts
2. File access methods
3. Actions with files
4. Folders
5. Allocating space for files
6. Manage free disk space
7. File system reliability
8. File system security
9. FAT File System

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 3
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
I. CONCEPTS

▪ A file is defined as a collection of interrelated information


that is named and stored on external storage
▪ File attributes: to manage files in addition to content, the
OS also defines attributes and properties. The file has the
following properties:
▪ Name
▪ Type
▪ Size
▪ Creator, owner
▪ File access
▪ Time to create files, edit files, and last access
▪ Location

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 4
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
I. CONCEPTS
▪ File name:
▪ Allows file identification
▪ This is the most commonly used user information when working with
files.
▪ Naming rules for files of some OS:
Hệ điều hành Độ dài tối đa Phân biệt chữ Cho phép sử dụng Các ký tự cấm
hoa, chữ thường dấu cách

MS-DOS 8 cho tên file không không Bắt đầu bằng chữ cái hoặc số
3 cho mở rộng Không được chứa các ký tự / \ [ ] : ; | = , ^ ?
@
Windows NT 255 ký tự cho cả tên không có Bắt đầu bằng chữ cái hoặc số
FAT file và đường dẫn Không được chứa các ký tự / \ [] : ; | = , ^ ?
@
Windows NT 255 không có Không được chứa các ký tự / \ < > * | :
NTFS

Linux (EXT3) 256 Có có (nếu tên file chứa Không được chứa các ký tự ! @ # $ % ^ & *
trong ngoặc kép) ()[]{}‘“/\:;<>`

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 5
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
I. CONCEPTS

▪ File Structure:
▪ The information in the file can be very different
▪ There are files that contain a lot of unstructured information: text
files. Structured files such as: database files, excel files.
• => The structure of the file is also very different and depends on the
information contained in the file
▪ Does OS need to know and support file structure types?
▪ Pros:
• Manipulation with files will be easier for application developers
• The operating system can control the operations with the file
▪ Cons:
• Increase system size
• The flexibility of OS is reduced
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 6
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
QUESTIONS

❖ What are the advantages of defining and using the


concept of files? What regulations should be
considered when naming files?
❖ Does the operating system need to know and support
file structure types? Why?

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 7
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
I. CONCEPTS
▪ Most OS do not support and manage file structure types
▪ The file structure is managed by the application program
and the user himself
▪ In UNIX, DOS, and Windows, a file is treated as a
collection of bytes.
▪ Different application programs will create and manage
their own file structures.
▪ For example, if a graphics program saves a file as a
decompressed binary code, the data management system
program will create the file that includes the records.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 8
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
II. FILE ACCESS METHODS

▪ In order to read/write files, the operating system must


specify how to access the file contents. Each OS can support
one or more different ways of access.
▪ Sequential Access:
▪ Information is read and written byte-by-byte/record in turn
from the beginning of the file
▪ Use a pointer to locate the current location in the file
▪ After each reading or writing operation, the pointer will be
increased to one to point to the next position
▪ This type of access is very suitable for files stored on
magnetic tape. Information is recorded or read in turn in the
direction of rotation of the tape.
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 9
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
II. FILE ACCESS METHODS
▪ Direct Access:
▪ Files are treated as numbered blocks/records
▪ Blocks can be accessed in any order
▪ For example, we can read block 50, then read block 13,
then block 101.
▪ Direct access based on the characteristics of the disk
allows access to any block
▪ Files are contained in different blocks of disk and thus
also allow non-sequential access

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 10
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
II. FILE ACCESS METHODS

▪ Metric-based access:
▪ Allows access to records in a file, not by the order or location of the
records in the file, but by the key corresponding to that record.
▪ The file contains a unique indicator: it contains keys and pointers
pointing to the records in the file.
▪ Access: find the corresponding key in the index, then follow the pointer
that identifies the record and access it directly

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 11
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
QUESTION

❖ Describes the methods of accessing the file.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 12
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
III. WORKING WITH FILES
▪ Create a file:
▪ Create a blank file without data; is reserved for a place in the folder
with some attributes such as file creation time, file name, file creator,...
▪ Delete the file:
▪ Free up space that the file's data occupies on the disk
▪ Free up space for files in the folder
▪ The liberation of space can merely mark space as free space.
▪ Open the file:
▪ Do it before writing and reading the file
▪ Read the properties of the file on the disk to the memory to speed up
the next read and write operation.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 13
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
III. WORKING WITH FILES
▪ Close file:
▪ Clear the file information from the table in the memory to
make room for files that are about to open.
▪ Many operating systems limit the number of files that can be
opened at once, so closing files that have already been
accessed is very important.
▪ Write to file
▪ Read the file

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 14
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
QUESTION

❖ Describe basic operations with the file. Clearly


analyze whether a file system necessarily has to
open the file or not.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 15
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
1. Concepts
▪ The number of files stored on the disk is very large = >
must be organized for easy management and access of files
▪ The space on the disk is divided into partitions/volumes
called logical disks
▪ To manage files on logical disks, information about the file
is saved in the disk's folder
▪ Folder = ∑ items ~ files
▪ The item contains information about the file: name, size,
location,… or pointer to where this information is stored
▪ Think of the folder as a table, each line is an item
corresponding to 1 file
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 16
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
1. Concepts

▪ To save information about files in a folder:


▪ All the properties of the file are stored in the folder, the file only
contains data => the size of items, folders is large
▪ A portion of the attribute is stored along with the file's data. The folder
only stores the minimum information needed to find the file location on
the disk => reduced size
thuộc
tính
file1.txt Thuộc tính file1.txt
thuộc
file2.c Thuộc tính file2.c
tính

file3.pas Thuộc tính file3.pas thuộc


tính
file4.doc Thuộc tính file4.doc
thuộc
tính
(a) (b)

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 17
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
2. Working with folders

▪ Open the file:


▪ OS finds in the item folder corresponding to the file name to be opened
▪ Read the file's properties and data location into a table containing
information about the open files
▪ If an item pointing to another software contains a file attribute, this
structure will be read

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 18
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
2. Working with folders
▪ File searching: the folder structure must allow searching
for files by file name
▪ Create file: create a new item and add it to the folder
▪ Delete file: information about the corresponding file and
item is deleted from the folder
▪ Browse folders: list the files in the folder and the
information contained in the file's item
▪ Rename the file: just do it with the folder, not the file's data

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 19
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
QUESTION

❖ Describe the concept of folders and operations with


folders

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 20
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
3. Folder system structure
▪ 1-level Folder:
▪ Simplest
▪ There is only 1 single folder and all files are kept in this folder
▪ Difficult to choose a name for a file
▪ Difficult file search

Thư mục

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 21
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
3. Folder system structure
▪ 2-level Folder:
▪ Assign each user a separate folder (UFD) containing their own
files
▪ When a user accesses a file, the file will be searched in the folder
corresponding to the person's name
▪ => different users can name the same file
▪ Isolate users
▪ Files that are accessed
by multiple users =>
copied to each user's
folder => wasted

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 22
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
3. Folder system structure
▪ Tree structure:
▪ Subfolders can Thư mục
gốc
contain other
subfolders and
files
▪ The directory
system is
represented
hierarchically
like a tree: = Thư mục = File

branches are
folders, leaves
are files

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 23
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
3. Folder system structure

▪ Tree structure:
▪ Differentiate between file items and subfolder items: add special
bits to the item
• 1: Items of the lower level folder
• 0: Item of the file
▪ At each point, the user works with the current directory
▪ Organize the folder tree for each disk:
• In a file system like DOS's FAT, a folder tree is built for each disk. The
directory system is considered forested, each tree on 1 disk
• Linux: the whole system consists of only 1 directory tree

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 24
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
3. Folder system structure
▪ Acyclic graph:
▪ Share files and folders so they can appear in various separate folders
▪ This is a graph structure that does not contain cycles, which is an extension of
the tree structure
▪ Trees: leaves and branches can belong to different branches at the same time
▪ Deploy:
• Use link: pointer to another folder or file
• Make copies of files and folders to be shared and stored in different folders => must ensure
synchronization and consistency => avoid overlapping backups and statistics of a file
multiple times. Thư mục

▪ Flexible but complex


gốc

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 25
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
4. Path

▪ Describe the location of the file in the folder


▪ Absolute path:
▪ The path from the root of the directory tree, goes through the
intermediate folders, leading to the
▪ C:\bc\bin\bc.exe
▪ Relative path:
▪ Adjectives from the current folder
▪ Add 2 special items in the folder: "." to represent the current
folder, and ".." for the top-level folder.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 26
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
QUESTIONS

❖Describe single-level and two-level directory system


structures.
❖Describe a tree-like folder structure and a graph
without cycles. What are the advantages of a non-
cyclic folder structure over a tree? What is an
absolute path and a relative path

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 27
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
5. Internal organization of folders

▪ List:
▪ Organize folders as a list of items
▪ Searching for items is done by browsing the list one by one
▪ Add new files to the folder:
▪ Browse the entire folder to check if the item with such a file name already
exists
▪ A new item is added to the bottom of the list or 1 cell in the table.
▪ Open the file, delete the file
▪ Search in the slow list
▪ Store folders in memory

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 28
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
5. Internal organization of folders

▪ Binary Tree:
▪ Speed up your search with a sortable database
▪ NTFS File System in WinNT.
▪ Hash table:
▪ Use the hash function to calculate the location of items in the
folder by file name
▪ Fast search time
▪ The hash function depends on the size of the hash table => fixed
table size

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 29
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
5. Internal organization of folders
▪ Directory Organization in DOS:
▪ Each logical disk has its own directory tree, starting from the
ROOT root directory
▪ The root directory is located at the top of the disk, just after the
BOOT sector and the FAT table
▪ The root folder contains files and subfolders
▪ Subfolders can contain files and subordinate folders as well
▪ Organized as a table: each item occupies 1 line in the table and
has a fixed size of 32 bytes

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 30
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. FOLDER
5. Internal organization of folders

▪ Directory Organization in Linux:


▪ Linux's Ext2 file system directory has a simple organization
▪ The item contains the file name and I-node address
▪ The rest of the information about the file properties and the
location of the data blocks is stored on the I-node and not the
directory
▪ Item size depends on filename length
▪ The beginning of the item has a field indicating the item size.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 31
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILES
▪ An important task of the OS in managing the file system is to
allocate space on disks and other external storage devices to
store files and folders
▪ At the same time, record the location of the allocated memory
blocks so that they can be accessed later.
❖ Sector is the smallest unit allowed
by the disk driver program to read
or write (physical block) 1
sector=512bytes
❖ The cluster consists of a number
of physical blocks, which is the
smallest unit of information that
the operating system allocates to a
file (logical block) of 2KB-32KB

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 32
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILES
▪ Each file consists of 1 set of blocks, the OS is responsible
for allocating blocks to the file:
▪ Space on the disk must be allocated for the file
▪ Need to monitor the available space for allocation
▪ This should be done in such a way as to save space on the disk and
increase the speed of file access.
▪ Some problems:
▪ What is the maximum space required for a 1-time file allocation?

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 33
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILE
1. Allocating consecutive blocks
▪ Each file is allocated 1 space consisting of consecutive
blocks on the disk
▪ The location of a file on disk is determined by the location
of the first block and the length (number of blocks) that the
file occupies
▪ When there is an allocation request, the OS will select 1
blank space with a sufficient number of blocks for that file
▪ The file allocation table only needs 1 item for 1 file,
indicating the starting block, and the length of the calculated
file = block
▪ As pre-allocation, use variable portion sizes

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 34
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILE
1. Allocating consecutive blocks(tt)

External fragmentation

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 35
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILE
▪ Advantage:1. Allocation of consecutive blocks (tt)
▪ Allow direct and sequential access
▪ Simple, high-speed due to saving time moving the word head
when reading the blocks of the file.
▪ Disadvantage:
▪ The file size must be known in advance when creating
▪ Difficult to find space on disk that looks large enough to allocate files
▪ After the use time, blocks that are allocated when creating a file and
freed when deleting a file will create a blank space on the disk =>
when there is an application to allocate an hdh that needs to check the
free space.
▪ External fragmentation: it is the phenomenon that the remaining free
space on the disk is too small and therefore cannot be allocated to
larger files.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 36
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. CẤP PHÁT KHÔNG GIAN CHO FILE
2. Sử dụng danh sách kết nối

▪ Các khối thuộc về mỗi file được kết nối với nhau thành
danh sách kết nối; phần đầu mỗi khối chứa con trỏ trỏ tới
khối tiếp theo
▪ Các khối thuộc về 1 file có thể nằm ở vị trí bất kì trên đĩa
▪ Khoản mục của thư mục chứa con trỏ tới khối đầu tiên của
file
▪ Khi file được cấp thêm khối mới, khối đó được thêm vào
cuối danh sách
▪ HDH đọc lần lượt từng khối và sử dụng con trỏ để xác
định khối tiếp theo

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 37
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATE SPACE FOR FILE
2. Using the Connection List (tt)

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 38
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATE SPACE FOR FILE
2. Use the connection list (tt)
▪ Advantage:
▪ Because blocks belonging to a file can be anywhere on
the disk, they don't necessarily have to be next to each
other
▪ => No external fragmentation
▪ No need to know the file size in advance at the time of
creation
▪ Easy to find locations for simple files and items

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 39
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATE SPACE FOR FILE
2. Using the Connection List (tt)
▪ Disadvatage:
▪ To read a certain block, we have to follow all the pointers
from the first block to the block to be read => Direct access
is not supported.
▪ The pointer is located right in the block and the block is the
smallest unit that can be read, so to determine the pointer,
we have to read the whole block => to read a block we have
to read from the first block to the block to be read.
▪ In case the value of the pointer changes => determining
which block belongs to which file will be incorrect =>
reduces the reliability and integrity of the file system
▪ The access speed is not high

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 40
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILE
3. Use the list of connections on the dashboard
▪ Indicator board: each cell of the table corresponds to 1
block of the disk
▪ The pointer to the next block of the file contained in the
corresponding cell of the table
▪ Each logical disk has 1 index panel saved in a specified
location
▪ The size of each tile on the board depends on the number of
blocks on the disk

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 41
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILE
4. Use index blocks/nodes

▪ All pointers to blocks belonging to a file are concentrated in


one place
▪ Each file has its own array contained in a block called an
index block (I-node)
▪ The array contains the properties of the file and the location
of the blocks of the file on the disk
▪ The ith cell of the array contains the pointer to the ith block
of the file
▪ The item of the file in the folder that contains the pointer to
this index block

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 42
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILE
4. Use index blocks/nodes

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 43
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILE
4. Use index blocks/nodes

▪ Choose the I-node size:


▪ Small: saves space but not enough pointers to blocks if the file is
large
▪ Large: with a small file that only occupies a few cells, it is wasteful
▪ Solution:
▪ Resize i-node = use connection list
▪ Use I-nodes with multi-level structure

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 44
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILE
4. Use index blocks/nodes

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 45
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. ALLOCATING SPACE FOR FILE
4. Use index blocks/nodes

▪ Advantage:
▪ Allow direct access
▪ Blocks in 1 file do not need to be contiguous.

▪ Disadvantage:
▪ Slow file access speed

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 46
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VI. MANAGE FREE DISK SPACE

▪ The space on the disk is allocated in undivided blocks. In


order to effectively manage disk space, in addition to the
method of allocating memory blocks to files, it is necessary
to pay attention:
▪ Size Selection for Blocks
▪ Blank-block Management.
▪ Block Size:
A block is the smallest allocator of the operating system, each
file consisting of an integer of memory blocks.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 47
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VI. MANAGE FREE DISK SPACE

▪ Large block size:


▪ Reduce the size of the index table, increase the speed of reading
files;
▪ Internal fragmentation.
▪ Small block size:
▪ Each file takes up a lot of memory blocks, scattered on the disk
▪ Long file read time.
▪ Choose the block size depending on:
▪ Disk size: large disk, choose large block size => fast access
time, simplify management
▪ File size: the system uses a lot of large files, the size increases
and reverses.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 48
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VI. QUẢN LÝ KHÔNG GIAN TRỐNG TRÊN ĐĨA

❖In order to be able to allocate a disk memory block to a


file, the HDH needs to know which block is currently
free. Empty blocks include those that have not been
allocated once or have already been allocated but have
been freed.
1. Bit Panels:
▪ Vector bits are 1-dimensional arrays
▪ Each cell is 1 bit in size corresponding to a block on the disk
▪ The allocated block has a corresponding plug of 0, empty block: 1
or vice versa
▪ Easy to find 1 or group of empty blocks in a row
▪ With large disks, reading the entire bit vector into the MEM can
require quite a bit of memory space
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 49
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VI. MANAGING FREE DISK SPACE
1. Bit Panels
▪ Example: In the following case, blocks 0, 1, 8, 9, 10 have
been allocated, the remaining blocks have not been
used:
00111111000111111...

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 50
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VI. MANAGING FREE SPACE ON DISK
2. List of connections

▪ Empty blocks linked together into a list


▪ Each empty block contains a pointer pointing to the next
empty block
▪ The address of the first blank block is stored in a special
location on the disk and is kept by OS in the MEM when
working with files
▪ Requires sequential access when you need to browse this
list
▪ OS can immediately allocate blocks at the top of the list

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 51
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VI. MANAGING FREE SPACE ON DISK
3. List of empty areas

▪ Adjacent blocks are usually allocated and released


simultaneously
▪ Save the location of the first empty block of the area of
consecutive empty blocks and the number of empty blocks
that are immediately after it
▪ The above information is saved in a separate list

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 52
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VII. FILE SYSTEM RELIABILITY

▪ Files are a place to store information that is very


important for users, even important for the computing
system itself.
▪ The file system must be highly sustainable, must ensure
that information is stored so that the information is intact
and not lost.
▪ Information of the system file stored on the disk and other
external memory may be distorted or lost due to:
▪ Hardware/software complaints
▪ Technical Fault
▪ While it is impossible to prevent such incidents => should also
be built in such a way that it is capable of detecting and
remediating the consequences in the best possible way
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 53
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VII. FILE SYSTEM RELIABILITY
1. Detect & exclude broken blocks
▪ During production as well as use, the disc may contain
damaged blocks, which cannot be used to read/write
information..
▪ Soft disks, damaged blocks often appear during use
▪ Hard disks: often have damaged blocks right in the
production process. These damaged blocks are detected
by the manufacturer during the inspection of the disc
and are stored in the list of damaged blocks that
accompany the disc

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 54
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VII. FILE SYSTEM RELIABILITY
1. Detect & exclude broken blocks

▪ Detecting and Eliminating Broken Blocks:


▪ Method 1:
▪ A sector on the reserved disk contains a list of broken blocks
▪ Some unbroken blocks are reserved for storage
▪ Broken blocks will be replaced by reserve blocks by replacing the address
▪ Access to a broken block becomes access to a reserved block.
▪ Method 2:
▪ Centralize all broken blocks into 1 file
▪ => is considered allocated and no longer used

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 55
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VII. FILE SYSTEM RELIABILITY
2. Backup star
▪ Create a copy of the disc on another carrier
▪ Full backup:
▪ Write all the information on the disk to another messenger
▪ Robust but time-consuming.
▪ Incremental backup:
▪ Used after a full backup has been performed at least 1 time
▪ Record only files that have been changed after the last backup
▪ The system stores information about file storage times
▪ DOS: file change, archive bit=1.
▪ Combination:
▪ Full backup: weekly/month
▪ Incremental backup: daily
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 56
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VII. FILE SYSTEM RELIABILITY
3. Check the integrity of the file system
▪ The file system contains many data records with links =>
information about the link is damaged, the integrity of the system is
broken = > broken, it is not known which block to save in the next
block
▪ Blocks are not present in the list of empty blocks, nor are they
present in a file
▪ A block can belong to both a file and be in the list of empty blocks
▪ The HDH has programs that check the integrity of the file system,
which are run when the system boots, especially after a crash
▪ For example, the SCANDISK program with WIN or DOS

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 57
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VII. FILE SYSTEM RELIABILITY
3. Check the integrity of the file system
▪ Examples in UNIX:
▪ Create two counts for each block:
▪ First count: the number of times the block appears in the list of empty
blocks.
▪ Second count: the number of times the block appears in the file.
▪ All counts are initialized with 0
▪ Browse the list of empty blocks and all i-nodes of the files:
▪ A block appears in the list of empty blocks, the first corresponding count is
incremented by one unit
▪ If the block appears in the i-node of the file, the second corresponding count
is incremented by one unit.
▪ Sum of 2 counts =1

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 58
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VII. FILE SYSTEM RELIABILITY
4. Ensure integrity by using transactions
▪ Although it is possible to check the integrity of the links
in the file system. However, checking the entire file
system requires a lot of time. Testing only allows errors to
be detected after they have occurred and does not
guarantee data recovery for some errors.
▪ A transaction is a set of operations that need to be
performed completely together
▪ With the file system: each transaction will include the link
changes that need to be performed together (e.g. link
update operations related to a block on disk)

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 59
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VII. FILE SYSTEM RELIABILITY
4. Ensure integrity by using transactions
▪ The entire file system state is recorded in the log file
▪ Every time a transaction is performed, the system checks
whether the transaction is fully executed.
▪ If the transaction is not fully executed, the OS uses the
information from the log to restore the file system to an
error-free state before performing the transaction.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 60
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VIII. FILE SYSTEM SECURITY

▪ Prevent unauthorized access to information stored in


files and folders
▪ For a small system for a user, the security problem is
relatively simple, which can be done by physical
measures => Do not allow others to access the system,
▪ In multi-user computing systems, the security of files
and folders is done by:
• Control access to files or folders
• Use passwords => Users have to remember many passwords
=> Every time they work with resources, they type
passwords

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 61
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VIII. FILE SYSTEM SECURITY

▪ Use the Access Control List


▪ Each file is assigned an accompanying list, containing the user
identifier and the permissions that person performs with the file
▪ ACLs are usually stored as properties of files/folders
▪ Often used in conjunction with a login mechanism
▪ Basic access rights:
▪ Read permission (r): the person with this permission is allowed to read the
contents of the file
▪ Permission to write, change (w): allowed to write to the file, i.e. change the
contents of the file
▪ Deletion permission: permission to delete files, this permission is
equivalent to the right to change files
▪ Change owner

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 62
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
VIII. FILE SYSTEM SECURITY

▪ Use the Access Control List

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 63
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM

▪ The FAT system was designed for use in DOS, which was
later used in some versions of Windows 3.0,3.1,95/98.
▪ Currently, FAT is still a common system, used in most
operating systems today to manage memory cards, floppy
disks, CDs
▪ 3 versions: FAT12, FAT16, FAT32
▪ The digit indicates the FAT table cell size of 12, 16 and 32
bits respectively
▪ Currently, FAT32 is often used for hard disks, FAT16 is
used for external memory devices with small capacities
such as CDs and external memory cards.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 64
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
1. LOGIC DISC
▪ The organizer in the FAT file system is the logical disk.
▪ The allocating units of space on disk (logical blocks) are
clusters. Each cluster contains a number of sectors to the power
of 2.
▪ Information on the organized logic disk:

▪ Boot sector:
▪ The first sector of the logical disk
▪ Contains information describing the logical disk structure:
sector size, cluster, FAT table size
▪ Contains the primer program code to load the OS if the
logical disk is the boot disk

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 65
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
1. ĐĨA LOGIC

Boot sector Bảng FAT1 Bảng FAT2 Thư mục gốc Phần còn lại cho tới cuối đĩa
và các khối dự phòng (chỉ có trên FAT12 và FAT16) chứa các file và thư mục của đĩa lô gic

▪ FAT: Dashboard manages block allocation for files. Because


this area information is so important, the HDH usually
maintains two FAT tables, one of which is a copy of the other.
The number of FATs is subject to change and is recorded in
the Boot sector.
▪ ROOT Directory: this region contains the root folders, i.e., the
top folder of the disk. This zone size is equal to the maximum
number of entries in the root directory and is recorded in the
boot sector. FAT32 does not use this partition but stores the
root directory like files in a regular folder.
▪ Data area: contains files and folders of logical disks
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 66
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
BOOT SECTOR
The boot sector is the first sector on the disk and contains information describing
the disk structure along with the code to download the HDH for the HDH primer
disk. The specific structure of the boot sector is as follows: First 32 Bytes
Vị trí Độ dài Ý nghĩa
Lệnh Jump. Chỉ thị cho CPU bỏ qua phần thông tin và nhẩy tới thực hiện phần mã mồi của hệ điều hành nếu đây là đĩa
0 3
mồi hệ điều hành.
3 8 Tên hãng sản xuất, bổ sung dấu trắng ở cuối cho đủ 8B. Ví dụ: IBM 3.3, MSDOS5.0.v.v.
Bytes per sector. Kích thước sector tính bằng byte. Giá trị thường gặp là 512 đối với đĩa cứng.
11 2
Đây cũng là vị trí bắt đầu của Khối Thông số BIOS (BIOS Parameter Block, viết tắt là BPB)
13 1 Sectors per cluster. Số sector trong một cluster, luôn là lũy thừa của 2 và không lớn hơn 128.
14 2 Reserved sectors. Số lượng sector dành cho vùng đầu đĩa đến trước FAT, bao gồm boot sector và các sector dự phòng.
16 1 Số lượng bảng FAT. Thường bằng 2.
17 2 Số khoản mục tối đa trong thự mục gốc ROOT. Chỉ sử dụng cho FAT12 và FAT16. Bằng 0 với FAT32.
19 2 Total sector. Tổng số sector trên đĩa. Nếu bằng không thì số lượng sector được ghi bằng 4 byte tại vị trí 0x20.
21 1 Mô tả loại đĩa. Ví dụ 0xF0 là đĩa mềm 3.5” hai mặt với 80 rãnh trên mỗi mặt, 0xF1 là đĩa cứng .v.v.
22 2 Sectors per FAT. Kích thước FAT tính bằng sector (đối với FAT12/16)
24 2 Sectors per track. Số sector trên một rãnh.
26 2 Number of heads. Số lượng đầu đọc (mặt đĩa được sử dụng)
28 4 Hidden sectors. Số lượng sector ẩn.
32 4 Total sector. Tổng số sector trên đĩa cho trường hợp có nhiều hơn 65535.

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 67
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
BOOT SECTOR
Next bytes with FAT12/16

Vị trí Độ dài Ý nghĩa

36 1 Số thứ tự vật lý của đĩa (0: đĩa mềm, 80h: đĩa cứng .v.v.)

37 1 Dự phòng

38 1 Dấu hiệu của phần mã mồi. Chứa giá trị 0x29 (ký tự ‘)’) hoặc 0x28.

39 4 Số xê ri của đĩa (Volume Serial Number) được tạo lúc format đĩa

43 11 Volume Label: Nhãn của đĩa được tạo khi format.

54 8 Tên hệ thống file FAT, ví dụ "FAT12 ", "FAT16 "

62 448 Mã mồi hệ điều hành, đây là phần chương trình tải hệ điều hành khi khởi động.

510 2 Dấu hiệu Boot sector (0x55 0xAA)

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 68
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
BOOT SECTOR
Next bytes with FAT32
Vị trí Độ dài Ý nghĩa

36 4 Sectors per FAT. Kích thước FAT tính bằng sector.


0x28 2 Cờ của FAT
0x2a 2 Version. Phiên bản.
0x2c 4 Số thứ tự của cluster đầu tiên của thư mục gốc root.
0x30 2 Số sector của Information Sector. Đây là phần nằm trong số sector dự phòng ngay sau boot sector.
0x32 2 Số thứ tự sector đầu tiên của bản sao của boot sector (nếu có)
0x34 12 Dự phòng
0x40 1 Số thứ tự vật lý của đĩa
0x41 1 Dự phòng
0x42 1 Dấu hiệu của phần mã mồi mở rộng.
0x43 4 Số xê ri của đĩa (Volume Serial Number)
0x47 11 Volume Label
0x52 8 "FAT32"
0x5a 420 Mã mồi hệ điều hành
0x1FE 2 Dấu hiệu Boot sector (0x55 0xAA)

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 69
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
BẢNG FAT

▪ Manage clusters on disks and files according to the


principle:
▪ Blocks belonging to the same file are linked into a list
▪ The cursor is contained in the corresponding cell of the FAT
table.
▪ Each cell in the FAT table corresponds to a cluster on
disk:
▪ Index of cluster next in the list of blocks of the file
▪ End sign if cell corresponds to the last cluster of files
▪ Signs of broken cluster marking, not used
▪ Signs of backup cluster marking
▪ 0 if the cluster is empty, no files have been allocated
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 70
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
FAT TABLE

▪ The first 2 cells of the FAT table are not used for cluster
management

FAT12 FAT16 FAT32 Ý nghĩa

0x000 0x0000 0x00000000 Cluster trống

Cluster dự phòng, không được


0x001 0x0001 0x00000001
sử dụng
Cluster đã được cấp cho file.
0x002–0xFEF 0x0002–0xFFEF 0x00000002–0x0FFFFFEF Chứa số thứ tự cluster tiếp theo
của file.
0xFF0–0xFF6 0xFFF0–0xFFF6 0x0FFFFFF0–0x0FFFFFF6 Cluster dự phòng
0xFF7 0xFFF7 0x0FFFFFF7 Cluster hỏng.
0xFF8–0xFFF 0xFFF8–0xFFFF 0x0FFFFFF8–0x0FFFFFFF Cluster cuối cùng của file

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 71
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
ROOT DIRECTORY

▪ Each folder is saved in the folder table, which is actually a


special file containing the items of the folder
▪ Each item contains information about a file or subfolder
of the folder under consideration
▪ With FAT12/16, the top folder of the disk is contained in
a special area called the root folder
▪ The lower level folders/root folders of FAT32 are
contained in the data area on the disk along with the files
▪ Each folder consists of 32-byte items stacked
contiguously
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 72
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
ROOT DIRECTORY
Vị trí Độ dài Mô tả
0 8 Tên file, thêm bằng dấu trắng ở cuối nếu ngắn hơn 8 byte
8 3 Phần mở rộng, thêm bằng dấu trắng ở cuối nếu ngắn hơn 3 byte
Byte thuộc tính của file. Các bit của byte này nếu bằng 1 sẽ có ý nghĩa như sau:

11 1 Bit 0: file chỉ được đọc; Bit 3: Volume label; Bit 6: thiết bị nhớ khác (dùng cho hệ điều
Bit 1: file ẩn; Bit 4: thư mục con hành);
Bit 2: file hệ thống; Bit 5: archive; Bit 7: không sử dụng
Byte thuộc tính bằng 0x0F là dấu hiệu của file tên dài.
12 1 Dự phòng
13 1 Thời gian tạo file tính theo đơn vị 10ms, giá trị từ 0 đến 199
14 2 Thời gian tạo file theo format sau: bit 15-11: giờ (0-23); bit 10-5: phút (0-59); bit 4-0: giây/2 (0-29)
16 2 Ngày tạo file theo format sau. Bit 15-9: năm (0-1980, 127 =2107); bit 8-5: tháng (1-12); bit 4-0: ngày (1-31)
18 2 Ngày truy cập cuối, theo format như ngày tạo file
20 2 2 byte cao của số thứ tự cluster đầu tiên của file trong FAT32
22 2 Thời gian sửa file lần cuối, theo format thời gian tạo file
24 2 Ngày sửa file lần cuôi, theo format như ngày tạo file
26 2 Số thứ tự cluster đầu tiên của file trong FAT12/16.
28 4 Kích thước file tính bằng byte. Bằng 0 với thư mục con

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 73
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
DISC READER

▪ int absread(int drive, int nsects, long lsect, void *buffer)


▪ drive: ổ đĩa cần đọc, A: 0, B:1, C:2
▪ nsects: số sector cần đọc
▪ lsect: vị trí sector bắt đầu đọc
▪ buffer: vùng nhớ lưu nội dung thông tin cần đọc

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 74
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
EXERCISE

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 75
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
EXERCISE

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 76
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IX. FAT FILE SYSTEM
EXERCISE

www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH


Trang 77
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1

You might also like