Directory Directory is a file containing list of entries,where each entry represents inode number and name of the file stored in that directory.

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
1 Files and Directories Hua LiSystems ProgrammingCS2690Files and Directories.
CSE 222 Systems Programming Time, Errors, and File Access Dr. Jim Holten.
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Files and Directories Hua LiSystems ProgrammingCS2690Files and Directories Spring 2003Page 1 of 60.
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.
CS 311 – Lecture 12 Outline File management system calls Stat() Directory Information  Opendir()  Readdir()  Closedir() Truncate() and remove() Lecture.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
File/Directory manipulation. Opening a File To read from a file, must use a file handle. –by convention, all caps open a file (for reading): –open FILE,
1 UNIX Systems Programming Interprocess communication.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Slide 1 Interprocess communication. Slide 2 1. Pipes  A form of interprocess communication Between processes that have a common ancestor  Typical use:
Chapter 5 Files and Directories Source: Robbins and Robbins, UNIX Systems Programming, Prentice Hall, 2003.
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.
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.
File IO and command line input CSE 2451 Rong Shi.
FTP Server API Implementing the FTP Server Registering FTP Command Callbacks Data and Control Port Close Callbacks Other Server Calls.
Files and Directories File types stat functions for file information
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.
Navigating Directories
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
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?
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
PHP-5- Working with Files and Directories. Reading Files PHP’s file manipulation API is extremely flexible: it lets you read files into a string or into.
CS 241 Section Week #8 (10/29/09). Outline MP5 Overview Files & I/O UNIX File Systems inodes Directories Links.
Directory Tree. Path Names (cont.) cp usr/ast/mailbox usr/ast/mailbox.bak and cp mailbox maibox.bak do the same thing if the working directory is /usr/ast.
FTP Client API FTP in embedded devices Implementing an FTP Client FTP Command APIs Other FTP Client APIs.
Learners Support Publications Working with Files.
File Subsystem in Linux by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
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.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 3.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
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.
Linux Filesystem Management
Unix Files Course code: 10CS62 Prepared by Department of CSE
Sorting Tutorial Using C On Linux.
Distributed Computing Systems
Systems Programming.
Command Line Arguments
Command line arguments
Command Line Arguments
CS111 Computer Programming
Programming Languages and Paradigms
LINUX programming Unit-3 PPT Slides
UNIX FILES
CSE 333 – Section 3 POSIX I/O Functions.
Command Line Arguments
CSE 333 – Section 3 POSIX I/O Functions.
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.
Persistence: File System API
Advanced UNIX progamming
CSE 333 – Section 3 POSIX I/O Functions.
ECE 103 Engineering Programming Chapter 46 argc, argv, envp
CSE 333 – Section 3 POSIX I/O Functions.
Extra C Material Based on material in: The C Programming Language, Second Edition by Brian W. Kernighan and Dennis M. Ritchie. Prentice Hall, Inc., 1988. 
Presentation transcript:

Directory Directory is a file containing list of entries,where each entry represents inode number and name of the file stored in that directory

Directory operations are performed using the following Directory API mkdir opendir readdir closedir rewinddir telldir seekdir rmdir chdir getcwd

MKDIR Purpose: to create directory files #include<sys/stat.h> #include<unistd.h> int mkdir(const char* path_name,mode_t mode) Here: The path_name argument is the path name of a directory file to be created. The mode arguments specifies the access permission for the owner,group,and others to be assigned to the file. (Note: Mode values is modified by the calling process umask) The Return value of mkdir is 0 if it success or -1 if it fails

OPENDIR Purpose: Opens a directory file for read-only #include<sys/types.h> #include<dirent.h> DIR* opendir(const char* path_name) Here: The Path_name argument is the path name of a directory file to be opened. The function returns a DIR* file handler. The DIR data structure is defined in the <dirent.h> header if it success or returns NULL if it fails

READDIR Purpose: reads the next directory record from a directory file referenced by the argument . The argument values is the DIR* return value from an opendir call. #include<sys/types.h> #include<dirent.h> struct dirent* readdir(DIR* f_dir) The function returns the address of a struct dirent if it success or NULL if it fails

CLOSEDIR Purpose: Closes a directory file referenced by f_dir #include<sys/types.h> #include<dirent.h> int closedir(DIR* f_dir) The function returns 0 if it success or -1 if it fails

REWINDDIR Purpose: Resets the file pointer to the beginning of the directory file referenced by f_dir #include<sys/stat.h> #include<dirent.h> void rewinddir(DIR* f_dir)

TELLDIR Purpose: returns the current location associated with the specified directory stream. #include<sys/types.h> #include<dirent.h> long int telldir(DIR *DirectoryPointer)

SEEKDIR Purpose: Changes the file pointer of a given f_dir to a specified address. #include<sys/types.h> #include<dirent.h> void seekdir(DIR *DirectoryPointer, long Location)

RMDIR Purpose: removes the directory specified by the path_name parameter #include<unistd.h> int rmdir(const char* path_name) The function returns 0 if it success or -1 if it fails

CHDIR Purpose: changes the current directory to the directory indicated by the Path parameter. #include<unistd.h> int chdir(const char* path) The function returns 0 if it success or -1 if it fails

GETCWD Purpose: places the absolute path name of the current working directory in the array pointed to by the Buffer parameter, and returns that path name. The size parameter specifies the size in bytes of the character array pointed to by the Buffer parameter. #include <unistd.h> char *getcwd ( char*Buffer,size_t size) If the getcwd subroutine is unsuccessful, a null value is returned.

The dirent structure contains the following fields for each directory entry: ulong_t d_offset; /* actual offset of this entry */ ino_t d_ino; /* inode number of entry */ ushort_t d_reclen; /* length of this entry */ ushort_t d_namlen; /* length of string in d_name */ char d_name[_D_NAME_MAX+1]; /* name of entry (filename) *

C program that simulates ls command #include<stdio.h> #include<string.h> #include<dirent.h> int main(int argc,char* argv[]) { DIR *dp; struct dirent *de; int i; if(argc==1)//Without arguments printing current directory files argv[1]="."; argc++; } for(i=1;i<argc;++i) dp=opendir(argv[i]); if(dp==NULL) perror(argv[i]); exit(1); printf("%s:\n",argv[i]); while((de=readdir(dp))!=NULL) if(de->d_name[0]!='.')//ignoring file which start with dot(.) printf("%s\t",de->d_name); printf("\n"); closedir(dp); return 0;