Process Need Outline File Systems

Process Need Outline File Systems

1/26/2016 Motivation – Process Need • Processes store, retrieve information • When process terminates, memory lost Distributed Computing Systems • How to make it persist? • What if multiple processes want to share? File Systems • Requirements: – large Solution? Files – persistent are large, – concurrent access persistent! Motivation – Disk Functionality (1 of 2) Motivation – Disk Functionality (2 of 2) • Questions that quickly arise – How do you find information? – How to map blocks to files? bs – boot sector sb – super block – How do you keep one user from reading another’s data? – How do you know which blocks are free? Solution? File Systems • Sequence of fixed-size blocks • Support reading and writing of blocks Outline File Systems • Abstraction to disk (convenience) • Files (next) – “The only thing friendly about a disk is that it has • Directories persistent storage.” – Devices may be different: tape, USB, SSD, IDE/SCSI, • Disk space management NFS • Misc • Users • Example file systems – don’t care about implementation details – care about interface • OS – cares about implementation (efficiency and robustness) 1 1/26/2016 File System Concepts Files: The User’s Point of View • Files - store the data • Naming: how does user refer to it? • Directories - organize files • Does case matter? Example: blah , BLAH , Blah – Users often don’t distinguish, and in much of Internet no • Partitions - separate collections of directories (also difference (e.g., domain name), but sometimes (e.g., URL called “volumes”) path) – all directory information kept in partition – Windows: generally case doesn’t matter, but is preserved – mount file system to access – Linux: generally case matters • Protection - allow/restrict access for files, directories, • Does extension matter? Example: file.c , file.com – Software may distinguish (e.g., compiler for .cpp , partitions Windows Explorer for application association) – Windows: explorer recognizes extension for applications – Linux: extension ignored by system, but software may use defaults Structure Type and Access • What’s inside? a) Sequence of bytes (most modern OSes (e.g., Linux, • Access Method: Windows)) – sequential (for character files, an abstraction of I/O of b) Records - some internal structure (rarely today) serial device, such as network/modem) c) Tree - organized records within file space (rarely – random (for block files, an abstraction of I/O of block today) device, such as a disk) • Type: – ascii - human readable – binary - computer only readable – Allowed operations/applications (e.g., executable, c-file …) (typically via extension type or “magic number” (see next slide) Determining File Type – Unix file Determining File Type – Unix file (1 of 2) (2 of 2) $ cat TheLinuxCommandLine 1. Use stat() system call (see Project 1; see also • What is displayed? system program) %PDF-1.6^M%âãÏÓ^M 3006 0 obj^M<>stream^M stat ... – “mode” for special file (socket, sym link, named pipes) • How to determine file type? file $ file grof 2. Try examining parts of file (“magic number”) • grof: PostScript document text – Bytes with specific format, specific location $ file Desktop/ 25 50 44 46, offset 0 PDF https://en.wikipedia.org/wiki • Desktop/: directory – Custom, too (see man magic ) /List_of_file_signatures $ file script.sh • script.sh: Bourne-Again shell script, ASCII, exe 3. Examine content $ file a.out – Text? Examine blocks for known types (e.g., tar ) • a.out: ELF 32-bit LSB executable, Intel 80386... $ file TheLinuxCommandLine 4. Otherwise data • TheLinuxCommandLine: PDF document, version 1.6 2 1/26/2016 Common Attributes System Calls for Files • Create • Seek • Delete • Get attributes • Truncate • Set attributes • Open • Rename • Read • Write • Append Example: Program to Copy File (1 of 2) Example: Program to Copy File (2 of 2) “man ” tells what system include files are needed Command line args. Next Zoom in on open() system call int in_fd = open (argv[1], O_RDONLY); /* open file for reading */ Example: Unix open() Unix open() – Under the Hood int open (char *path, int flags [, int mode]) int fid = open (“blah”, flags); read (fid, …); User Space • path is name of file (NULL terminated string) System Space • flags is bitmap to set switch – O_RDONLY, O_WRONLY, O_TRUNC … 0 stdin 1 stdout – O_CREATE then use mode for permissions 2 stderr ... • success, returns index 3 File File Structure – On error, -1 and set errno (see Project 1) ... Descriptor ... (where blocks are) (index) (attributes) (Per file) (Per process) (Per device) 3 1/26/2016 Example: Windows CreateFile() Disk Partitions • Returns file object handle: • Partition large group HANDLE CreateFile ( of sectors allocated lpFileName , // name of file for specific purpose dwDesiredAccess , // read-write • Specify number of dwShareMode , // shared or not cylinders to use lpSecurity , // permissions • Specify type ... ) • Linux: “ df –h” and • File objects used for all: files, directories, “fdisk ” disk drives, ports, pipes, sockets and console (“System Reserved” partition for Windows contains OS boot code and code to do HDD decryption, if set) File System Layout MBR vs. GPT • BIOS reads in program (“bootloader”, e.g., grub ) from known disk location ( Master Boot Record or GUID Partition Table ) • MBR = Master Boot Record • MBR /GPT has partition table (start, end of each partition) – Older standard, still in widespread use • Bootloader reads first block (“boot block”) of partition • GPT = GUID (Globally Unique ID) Partition Table • Boot block knows how to read next block and start OS – Newer standard • Rest can vary. Often “superblock” with details on file system • Both help OS know partition structure of hard disk – Type, number of blocks,… • Linux – default GPT (must use Grub 2), but can use MBR • Mac – default GPT . Can run on MBR disk, but can’t install on it • Windows – 64-bit support GPT . Windows 7 default (or GPT MBR , but Windows 8 & 10 default GPT see next) Master Boot Record ( MBR ) GUID Partition Table ( GPT ) • Old standard, still widely in • Newest standard use • GUID = globally unique • At beginning of disk, hold identifiers information on partitions • Unlimited partitions (but most • Also code that can scan for OSes limit to 128) active OS and load up boot • Since 64-bit, 1 billion TB (1 code for OS Zettabyte) partition size • Only 4 partitions, unless 4 th is (Windows limit ~18 million TB) extended • Backup table stored at end • 32-bit, so partition size • CRC32 checksums to detect limited to 2TB errors • If MBR corrupted trouble! • Protective MBR layer for apps that don’t know about GPT 4 1/26/2016 File System Implementation Example – Linux (1 of 3) Process Open File File Descriptor Disk Control Block Table Table Each task_struct describes a process, refers to open file table File sys info // /usr/include/linux/sched.h Copy fd File struct task_struct { to mem descriptors Open volatile long state; File long counter; Directories Pointer long priority; Array … struct files_struct *files; // open file table (per process) (in memory Data … copy, one per } device) Example – Linux (2 of 3) Example – Linux (3 of 3) The files_struct data structure describes files Each open file is represented by file descriptor , refers to blocks of data on disk process has open, refers to file descriptor table struct file { mode_t f_mode; // /usr/include/linux/fs.h loff_t f_pos; struct files_struct { unsigned short f_flags; unsigned short f_count; int count; unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin; fd_set close_on_exec; struct file *f_next, *f_prev; fd_set open_fds; int f_owner; struct inode *f_inode; // file descriptor (next) struct file *fd[NR_OPEN]; // file descriptor table struct file_operations *f_op; }; unsigned long f_version; void *private_data; }; File System Implementation Contiguous Allocation (1 of 2) • Core data to track: which blocks with which • Store file as contiguous block – ex: w/ 1K block, 50K file has 50 consecutive blocks file? File A: start 0, length 2 File B: start 14, length 3 • File descriptor implementations: • Good : – Contiguous allocation – Easy: remember location with 1 number – Linked list allocation – Fast: read entire file in 1 operation (length) – Linked list allocation with index • Bad : – Static: need to know file size at creation – inode File Descriptor • Or tough to grow! – Fragmentation: remember why we had paging in memory? (Example next slide) 5 1/26/2016 Contiguous Allocation (2 of 2) Linked List Allocation • Keep linked list with disk blocks null null File File File File File Block Block Block Block Block 0 1 2 0 1 Physical 4 7 2 6 3 Block • Good : – Easy: remember 1 number (location) – Efficient: no space lost in fragmentation a) 7 files • Bad : b) 5 files (file D and F deleted) – Slow: random access bad Linked List Allocation with Index inode Physical Block 0 • Table in memory 1 – MS-DOS FAT, Win98 VFAT 2 null • Good: faster random access 3 null • Bad: can be large! e.g., 1 TB • Fast for small files disk, 1 KB blocks 4 7 • Can hold large files – Table needs 1 billion entries 5 – Each entry 3 bytes (say 4 typical) Typically 15 pointers • Number of pointers per block? Depends 6 3 • 4 GB memory! 12 to direct blocks upon block size and pointer size – – e.g., 1k byte block, 4 byte pointer each indirect 7 2 – 1 single indirect has 256 pointers Common format still (e.g., USB drives) since – 1 doubly indirect • Max size of file? Same – it depends upon block size and pointer size supported by many Oses & additional features – 1 triply indirect not needed – e.g., 4KB block,

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    18 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us