MentOS
0.8.0
The Mentoring Operating System
|
Functions used to manage files. More...
Go to the source code of this file.
Macros | |
#define | STDIN_FILENO 0 |
Standard input file descriptor. | |
#define | STDOUT_FILENO 1 |
Standard output file descriptor. | |
#define | STDERR_FILENO 2 |
Standard error file descriptor. | |
#define | stdin STDIN_FILENO |
Standard input file descriptor. | |
#define | stdout STDOUT_FILENO |
Standard output file descriptor. | |
#define | stderr STDERR_FILENO |
Standard error file descriptor. | |
Functions | |
ssize_t | read (int fd, void *buf, size_t nbytes) |
Read data from a file descriptor. More... | |
ssize_t | write (int fd, const void *buf, size_t nbytes) |
Write data into a file descriptor. More... | |
int | open (const char *pathname, int flags, mode_t mode) |
Opens the file specified by pathname. More... | |
int | close (int fd) |
Close a file descriptor. More... | |
off_t | lseek (int fd, off_t offset, int whence) |
Repositions the file offset inside a file. More... | |
int | unlink (const char *path) |
Delete a name and possibly the file it refers to. More... | |
int | symlink (const char *linkname, const char *path) |
Creates a symbolic link. More... | |
int | readlink (const char *path, char *buffer, size_t bufsize) |
Read the symbolic link, if present. More... | |
void | exit (int status) |
Wrapper for exit system call. More... | |
pid_t | getpid (void) |
Returns the process ID (PID) of the calling process. More... | |
pid_t | getsid (pid_t pid) |
Return session id of the given process. If pid == 0 return the SID of the calling process If pid != 0 return the SID corresponding to the process having identifier == pid. More... | |
pid_t | setsid (void) |
creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session (i.e., its session ID is made the same as its process ID). The calling process also becomes the process group leader of a new process group in the session (i.e., its process group ID is made the same as its process ID). More... | |
pid_t | getpgid (pid_t pid) |
returns the Process Group ID (PGID) of the process specified by pid. If pid is zero, the process ID of the calling process is used. More... | |
int | setpgid (pid_t pid, pid_t pgid) |
Sets the Process Group ID (PGID) of the process specified by pid. If pid is zero, the process ID of the calling process is used. More... | |
gid_t | getgid (void) |
returns the real group ID of the calling process. More... | |
gid_t | getegid (void) |
returns the effective group ID of the calling process. More... | |
int | setgid (gid_t gid) |
sets the group IDs of the calling process. More... | |
int | setregid (gid_t rgid, gid_t egid) |
sets the real and effective group IDs of the calling process. More... | |
uid_t | getuid (void) |
Returns the real User ID of the calling process. More... | |
uid_t | geteuid (void) |
Returns the effective User ID of the calling process. More... | |
int | setuid (uid_t uid) |
Sets the User IDs of the calling process. More... | |
int | setreuid (uid_t ruid, uid_t euid) |
Sets the effective and real User IDs of the calling process. More... | |
pid_t | getppid (void) |
Returns the parent process ID (PPID) of the calling process. More... | |
pid_t | fork (void) |
Clone the calling process, but without copying the whole address space. The calling process is suspended until the new process exits or is replaced by a call to ‘execve’. More... | |
int | execl (const char *path, const char *arg,...) |
Replaces the current process image with a new process image (argument list). More... | |
int | execlp (const char *file, const char *arg,...) |
Replaces the current process image with a new process image (argument list). More... | |
int | execle (const char *path, const char *arg,...) |
Replaces the current process image with a new process image (argument list). More... | |
int | execlpe (const char *file, const char *arg,...) |
Replaces the current process image with a new process image (argument list). More... | |
int | execv (const char *path, char *const argv[]) |
Replaces the current process image with a new process image (argument vector). More... | |
int | execvp (const char *file, char *const argv[]) |
Replaces the current process image with a new process image (argument vector). More... | |
int | execve (const char *path, char *const argv[], char *const envp[]) |
Replaces the current process image with a new process image (argument vector), allows the caller to specify the environment of the executed program via envp . More... | |
int | execvpe (const char *file, char *const argv[], char *const envp[]) |
Replaces the current process image with a new process image (argument vector), allows the caller to specify the environment of the executed program via envp . More... | |
int | nice (int inc) |
Adds inc to the nice value for the calling thread. More... | |
int | reboot (int magic1, int magic2, unsigned int cmd, void *arg) |
Reboots the system, or enables/disables the reboot keystroke. More... | |
char * | getcwd (char *buf, size_t size) |
Get current working directory. More... | |
int | chdir (char const *path) |
Changes the current working directory to the given path. More... | |
int | fchdir (int fd) |
Is identical to chdir(), the only difference is that the directory is given as an open file descriptor. More... | |
ssize_t | getdents (int fd, dirent_t *dirp, unsigned int count) |
int | dup (int fd) |
Return a new file descriptor. More... | |
unsigned | alarm (int seconds) |
Send signal to calling thread after desired seconds. More... | |
int | chmod (const char *pathname, mode_t mode) |
Change the file's mode bits. More... | |
int | fchmod (int fd, mode_t mode) |
Change the file's mode bits. More... | |
int | chown (const char *pathname, uid_t owner, gid_t group) |
Change the owner and group of a file. More... | |
int | fchown (int fd, uid_t owner, gid_t group) |
Change the owner and group of a file. More... | |
int | lchown (const char *pathname, uid_t owner, gid_t group) |
Change the owner and group of a file. More... | |
Functions used to manage files.
unsigned alarm | ( | int | seconds | ) |
Send signal to calling thread after desired seconds.
seconds | the amount of seconds. |
int chdir | ( | char const * | path | ) |
Changes the current working directory to the given path.
path | The new current working directory. |
int chmod | ( | const char * | pathname, |
mode_t | mode | ||
) |
Change the file's mode bits.
pathname | The pathname of the file to change mode. |
mode | The mode bits to set. |
Change the owner and group of a file.
pathname | The pathname of the file to change. |
owner | The new owner to set. |
group | The new group to set. |
int close | ( | int | fd | ) |
Close a file descriptor.
fd | The file descriptor. |
int dup | ( | int | fd | ) |
Return a new file descriptor.
fd | The fd pointing to the opened file. |
int execl | ( | const char * | path, |
const char * | arg, | ||
... | |||
) |
Replaces the current process image with a new process image (argument list).
path | The absolute path to the binary file to execute. |
arg | A list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. |
... | The argument list. |
int execle | ( | const char * | path, |
const char * | arg, | ||
... | |||
) |
Replaces the current process image with a new process image (argument list).
path | The absolute path to the binary file to execute. |
arg | A list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. |
... | The argument list which contains as last argument the environment. |
int execlp | ( | const char * | file, |
const char * | arg, | ||
... | |||
) |
Replaces the current process image with a new process image (argument list).
file | The name of the binary file to execute, which is searched inside the paths specified inside the PATH environmental variable. |
arg | A list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. |
... | The argument list. |
int execlpe | ( | const char * | file, |
const char * | arg, | ||
... | |||
) |
Replaces the current process image with a new process image (argument list).
file | The name of the binary file to execute, which is searched inside the paths specified inside the PATH environmental variable. |
arg | A list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. |
... | The argument list which contains as last argument the environment. |
int execv | ( | const char * | path, |
char *const | argv[] | ||
) |
Replaces the current process image with a new process image (argument vector).
path | The absolute path to the binary file to execute. |
argv | A vector of one or more pointers to null-terminated strings that represent the argument list available to the executed program. |
int execve | ( | const char * | path, |
char *const | argv[], | ||
char *const | envp[] | ||
) |
Replaces the current process image with a new process image (argument vector), allows the caller to specify the environment of the executed program via envp
.
path | The absolute path to the binary file to execute. |
argv | A vector of one or more pointers to null-terminated strings that represent the argument list available to the executed program. |
envp | A vector of one or more pointers to null-terminated strings that represent the environment list available to the executed program. |
int execvp | ( | const char * | file, |
char *const | argv[] | ||
) |
Replaces the current process image with a new process image (argument vector).
file | The name of the binary file to execute, which is searched inside the paths specified inside the PATH environmental variable. |
argv | A vector of one or more pointers to null-terminated strings that represent the argument list available to the executed program. |
int execvpe | ( | const char * | file, |
char *const | argv[], | ||
char *const | envp[] | ||
) |
Replaces the current process image with a new process image (argument vector), allows the caller to specify the environment of the executed program via envp
.
file | The name of the binary file to execute, which is searched inside the paths specified inside the PATH environmental variable. |
argv | A vector of one or more pointers to null-terminated strings that represent the argument list available to the executed program. |
envp | A vector of one or more pointers to null-terminated strings that represent the environment list available to the executed program. |
void exit | ( | int | status | ) |
Wrapper for exit system call.
status | The exit status. |
int fchdir | ( | int | fd | ) |
Is identical to chdir(), the only difference is that the directory is given as an open file descriptor.
fd | The file descriptor of the open directory. |
int fchmod | ( | int | fd, |
mode_t | mode | ||
) |
Change the file's mode bits.
fd | The fd pointing to the opened file. |
mode | The mode bits to set. |
Change the owner and group of a file.
fd | The fd pointing to the opened file. |
owner | The new owner to set. |
group | The new group to set. |
pid_t fork | ( | void | ) |
Clone the calling process, but without copying the whole address space. The calling process is suspended until the new process exits or is replaced by a call to ‘execve’.
char* getcwd | ( | char * | buf, |
size_t | size | ||
) |
Get current working directory.
buf | The array where the CWD will be copied. |
size | The size of the array. |
Provide access to the directory entries.
fd | The fd pointing to the opened directory. |
dirp | The buffer where de data should be placed. |
count | The size of the buffer. |
gid_t getegid | ( | void | ) |
returns the effective group ID of the calling process.
uid_t geteuid | ( | void | ) |
Returns the effective User ID of the calling process.
gid_t getgid | ( | void | ) |
returns the real group ID of the calling process.
returns the Process Group ID (PGID) of the process specified by pid. If pid is zero, the process ID of the calling process is used.
pid | process of which we want to know the PGID. |
pid_t getpid | ( | void | ) |
Returns the process ID (PID) of the calling process.
pid_t getppid | ( | void | ) |
Returns the parent process ID (PPID) of the calling process.
Return session id of the given process. If pid == 0 return the SID of the calling process If pid != 0 return the SID corresponding to the process having identifier == pid.
pid | process identifier from wich we want the SID |
uid_t getuid | ( | void | ) |
Returns the real User ID of the calling process.
Change the owner and group of a file.
pathname | The pathname of the file to change. |
owner | The new owner to set. |
group | The new group to set. |
Repositions the file offset inside a file.
fd | The file descriptor of the file. |
offset | The offest to use for the operation. |
whence | The type of operation. |
int nice | ( | int | inc | ) |
Adds inc to the nice value for the calling thread.
inc | The value to add to the nice. |
int open | ( | const char * | pathname, |
int | flags, | ||
mode_t | mode | ||
) |
Opens the file specified by pathname.
pathname | A pathname for a file. |
flags | file status flags and file access modes of the open file description. |
mode | the file mode bits be applied when a new file is created. |
Read data from a file descriptor.
fd | The file descriptor. |
buf | The buffer. |
nbytes | The number of bytes to read. |
int readlink | ( | const char * | path, |
char * | buffer, | ||
size_t | bufsize | ||
) |
Read the symbolic link, if present.
path | the file for which we want to read the symbolic link information. |
buffer | the buffer where we will store the symbolic link path. |
bufsize | the size of the buffer. |
int reboot | ( | int | magic1, |
int | magic2, | ||
unsigned int | cmd, | ||
void * | arg | ||
) |
Reboots the system, or enables/disables the reboot keystroke.
magic1 | fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC1. |
magic2 | fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC2. |
cmd | The command to send to the reboot. |
arg | Argument passed with some specific commands. |
int setgid | ( | gid_t | gid | ) |
sets the group IDs of the calling process.
gid | the Group ID to set |
Sets the Process Group ID (PGID) of the process specified by pid. If pid is zero, the process ID of the calling process is used.
pid | process of which we want to set the PGID. |
pgid | the PGID we want to set. |
sets the real and effective group IDs of the calling process.
rgid | the new real Group ID. |
egid | the effective real Group ID. |
Sets the effective and real User IDs of the calling process.
ruid | the new real User ID. |
euid | the effective real User ID. |
pid_t setsid | ( | void | ) |
creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session (i.e., its session ID is made the same as its process ID). The calling process also becomes the process group leader of a new process group in the session (i.e., its process group ID is made the same as its process ID).
int setuid | ( | uid_t | uid | ) |
Sets the User IDs of the calling process.
uid | the new User ID. |
int symlink | ( | const char * | linkname, |
const char * | path | ||
) |
Creates a symbolic link.
linkname | the name of the link. |
path | the entity it is linking to. |
int unlink | ( | const char * | path | ) |
Delete a name and possibly the file it refers to.
path | The path to the file. |