X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=_ldd.xml;h=fbc7570dcfcec073b04769059a0b6aa6579cad1e;hb=bf0e24d8659e732694493d863b2c73cfcecf8bab;hp=3d7a928e61e77d5ebe6752e6fa6879dfef1c34a7;hpb=57df6d3b56b604c1369e28132e4967dbacaeaa8f;p=cascardo%2Fkernel%2Fold_slides%2F.git diff --git a/_ldd.xml b/_ldd.xml index 3d7a928..fbc7570 100644 --- a/_ldd.xml +++ b/_ldd.xml @@ -56,7 +56,7 @@ write close -seek +lseek ioctl @@ -75,14 +75,118 @@ once at a time. int open (char * filename, int flags); -flags may be O_RDONLY, O_WRONLY, O_RDWR and many others, some not +flags may be O\_RDONLY, O\_WRONLY, O\_RDWR and many others, some not important for devices. Example: -fd = open ("/dev/ttyS0", O_RDWR); +fd = open ("/dev/ttyS0", O\_RDWR); + + + + +close + +The close system call closes an open file. + + +int close (int fd); + + +Example: + + +close (fd); + + + + +read + +The read system call reads data from an open file into a buffer. For +devices, it reads from the device. + + +int read (int fd, char *buffer, int bsz); + + +Read returns the number of bytes written into the buffer, which may be +less than the number of bytes requested for any number of reasons. + + +Example: + + +c = read (fd, buffer, sizeof (buffer)); + + + + +write + +The write system call writes data to an open file from a buffer. For +devices, it writes to the device. + + +int write (int fd, char *buffer, int bsz); + + +Write returns the number of bytes written to the file, which may be +less than the number of bytes requested for any number of reasons. + + +Example: + + +c = write (fd, buffer, strlen (buffer)); + + + + +lseek + +The lseek system call changes the current position of the file, allowing +to read or write in that position. Seeking on a device may have many +different meanings. + + +off\_t lseek (int fd, off\_t pos, int whence); + + +The meaning of the position depends on the value of whence, which can be +SEEK\_SET (the absolute position), SEEK\_CUR (relative to the current +position), SEEK\_END (relative to the end of the file). + + +Example: + + +lseek (fd, 0, SEEK\_END); + + + + +ioctl + +The ioctl system call is a catch-all operation. For those operations +which doesn't fit in the read/write model, the ioctl allows the user to +send a command with an optional argument to the device. This command may +accept input or generate output. + + +int ioctl (int fd, int request, char *arg); + + +The last argument is optional and depends on the type of request. Every +device or device class may have its different set of ioctl's. + + +Example: + + +struct ifreq req; ioctl (fd, SIOCGIFFLAGS, \&req);