RTEMS Logo

RTEMS 4.7.1 On-Line Library


close

PREV UP NEXT Bookshelf RTEMS Filesystem Design Guide

4.5: close

File:

close.c

Processing:

This routine will allow for the closing of both network connections and file system devices. If the file descriptor is associated with a network device, the appropriate network function handler will be selected from a table of previously registered network functions (rtems_libio_handlers) and that function will be invoked.

If the file descriptor refers to an entry in the filesystem, the appropriate handler will be selected using information that has been placed in the file control block for the device (rtems_libio_t structure).

Development Comments:

rtems_file_descriptor_type examines some of the upper bits of the file descriptor index. If it finds that the upper bits are set in the file descriptor index, the device referenced is a network device.

Network device handlers are obtained from a special registration table (rtems_libio_handlers) that is set up during network initialization. The network handler invoked and the status of the network handler will be returned to the calling process.

If none of the upper bits are set in the file descriptor index, the file descriptor refers to an element of the RTEMS filesystem.

The following sequence will be performed for any filesystem file descriptor:

  1. Use the rtems_libio_iop() function to obtain the rtems_libio_t structure for the file descriptor
  2. Range check the file descriptor using rtems_libio_check_fd()
  3. Determine if there is actually a function in the selected handler table that processes the close() operation for the filesystem and node type selected. This is generally done to avoid execution attempts on functions that have not been implemented.
  4. If the function has been defined it is invoked with the file control block pointer as its argument.
  5. The file control block that was associated with the open file descriptor is marked as free using rtems_libio_free().
  6. The return code from the close handler is then passed back to the calling program.


PREV UP NEXT Bookshelf RTEMS Filesystem Design Guide

Copyright © 1988-2004 OAR Corporation