My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Functions | Variables
syscalls.c File Reference
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <sys/times.h>
#include <sys/time.h>
#include <sys/errno.h>
#include "fat32.h"
#include <sw_string_functions.h>
#include <mem_mng.h>
#include <sw_buddy.h>
#include <sw_mem_functions.h>
#include <sw_debug.h>
#include <unused.h>

Classes

struct  FILE
 

Macros

#define SEEK_SET   0 /* Seek from beginning of file. */
 
#define SEEK_CUR   1 /* Seek from current position. */
 
#define SEEK_END   2 /* Seek from end of file. */
 
#define FILE_CNTR_START_INDEX   3
 
#define MAX_OPEN_FILES   (32+FILE_CNTR_START_INDEX)
 
#define MAX_FILENAME_LENGTH   255
 
#define __MYPID   1
 

Functions

int _close (int file)
 function will flushes the stream pointed to by fd More...
 
int _fstat (int file, struct stat *st)
 These functions return information about a file. More...
 
int _isatty (int file)
 function tests whether fd is an open file descriptor referring to a terminal More...
 
off_t _lseek (int file, off_t offset, int flags)
 function repositions the offset of the open file associated with the file descriptor fd More...
 
int _open (const char *name, int flags,...)
 function opens the file whose name is the string pointed to by path and associates a stream with it More...
 
int _read (int file, char *ptr, int len)
 reads nmemb elements of data, each size bytes long, from the stream pointed to by stream, storing them at the location given by fd More...
 
caddr_t sbrk (int incr)
 sbrk system call implementation More...
 
caddr_t _sbrk (int incr)
 change data segment size More...
 
int _write (int file, char *ptr, int len)
 writes nmemb elements of data, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr More...
 
void _exit (int val)
 the command does nothing beyond expanding arguments and performing any specified redirections More...
 
int _execve (char *name, char **argv, char **env)
 executes the program pointed to by filename More...
 
int _getpid ()
 returns the process ID of the calling process More...
 
int _fork (void)
 creates a new process by duplicating the calling process More...
 
int _kill (int pid, int sig)
 terminate a process.Sends the specified signal to the specified process or process group More...
 
int _wait (int *status)
 The parent process may then issue a wait system call, which suspends the execution of the parent process while the child executes. More...
 
int _link (char *old, char *new)
 call the link function to create a link to a file More...
 
int _stat (const char *file, struct stat *st)
 These functions return information about a file. More...
 
int _unlink (char *name)
 call the unlink function to remove the specified file More...
 
clock_t _times (struct tms *buf)
 giving timing statistics about this program run More...
 
int _gettimeofday (struct timeval *buf, void *buf2)
 get time of the day More...
 
int clock_gettime (clockid_t clk_id, struct timespec *tp)
 finds the resolution (precision) of the specified clock clk_id More...
 

Variables

char * __env [1] = {0}
 
char ** environ = __env
 
FILE file_pointers [MAX_OPEN_FILES]
 
u8 file_names [MAX_OPEN_FILES][MAX_FILENAME_LENGTH]
 
unsigned char * heap_end = 0
 
unsigned char * heap_low = 0
 
unsigned char * heap_top = 0
 

Macro Definition Documentation

#define __MYPID   1
#define FILE_CNTR_START_INDEX   3
#define MAX_FILENAME_LENGTH   255
#define MAX_OPEN_FILES   (32+FILE_CNTR_START_INDEX)
#define SEEK_CUR   1 /* Seek from current position. */
#define SEEK_END   2 /* Seek from end of file. */
#define SEEK_SET   0 /* Seek from beginning of file. */

Function Documentation

int _close ( int  file)

function will flushes the stream pointed to by fd

Parameters
filefile descriptor of the file
Returns
Upon successful completion 0 is returned. Otherwise, EOF is returned and errno is set to indicate the error
int _execve ( char *  name,
char **  argv,
char **  env 
)

executes the program pointed to by filename

Parameters
name: file name of the file
argv: is an array of argument strings passed to the new program
env: an array of strings, conven‐tionally of the form key=value, which are passed as environment to the new program
Returns
On success, _execve() does not return, on error -1 is returned, and errno is set appropriately
void _exit ( int  val)

the command does nothing beyond expanding arguments and performing any specified redirections

Parameters
valfile descriptor of the file
Returns
A zero exit code is returned
int _fork ( void  )

creates a new process by duplicating the calling process

Returns
On success, the PID of the child process is returned in the parent, and 0 is returned in the child.On failure, -1 is returned in the parent, no child process is created, and errno is set appropriately
int _fstat ( int  file,
struct stat *  st 
)

These functions return information about a file.

Parameters
filefile descriptor of the file
stfile pointed to by path and fills in st structure
Returns
On success, zero is returned. On error, -1 is returned, and errno is set appropriately
int _getpid ( )

returns the process ID of the calling process

Returns
returns the process ID of the parent of the calling process
int _gettimeofday ( struct timeval *  buf,
void *  buf2 
)

get time of the day

Parameters
buftimezone structure contains information of the program runtime in term of seconds and microseconds
buf2corresponding timezone structure contains information of the program runtime in term of minutes west of Greenwich with type of DST correction
Returns
On success, _times() does not return, on error -1 is returned, and errno is set appropriately
int _isatty ( int  file)

function tests whether fd is an open file descriptor referring to a terminal

Parameters
filefile descriptor of the file
Returns
returns 1 if fd is an open file descriptor referring to a terminal; otherwise 0 is returned,and errno is set to indicate the error
int _kill ( int  pid,
int  sig 
)

terminate a process.Sends the specified signal to the specified process or process group

Parameters
pidSpecify the list of processes that kill should signal
sigSpecify the signal to send. The signal may be given as a signal name or number
Returns
If sig is 0, then no signal is sent, but error checking is still performed
int _link ( char *  old,
char *  new 
)

call the link function to create a link to a file

Parameters
oldold existing file
newNew file to be link with old one
Returns
On success, _wait() does not return, on error -1 is returned, and errno is set appropriately
off_t _lseek ( int  file,
off_t  offset,
int  flags 
)

function repositions the offset of the open file associated with the file descriptor fd

Parameters
filefile descriptor of the file
offsetoffset assigned according to whence as follows SEEK_SET,SEEK_CUR and SEEK_END
flagsMoving position from offset
Returns
Upon successful completion, lseek() returns the resulting offset location as measured in bytes from the beginning of the file. Otherwise, a value of (off_t) -1 is returned and errno is set to indicate the error
int _open ( const char *  name,
int  flags,
  ... 
)

function opens the file whose name is the string pointed to by path and associates a stream with it

Parameters
namename of the file to be open
flagsMode Translated flag value for file to be open
...optional third argument
Returns
Returns the Index the of the FILE structure Otherwise, NULL is returned and errno is set to indicate the error
int _read ( int  file,
char *  ptr,
int  len 
)

reads nmemb elements of data, each size bytes long, from the stream pointed to by stream, storing them at the location given by fd

Parameters
filefile descriptor of the file
ptrreaded data stores from memory location of ptr
lenlength of data to be read
Returns
the number of items successfully read If an error occurs, or the end-of-file is reached the return value is a short item count (or zero)
caddr_t _sbrk ( int  incr)

change data segment size

Parameters
incrchange of the location of the program break, which defines the end of the process's data segment
Returns
On success,returns zero. On error, -1 is returned, and errno is set.
int _stat ( const char *  file,
struct stat *  st 
)

These functions return information about a file.

Parameters
filefile descriptor of the file
stfile pointed to by path and fills in st structure
Returns
On success, zero is returned. On error, -1 is returned, and errno is set appropriately
clock_t _times ( struct tms *  buf)

giving timing statistics about this program run

Parameters
buftimezone structure contains information of the program runtime in term of seconds and microseconds
Returns
On success, _times() does not return, on error -1 is returned, and errno is set appropriately
int _unlink ( char *  name)

call the unlink function to remove the specified file

Parameters
namename of the file to be unlink
Returns
On success,return 0, on error -1 is returned, and errno is set appropriately
int _wait ( int *  status)

The parent process may then issue a wait system call, which suspends the execution of the parent process while the child executes.

Parameters
statusstatus of the process
Returns
On success, _wait() does not return, on error -1 is returned, and errno is set appropriately
int _write ( int  file,
char *  ptr,
int  len 
)

writes nmemb elements of data, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr

Parameters
filefile descriptor of the file
ptrcontains data to be write in a file
lenlength of data to be read
Returns
the number of items successfully read If an error occurs, or the end-of-file is reached the return value is a short item count (or zero)
int clock_gettime ( clockid_t  clk_id,
struct timespec *  tp 
)

finds the resolution (precision) of the specified clock clk_id

Parameters
clk_idstructue contains id of specific clock
tpstructue contains information of the program runtime in term of seconds and nanoseconds
Returns
On success, clock_gettime() does not return, on error -1 is returned and errno is set appropriately
caddr_t sbrk ( int  incr)

sbrk system call implementation

Parameters
incraddress of the location of the program break, which defines the end of the process's data segment
Returns
On success,returns zero. On error, -1 is returned, and errno is set.

Variable Documentation

char* __env[1] = {0}
char** environ = __env
FILE file_pointers[MAX_OPEN_FILES]
unsigned char* heap_end = 0
unsigned char* heap_low = 0
unsigned char * heap_top = 0