Lecture 6 - Linux InputOutput System Calls

Lecture 6 - Linux InputOutput System Calls - Linux I/O...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Linux I/O System Calls
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Linux I/O Linux provides uniform access to most devices or file Five major functions open() close() read() write() ioctl()
Background image of page 2
open() Syntax NAME open, creat - open and possibly create a file or device SYNOPSIS #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int open(const char *pathname, int flags, mode_t mode); int creat(const char *pathname, mode_t mode);
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
open() flags O_RDONLY request opening the file read-only O_WRONLY request opening the file write-only O_RDWR request opening the file read/write O_CREAT If the file does not exist it will be created. O_APPEND The file is opened in append mode.
Background image of page 4
open() mode Based on the UNIX file permissions, (R)ead, (W)rite and e(X)ecute Recall Linux chmod, chgrp, chown commands S_IRWXU 00700 user (file owner) has read, write and execute permission S_IRUSR (S_IREAD) 00400 user has read permission S_IWUSR (S_IWRITE) 00200 user has write permission S_IXUSR (S_IEXEC) 00100 user has execute permission
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
mode in <sys/stat.h> S_IRUSR - Read by owner S_IWUSR - Write by owner S_IXUSR - Execute by owner S_IRWXU - Read, write, and execute by owner S_IRGRP - Read by group S_IWGRP - Write by group S_IXGRP - Execute by group S_IRWXG - Read, write, and execute by group S_IROTH - Read by others S_IWOTH - Write by others S_IXOTH - Execute by others S_IRWXO - Read, write, and execute by others
Background image of page 6
open() Return Value If successful, a new file descriptor If unsuccessful, -1 and the errno is set appropriately * creat() is similar to open in terms of usage
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
close() Syntax NAME close - close a file descriptor fd Return Value Zero ( 0 ) on success -1 on error SYNOPSIS #include <unistd.h> int close(int fd);
Background image of page 8
write() Syntax NAME write - write to a file descriptor SYNOPSIS #include <unistd.h> ssize_t write( int fd, const void *buf, size_t count);
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
write() Syntax fd The file descriptor to write bytes to count The number of bytes to write buf Pointer / location where the bytes are stored
Background image of page 10
write() Return Value number of bytes written On error, -1 is returned errno is set appropriately
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Linux I/O vs stdio FILE I/O open() <==> fopen() close() <==> fclose() write() <==> fwrite()
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 44

Lecture 6 - Linux InputOutput System Calls - Linux I/O...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online