In: Computer Science
What are System calls. Provide 6 file and directory system calls
Systen call provides the interface between a process & operating system, these calls are generally available in assembly language instruction and they are usually listed in various mannuals used by Assembly Language proframmers.
System allows system calls to be made directly from a high level language program , in which case the calls normally made by pre-defined functins and subroutine calls.
Several languages such as C,C++ etc, have defined to replace Assembly language for system programming. These languages allow system calls to made directly.
For Example: UNIX system calls may be invoke directly from C orC++ program. System calls are modern microsoft windows platform are part of the Win 32 API (Application program interface).
Directory for system call.
1. System call OPEN
Opening or creating a file can be done using the system call open. The syntax is:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *path,
int flags,... /* mode_t mod */);
O_RDONLY
Opens the file for reading.
O_WRONLY
Opens the file for writing.
O_RDWR
The file is opened for reading and writing.
O_APPEND
It writes successively to the end of the file.
O_CREAT
The file is created in case it didn\92t already exist.
O_EXCL
If the file exists and O_CREAT is positioned, calling open will fail.
O_NONBLOCK
In the case of pipes and special files, this causes the open system call and any other future I/O operations to never block.
O_TRUNC
If the file exists all of its content will be deleted.
O_SYNC
It forces to write on the disk with function write. Though it slows down all the system, it can be useful in critical situations.
The third argument, mod, is a bitwise OR made between a combination of two from the following list:
S_IRUSR, S_IWUSR, S_IXUSR
Owner: read, write, execute.
S_IRGRP, S_IWGRP, S_IXGRP
Group: read, write, execute.
S_IROTH, S_IWOTH, S_IXOTH
Others: read, write, execute.
2:
System call CREAT
A new file can be created by:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int creat(const char *path, mode_t mod);
The function returns the file descriptor or in case of an error it returns the value -1. This call is equivalent with:
open(path, O_WRONLY | O_CREAT | O_TRUNC, mod);
3:
System call READ
When we want to read a certain number of bytes starting from the current position in a file, we use the read call. The syntax is:
#include <unistd.h>
ssize_t read(int fd, void* buf, size_t noct);
4:
System call WRITE
For writing a certain number of bytes into a file starting from the current position we use the write call. Its syntax is:
#include <unistd.h>
ssize_t write(int fd, const void* buf, size_t noct);
5:
System call CLOSE
For closing a file and thus eliminating the assigned descriptor we use the system call close.
#include <unistd.h>
int close(int fd);
The function returns 0 in case of success and -1 in case of an error. At the termination of a process an open file is closed anyway.
6:
System call LSEEK
To position a pointer (that points to the current position) in an absolute or relative way can be done by calling the lseek function. Read and write operations are done relative to the current position in the file. The syntax for lseek is:
#include <sys/types.h>
#include <unistd.h>
off_t lseek(int fd, off_t offset, int ref);
These all about the system call and its directory . Dear Student if you still have any query then ask me again..Thankyou!!!