UNIX Files. How UNIX Sees and Uses Files

Similar documents
Outline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra

Design Overview of the FreeBSD Kernel CIS 657

UNIX Kernel. UNIX History

UNIX File Systems. How UNIX Organizes and Accesses Files on Disk

Table 12.2 Information Elements of a File Directory

File I/O and File Systems

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

File Management 1/34

5/8/2012. Creating and Changing Directories Chapter 7

Files and the Filesystems. Linux Files

Files and Directories

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

CS 201. Files and I/O. Gerson Robboy Portland State University

Lecture 2: The file system

Introduction to File Systems

Motivation. Operating Systems. File Systems. Outline. Files: The User s Point of View. File System Concepts. Solution? Files!

File Systems. What do we need to know?

Data and File Structures Chapter 2. Basic File Processing Operations

Inter-Process Communication

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

Virtual File System. Don Porter CSE 306

File Systems. CS170 Fall 2018

CHAPTER 11: IMPLEMENTING FILE SYSTEMS (COMPACT) By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

TDDB68 Concurrent Programming and Operating Systems. Lecture: File systems

UNIX input and output

Chapter 11: File System Implementation. Objectives

8. Files and File Systems

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

UNIX File System. UNIX File System. The UNIX file system has a hierarchical tree structure with the top in root.

The UNIX file system! A gentle introduction"

File System Internals. Jo, Heeseung

IPC and Unix Special Files

File I/O. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

Virtual File System. Don Porter CSE 506

What is an Operating System? A Whirlwind Tour of Operating Systems. How did OS evolve? How did OS evolve?

ADVANCED OPERATING SYSTEMS

Accessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts

CS333 Intro to Operating Systems. Jonathan Walpole

Disk divided into one or more partitions

File I/O. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Unix Processes. What is a Process?

CSCI 2132 Software Development. Lecture 4: Files and Directories

CS 111. Operating Systems Peter Reiher

Chapter 1 - Introduction. September 8, 2016

OPERATING SYSTEM. Chapter 12: File System Implementation

UNIX File Hierarchy: Structure and Commands

Introduction to OS. File Management. MOS Ch. 4. Mahmoud El-Gayyar. Mahmoud El-Gayyar / Introduction to OS 1

Chapter 11: Implementing File-Systems

History of FreeBSD. FreeBSD Kernel Facilities

Chapter 11: Implementing File Systems

File System Internals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 11: Implementing File

Goals of this Lecture

File-System Interface. File Structure. File Concept. File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection

Chapter 11: Implementing File Systems. Operating System Concepts 9 9h Edition

Module A: The FreeBSD System

Module A: The FreeBSD System

I/O Systems. 04/16/2007 CSCI 315 Operating Systems Design 1

I/O Management! Goals of this Lecture!

I/O Management! Goals of this Lecture!

Contents. PA1 review and introduction to PA2. IPC (Inter-Process Communication) Exercise. I/O redirection Pipes FIFOs

Fall 2017 :: CSE 306. File Systems Basics. Nima Honarmand

PEMP ESD2531. I/O and File System. Session Speaker. Deepak V. M.S Ramaiah School of Advanced Studies - Bengaluru

V. File System. SGG9: chapter 11. Files, directories, sharing FS layers, partitions, allocations, free space. TDIU11: Operating Systems

Appendix A: FreeBSD. Operating System Concepts 9 th Edition

What is a file system

OS structure. Process management. Major OS components. CSE 451: Operating Systems Spring Module 3 Operating System Components and Structure

The Classical OS Model in Unix

Unix System Architecture, File System, and Shell Commands

Lecture 23: System-Level I/O

ICS Principles of Operating Systems

Processes COMPSCI 386

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Files and Directories

Chapter 12: File System Implementation

RCU. ò Dozens of supported file systems. ò Independent layer from backing storage. ò And, of course, networked file system support

Last Class: Memory management. Per-process Replacement

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Chapter 10: File System Implementation

FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 23

Process Management! Goals of this Lecture!

Computer Systems Laboratory Sungkyunkwan University

CS3600 SYSTEMS AND NETWORKS

OPERATING SYSTEMS II DPL. ING. CIPRIAN PUNGILĂ, PHD.

CS720 - Operating Systems

Da-Wei Chang CSIE.NCKU. Professor Hao-Ren Ke, National Chiao Tung University Professor Hsung-Pin Chang, National Chung Hsing University

Chapter 12: File System Implementation. Operating System Concepts 9 th Edition

CSE 4/521 Introduction to Operating Systems. Lecture 24 I/O Systems (Overview, Application I/O Interface, Kernel I/O Subsystem) Summer 2018

Chapter 12: File System Implementation

Module 12: I/O Systems

There is a general need for long-term and shared data storage: Files meet these requirements The file manager or file system within the OS

CS2028 -UNIX INTERNALS

Outline. Operating Systems. File Systems. File System Concepts. Example: Unix open() Files: The User s Point of View

Files. Eric McCreath

Operating Systems: Lecture 12. File-System Interface and Implementation

Chapter 12 File-System Implementation

Week 12: File System Implementation

Chp1 Introduction. Introduction. Objective. Logging In. Shell. Briefly describe services provided by various versions of the UNIX operating system.

Chapter 12: File System Implementation

Transcription:

UNIX Files How UNIX Sees and Uses Files

I/O: UNIX approach The basic model of the UNIX I/O system is a sequence of bytes that can be accessed either randomly or sequentially. The UNIX kernel uses a single data model, byte stream, to serve all applications. It imposes no structure on the data but instead views it as a stream of bytes. Put another way, everything to the kernel is a stream of bytes stream I/O. As a result an I/O stream from one program can be fed as input to any other program; Pipelines can be formed between processes for exchanging data. Applications may impose various levels of structure for their data, but the kernel imposes no structure on I/O. Example: ASCII text editors process documents consisting of lines of characters where each line is terminated by ASCII line-feed character. Kernel knows nothing about this convention

What is a file? File is a named persistent collection of data; a linear array of bytes with a one name. To the kernel, data is unstructured, sequential bytes is accessed by specifying an offset from beginning of the file. File attributes (metadata) include owner(s), permissions, time stamps, size etc. A file exists until all its names are deleted, or no process holds a descriptor for it. In the kernel I/O devices are accessed as files. These are called special device files. UNIX processes pass information to each other using in memory special files: pipes, FIFO, sockets. User processes access all files as ordinary files - regular files on disk, device special files or in memory pipe files. Terminals, printers, tapes are all accessed as if they were streams of bytes. They have names in the file system and are referred to through their descriptors.

Special (Device) Files The kernel can determine to what hardware device a special file refers and uses a resident module called device driver to communicate with the device. Device special files are created by the mknode() system call (by the super-user only) To manipulate device parameters ioctl() system call is used; Different devices allow different operations through ioctl() Devices are divided into two groups: Block devices (structured) Character devices (unstructured)

Block devices Random (anywhere in the stream) access devices; Filetype b in ls al listing of /dev directory Internal implementation is based on the notion of block, a minimal group of bytes that can be transferred in one operation to and from the device. A number of blocks can be transferred in one operation (for effiiciency), but less then block bytes of data is not transferred. To user application, the block structure of the device is transparent through internal buffering being done in kernel. User process may read/write a single byte because it works with I/O stream abstraction Examples: tapes, magnetic disks, drums, cd-roms, zip disks, floppy disks, etc.

Character devices Sequential access devices. Filetype c in ls-al listing of /dev directory Internal implementation often supports the notion of block transfer, In many cases the blocks supported by character devices are very large due to efficiency considerations (e.g., communication interfaces) Called character because the first such devices were terminals, Mouse, keyboard, display, network interface, printer, etc. Sometime devices listed as rxxx, raw devices of xxx block devices.

Disk devices Disk device files are natively defined as block devices. On some systems also support character device interface raw disk. This feature is going away on some systems. File systems, organized, collections of files, are always created on the block devices, and never on the character devices. Single physical block device can be partitioned into a number of logical devices (partition). The physical device is usually named hda, hdb, sda, sdb representing IDE drive 1, SCSI drive 1, 2 Each such logical device can have its own file system and is represented by its own special device file. sda1, sda2, sda3, sda4, sda5.

In memory files Interprocess communication occurs in memory. These files are always sequential, may be unidirectional or bidirectional. Usually limited in size, may be represented by a temporary file in /tmp for user processes.

Pipe A linear array of bytes as files, but they are unidirectional sequential communication links between the related processes (parent/child).; Transient objects of limited size They get their file names in the /tmp directory automatically, but open() cannot be used for them. Descriptors obtained from pipe() system call. Data written to a pipe can be read only once from it, and only in the order it was written (FIFO);

FIFO There is a special kind of pipes, called named pipes. They are identical to unnamed pipes in function, size and use. Except they have normal names, as any other file, and descriptors for them can be obtained through open() system call; Processes that wish to communicate through FIFO in both directions must open one FIFO for each direction.

Socket Socket is a transient object that is used for inter-process communication; usually over a network protocol. It exists only as long as some process holds a descriptor on it. Descriptor is created through the socket() system call. Sequential access; similar to pipes; Different types of sockets exist: Local/Remote, RPC/IPC, reliable/unreliable etc.

File Descriptor A control structure, File Control Block (FCB) e.g. descriptor, is associated with each file in the file system Each FCB has a unique identifier (FCB ID) UNIX: i-node, identified by i-node number When opened, a filenumber presented to process as filehandle FCB structure: File attributes (INODE) A data structure for accessing the file s data Operations: OPEN: Associate an FCB with a resource path READ: Bring a specified chunk of data from file into the process virtual address space WRITE: Write a specified chunk of data from the process virtual address space to the file CLOSE: Close FCB, release resource pathh Other operations: CREATE, DELETE, SEEK, TRUNCATE, SET_ATTRIBUTES

File Descriptors open, close, set_attributes Unix processes use descriptors to reference I/O streams. Descriptors are small unsigned integers. Descriptors are obtained from system calls open(), socket(), pipe(). System calls read() and write() are applied to descriptors to transfer data. System call lseek() is used to specify position in the stream referred by descriptor. System call close() is used to de-allocate descriptors and the objects they refer to. File Descriptors represent objects whose access supported by the kernel: file, pipe, socket

File Descriptor Table The kernel maintains a per-process descriptor table that kernel uses to translate the external representation of I/O stream into internal representation. Descriptor is simply an index into this table. Consequently, descriptors have only local meaning. Note the standard filehandles provided to all processes 0 (STDIN), 1 (STDOUT), 2 (STDERR) Different descriptors in different processes can refer to the same I/O stream; Descriptor table is inherited upon fork(); Descriptor table is preserved upon exec(); When a process terminates the kernel reclaims all descriptors that were in use by this process Which is why UNIX processes inherit variables in only one direction

File descriptor

File descriptor

File descriptor

File descriptor

File descriptor

File commands cp, rm, touch, ln.etc base64, uuencode, uudecode ls (-i for inode) lsof stat fuser od find inum (see ls i)