230 likes | 322 Views
ITFN 2601 Introduction to Operating Systems. Lecture 22 Files & Directories. Agenda. Files Naming Structure Attributes Operations Directories Structure Operations. File Naming. File names are used to reflect the content The name is useful to the user
E N D
ITFN 2601Introduction to Operating Systems Lecture 22 Files & Directories
Agenda • Files • Naming • Structure • Attributes • Operations • Directories • Structure • Operations
File Naming • File names are used to reflect the content • The name is useful to the user • The extension(s) are knowledge for the OS • DOS supported 8.3 • 8 characters (a-z, _, -) in the filename • 3 characters as an extension • Most modern systems allow arbitrarily long filenames and extensions
File Structure (Byte) • Byte Ordered • File is a sequence of bytes • Binary values • System doesn’t care • FAT32, NTFS, ext2fs
File Structure (Records) • Files are kept as a set of records • Each record contains data • Records are typed • Data in a record is expected to be the proper type
File Structure (Keyed) • Files stored as a tree of records • Each record has some “key” value • Tree is restructured whenever it becomes unbalanced
File Attributes (Type) • Files have a type • ASCII • Binary • Either Executable or construct file • Can be dictated by the file extension • .exe is an executable windows file • Can be appointed in the file • All JAVA programs start with CAFÉ OS
File Attributes (Access) • Files can be accessed in multiple methods • Usually based on storage • Sequential Access • Reel-to-Reel storage media • Movement is linear • Random Access • Platter-based media • Movement is multi-dimensional
File Attributes (General) • Informational • Who owns the file • Who can read the file • System/Hidden flag • Creation Time • Modification Time • Size • Etc
File Operations • Create • Create a 0-size file • Announces the file is coming • Reserves the filename • Delete • Destroys the file • Removes all OS information about the file
File Operations (2) • Open • Open the file for use • Locks the file (if the open is for a write) • Close • Close the file after use • Releases any locks held on the file
File Operations (3) • Read • Reads the next chunk from the file • Starts from the file-cursor • Write • Writes the designated chunk to the file • Starts at the file-cursor
File Operations (4) • Append • Special write that ALWAYS goes to the end of the file • Seek • Move the file-cursor to the location specified • Rename • Changes the files name • Sometimes a copy-delete
File Operations (5) • GetAttr • Get Attributes • Returns the list of file-attributes for the file • Can request specific attributes • SetAttr • Set Attributes • Sets the file-attributes • Given an attribute-list to use
Directory Structure(Single Level) • One directory listing • All files at one level • Two users can’t have the same filename • Very restrictive
Directory Structure(Two-Level) • Main listing shows user-directories • Each user gets their own file-name-space • Same filename can be used by every user! • System files • How does everyone get access? • Copy to every user directory?
Directory Structure(Hierarchical) • Main directory lists other directories • Uses paths to reach other directories for system or shared files • At some level are “user” directories • C:\documents and settings\jjones (Win 2k) • /home/jjones (unix) • User directories can have their own directory listings, too!
Directory Paths • Each file is in some directory • Path tells the OS how to find the file • Absolute Path • C:\windows\command.exe • Relative Path • ..\windows\command.exe
Directory Operations • Create • Generates an empty directory • Has two entries • . – Current directory • .. – Directory one level up • Delete • Removes the directory listing • Generally only works on empty directories
Directory Operations (2) • Opendir • Opens the directory for reading by a program • Necessary to retrieve a directory listing • Closedir • Closes the directory after a read
Directory Operations (3) • Readdir • Reads the next filename from the directory listing • Starts at the directory-cursor
Directory Operations (4) • Rename • Rename the directory • Link • Create a special file that mimics the linked file • Saves disk-space by not needing a true copy