
File-System Interface Electrical and Computer Engineering Stephen Kim ([email protected]) ECE/IUPUI RTOS & APPS 1 Chapter 11: File-System Interface n File Concept n Access Methods n Directory Structure n File System Mounting n File Sharing n Protection ECE/IUPUI RTOS & APPS 2 1 File Concept (1) n Contiguous logical address space n Usually nonvolatile such as a hard-disk n Most RTOS’s do not use a hard-disk because of u its mechanical components that cannot sustain in harsh environments like impact and vibration u its power consumer (mostly battery-powered RTOS) u exceptions are some printers, digital recorder, mp3 players, which required huge storage n Recently, non-mechanical storage becomes very popular u Simulating hard-disk as an interface u Use FlashRAM technology n In future, file-system in embedded/real-time system will be more popular ECE/IUPUI RTOS & APPS 3 File Concept (2) n File types: u Data – numeric, character, alphanumeric, binary u Program n Generally, a file is sequence of bits, bytes, lines, or records u The meaning is defined by its creator or user ECE/IUPUI RTOS & APPS 4 2 File Structure n None - sequence of words, bytes n Simple record structure u Lines u Fixed length u Variable length n Complex Structures u Formatted document u Relocatable load file n Can simulate last two with first method by inserting appropriate control characters. n Who decides: u Operating system u Program ECE/IUPUI RTOS & APPS 5 File Attributes n Name – only information kept in human-readable form. u Unix differentiates upper- and lowercase u DOS and its predecessors do not distinguish them n Identifier – unique tag internal to the file system n Type – needed for systems that support different types. n Location – pointer to file location on device. n Size – current file size. n Protection – controls who can do reading, writing, executing, and so on. n Time , date , and user identification – data for protection, security, and usage monitoring. n Information about files are kept in the directory structure, which is maintained on the disk. ECE/IUPUI RTOS & APPS 6 3 File Operations (1) n OS provides system calls for each operation u Create – space allocation and a new entry in the directory u Write – For a given file name, search the directory. OS keeps a write-pointer to the location where the next write is to take place u Read – Search the directory for a given name. OS maintains a read-pointer to the location where the next read is to take place ECE/IUPUI RTOS & APPS 7 File Operations (2) u Reposition within file – the current-file-position is set to a given value u Delete – release all file space u Truncate – erase the contents of a file, but keep the file attribute. ECE/IUPUI RTOS & APPS 8 4 File Open and Close n Open(Fi) - search the directory structure on disk for entry Fi, and move the content of entry to an open-file table. So, the system does not need to search directory for subsequent read or write n Close (Fi) – remove the entry of Fi from the open-file table and finish the file access. n Implicit open/close u open a file when the first reference is made u close a file when the job opened the file terminates n Explicit open/close u Most systems require the programmer open and close a file explicitly. u Open system calls returns a pointer to the entry in the open-file table. The pointer, or file descriptor, is used all subsequent IO operation ECE/IUPUI RTOS & APPS 9 Open/Close in Multi-process Systems n Multiple users can open a file simultaneously n OS uses two-level of internal tables, u per-process table – keep info for all files a process has open (current file pointer, access right, accounting info), and pointing to the system-wide table entry u system-wide table – contains process-independent info (file location, access date, file size) u Typically, the open-file table has a counter indicating the number of processes opening the file t increment when a process opens the file t decrement when a process closes the file t when the counter is zero, the file is not in-use anymore. remove the file entry from the open-file table. ECE/IUPUI RTOS & APPS 10 5 File Types n A part of filename indicates the file type u For example, In DOS, .com, .exe, .bat indicates an executable file n In some systems, the use of file extension is optional and just hint. n In Apple, each file has a type made by the creator of the file n Unix does not support any file type, even though file extension can be used as a hint n What is the advantage for supporting file types by OS? n What is the disadvantage? ECE/IUPUI RTOS & APPS 11 File Types – Name, Extension ECE/IUPUI RTOS & APPS 12 6 Access Methods, Sequential Access n most common access method n based on a tape model of a file, but work well on random-access devices such as hard-disk n read-operation reads the next position of a file n write-operation appends to the end of file and advances to the end of the newly written material n A file may move the CP u to the beginning of the file u to n records forward or backward ECE/IUPUI RTOS & APPS 13 Sequential-access File ECE/IUPUI RTOS & APPS 14 7 Access Methods, Direct Access n based on a disk model u block, sector, cylinder n A file is made up of fixed length logical records n A record can be accessed without particular order n Relative block number – index relative to the beginning of the file u the first relative block is the index 0 n Given a logical record length L and a request for record N u IO request must be made starting at location N´ L n Simulation of sequential access using direct access reset Þ cp=0; read next Þ read cp; cp++; write next Þ write cp; cp++; ECE/IUPUI RTOS & APPS 15 Access Methods, Index Access n a file containing the record pointers, to access the file record directly, with little IO ECE/IUPUI RTOS & APPS 16 8 Directory Structure (1) n A disk can be divided into one or more partitioned n MS-DOS/Windows – each partition is treated as a separate storage. ie. only dividing n In Unix, several partitions can be organized into one logical structure n Each partition contains a device directory, or volume table of contents (VTOC) u to keep information about file within it t name, location, size, type, and so forth ECE/IUPUI RTOS & APPS 17 Directory Structure (2) n A collection of nodes containing information about all files. Directory Files F1 F2 F4 F3 Fn Both the directory structure and the files reside on disk. ECE/IUPUI RTOS & APPS 18 9 Typical File-system Organization ECE/IUPUI RTOS & APPS 19 Information in a Device Directory n Name n Type n Address n Current length n Date created n Date last accessed n Date last updated n Owner ID n Protection information ECE/IUPUI RTOS & APPS 20 10 Operations Performed on Directory n Search for a file u simple search or complicate pattern matching n Create a file u When a new file is created, add the info to the directory n Delete a file n List a directory n Rename a file n Traverse the file system u access every directory and every file within a directory structure ECE/IUPUI RTOS & APPS 21 Organize the Directory (Logically) to Obtain n Efficiency – locating a file quickly. n Naming – convenient to users. u Two users can have same name for different files. u The same file can have several different names. n Grouping – logical grouping of files by properties, (e.g., all Java programs, all games, … ) ECE/IUPUI RTOS & APPS 22 11 Single-Level Directory n A single directory for all users. Naming problem Grouping problem ECE/IUPUI RTOS & APPS 23 Two-Level Directory n Separate directory for each user. •Path name •Can have the same file name for different user •Efficient searching •No grouping capability ECE/IUPUI RTOS & APPS 24 12 Tree-Structured Directories (1) ECE/IUPUI RTOS & APPS 25 Tree-Structured Directories (2) n Efficient searching n Grouping Capability n Current directory (working directory) u cd /spell/mail/prog u type list ECE/IUPUI RTOS & APPS 26 13 Tree-Structured Directories (3) n Absolute or relative path name n Creating a new file is done in current directory. n Delete a file rm <file-name> n Creating a new subdirectory is done in current directory. mkdir<dir-name> Example: if in current directory /mail mkdircount mail prog prt count Deleting “mail”Þ deleting the entire subtree rooted by “mail”. ECE/IUPUI RTOS & APPS 27 Acyclic-Graph Directories (1) n Have shared subdirectories and files. ECE/IUPUI RTOS & APPS 28 14 Acyclic-Graph Directories (2) n Two different names (aliasing) n If /dict/count is deleted, /spell/count is a dangling pointer. Solutions: u Backpointers, so we can delete all pointers. Variable size records a problem. u Backpointers using a daisy chain organization. u Entry-hold-count solution. ECE/IUPUI RTOS & APPS 29 General Graph Directory (1) ECE/IUPUI RTOS & APPS 30 15 General Graph Directory (2) n Search a file when there is cycle, it might search forever n How do we guarantee no cycles? u Allow only links to file not subdirectories. u Garbage collection. t traverse an entire file system t time-consuming task - inadequate u Every time a new link is added, use a cycle detection algorithm to determine whether it is OK.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages18 Page
-
File Size-