CS 311 – Lecture 12 Outline File management system calls Stat() Directory Information  Opendir()  Readdir()  Closedir() Truncate() and remove() Lecture.

Slides:



Advertisements
Similar presentations
File and I/O system calls int open(const char* path, int flags, mode_t modes) int creat(const char *path, mode_t mode) ssize_t read(int fd, void *buf,
Advertisements

1 Files and Directories Hua LiSystems ProgrammingCS2690Files and Directories.
System-Level I/O Topics Unix I/O Robust reading and writing Reading file metadata Sharing files I/O redirection Standard I/O.
CS 311 – Lecture 09 Outline Introduction to Systems programming – System calls – Categories of system calls Error Management System calls File Handling.
CS 311 – Lecture 13 Outline File management system calls chown() chmod() dup() and dup2() link() Lecture 131CS Operating Systems 1.
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Files and Directories Hua LiSystems ProgrammingCS2690Files and Directories Spring 2003Page 1 of 60.
I/O April 16, 2002 Topics Files Unix I/O Standard I/O Reading: (Beta) or (New) Problems: 12.9 (Beta) or 12.4 (New) class24.ppt
Lecture 17 FS APIs and vsfs. File and File Name What is a File? Array of bytes. Ranges of bytes can be read/written. File system consists of many files,
Kernel Directory Interface. DirectoriesDirectories Recall that in Unix your hard drive is organized into a hierarchical system of directories and files.
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
1 Unix File System API Operating System Hebrew University Spring 2007.
1 UNIX Systems Programming Interprocess communication.
Chapter 39 Virtsualization of Storage: File and Directory Chien-Chung Shen CIS, UD
Input and Output Topics I/O hardware Unix file abstraction Robust I/O File sharing io.ppt CS 105 “Tour of the Black Holes of Computing”
1 System-Level I/O Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O’Hallaron.
Week 12 - Friday.  What did we talk about last time?  Exam 2 post mortem  Low level file I/O.
Chapter 5 Files and Directories Source: Robbins and Robbins, UNIX Systems Programming, Prentice Hall, 2003.
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 Long-term Information Storage Store large amounts of information Information must survive the termination of the process using it Multiple.
1 UNIX System Programming Files and Directories. 2 File Pointer Both read() and write() will change the file pointer. The pointer will be incremented.
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.
UNIX Files File organization and a few primitives.
Files and Directories File types stat functions for file information
Navigating Directories
Advanced Programming in the Unix Environment
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?
The UNIX File System (1) Some important directories found in most UNIX systems.
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.
Programming with UNIX File Systems (Chap 3, 4. in the book “Advanced Programming in the UNIX Environment”) Acknowledgement : Prof. Y. Moon at Kangwon Nat’l.
1 Contents 1. Preface/Introduction 2. Standardization and Implementation 3. File I/O 4. Standard I/O Library  5. Files and Directories 6. System Data.
NCHU System & Network Lab Lab 14 File and Directory.
CSCI 330 UNIX and Network Programming
CSE333 SECTION 3. Important Dates Jan 27 th – Homework 1 Due Feb 6 th – Midterm.
CSCE Systems Programming Lecture 02 - System Calls CSCE 510 Jan 16, 2013.
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 PART II System Programming. 2 Chapter 10 The File and I/O System.
Adv. UNIX: FileAgain/171 Advanced UNIX v Objectives –to look at the low-level manipulation of files and their properties (e.g. permissions)
File Subsystem in Linux by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Files Oct. 28, 2008 Topics Mapping file offsets to disk blocks File system buffering and you The directory hierarchy lecture-18.ppt “The course.
CSC 271 – Software I: Utilities and Internals An Introduction to File I/O in Linux Credited to Dr. Robert Siegfried and Beginning Linux Programming by.
CSCE Systems Programming Lecture 07 – Make, Stdio, I/O Buffering CSCE 510 Jan 23, 2013.
Week 12 - Friday.  What did we talk about last time?  Exam 2 post mortem.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 3.
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.
Unix Programming Environment
Unix Files Course code: 10CS62 Prepared by Department of CSE
Supplementary Material on Unix System Calls and Standard I/O
Systems Programming.
Directory Directory is a file containing list of entries,where each entry represents inode number and name of the file stored in that directory.
UNIX FILES
Operating System Hebrew University Spring 2004
An overview of the kernel structure
Network Programming CSC- 341
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
CSE 333 – Section 3 POSIX I/O Functions.
File Structure Related system calls
“The course that gives CMU its Zip!”
File I/O (1) Prof. Ikjun Yeom TA – Hoyoun
CSE 333 – Section 3 POSIX I/O Functions.
Persistence: File System API
CSE 333 – Section 3 POSIX I/O Functions.
Programming with UNIX File Systems (Chap 3, 4
Chien-Chung Shen CIS, UD
Presentation transcript:

CS 311 – Lecture 12 Outline File management system calls Stat() Directory Information  Opendir()  Readdir()  Closedir() Truncate() and remove() Lecture 121CS Operating Systems 1

stat() Used to obtain file information The stat structure is defined in /usr/include/sys/stat.h (#include ) Prototype: – int stat() (const char name, struct stat* buf) – int lstat() (const char* name, struct stat* buf) – returns information of any symbolic links to the file – int fstat() (int fd, struct stat* buf) – similar to stat but uses fd as the first argument The file information can be accessed by “buf” which is a pointer to stat structure. Lecture 122CS Operating Systems 1

Stat() - Members of the structure st_dev Device ID of device containing file. st_ino File serial number. st_mode Mode of file. st_nlink Number of hard links to the file. st_uid User ID of file. st_gid Group ID of file. st_rdev Device ID (if file is character or block special). st_size For regular files, the file size in bytes. st_atime Time of last access. st_mtime Time of last data modification. st_ctime Time of last status change. Lecture 123CS Operating Systems 1

Stat() modes S_ISDIR – directory S_ISCHR – character oriented special device S_ISBLK – block oriented special device S_ISREG – regular file S_ISFIFO - pipe Lecture 124CS Operating Systems 1

Stat() - time fields Time fields in the stat structure like the atime, ctime, ftime are in an encoded format and can be decoded using standard C time functions in time.h asctime(), localtime() subroutines help in decoding the time fields. More time functions can be found at this URL - h/time.h.html Lecture 125CS Operating Systems 1

Directory information opendir() - opens a directory file for reading and returns a pointer to a stream descriptor. Prototype: DIR* opendir (char* filename) The DIR* directory pointer is defined in /usr/include/dirent.h (#include ) The fields in ‘dirent’ structure d_ino – inode number d_off – offset of next directory entry d_reclen – the length of directory entry structure d_name – filename DIR * pointer will be used in other system calls related to directory (DIR* is different struct dirent) Lecture 126CS Operating Systems 1

Directory information To read directory contents use readdir() system call Prototype: struct dirent *readdir(DIR *dir) returns a pointer to dirent structure containing information about the next directory entry. To close a directory contents use closedir() system call Prototype: int closedir(DIR *dir) Lecture 127CS Operating Systems 1

truncate() Used to decrease a size of a file to the size specified. Prototype: – int truncate(const char *path, off_t length); – int ftruncate(int fd, off_t length) Length specifies the resulting size of file after truncation. Returns 0 on success and -1 on failure. Lecture 12CS Operating Systems 18

remove() Used to delete a whole file. Prototype: int remove ( const char * filename ); Returns a non-zero value if failure and zero if success. Lecture 12CS Operating Systems 19