wiki:LindSysCallManual

Lind System Call Manual

This page gives you brief introduction about the system calls that are available in Lind

Filesystem functions


access(2)

Check real user’s permissions for a file.

  • access_syscall(path, amode):

path: a string that consists actual path.
amode: F_OK, R_OK, W_OK, X_OK

  • Return:

0 on success.

  • Errors:

ENOENT, EACCES

  • Status:

Actual. Syscall Ref. no.: 2

  • Unit Test:

Yes. Filename: ut_lind_fs_simple.py

  • Known bugs:
    • EINVAL should be raised if the amode is specified incorrectly.
    • Symlink is not tested yet. This actually is not supported by lind, so doesn’t really fall under as a bug for access.
    • UID/GID are not checked. This check isn’t really important since lind runs as a single-user mode.


unlink(2)

Removes filename -> inode map/decrements the link count. If the link count is zero, deletes the file.

  • unlink_syscall(path):

path: a string that consists actual path to the file.

  • Return:

0 on success.

  • Errors:

ENOENT, EISDIR

  • Status:

Actual. Syscall Ref. no.: 4

  • Unit Test:

Yes. Filename: ut_lind_fs_file_link_unlink.py

  • Know Bugs:
    • If the link count is zero, the inode entry is removed from the inode table. But the file is not removed. Special things need to be done to remove the file, like wait until it is closed to remove.


link(2)

Increments the link count and adds a new filename -> inode map.

  • link_syscall(oldpath, newpath):

oldpath: a string that consists actual path to the file.
newpath: a string that consists actual path to the file.

  • Return:

0 on success.

  • Errors:

ENOENT, EPERM, EEXIST, ENOTDIR

  • Status:

Actual. Syscall Ref. no.: 5

  • Unit Test:

Yes. Filename: ut_lind_fs_file_link_unlink.py


chdir(2)

Sets the current directory for other calls.

  • chdir_syscall(path):

path: a string that consists actual path to the file.

  • Return:

0 on success.

  • Errors:

ENOENT

  • Status:

Actual. Syscall Ref. no.: 6

  • Unit Test:

Yes. Filename: ut_lind_fs_dir_chdir.py


mkdir(2)

Creates a directory.

  • mkdir_syscall(path):

path: a string that consists actual path to the file.

  • Return:

0 on success.

  • Errors:

ENOENT, EEXIST, ENOTDIR

  • Status:

Actual. Syscall Ref. no.: 7

  • Unit Test:

Yes. Filename: ut_lind_fs_rmdir.py

  • Know Bugs:
    • Timestamp of a newly created directory are set to a constant arbitrary value.


rmdir(2)

Removes a directory.

  • rmdir_syscall(path):

path: a string that consists actual path to the file.

  • Return:

0 on success.

  • Errors:

EINVAL, EEXIST, ENOTDIR, ENOTEMPTY

  • Status:

Actual. Syscall Ref. no.: 8

  • Unit Test:

Yes. Filename: ut_lind_fs_rmdir.py


open(2)

A call to open creates a new open file descriptor, an entry in the file descriptor table is made which can be used for subsequent calls like read, write etc.

  • open_syscall(path, flags, mode):

path: a string that consists actual path to the file.
flags: O_CREAT, O_EXCL, O_APPEND, O_TRUNC, O_RDONLY, O_WRONLY, O_RDWR
mode: S_IRWXA, S_IRWXU, S_IRUSR (for more refer to man page for open.)

  • Return:

A new file descriptor which is a non-negative integer.

  • Errors:

ENOENT, ENOTDIR, E_EXISTS

  • Status:

Actual. Syscall Ref, no.: 10

  • Unit Test:

Yes. Filename: ut_lind_fs_multiple_open.py


close(2)

Closes a file descriptor, so that it no longer refers to any file and may be reused.

  • close_syscall(fd):

fd: File descriptor usually returned by open, creat or socket syscalls.

  • Return:

0 on success.

  • Errors:

EBADF

  • Status:

Actual. Syscall Ref. no.: 11

  • Unit Test:

Yes. Filename: ut_lind_fs_broken_close.py

  • Known Bugs:
    • Need to handle unlinked files.


read(2)

Read attempts to read upto count bytes from file descriptor and returns the data.

  • read_syscall(fd, count):

fd: File descriptor usually returned by open, creat or socket syscalls.
count: A non-negative integer value to read number of bytes.

  • Return:

A string of size of count.

  • Errors:

EBADF, EINVAL

  • Status:

Actual. Syscall Ref. no.: 12

  • Unit Test:

Yes. Filename: ut_lind_fs_file_read_write.py

  • Known Bugs:
    • EISDIR is not checked.
    • Seek should be set to beginning of the file before doing a read for first time.


write(2)

Writes up to count bytes from the buffer to the file referred by the file descriptor.

  • write_syscall(fd, data):

fd: File descriptor usually returned by open, creat or socket syscalls.
data: A string that needs to be written to the file.

  • Return:

Number of bytes written.

  • Errors:

EBADF, EINVAL

  • Status:

Actual. Syscall Ref. no.: 13

  • Unit Test:

Yes. Filename: ut_lind_fs_file_read_write.py

  • Known Bugs:
    • Write writes all the data to a file instead of passing count and writing only count bytes.


lseek(2)

lseek repositions the offset of the open file associated with file descriptor.

  • lseek_syscall(fd, offset, whence):

fd: File descriptor usually returned by open, creat or socket syscalls.
offset: An interger
whence: SEEK_SET, SEEK_CUR, SEEK_END

  • Return:

Offset location as measured in bytes from the beginning of the file.

  • Errors:

EBADF, ESPIPE, EINVAL

  • Status:

Actual. Syscall ref. no.: 14

  • Unit Test:

Yes. Filename: ut_lind_fs_file_lseek_past_end.py


fxstat(2)

Returns information about a file. fstat is identical to stat, except the file to be stat-ed is specified by file descriptor.

  • fstat_syscall(fd):

fd: File descriptor usually returned by open, creat or socket syscalls.

  • Return:

A tuple which is similar to struct stat.

  • Errors:

EBADF

  • Status:

Emulated. Syscall ref. no.: 17

  • Unit Test:

Yes. Filename: ut_lind_fs_fstat_complex.py


fstatfs(2)

It is used to know more information about a mounted file system.

  • fstatfs_syscall(fd):

fd: File descriptor usually returned by open, creat or socket syscalls.

  • Return:

A tuple which is similar to struct statfs.

  • Errors:

EBADF

  • Status:

Emulated. Syscall ref. no.: 19

  • Unit Test:

No.


getdents(2)

The function call reads several linux_dirent structures from the directory referred to by the open file descriptor.

  • getdents_syscall(fd):

fd: File descriptor usually returned by open, creat or socket syscalls.

  • Return:

A tuple which is similar to struct linux_dirent.

  • Errors:

EBADF, EINVAL

  • Status:

Emulated. Syscall ref. no.: 23

  • Unit Test:

Yes. Filename: ut_lind_fs_getdents.py


dup(2)

dup uses the lowest-numbered unused descriptor for the new descriptor.

  • dup_syscall(fd):

fd: File descriptor usually returned by open, creat or socket syscalls.

  • Return:

A new file descriptor which points to the same file.

  • Errors:

EBADF

  • Status:

Actual. Syscall ref. no.: 24

  • Unit Test:

Yes. Filename: ut_lind_fs_dup.py


dup2(2)

Makes the newfd be the copy of oldfd.

  • dup2_syscall(oldfd, newfd):

oldfd: File descriptor usually returned by open, creat or socket syscalls.
newfd: File descriptor usually returned by open, creat or socket syscalls.

  • Return:

newfd is returned which now points to the same file as oldfd.

  • Errors:

EBADF

  • Status:

Actual. Syscall ref. no.: 25

  • Unit Test:

Yes. Filename: ut_lind_fs_dup2.py


statfs(2)

It is used to know more information about a mounted file system.

  • fstatfs_syscall(path):

path: a string that consists actual path to the file.

  • Return:

A tuple which is similar to struct statfs.

  • Errors:

ENOENT

  • Status:

Emulated. Syscall ref. no.: 26

  • Unit Test:

Yes. Filename: ut_lind_fs_statfs.py


fcntl(2)

fcntl performs one of the operations described by cmd on the open file descriptor

  • fcntl_syscall(fd, cmd, *args):

fd: File descriptor usually returned by open, creat or socket syscalls. cmd: F_SETFD, F_GETFD, F_SETFL, F_GETFL, F_GETOWN, F_SETOWN *args: This lets us pass any no. of arguments, this depends on cmd.

  • Return:

Depends on the cmd.

  • Errors:

EBADF, EINVAL

  • Status:

Emulated. Syscall ref. no.: 28

  • Unit Test:

Yes. Filename: ut_lind_fs_fcntl.py

  • Known Bugs:
    • Only partial implementation is done. We will be grown according to the requirements.

Network functions


socket(2)

The socket function shall create an unbound socket in a communications domain, and return a file descriptor that can be used in later function calls that operate on sockets.

  • socket_syscall(domain, socktype, protocol):

domain: PF_INET socktype: SOCK_STREAM, SOCK_DGRAM protocol: IPPROTO_TCP, IPPROTO_UDP

  • Return:

A non-negative integer, socket file descriptor.

  • Errors:

EPROTOTYPE, EPROTONOSUPPORT (should be added.)

  • Status:

Emulated. Syscall Ref. No.: 32

  • Unit Test:

Yes. Filename: ut_lind_net_socket.py

bind(2)

Bind assigns the address specified to by (localip, localport) to the socket referred to by the file descriptor sockfd.

  • bind_syscall(fd, localip, localport):

fd: File descriptor returned by socket syscall. localip: A string which represents IPv4 address. localport: A positive integer

  • Return:

0 on success.

  • Errors:

EBADF, ENOTSOCK, EINVAL, EADDRINUSE

  • Status:

Actual. Syscall ref. no.: 33

  • Unit Test:

Yes. Filename: ut_lind_net_bind.py, ut_lind_net_bind_multiple.py, ut_lind_net_bind_on_zero.py

  • Know Bugs:
    • Multiple interfaces are not supported.
    • Old UDP listeners should be closed when re-binding.

send(2)

The send is used to transmit a message to another socket.

  • send_syscall(fd, message, flags):

fd: File descriptor returned by socket syscall. message: A string of data that needs to be transmitted. flags: 0, MSG_NOSIGNAL

  • Return:

no. of bytes sent.

  • Errors:

EBADF, ENOTSOCK, ENOTCONN, EOPNOTSUPP

  • Status:

Actual. Syscall ref. no.: 34

  • Unit Test:

No.

sendto(2)

This call is used to transmit messages over non-connected sockets.

  • sendto_syscall(fd, message, remoteip, remoteport, flags):

fd: File descriptor returned by socket syscall. message: A string of data that needs to be transmitted. remoteip: A string which represents IPv4 address. remoteport: A positive integer flags: 0, MSG_NOSIGNAL

  • Returns:

No. of bytes sent.

  • Errors:

EBADF, ENOTSOCK, EISCONN, ENETUNREACH, EADDRINUSE

  • Status:

Actual. Syscall ref. no.: 35

  • Unit Test:

No.

recv(2)

The call is used to receive messages from a socket. It is normally used on connected sockets.

  • recv_syscall(fd, length, flags):

fd: File descriptor returned by socket syscall. length: read length no. of bytes from socket. flags: MSG_PEEK, O_NONBLOCK

  • Return:

A string of size length.

  • Errors:

EBADF, ENOTSOCK

  • Status:

Actual. Syscall ref. no.: 36

  • Unit Test:

No.

recvfrom(2)

The call is used to receive messages from a socket, and may be used to receive data on a socket whether or not it is connection-oriented.

  • recvfrom_syscall(fd, length, flags):

fd: File descriptor returned by socket syscall. length: read length no. of bytes from socket. flags: MSG_PEEK, O_NONBLOCK

  • Return:

A string of size length.

  • Errors:

EBADF, ENOTSOCK, ENOTCONN

  • Status:

Actual. Syscall ref. no.: 37

  • Unit Test:

Yes. Filename: ut_lind_net_recvfrom.py

  • Know Bugs:
    • Calling this with UDP and without binding raises an error.

connect(2)

The connect system call connects the socket referred to by the file descriptor fd to the address specified.

  • connect_syscall(fd, remoteip, remoteport):

fd: File descriptor returned by socket syscall. remoteip: A string which represents IPv4 address. remoteport: A positive integer

  • Returns:

0 on success.

  • Errors:

EBADF, ENOTSOCK, EISCONN, ENETUNREACH, ETIMEDOUT, EADDRINUSE, ECONNREFUSED

  • Status:

Actual. Syscall ref. no.: 38

  • Unit Test:

Yes. Filename: ut_lind_net_connect_basic_udp.py

listen(2)

listen marks the socket referred to by fd as a passive socket, that is, as a socket that will be used to accept incoming connection requests using accept(2).

  • listen_syscall(fd, backlog):

fd: File descriptor returned by socket syscall. backlog: a positive integer.

  • Returns:

0 on success.

  • Errors:

EBADF, ENOTSOCK, EOPNOTSUPP, EADDRINUSE

  • Status:

Actual. Syscall ref. no.: 39

  • Unit Test:

Yes. Filename: ut_lind_net_listen.py

Misc functions


getpid(2)

Gives the process ID of the calling process.

  • getpid_syscall():
  • Return:

1000

  • Errors:

This function is always successful.

  • Status:

Hardcoded. Syscall Ref. no.: 31

  • Unit Test:

No.

  • Know Bugs:
    • Impact unknown by doing this.


getuid(2)

Gives the real user ID of the calling process.

  • getuid_syscall():
  • Return:

1000

  • Errors:

This function is always successful.

  • Status:

Hardcoded. Syscall Ref. no.: 50

  • Unit Test:

Yes. Filename: ut_lind_fs_getuid.py

  • Know Bugs:
    • Impact unknown by doing this.


geteuid(2)

Gives the effective user ID of the calling process.

  • geteuid_syscall():
  • Return:

1000

  • Errors:

This function is always successful.

  • Status:

Hardcoded. Syscall Ref. no.: 51

  • Unit Test:

Yes. Filename: ut_lind_fs_getuid.py

  • Know Bugs:
    • Impact unknown by doing this.


getgid(2)

Gives the real group ID of the calling process.

  • getgid_syscall():
  • Return:

1000

  • Errors:

This function is always successful.

  • Status:

Hardcoded. Syscall Ref. no.: 52

  • Unit Test:

Yes. Filename: ut_lind_fs_getuid.py

  • Know Bugs:
    • Impact unknown by doing this.


getegid(2)

Gives the effective group ID of the calling process.

  • getegid_syscall():
  • Return:

1000

  • Errors:

This function is always successful.

  • Status:

Hardcoded. Syscall Ref. no.: 53

  • Unit Test:

Yes. Filename: ut_lind_fs_getuid.py

  • Know Bugs:
    • Impact unknown by doing this.
Last modified 5 years ago Last modified on Jan 18, 2013 2:04:05 PM