next up previous contents
Next: Virtual Memory Up: Processes Previous: Scheduling in Multiprocessor Systems

Files

 

   figure2471
Figure: A Processes Files

Figure gif shows that there are two data structure that describe file system specific information for each process in the system. The first, the fs_struct 

contains pointers to this processes VFS inodes and its umask . The umask  is the default mode that new files will be created in and can be changed via system calls.

The second data structure, the files_struct , contains information about all of the files that this process is currently using. Programs read from standard input and write to standard output. Any error messages should go to standard error. These may be files, terminal input/output or a real device but so far as the program is concerned they are all treated as files. Every file has its own descriptor and the files_struct  contains pointers to up to 256 file  data structures, each one describing a file being used by this process. The f_mode  field describes what mode the file has been created in; read only, read and write or write only. f_pos  holds the position in the file where the the next read or write operation will will occur. f_inode  points at the VFS inode describing the file and f_ops  is a pointer to a vector of routine addresses; one for each function that you might wish to perform on a file. There is, for example, a write data function. This abstraction of the interface is very powerful and allows Linux to support a wide variety of file types. In Linux, pipes are implemented using this mechanism as we shall see later. Each VFS inode uniquely describes a file or directory within a file system and also provides a uniform interface to the underlying file systems. How file systems are supported under Linux is described in Chapter gif.

Every time a file is opened, one of the free file  pointers in the files_struct  is used to point to the new file  structure. Most Linux processes expect three file descriptors to be open when they start. These are known as standard input, standard output and standard error and they are usually inherited from the creating parent process. All accesses to files are via standard system calls which pass or return file descriptors. These descriptors are indices into the processes fd  vector, so standard input, standard output and standard error have file descriptors 0, 1 and 2. Each access to the file uses the file  data structure's file operation routines to together with the VFS inode to achieve its needs.


next up previous contents
Next: Virtual Memory Up: Processes Previous: Scheduling in Multiprocessor Systems

David A. Rusling
david.rusling@reo.mts.dec.com