Skip to Content
UNIX Filesystems: Evolution, Design, and Implementation
book

UNIX Filesystems: Evolution, Design, and Implementation

by Steve D. Pate
January 2003
Intermediate to advanced content levelIntermediate to advanced
480 pages
13h 22m
English
Wiley
Content preview from UNIX Filesystems: Evolution, Design, and Implementation

The FILE Structure

Where system calls such as open() and dup() return a file descriptor through which the file can be accessed, the stdio library operates on a FILE structure, or file stream as it is often called. This is basically a character buffer that holds enough information to record the current read and write file pointers and some other ancillary information. On Linux, the IO_FILE structure from which the FILE structure is defined is shown below. Note that not all of the structure is shown here.

struct _IO_FILE {
   char  *_IO_read_ptr;   /* Current read pointer */
   char  *_IO_read_end;   /* End of get area. */
   char  *_IO_read_base;  /* Start of putback and get area. */
   char  *_IO_write_base; /* Start of put area. */
   char  *_IO_write_ptr;  /* Current put pointer. */
   char  *_IO_write_end;  /* End of put area. */
   char  *_IO_buf_base;   /* Start of reserve area. */
   char  *_IO_buf_end;   /* End of reserve area. */
   int   _fileno;
   int   _blksize;
};

typedef struct _IO_FILE FILE;

Each of the structure fields will be analyzed in more detail throughout the chapter. However, first consider a call to the open() and read() system calls:

fd = open(“/etc/passwd”, O_RDONLY);
read(fd, buf, 1024);

When accessing a file through the stdio library routines, a FILE structure will be allocated and associated with the file descriptor fd, and all I/O will operate through a single buffer. For the _IO_FILE structure shown above, _fileno is used to store the file descriptor that is used on subsequent calls to read() or ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Marshall Kirk McKusick, George V. Neville-Neil, Robert N.M. Watson

Publisher Resources

ISBN: 9780471456759Purchase book