Presentation on theme: "Operating Systems File Management. What Is A File? Named collection of data stored on hard disk, CD-ROM etc. Can be programs (both source and object forms)"— Presentation transcript:
Operating Systems File Management
What Is A File? Named collection of data stored on hard disk, CD-ROM etc. Can be programs (both source and object forms) or data. The UNIX/Linux and Windows OS’s do not know anything about the file structure. The application program associated with the file knows how to interpret the file. – Interpretation logged by OS
What Is File Management? The creation and deletion of files. The creation and deletion of directories/ folders. The manipulation of files and directories The mapping of files onto disk storage. Backup of files on stable (non volatile) storage.
What is a Directory / Folder? A logical grouping of files. – Actually a special type of file. Directories can contain other directories known as sub-directories, creating a tree structure. – Hierarchical UNIX/Linux uses the term directory, Windows uses the term folder.
Example of a Directory Structure Windows Explorer – The yellow icons are directories (folders). – The plus (+) sign next to the directory indicates that it contains sub- directories.
Pathnames In order to uniquely specify a file in a tree-structured directory, a pathname must be used. A pathname prefixes the filename with a list of the directories from the base directory which have to be traversed in order to reach the file. The pathname separator is the forward-slash (/) in UNIX/Linux and the backslash (\) in Windows. At any instant, a process has a current directory, which is where the operating system will look for a file whose pathname is not specified.
Pathname Examples UNIX/Linux – Full pathname - /cprogs/work/file1.txt – Relative pathname - work/file1.txt Windows – Full pathname - C:\CPROGS\WORK\FILE1.TXT – Relative pathname – WORK\FILE1.TXT
Common Directory Commands FUNCTIONUNIX/LinuxWindows/ DOS Change DirectorycdCD CHDIR Make DirectorymkdirMD MKDIR Remove DirectoryrmdirRD RMDIR List Directory ContentslsDIR Display Current DirectorypwdCD CHDIR
File Naming UNIX/Linux – File names are case-sensitive. – File name can be up to 255 characters in length. – File name can contain any character except /. – Characters that have special meaning to the shell (* > < ? \ ; : | [ ] ( )) should not be included in a file name. – Linux does allow spaces in the file name, other flavours of UNIX may not.
File Naming Windows – File names are not case sensitive, but the case will be preserved. – File name can be up to 255 characters in length. – File name can contain any character except / \ “ ; * ? |. – The portion of the file name after the last dot (.) is known as the extension. – The extension is used to specify the nature of the file. – Windows also maintains a short file name using the first 8 characters of the file name and the first three characters of the extension.
File Naming Both UNIX/Linux and Windows allow a file to be referenced using wildcard characters. In both OS’s - * can be replaced by zero or more characters; ? can be replaced by one character. UNIX/Linux also supports more complex wild- carding. – [a,b,c] - character can be either a, b or c. – [a-d] - character can be either a,b,c or d – [a-d,f] – character can be either a,b,c,d or f
Hard Disk Partitioning Partitioning is a means of sub-dividing a hard disk. A hard disk must contain at least one partition. There are two types of partitions – primary and extended. A disk can contain up to 4 primary partitions or up to 3 primary and 1 extended partition. One primary partition may be designated as active, this will be used for booting the computer. Different operating systems can be installed on different primary partitions – allowing multi-booting. An extended partition cannot be accessed directly by the operating system but is instead sub-divided into logical drives.
Hard Disk Partitioning In UNIX/Linux the fdisk command is used to manage hard disk partitions. In Windows use the DISKPART command or the Disk Management tool.
Hard Disk Initialization In order to be usable by the OS a partition must be initialized. In UNIX/Linux the mkfs command is used, in Windows the command is FORMAT. The initialisation process sets up the necessary structures on a disk partition. In UNIX/Linux an initialized partition is referred to as a file system on Windows it is called a drive.
File Space Allocation Disk space is dynamically allocated to files. Space is allocated in units of fixed size called allocation units or clusters. When a new file is created, it is allocated one cluster. As the file is extended the cluster eventually becomes filled and more clusters are assigned to the file.
File Space Allocation Ideally, successive file clusters should occupy contiguous space on the disk. In general, the disk will contain many different files whose clusters are intermingled with each other. Clusters are released when a file is deleted or shrunk, so free clusters may be intermingled with allocated clusters. AABABCCBB End of file A Free cluster End of file B
UNIX/Linux File System 4 classes of files: – regular file. – directory. – character or block special file: device such as a disk, printer, terminal. – named pipe: queuing buffer which passes the output of one process to the input of another.
UNIX/Linux File System A file is described by an information block called an inode. Every file on disk has an associated inode. Kernel memory contains a copy of the inode for every open file. A directory entry holds the filename and a reference to its associated inode or its inode number.
UNIX/Linux File System The inode contains all information about a file, except its name. This information includes – File access and type information, collectively known as the mode. – File ownership information. – Time stamps for last modification, last access and last mode modification. – File size in bytes. – Addresses of physical blocks.
UNIX/Linux File System - Inodes The inode records which disk blocks/clusters have been allocated to a file. This information is stored in 13 “pointers” in the inode structure. The first 10 are direct pointers – they map directly to the physical address of a block of a file. The other 3 pointers point to index blocks which themselves contain lists of pointers. The pointers in the index blocks reference either data blocks or further index blocks.
UNIX/Linux File System – Volume Structure When the mkfs command is run to initialize a partition the following layout is created: – Boot block: first stage boot program. – Super block: contains details of disk size and allocation of inodes and data blocks. – Inodes: storage space for inodes. – Data Blocks: rest of disk available for directories and files.
UNIX/Linux File System – Free Space Control When the mkfs command is run it creates a chain of linked blocks. The super block contains the start block in the chain. Each block contains an array of free data block numbers and a pointer to the next block in the chain.
Windows File System Windows supports 3 different file systems: – FAT also called FAT16 – FAT32 – NTFS FAT and FAT32 are implemented similarly.
FAT16/FAT32 File System The FAT system maintains a table of entries known as the File Allocation Table (hence the name FAT). The table consists of an array of 16-bit (FAT16) or 32-bit (FAT32) values. The first value in the array identifies the disk system type and the second entry is set to all 1’s. Each of the remaining entries maps to a cluster on the disk.
FAT16/FAT32 File System Each entry records one of five things: – the address of the next cluster in a chain – a special end of file (EOF) character that indicates the end of a chain – a special character to mark a bad cluster – a special character to mark a reserved cluster – a zero to note that that cluster is unused
FAT16/FAT32 File System Prior to any data being written to the disk, the FAT entries are all set to zero, indicating a free cluster. As file space is allocated, the FAT entries contain pointers to the next entry in the chain. When more file space is requested, the OS searches the FAT for an entry with a value of zero (unused) and allocates it to the file.
FAT16/FAT32 File System – Volume Structure When the FORMAT command is run on a partition to create a FAT file system, the following layout is created: – Boot sector: details about the disk’s characteristics and a bootstrap loader. – FAT: principal file allocation table. – Additional FAT(s): Duplicate table(s) which are updated at the same time as the principal FAT. – Root directory – File space: The rest of the disk.
Disk Fragmentation Over time, allocation of clusters becomes less contiguous. Deletion and resizing of files may result in free clusters located in random positions on the disk. Such a situation is called fragmentation and can result in reduced performance of the computer. To correct this situation a defragmenting tool must be used which can put all the clusters of a file in contiguous locations and coalesce the free clusters.
Disk Fragmentation Windows comes with a disk defragmenting tool.