The logical IO layer maps IO requests to blocks and maintains owner ship and

The logical io layer maps io requests to blocks and

This preview shows page 5 - 9 out of 23 pages.

The logical I/O layer maps I/O requests to blocks, and maintains owner- ship and access information about files. 5
Image of page 5
The Role of Directory Structures All modern operating systems have adopted the hierarchical directory model to represent collections of files. A directory itself is typically a special type of file storing information about the files (and hence directories) it contains. Although a directory is “owned” by a user, the directory is truly owned by the operating system itself. The operating system must constrain access to important, and often hidden, information in the directory itself. Although the “owner” of a directory may examine and (attempt to) modify it, true modification is only permitted through operating system primitives affecting the internal directory structure. For example, deleting a file involves both deallocating any disk blocks used by that file, and removing that file’s information from its container directory. If direct modification of the directory were possible, the file may become “un- linked” in the hierarchical structure, and thereafter be inaccessible (as it could not be named and found by name). In general, each directory is stored as a simple file, containing the names of files within it. The directory’s “contents” may be read with simple user-level routines. Reading Directory Information Under both Unix and Windows-NT, user-level library routines simplify the reading of a directory’s contents. Libraries use the standard open , read , and close calls to examine the contents of a directory. 6
Image of page 6
Under Unix: #include <dirent.h> DIR *dirp; struct dirent *dp; dirp = opendir("."); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) printf("%s\n", dp->d_name); closedir (dirp); Under Windows-NT: #include <windows.h> HANDLE filehandle; WIN32_FIND_DATA finddata; filehandle = FindFirstFile("*.*", &finddata); if (filehandle != INVALID_HANDLE_VALUE) { printf("%s\n", finddata->cFileName); while (FindNextFile(filehandle, &finddata)) printf("%s\n", finddata->cFileName); } FindClose(filehandle); Note that the files will not be listed in alphabetical order; any sorting is provided by programs such as ls or dir . 7
Image of page 7
File Information Structures Early operating systems maintained information about each file in the directory entries themselves. However, the use of the hierarchical directory model encourages a separate information structure for each file. Each information structure is accessed by a unique key (unique within the context of its I/O device), and the role of the directory is now simply to provide file names. As an example, Unix refers to these information structures as inodes , accessing them by their integral inode number on each device (themselves referred to by two integral device numbers). A distinct file is identified by its major and minor device numbers and its inode number.
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 23 pages?

  • One '20

What students are saying

  • Left Quote Icon


    Student Picture


  • Left Quote Icon


    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon


    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Answers in as fast as 15 minutes