Lecture 3 & 4: FILE SYSTEM.

Slides:



Advertisements
Similar presentations
CSCI 1730 April 1 st, Materials Class notes slides & some “plain old” html & source code examples linked from course calendar board notes & diagrams.
Advertisements

Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
The Unix File System. What are the three parts of every file on a Unix filesystem? And where is each stored? Filename - stored in directories Inode -
UNIX File Systems (Chap 4. in the book “the design of the UNIX OS”) Acknowledgement : Soongsil Univ. Presentation Materials.
UNIX file systems Learning Objectives: 1. To understand the basics of file systems 2. To understand the hierarchical structure in Unix file system 3. To.
Lecture 4: FILE SYSTEM.
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
Linux+ Guide to Linux Certification, Second Edition
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Linux Linux File System.
Guide To UNIX Using Linux Third Edition
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Introduction to Linux and Shell Scripting Jacob Chan.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
1 File Management Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology
Files & Directories Objectives –to be able to describe and use the Unix file system model and concepts Contents –directory structure –file system concepts.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
Unix Basics Chapter 4.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Linux+ Guide to Linux Certification, Second Edition
ENGR 3950U / CSCI 3020U: Operating Systems Description and C Code of Major Functions in Simulated Unix File System. Instructor: Dr. Kamran Sartipi Faculty.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Chapter 4. INTERNAL REPRESENTATION OF FILES
10/23/ File System Architecture. 10/23/ / bin unixdev etc user jim mike x y z tty00 tty01 File System architecture.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Chapter 4. INTERNAL REPRESENTATION OF FILES
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Computer Science Lecture 19, page 1 CS677: Distributed OS Last Class: Fault tolerance Reliable communication –One-one communication –One-many communication.
Project 6 Unix File System. Administrative No Design Review – A design document instead 2-3 pages max No collaboration with peers – Piazza is for clarifications.
E X C E E D I N G E X P E C T A T I O N S Basic LINUX Linux System Administration Dr. Hoganson Kennesaw State University Operating Systems Directory structure:
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
1 Chapter 4. INTERNAL REPRESENTATION OF FILES THE DESIGN OF THE UNIX OPERATING SYSTEM Maurice J. bach Prentice Hall.
Manage Directories and Files in Linux Part 2. 2 Identify File Types in the Linux System The file types in Linux referred to as normal files and directories.
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Linux Commands C151 Multi-User Operating Systems.
Linux File system Implementations
Laface 2007 File system 2.1 Operating System Design Filesystem system calls buffer allocation algorithms getblk brelse bread breada bwrite iget iput bmap.
Foundation of Unix Operating Systems
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
THE FILE SYSTEM Files long-term storage RAM short-term storage Programs, data, and text are all stored in files, which is stored on.
Lecture 19 Linux/Unix – File System
4P13 Week 9 Talking Points
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
1 Introduction to Unix. 2 What is UNIX?  UNIX is an Operating System (OS).  An operating system is a control program that helps the user communicate.
UNIX file systems Learning Objectives: 1. To understand the basics of file systems 2. To understand the hierarchical structure in Unix file system 3. To.
The Unix File System R Bigelow. The UNIX File System The file system refers to the way in which UNIX implements files and directories. The UNIX file system.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
Computer Science Lecture 19, page 1 CS677: Distributed OS Last Class: Fault tolerance Reliable communication –One-one communication –One-many communication.
BILKENT UNIVERSITY DEPARTMENT OF COMPUTER TECHNOLOGY AND INFORMATION SYSTEMS CTIS156 INFORMATION TECHNOLOGIES II FILES AND FILE SYSTEM STRUCTURE.
Getting Started with Linux
Linux 101 Training Module Linux Basics.
Some Linux Commands.
Buffer Cache.
Shell Script Assignment 1.
Tutorial of Unix Command & shell scriptS 5027
Chapter 4: System calls for the file system
Tutorial of Unix Command & shell scriptS 5027
An overview of the kernel structure
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Tutorial of Unix Command & shell scriptS 5027
Introduction Paul Flynn
UNIX File Systems (Chap 4. in the book “the design of the UNIX OS”)
Internal Representation of Files
Mr. M. D. Jamadar Assistant Professor
Presentation transcript:

Lecture 3 & 4: FILE SYSTEM

INTERNAL REPRESENTATION OF FILES Every file on a UNIX system has a unique inode (contains information necessary for a process to access a file) Inodes exist in a static form on disk and the kernel reads them into an in-core inode to manipulate them

Inodes Consist of: File owner identifier (individual owner & group owner) File type (regular, directory, character or block special, or FIFO – pipes) File access permissions (owner, group, other: read, write, execute) File access time Number of links to the file Table of contents for the disk addresses of data in a file File size

Sample Disk Inode Owner mjb Group os Type regular file Perms rwxr-xr-x Accessed Oct 23 1984 1:45 P.M. Modified Oct 22 1984 10:30 A.M. Inode Oct 23 1984 1:30 P.M. Size 6030 bytes Disk addresses

Algorithm for allocation of in-core inodes algorithm iget input: file system inode number output: locked inode { while (not done) if (inode in inode cache) if (inode locked) sleep (event inode becomes unlocked); continue; /*loop back to while */ } /*special processing for mount points */ if (inode on inode free list) remove from free list; increment inode reference count; return (inode); /*inode not in inode cache */ if (no inodes on free list) return (error); remove new inode from free list; reset inode number and fiel system; remove inode from old hash queue, place on new one; read inode from disk (algorithm bread); initialise inode (e.g. reference count to 1);

Structure of a regular file File A File C File B …….. Block address 40 50 60 70 …….. File A Free File C File B …….. 40 50 60 70 81 Block address Allocation of Contigiguous Files and Fregmentation of Free Space

Direct and Indirect Blocks in Inode Single direct Double direct Triple direct . . . .

Directories Give the file system its hierarchical structure Important role in conversion of a file name to an inode number Initial access: open, chdir, link system calls Algorithm namei uses intermediate indoes as it parses a path name

Algorithm for conversion of path name to an inode algorithm namei /* convert path name to inode */ input: path name output: locked inode { if (path name starts from root) working inode = root inode (algorithm iget); else working inode = current directory inode (algorithm iget); while (there is more path name) read next path name component from input; verify that working inode is of directory, access permissions OK; if (working inode is of root and component is “..”) continue; /*loop back to while */ read directory (working inode) by repeated use of algorithms bmap, bread and brelse; if (component matches an entry in directory (working inode)) get inode number for matched component; release working inode (algorithm iput); working inode = inode of matched component (algorithm iget); } else /*component not in directory */ return (no inode); return (working node);

Super block Consists of: The size of the file system The number of free blocks in the file system A list of free blocks available on the file system The index of the next free block in the free block list The size of the inode list The number of free inodes in the file system A list of free inodes in the file system The index of the next free inode in the free inode list Lock fields for the free block and free inode lists A flag indicating that the super block has been modified

Algorithm for assigning new inodes algorithm ialloc /* allocate inode */ input: file system output: locked inode { while (not done) { if (super blocked locked) { sleep (event super block becomes free); continue; /*loop back to while */ } if (inode list in super block is empty) { lock super block; get remembered inode for free inode search; search disk for free inodes until super block full, or no more free inodes (algorithms bread and brelse); unlock super block; wake up (event super block becomes free); if (no free inodes found on disk) return (no inode); set remembered inode for next free inode search; /*there are inodes in super block inode list */ get inode number form super block inode list; get inode (algorithm iget); if (inode not free after all) { write inode to disk; release inode (algorithm iput); continue; /*inode is free */ initialise inode; write inode to disk; decrement file system free inode count; return (inode);}

Assigning Free Inode from Middle of List Free inodes Super Block Free Inode List 83 48 empty 18 19 20 index array 1 array 2

Assigning Free Inode – Super Block List Empty Super Block Free Inode List 470 empty array 1 index Remembered inode Super Block Free Inode List array 2 535 free inodes 476 475 471 48 49 50 index

The File System The best way to learn about files is to play with them. Creating a small file: $ ed a Now is the time For all good people . w junk 36 q $ ls –l junk -rw-r--r– 1 you 36 Sept 27 06:11 junk $ $ cat junk

Basics Cat shows what the file looks like. The command od (octal dump) prints a visible representation of all the bytes of a file. Try: $ od –c junk -c means “interpret bytes as characters”. Turning on the –b option will show the bytes as octal (base 8) numbers as well. $ od -cb junk Try something different: type some characters and then a ctr-d, rather than a return. This will immediately send the characters you have typed to the program that is reading from the terminal. (Ctr-d logs you out, as the shell sees no more input). What happens when you type ctl-d to ed?

What is in a file? The file command makes an educated guess: $ file /bin /bin/ed /usr/src/cmd/ed.c /usr/man/man1/ed.1 /bin: directory /bin/ed: pure executable /usr/src/cmd/ed.c: c program text /usr/man/man1/ed.1 roff, nroff, or eqn input text -c means “interpret bytes as characters”. Turning on the –b option will show the bytes as octal (base 8) numbers as well. $ sort /bin/ed Directories and filenames: $ ls $ pwd $ mkdir recipes $ file * $ ls recipes

Permissions Every file has a set of permissions associated with it, which determine who can do what with the file. The file /etc/passwd is the password file; it contains all the login information about each user. You can discover you uid and groupid, as does the system, by looking up your name in /etc/passwd $ grep you /etc/passwd you:gkmbCTrJ04COM:604:1:Y.O.A.People:/usr/you: The –l option of ls command prints the permissions information, among other things: $ ls –l /etc/passwd -rw-r- - r - - 1 root 5115 Aug 30 10:40 /etc/passwd The chmod command changes permissions on files: $ chmod permissions filenames…. $ chmod +x command $ chmod –w command

Inodes A file has several components: a name, contents and administrative information such as permissions and modification times. The administrative information is stored in the inode along with essential system data such as how long it is, where on the disc the contents of the file are stored and so on There are three times in the inode: the time that the contents of the file were last modified (written); the time that the file was last used (read or executed); and the time that the inode itself was last changed, for example to set the permissions

Interesting directories / Root of the file system /bin Essential programs in executable form (“binaries”) /dev Device files /etc System miscellany /etc/motd Login message of the day /etc/passwd Password file /lib Essenhtial libraries /tmp Temporary files; cleaned when system is restarted /unix Executable form of the operating system /usr User file system /usr/adm System administration: accounting info /usr/bin User binaries /usr/dict Dictionary and support for spell() /usr/games Game programs /usr/include Header files for C programs

Interesting directories /usr/include/sys System header files for C programs /usr/lib Libraries for C, etc /usr/man On-line manual /usr/man/man1 Manual pages for section 1 of manual /usr/mdec Hardware diagnostics, bootstrap programs /usr/news Community service messages /usr/pub Public oddments /usr/src Source code for utilities and libraries /usr/src/cmd Source for commands /usr/src/lib Source code for subroutine libraries /usr/spool Working directories for communication programs /usr/spool/lpd Line printer temporary directory /usr/spool/mail Mail in-boxes /usr/spool/uucp Working directory for the uucp programs /usr/sys Source for the operating system kernel /usr/tmp Arternate temporary directory /usr/you Your login directory /usr/you/bin Your personal programs