Structure of File Systems - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Structure of File Systems

Description:

Microsoft file systems - FAT and NTFS. C/C Access to File System ... int _write( int handle, const void *buffer, unsigned int count ) ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 28
Provided by: Gri86
Category:

less

Transcript and Presenter's Notes

Title: Structure of File Systems


1
Structure of File Systems
  • CP2088
  • Operating Systems Programming

2
Summary
  • Contents
  • File system requirements
  • Microsoft file systems - FAT and NTFS
  • C/C Access to File System

3
What does user want from a file system?

4
Directories of files
  • Typical directory entries
  • name
  • type
  • dir, exe, link, ...
  • pointer to start of file on device
  • size
  • protection status
  • time/date - creation and update

5
File Operations
  • File access
  • opening, closing
  • sequential access
  • read/write, seek ...
  • direct access
  • read n/write n (n record number)
  • File and directory operations
  • create, delete, rename, search ...

6
File/Directory Operations
  • File access
  • opening, closing
  • sequential access
  • read/write, seek ...
  • direct access
  • read n/write n (n record number)
  • File and directory operations
  • create, delete, rename, search

7
Disk Space Allocation
  • Basic requirements
  • Disc space used efficiently
  • Fast access of file content
  • Three basic approaches to allocation of free
    space to files.
  • Contiguous allocation
  • Linked allocation
  • Indexed

8
Allocation Strategy
  • All rely on allocation of fixed size blocks on
    disc.
  • 1 block 1 sector
  • efficient use of disc free space
  • management of free space becomes inefficient - to
    much time spent in block allocation
  • Solution
  • 1 block 2n sectors - cluster

9
Linking
  • Used by FAT 16/32
  • Directory entry points at first block
  • Pointer in block to next block in file
  • For
  • No fragmentation
  • No prior knowledge of file size needed
  • Against
  • File can be spread across disc - slow access
  • Direct access slow - why?
  • You have to look through blocks to locate the
    physical disk block containing record 'n'
  • Recovery of file difficult if link lost - power
    failure

10
Linkage

0
1
2
3
4
5
6
7
8
9
14
-1
26
10
11
12
13
14
15
16
17
18
19
-1
8
19
5
20
21
22
23
24
25
26
27
28
29
3
12
file start
22
11
Free Space
  • List of all free blocks on disc must be kept.
  • List should be cached
  • Free-space list searched for free block to
    allocate to file.
  • Blocks added to list when file deleted.
  • Should first free block found be allocated to
    file?

12
Typical File System approach
application
high level I/O requests

directs request to file system driver
virtual file system
understands directory/file structure
logical file system
maps logical blocks to track/sector
logical device driver
physical device driver
controls device
device
13
Windows
  • FAT 16
  • MS-DOS, Win95/98/NT/2000
  • FAT 32
  • Win95 (OSR 2), NT using 3rd party driver, Win2000
  • Windows NT File System (NTFS)
  • Win NT/2000, Win 95 using 3rd party driver

14
FAT 16
  • Partition layout - set of logical sectors
  • 1 logical sector 1 physical sector
  • Disc space allocation unit cluster
  • cluster 2n sectors
  • Disc allocation/management variant of linked
    allocation - file allocation table
  • FAT
  • array of cluster numbers
  • one entry per cluster
  • entry 0 - cluster free
  • FAT cached in memory

15
FAT32
  • 32 bit cluster numbers
  • more files
  • smaller clusters - less wasted space
  • bigger partitions
  • No security - user access
  • Root directory ordinary cluster chain - no limit
    on size
  • Limited error recovery
  • can use backup copy of FAT

16
NTFS
  • 64 bit cluster numbers
  • more files
  • smaller clusters - less fragmentation
  • bigger partitions
  • Secure - limiting access to files
  • Recovery - transaction logging
  • Journaling File System

17
C/C Access to File System
  • Directory Information
  • _findfirst() provides information about the
    first instance of a filename that matches the
    file specified in the filespec argument.
  • Header ltio.hgt
  • long _findfirst( char filespec, struct
    _finddata_t fileinfo )

18
struct _finddata_t
  • struct _finddata_t
  • unsigned attrib
  • time_t time_create / -1 for FAT
    file systems /
  • time_t time_access / -1 for FAT
    file systems /
  • time_t time_write
  • _fsize_t size
  • char name260

19
FindNext
  • Once we have a file match then we can search for
    any other match.
  • Find the next name, if any, that matches the
    filespec argument in a previous call to
    _findfirst, and then alters the fileinfo
    structure contents accordingly.
  • int _findnext( long handle, struct _finddata_t
    fileinfo )

20
Reading a File.
  • Many options available
  • The simplest being
  • FILE fopen( const char filename, const char
    mode )
  • File must first be opened in the correct mode
  • Read till we get to the EOF marker
  • Closed

21
Reading Continued
  • size_t fread( void buffer, size_t size, size_t
    count, FILE stream )
  • size_t is the actual number of bytes read.
  • buffer must be bigger than we expect.
  • size is the size of the element to read
  • count - Maximum number of elements expected.

22
Alternative File commandsusing int handles not
streams
  • int _open( const char filename, int oflag , int
    pmode )
  • int _read( int handle, void buffer, unsigned int
    count )
  • int _write( int handle, const void buffer,
    unsigned int count )
  • Do not mix these up with _fopen etc..

23
Windows Options
  • In Windows we have to use the specific Windows
    functions.
  • HANDLE CreateFile( LPCTSTR lpFileName, // file
    name
  • DWORD dwDesiredAccess, // access mode
    DWORD dwShareMode, // share mode
    LPSECURITY_ATTRIBUTES lpSecurityAttributes,
    DWORD dwCreationDisposition, // how to create
    DWORD dwFlagsAndAttributes, // file attributes
    HANDLE hTemplateFile // handle to template
    file
  • )

24
Windows Continued
  • The idea of handling files etc., using an object
    Handle.
  • Therefore the file handling is far more complex.
  • Come to the Level 3 module to learn more.

25
Writing to file
  • size_t fwrite( const void buffer, size_t size,
    size_t count, FILE stream )
  • size_t is the actual number of bytes written.
  • buffer Contains the data to write
  • size is the size of the element to write
  • count - Maximum number of elements to write.

26
Summary
  • Requirements of a File System
  • Directories of files
  • Basic structure
  • File allocation table techniques
  • Disk space allocation
  • Free Space.

27
Summary
  • Fat 16, Fat 32 and NTFS
  • File System APIs
  • Opening a File
  • Writing a File
  • Reading a File
  • Looked at different levels of API interface.
Write a Comment
User Comments (0)
About PowerShow.com