NCHU System & Network Lab Lab 14 File and Directory.

Slides:



Advertisements
Similar presentations
Chapter 12: File System Implementation
Advertisements

Concepts about the file system 2. The disk structure 3. Files in disk – The ext2 FS 4. The Virtual File System (c) 2013, Prof. Jordi Garcia.
NCHU System & Network Lab Lab 15 Record Locking. NCHU System & Network Lab Record Locking (1/4) What happens when two process attempt to edit the same.
File Systems Examples.
File System Interface CSCI 444/544 Operating Systems Fall 2008.
Dr. Kalpakis CMSC 421, Operating Systems. Fall File-System Interface.
1 Files and Directories Hua LiSystems ProgrammingCS2690Files and Directories.
1 Case Study 1: UNIX and LINUX Chapter History of unix 10.2 Overview of unix 10.3 Processes in unix 10.4 Memory management in unix 10.5 Input/output.
NCHU System & Network Lab Lab 12 Page Replacement Algorithm.
Operating Systems File Systems (in a Day) Ch
File Systems Implementation
Operating Systems File Systems (Select parts of Ch 6)
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
9 Advanced Operating Systems File System Internals.
Project 3: File System Design COS318 Fall Last Time Web Server Extensive use of a file system on server machine without actually worrying about.
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 24 October 24, 2014 Reading: A&D 13.3 HW 4 due 10/27 Proj.
NCHU System & Network Lab Lab 10 Message Queue and Shared Memory.
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
CS 311 – Lecture 12 Outline File management system calls Stat() Directory Information  Opendir()  Readdir()  Closedir() Truncate() and remove() Lecture.
NCHU System & Network Lab Lab 13 File I/O & Standard I/O.
Ext* Content Areas Inodes, Directories & Files. Review Recall …the file system metadata The superblock describes the file system The group descriptor.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
CS 6560 Operating System Design Lecture 13 Finish File Systems Block I/O Layer.
1Fall 2008, Chapter 11 Disk Hardware Arm can move in and out Read / write head can access a ring of data as the disk rotates Disk consists of one or more.
Week 12 - Friday.  What did we talk about last time?  Exam 2 post mortem  Low level file I/O.
Silberschatz, Galvin and Gagne  Operating System Concepts File Concept Contiguous logical address space Smallest user allocation Non-volatile.
SIMULATED UNIX FILE SYSTEM Implementation in C Tarek Youssef Bipanjit Sihra.
1 UNIX System Programming v Objectives –look at how to program with directories –briefly describe the UNIX file system Directories and File System.
File Systems CSCI What is a file? A file is information that is stored on disks or other external media.
Page 110/19/2015 CSE 30341: Operating Systems Principles Chapter 10: File-System Interface  Objectives:  To explain the function of file systems  To.
Chapter 5 File Management File System Implementation.
Adv. UNIX: dirs/181 Advanced UNIX v Objectives –look at how to program with directories –briefly describe the UNIX file system Special.
Directory structure. Slide 2 Directory Structure  A directory ‘file’ is a sequence of lines; each line holds an i-node number and a file name.  The.
NCHU System & Network Lab Lab 11 Memory Mapped File.
Some basic concepts and information on file systems Portions taken and modified from books by ANDREW S. TANENBAUM.
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Files and Directories File types stat functions for file information
Navigating Directories
Today’s topic Access and manipulate meta data for files –File type, ownership, access permissions, access time, etc How to determine if a file is not there?
UNIX File System (UFS) Chapter Five.
The UNIX File System (1) Some important directories found in most UNIX systems.
File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted).
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Files and file allocation.
Laface 2007 File system 2.1 Operating System Design Filesystem system calls buffer allocation algorithms getblk brelse bread breada bwrite iget iput bmap.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 1, 2005 File-System Interface.
CSCI 330 UNIX and Network Programming
Lecture 19 Linux/Unix – File System
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 10 & 11: File-System Interface and Implementation.
It consists of two parts: collection of files – stores related data directory structure – organizes & provides information Some file systems may have.
Linux file systems Name: Peijun Li Student ID: Prof. Morteza Anvari.
CS 241 Section Week #8 (10/29/09). Outline MP5 Overview Files & I/O UNIX File Systems inodes Directories Links.
CSCI 330 UNIX and Network Programming Unit VIII: I/O Management II.
1 The File System. 2 Linux File System Linux supports 15 file systems –ext, ext2, xia, minix, umsdos, msdos, vfat, proc, smb, ncp, iso9660, sysv, hpfs,
File Subsystem in Linux by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
W4118 Operating Systems Instructor: Junfeng Yang.
Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 5 Files.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 3.
CSE Operating System Principles File Systems.
COMP 3500 Introduction to Operating Systems Directory Structures Block Management Dr. Xiao Qin Auburn University
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
Week 12 - Thursday CS222.
Directory Directory is a file containing list of entries,where each entry represents inode number and name of the file stored in that directory.
An overview of the kernel structure
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
CSE 333 – Section 3 POSIX I/O Functions.
File Structure Related system calls
CSE 333 – Section 3 POSIX I/O Functions.
Off-line Direct Disk Access System
Lab 10 Paging.
Presentation transcript:

NCHU System & Network Lab Lab 14 File and Directory

NCHU System & Network Lab Introduction (1/3) An efficient method to access our data in any permanently storage – file system. –File : Data unit Related information for management –The smallest storage unit, block One or more sectors compose a block. –How to decide the size of blocks, larger or smaller ? –File-System provides : Mapping from the logical file system to disk. Access operations and related attributes of each file.

NCHU System & Network Lab Introduction (2/3) VFS –The purpose of VFS is to allow applications to access different types of concrete file systems in an uniform way. VFS provides an interface between kernel and file systems. –VFS separates the detail implementation from kernel operations. –It is easy to add support for new file system types.

NCHU System & Network Lab Introduction (3/3)

NCHU System & Network Lab Linux File System (1/5) Linux EXT2 file system –Each file includes two parts : i-node and data The kernel identifies all files by i-nodes i-node contains: –Related attributes to each file. –Pointers to real data blocks. A directory is also a file, that it contains a list of name and i-node number of files. owner permission access time flags size Pointers to blocks i-node

NCHU System & Network Lab Linux File System (2/5) Glance at Linux file system (ext2) structure : Super block i-node bit map block bit map i-node table Data blocks i-node table data blocks

NCHU System & Network Lab Introduction of File System (3/5) –Super block (partition control block) Counters of the free/used blocks and i-nodes Default size of each block and i-node Valid bit : the system is mounted or not. –block / i-node bit map Record the usage of blocks / i-nodes –i-node table (file control block) Information of each i-node

NCHU System & Network Lab Introduction of file system (4/5) Links : –Hard link : Hard-link only adds one item into a directory entry. –No new i-node and blocks are allocated. Making hard-link to directory is prohibited on Linux file system. dir A new item added i-node table B C data blocks

NCHU System & Network Lab Introduction of File System (5/5) –Symbolic link : In this case, using symbolic link will create a new file contains the destination file name. Data : AAA New i-node New data i-node table data blocks then FS search the requested file: AAA

NCHU System & Network Lab Operation for Directory File Functions : #include DIR *opendir( const char *pathname); struct dirent *readdir (DIR *dp); int closedir (DIR *dp); …

NCHU System & Network Lab opendir() This function opens a directory stream and returns a DIR pointer. –Open a directory stream of a directory for related operations. –This stream contains a list of (name,i-node num) in pathname directory. #include DIR *opendir( const char *pathname);

NCHU System & Network Lab readdir() Get information from a DIR stream : –It returns the next name and i-node number in this stream in a dirent structure. struct dirent { ino_t d_ino; // i-node num char d_name[]; } // file name #include struct dirent *readdir (DIR *dirptr);

NCHU System & Network Lab closedir() A function to close a DIR stream –Close this directory data stream dirptr Returned value,0 if success and -1 on error #include int closedir (DIR *dirptr);

NCHU System & Network Lab stat()& lstat() We can use these function to get information about a file : –It returns the information of pathname and stored it into buf. –lstat() is specified to get information about “link” It returns the status about “link” itself. –return value,0 if ok and -1 on error. #include int stat (char *pathname, struct stat *buf); int lstat (char *pathname, struct stat *buf);

NCHU System & Network Lab stat()& lstat() (cont.) struct stat { mode_tst_mode;/*file types and mode*/ ino_tst_ino;/*i-node number*/ dev_tst_dev;/*device number*/ dev_tst_rdev; nlink_tst_nlink;/*number of links*/ uid_tst_uid;/*user ID of owner*/ gid_tst_gid;/*group ID of owner*/ off_tst_size;/*size in bytes*/ time_tst_atime;/* time*/ time_tst_mtime; time_tst_ctime; blksize_tst_blksize;/*block size*/ blkcnt_tst_blocks;/*block numbers*/ }

NCHU System & Network Lab utime() The access time (st_atime) and modification time (st_mtime) of a file can be changed with the utime() function. –You must have the right to access this file. –st_ctime,i-node change-status time, is protected. –If *times is a NULL pointer, it sets (atime, mtime) to the current time. struct utimbuf { time_t actime; /* st_atime */ time_t modtime; /*st_mtime*/ } #include int utime (const char *pathname, const struct utimbuf *times);

NCHU System & Network Lab Lab 1 Make a symbolic link Try to use lstat() and stat() to get information about this link and show the difference. –Size of the file and its type.

NCHU System & Network Lab Lab2 A directory scan program : –Create a testing directory contains four files. –This program will scan this directory and show file names on screen.

NCHU System & Network Lab Lab2 (cont.) Open a directory stream Read each file name from stream. No “.” and “..” directory names

NCHU System & Network Lab Lab 3 Try to modify an existing file truncated to 0 length but does not change their access or modification time. –Make an non-empty file –Start your program Open the file and truncate it,and then close the file. Modify atime and mtime of this file to the earlier value. –Use ls -l to check the result

NCHU System & Network Lab Lab 3 (cont.) /* a simple program to set mtime and atime of a file to current time. */ #include int main(){ struct utimbuf timebuf; *timebuf = NULL; utime (testfile, &timebuf); exit(0); }

NCHU System & Network Lab Reference Advanced Programming in the UNIX Environment 2nd Author : Richard Stevens, Stephen A.Rago, Publisher : Addison-Wesley Beginning Linux Programming Author : Richard Stones, Neil MatthewPublisher : Wrox jollen’s Bloghttp:// Operating System Concepts 6th