Posix System Calls

What is POSIX

Portable Operating System Interface,is a family of standards specified by the IEEE for maintaining compatibility between operating systems. POSIX defines the application programming interface (API), along with command line shells and utility interfaces, for software compatibility with variants of Unix and other operating systems.

How System Calls Work (in earlier MINIX versions)

Basically Servers handle the system calls. Servers contain the program for System Call Handler. Each System Call also has an entry in User Library, which packages the parameters for system call and calls the handler on appropriate server.

A System Call Handler is placed in appropriate server in /usr/src/servers directory. Eg. A handler for a system call which deals with files will be put in /usr/src/servers/fs directory. Each server source directory contains two important files - table.c and proto.h.

In each line in file table.c, address of system call handler function is assigned to one entry in table and index of entry is the system call number. It basically contains definition for call_vec_table, which is an array of function pointers that is indexed by the system call numbers.Eg.

do_write, /* 4 = write */
do_open, /* 5 = open */
do_close, /* 6 = close */

In proto.h, prototypes of system call handlers are declared eg. _PROTOTYPE(int do_systemCall(void));

the files such as misc.c, stadir.c, write.c, read.c contain the definitions for system call handler functions. A system call handler funtion is called by PUBLIC int _syscall(int who, int syscallnr, register *msgptr); . The parameter "who" refers to the recipent process id, syscallnr to system call number and *msgptr is reference to message data structure which can be used to pass additional parameters.
eg. message m;
_syscall(FS, 89, &m);

The user library function do_mySystemCall is implemented in mySystemCall.c placed in /usr/src/lib/posix.This function calls system call handler using _syscall(int who, int syscallnr, register *msgptr);.

Sequence in Earlier MINIX versions

1. A user program invokes the system call mySystemCall().

2. It is then handled by user library funtion.
PUBLIC int mySystemCall(void)
{ message m;
return(_syscall(FS,SYSCALL,&m));
}

3. Now it is handled by the system call handler in the server, which is mapped using system call number, where the handler is defined.

4. Any return parameters and other data is communicated through the message data structure.

How MINIX 3.2 is different

File System in MINIX 3.2 is different from the earlier versions because of inclusion of Virtual File System in it. It acts as an interface between FS and User processes to increase modularity and abstraction.

Important POSIX System Calls in File System in MINIX 3.2

Some important system calls in file system are - open, close, create, delete, write. They are explaned in detail in Implementation of System Calls in File System.

Reference : http://www.cis.syr.edu/~wedu/seed/Labs/Documentation/Minix3/How_to_add_system_call.pdf