Linuxdoc Linux Questions
Click here to ask our community of linux experts!
Custom Search

Chapter 7. System calls

Table of Contents
7.1. open()
7.2. write()
7.3. read()
7.4. poll()
7.5. close()
7.6. mmap()
7.7. fcntl(sg_fd, F_SETFL, oflags | FASYNC)
7.8. Errors reported in errno

System calls that can be used on sg devices are discussed in this chapter. The ioctl() system call is discussed in the following chapter [ see Chapter 8 ].

Successfully opening a sg device file name (e.g. /dev/sg0) establishes a link between a file descriptor and an attached SCSI device. The sg driver maintains state information and resources at both the SCSI device (e.g. exclusive lock) and the file descriptor (e.g. reserved buffer) levels.

A SCSI device can be detached while an application has a sg file descriptor open. An example of this is a "hotplug" device such as a USB mass storage device that has just been unplugged. Most subsequent system calls that attempt to access the detached SCSI device will yield ENODEV. The close() call will complete silently while the poll() call will "or" in POLLHUP to its result. A subsequent attempt to open() that device name will yield ENODEV.