Skip to main content
Engineering LibreTexts

21.3: Appendix C - System Services

  • Page ID
    54595
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    This appendix provides a listing and brief description of a subset of the system service calls. This list is for 64-bit Ubuntu systems. A more complete list can be obtained from multiple web sources.

    23.1 Return Codes

    The system call will return a code in the rax register. If the value returned is less than 0, that is an indication that an error has occurred. If the operation is successful, the value returned will depend on the specific system service. Refer to the Error Codes section for additional information regarding the values of the error codes.

    23.2 Basic System Services

    The following table summarizes the more common system services.

    Call Code (rax)

    System Service

    Description

    0

    SYS_read

    Read characters

       

    rdi = file descriptor (of where to read from)

       

    rsi = address of where to store characters

       

    rdx = count of characters to read

     

    If unsuccessful, returns negative value. If successful, returns count of characters actually read.

    1

    SYS_write

    Write characters

       

    rdi = file descriptor (of where to write to)

       

    rsi = address of characters to write

       

    rdx = count of characters to write

     

    If unsuccessful, returns negative value. If successful, returns count of characters actually written.

    2

    SYS_open

    Open a file

       

    rdi = address of NULL terminated file name

       

    rsi = file status flags (typically O_RDONLY)

     

    If unsuccessful, returns negative value. If successful, returns file descriptor.

    3

    SYS_close

    Close an open file

       

    rdi = file descriptor of open file to close

     

    If unsuccessful, returns negative value.

    8

    SYS_lseek

    Reposition the file read/write file offset.

       

    rdi = file descriptor (of where to write to)

       

    rsi = offset

       

    rdx = origin

     

    If unsuccessful, returns negative value.

         

    57

    SYS_fork

    Fork current process.

    59

    SYS_execve

    Execute a program

       

    rdi = Address of NULL terminated string for name of program to execute.

       

    60

    SYS_exit

    Terminate executing process.

       

    rdi = exit status (typically 0)

    85

    SYS_creat

    Open/Create a file.

       

    rdi = address of NULL terminated file name

       

    rsi = file mode flags

     

    If unsuccessful, returns negative value. If successful, returns file descriptor.

    96

    SYS_gettimeofday

    Get date and time of day

       

    rdi = address of time value structure

       

    rsi = address of time zone structure

     

    If unsuccessful, returns negative value. If successful, returns information in the passed structures.

         

    23.3 File Modes

    When performing file operations, the file mode provides information to the operating system regarding the file access permissions that will be allowed.

    When opening an existing file, one of the following file modes must be specified.

    Mode

    Value

    Description

    O_RDONLY

    0

    Read only. Allow reading from the file, but to not allow writing to the file. Most common operation.

    O_WRONLY

    1

    Write only. Typically used if information is to be appended to a file.

    O_RDWR

    2

    Allow simultaneous reading and writing.

    When creating a new file, the file permissions must be specified. Below are the complete set of file permissions. As is standard for Linux file systems, the permission values are specified in Octal.

    Mode

    Value

    Description

    S_IRWXU

    00700q

    User (file owner) has read, write, and execute permission.

    S_IRUSR

    00400q

    User (file owner) has read permission.

    S_IWUSR

    00200q

    User (file owner) has write permission.

    S_IXUSR

    00100q

    User (file owner) has execute permission.

    S_IRWXG

    00070q

    Group has read, write, and execute permission.

    S_IRGRP

    00040q

    Group has read permission.

    S_IWGRP

    00020q

    Group has write permission.

    S_IXGRP

    00010q

    Group has execute permission.

    S_IRWXO

    00007q

    Others have read, write, and execute permission.

    S_IROTH

    00004q

    Others have read permission.

    S_IWOTH

    00002q

    Others have write permission.

    S_IXOTH

    00001q

    Others have execute permission.

    The text examples only address permissions for the user or owner of the file.

    23.4 Error Codes

    If a system service returns an error, the value of the return code will be negative. The following is a list of the error code. The code value is provided along with the Linux symbolic name. High-level languages typically use the name which is not used at the assembly level and is only provided for reference.

    Error Code

    Symbolic Name

    Description

    -1

    EPERM

    Operation not permitted.

    -2

    ENOENT

    No such file or directory.

    -3

    ESRCH

    No such process.

    -4

    EINTR

    Interrupted system call.

    -5

    EIO

    I/O Error.

    -6

    ENXIO

    No such device or address.

    -7

    E2BIG

    Argument list too long.

    -8

    ENOEXEC

    Exec format error.

    -9

    EBADF

    Bad file number.

    -10

    ECHILD

    No child process.

    -11

    EAGAIN

    Try again.

    -12

    ENOMEM

    Out of memory.

    -13

    EACCES

    Permission denied.

    -14

    EFAULT

    Bad address.

    -15

    ENOTBLK

    Block device required.

    -16

    EBUSY

    Device or resource busy.

    -17

    EEXIST

    File exists.

    -18

    EXDEV

    Cross-device link.

    -19

    ENODEV

    No such device.

    -20

    ENOTDIR

    Not a directory.

    -21

    EISDIR

    Is a directory.

    -22

    EINV AL

    Invalid argument.

    -23

    ENFILE

    File table overflow.

    -24

    EMFILE

    Too many open files.

    -25

    ENOTTY

    Not a typewriter.

    -26

    ETXTBSY

    Text file busy.

    -27

    EFBIG

    File too large.

    -28

    ENOSPC

    No space left on device.

    -29

    ESPIPE

    Illegal seek.

    -30

    EROFS

    Read-only file system.

    -31

    EMLINK

    Too many links.

    -32

    EPIPE

    Broken pipe.

    -33

    EDOM

    Math argument out of domain of function.

    -34

    ERANGE

    Math result not representable.

    Only the most common error codes are shown. A complete list can be found via the Internet or by looking on the current system includes files. For Ubuntu, this is typically located in /usr/include/asm-generic/errno-base.h.


    21.3: Appendix C - System Services is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?