1 / 23

COMP5102 Lecture 3

phones off (please). COMP5102 Lecture 3. Operating Systems (OS) File systems. Lecture Outline. File Types Files information File Access File Structure Disk Construction File Allocation Tables. File Types. A file may have a specific type or purpose, e.g.

ulfah
Download Presentation

COMP5102 Lecture 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. phones off(please) COMP5102 Lecture 3 Operating Systems (OS) File systems

  2. Lecture Outline • File Types • Files information • File Access • File Structure • Disk Construction • File Allocation Tables Comp5102/5122 - L3

  3. File Types • A file may have a specific type or purpose, e.g. • regular files, directories, character/block special files, pipes • Some systems have specific types for things like • ASCII (text) files • executable (machine code) files • File types may be enforced • MS-DOS executable must have ‘.exe’ extension or not (they are just a hint to the user) • UNIX text files may have ‘.txt’ extension • File types may have associations • Apple Mac types associate a file with its creator Comp5102/5122 - L3

  4. File Types – Name, Extension Comp5102/5122 - L3

  5. Unix File Types • Four basic types: • Regular Files • may contain text, a program, or other data, • either in ASCII, in the numerical range 0 to 127, i.e. in the 7-bit range • or a binary file, whose bytes can be of all possible values 0 to 255, in the 8-bit range. • Directory Files • A directory containing files within a directory • E.g. directory x may contain a, b and c, and that b is a directory, containing files u and v. b can be viewed as a directory, containing files and as a file itself. Comp5102/5122 - L3

  6. Unix File Types …. • Device Files • In Unix, physical devices (printers, terminals etc.) are represented as ``files.'' • In his way, the same read() and write() functions used to read and write real files can also be used to read from and write to these devices. • Link Files • new name for another file • suppose we have a file X, and type ln X Y If we then run ls, it will appear that a new file, Y, has been created, as a copy of X, Comp5102/5122 - L3

  7. Files info. In a given Directory • The `a' (``all'') and `l' (``long'') options of the ls command can give us a lot of information about files in a specified directory: • bash-2.05$ ls -al • total 448 • drwx--x--x 3 msaf csstf 4096 Nov 17 10:44 . • drwx--x--x 69 msaf csstf 86016 Nov 17 10:39 .. • -rwx--x--x 1 msaf csstf 83012 Nov 5 2002 a.out • -rwx--x--x 1 msaf csstf 14964 Oct 9 2002 prg1 • -rw------- 2 msaf csstf 343 Oct 9 2002 prog1.c Comp5102/5122 - L3

  8. Files info. … • The output is separated into six columns: • 1st column - access permissions (see below) • 2nd column - number of file entries (in the case of directory files) • 3rd column - owner • 4th column - size in bytes • 5th column - date and time of last modification • 6th column – file name Comp5102/5122 - L3

  9. File Access Control • In Unix, all files are protected under some access control mechanism • the owner of a file can deny access of his files to others. • e.g. drwxr-xr-x. • The meanings of the flags are shown below: • file type: • d (directory) • - (ordinary file) • l (symbolic link) Comp5102/5122 - L3

  10. File Access … • permissions for the owner: • r (read) • w (write) • x execute • r-x read and execute permission are granted, but not write permission, for other users. • To change or delete a file you need to have write permission • To view a file you need to have read permission Comp5102/5122 - L3

  11. Some File Commands • chmod • change access permissions of any of your own file. • u user (i.e. owner) • g group • o others • + add permission • - remove permission • r read • w write • x execute Comp5102/5122 - L3

  12. e.g. • chmod ugo+rw prog2 • adds read and write permission for all users to the prog2 file or directory of the person issuing this command. • In some cases it is useful for a user to deny himself/herself permission to write to a file, • e.g. to make sure the file not deleted by mistake. Comp5102/5122 - L3

  13. du and df • The du command displays the sizes in kilobytes of all files in the specified directory, and the total of all those sizes; • The df command displays the amount of unused space left in your disk systems. • diff • displays line-by-line differences between two ASCII files. If for example, you have two versions of a C source file but don't remember how the new version differs from the old one, you could type • diff oldprog.c newprog.c Comp5102/5122 - L3

  14. Wild Cards • There are two wild-card characters in Unix, `*' and `?'. rm *.c rm x?b.c rm test[1-3].c Comp5102/5122 - L3

  15. File Access Methods • There are two distinct classes of access method • sequential access • suited to magnetic tape devices • the information in a file (bytes or records) can only be written at the end (appended) or read in sequential order • random access • suited to hard disks • bytes or records can be read or written in any order • sometimes this is implemented by each read and write operation specifying a position parameter, or Comp5102/5122 - L3

  16. File System Structure • Hard disks provide the bulk of secondary storage on which a file system is maintained • to improve input / output efficiency, I/O transfers are performed in units of blocks • Each block consists of one or more physical hard disk sectors • typical physical sector sizes vary from 32 to 4K bytes • usually, particularly on PC’s, sectors are 512 bytes • Hard disks have two important characteristics • blocks can be read, modified and written (in place) • blocks can be directly accessed in any order Comp5102/5122 - L3

  17. File System Layers • In order to provide convenient and efficient user access to the disk, the operating system imposes a file system structure • this generally comprises a number of layers • to insulate the logical structure from device dependencies application programs logical file system (files, directories, etc) basic file system (block read & write) I/O control (interrupts, device drivers) hardware devices Comp5102/5122 - L3

  18. Disk Construction • A hard disk consists of a number of platters • made of aluminium or glass • with a thin magnetic film on the surface • common platter diameters range from 1.8 - 5.25 inches • Information is stored magnetically on both surfaces (sides) of each platter • The platters rotate at a fixed rate on the spindle • e.g. modern PC drives rotate at 5,400 or 7,200 rpm Comp5102/5122 - L3

  19. Read / Write Heads r/w heads arms actuator side view • Each surface has a read/write head to access the magnetic fields • the heads are mounted on arms and their movement is controlled by an actuator • all the heads move together • The heads do not touch the surface, but ‘fly’ a very small distance above the surface • the fly height • typically between around 0.2 to 0.07 mm Comp5102/5122 - L3

  20. The Disk Surface • The surface of a disk is logically divided into concentric circular tracks • 1,000’s are now common • The surface is also divided into segments • a track through a particular segment is a sector • note: often the term sector is confusingly used to refer to both segments and sectors! • on typical PC disks, each sectorholds 512 bytes Comp5102/5122 - L3

  21. data capacity of a disk is described best by: • Disk Capacity = Cylinders * Heads * Sectors * (# bytes / disk block) • A typical example for a 2.1 GB IDE disk on a Linux-based PC would be:C/H/S = 1024/64/63 • Disk Capacity = 1024 * 64 * 63 * 512 bytes/block = 2113929216 bytes = 2.11 gigabytes Comp5102/5122 - L3

  22. File Allocation Tables • The FAT is an index array of linked-list block numbers kept in its own disk block • the FAT contents are critical to finding all file blocks, so it is (usually) held twice at the start of each partition • the root directory immediately follows the FATs • The directory entry holds the start block of a file • the FAT entry indexed by that block number contains the block number of the next block in the chain • there is a special value to signify end of file • Special values signify free blocks and bad blocks Comp5102/5122 - L3

  23. File Systems in Unix • In Unix, the files are organized into a tree structure with a root named by the character '/'. • The first few levels of the tree look like this: Comp5102/5122 - L3

More Related