Sunday 22 October 2017

I/O devices










I/O system provides standard C libraries for both basic and buffered I/O. The basic I/O libraries are UNIX-compatible; the buffered I/O libraries are ANSI C-compatible. 

The basic I/O interface is source-compatible with the I/O primitives in the standard C library.
1)fd = creat("name", flag ) :   Creates a file.
2)remove(fd ):    Deletes a file.
3)fd = open( "name", flags, mode):    Opens a file (optionally, creates a file if it does not already exist.)
4)close( fd):    Closes a file.
5)read((fd, &buffer, maxBytes ):    Reads a previously created or opened file.
6)write( ):    Writes to a previously created or opened file.
7)result = ioctl (fd, function, arg) :   Performs special control functions on files.

At the basic I/O level, files are referred to by a file descriptor. A file descriptor is a small integer returned(>2) by a call to open( ) or creat( ). The other basic I/O calls take a file descriptor as a parameter to specify a file. File descriptors are not global.

When a file is opened, a file descriptor is allocated and returned. When the file is closed, the file descriptor is deallocated.  standard I/O file descriptors 0, 1 and 2
0 is used for standard input (stdin).
1 is used for standard output (stdout).
2 is used for standard error output (stderr). 

The ioctl( ) routine provides an open-ended mechanism for performing I/O functions that are not performed by the other basic I/O calls.

For example, the following call uses the FIOBAUDRATE function to set the baud rate of a tty device to 9600: status = ioctl (fd, FIOBAUDRATE, 9600);



 The VxWorks I/O system is flexible, allowing specific device drivers to handle above seven basic I/O functions. All VxWorks device drivers follow the basic I/O.

 

No comments:

Post a Comment