# file.c File Reference

`#include <vfs/vfs.h>`
`#include <vfs/file.h>`
`#include <ubixos/sched.h>`
`#include <ubixos/vitals.h>`
`#include <ubixos/kpanic.h>`
`#include <ubixos/spinlock.h>`
`#include <lib/kmalloc.h>`
`#include <lib/string.h>`
`#include <vmm/paging.h>`
`#include <lib/kprintf.h>`
`#include <assert.h>`

Include dependency graph for file.c:

Go to the source code of this file.

## Functions

int | fclose (fileDescriptor *fd)
int | feof (fileDescriptor *fd)
int | fgetc (fileDescriptor *fd)
fileDescriptor * | fopen (const char *file, const char *flags)
int | fputc (int ch, fileDescriptor *fd)
size_t | fread (void *ptr, size_t size, size_t nmemb, fileDescriptor *fd)
int | fseek (fileDescriptor *tmpFd, long offset, int whence)
size_t | fwrite (void *ptr, int size, int nmemb, fileDescriptor *fd)
void | sysChDir (const char *path)
void | sysFclose (userFileDescriptor *userFd, int *status)
void | sysFgetc (int *ptr, userFileDescriptor *userFd)
void | sysFopen (const char *file, char *flags, userFileDescriptor *userFd)
void | sysFread (void *data, long size, userFileDescriptor *userFd)
void | sysFseek (userFileDescriptor *userFd, long offset, int whence)
void | sysFwrite (char *ptr, int size, userFileDescriptor *userFd)
void | sysMkDir (const char *path)
void | sysRmDir ()
void | sysUnlink (const char *path, int *retVal)
int | unlink (const char *node)

## Variables

fileDescriptor * | fdTable = 0x0
static spinLock_t | fdTable_lock = SPIN_LOCK_INITIALIZER

## Function Documentation

int fclose | ( | fileDescriptor * | fd | ) |

Definition at line 398 of file file.c.

References assert, fileDescriptorStruct::buffer, fdTable, fdTable_lock, kfree(), fileDescriptorStruct::next, NULL, vitalsStruct::openFiles, fileDescriptorStruct::prev, spinLock(), spinUnlock(), systemVitals, and x1.

Referenced by elf_loadfile(), execFile(), kmod_load(), ldEnable(), sys_exec(), sysExec(), sysFclose(), sysMkDir(), and systemTask().

Here is the call graph for this function:

int feof | ( | fileDescriptor * | fd | ) |

Definition at line 220 of file file.c.

References fdEof, and fileDescriptorStruct::status.

int fgetc | ( | fileDescriptor * | fd | ) |

Definition at line 251 of file file.c.

References vfs_mountPoint::fs, fileDescriptorStruct::mp, fileDescriptorStruct::offset, and fileSystem::vfsRead.

Referenced by sysFgetc().

fileDescriptor* fopen | ( | const char * | file,
|  | const char * | flags |
| ) |  |  |

Definition at line 274 of file file.c.

References fileDescriptorStruct::buffer, fdOpen, fdTable, fdTable_lock, fileAppend, fileBinary, fileDescriptorStruct::fileName, fileRead, fileWrite, vfs_mountPoint::fs, kfree(), kmalloc(), kprintf(), fileDescriptorStruct::mode, fileDescriptorStruct::mp, fileDescriptorStruct::next, NULL, fileDescriptorStruct::offset, vitalsStruct::openFiles, fileDescriptorStruct::prev, spinLock(), spinUnlock(), sprintf(), fileDescriptorStruct::status, strcpy, strstr(), strtok(), systemVitals, vfs_findMount(), and fileSystem::vfsOpenFile.

Referenced by elf_loadfile(), execFile(), kmod_load(), ldEnable(), sys_exec(), sys_open(), sysExec(), sysFopen(), and sysMkDir().

Here is the call graph for this function:

int fputc | ( | int | ch,
|  | fileDescriptor * | fd |
| ) |  |  |

Definition at line 234 of file file.c.

References vfs_mountPoint::fs, fileDescriptorStruct::mp, fileDescriptorStruct::offset, and fileSystem::vfsWrite.

size_t fread | ( | void * | ptr,
|  | size_t | size,
|  | size_t | nmemb,
|  | fileDescriptor * | fd |
| ) |  |  |

Definition at line 178 of file file.c.

References assert, vfs_mountPoint::fs, fileDescriptorStruct::mp, fileDescriptorStruct::offset, and fileSystem::vfsRead.

Referenced by elf_loadfile(), execFile(), kmod_load(), ldEnable(), read(), sys_exec(), sysExec(), and sysFread().

int fseek | ( | fileDescriptor * | tmpFd,
|  | long | offset,
|  | int | whence |
| ) |  |  |

Definition at line 208 of file file.c.

References fileDescriptorStruct::offset.

Referenced by elf_loadfile(), execFile(), kmod_load(), ldEnable(), sys_exec(), and sysExec().

size_t fwrite | ( | void * | ptr,
|  | int | size,
|  | int | nmemb,
|  | fileDescriptor * | fd |
| ) |  |  |

Definition at line 200 of file file.c.

References vfs_mountPoint::fs, fileDescriptorStruct::mp, fileDescriptorStruct::offset, and fileSystem::vfsWrite.

Referenced by sysFwrite().

void sysChDir | ( | const char * | path | ) |

Definition at line 102 of file file.c.

References _current, osInfo::cwd, taskStruct::oInfo, sprintf(), and strstr().

Here is the call graph for this function:

void sysFclose | ( | userFileDescriptor * | userFd,
|  | int * | status |
| ) |  |  |

Definition at line 157 of file file.c.

References fclose(), userFileDescriptorStruct::fd, and NULL.

Here is the call graph for this function:

void sysFgetc | ( | int * | ptr,
|  | userFileDescriptor * | userFd |
| ) |  |  |

Definition at line 59 of file file.c.

References _current, userFileDescriptorStruct::fd, fgetc(), getch(), sched_yield(), taskStruct::term, and tty_foreground.

Here is the call graph for this function:

void sysFopen | ( | const char * | file,
|  | char * | flags,
|  | userFileDescriptor * | userFd |
| ) |  |  |

Definition at line 122 of file file.c.

References userFileDescriptorStruct::fd, userFileDescriptorStruct::fdSize, fopen(), kprintf(), NULL, and fileDescriptorStruct::size.

Here is the call graph for this function:

void sysFread | ( | void * | data,
|  | long | size,
|  | userFileDescriptor * | userFd |
| ) |  |  |

Definition at line 140 of file file.c.

References userFileDescriptorStruct::fd, fread(), and NULL.

Here is the call graph for this function:

void sysFseek | ( | userFileDescriptor * | userFd,
|  | long | offset,
|  | int | whence |
| ) |  |  |

Definition at line 92 of file file.c.

References userFileDescriptorStruct::fd, NULL, and fileDescriptorStruct::offset.

void sysFwrite | ( | char * | ptr,
|  | int | size,
|  | userFileDescriptor * | userFd |
| ) |  |  |

Definition at line 49 of file file.c.

References _current, userFileDescriptorStruct::fd, fwrite(), taskStruct::term, and tty_print().

Here is the call graph for this function:

void sysMkDir | ( | const char * | path | ) |

Definition at line 436 of file file.c.

References _current, osInfo::cwd, fclose(), fopen(), vfs_mountPoint::fs, kprintf(), fileDescriptorStruct::mp, NULL, taskStruct::oInfo, sprintf(), strstr(), strtok(), and fileSystem::vfsMakeDir.

Here is the call graph for this function:

void sysRmDir | ( |  | ) |

Definition at line 88 of file file.c.

void sysUnlink | ( | const char * | path,
|  | int * | retVal |
| ) |  |  |

Definition at line 111 of file file.c.

References unlink().

Here is the call graph for this function:

int unlink | ( | const char * | node | ) |

Definition at line 480 of file file.c.

References vfs_mountPoint::fs, vfs_mountPoint::mountPoint, NULL, strtok(), vfs_findMount(), and fileSystem::vfsUnlink.

Referenced by sysUnlink().

Here is the call graph for this function:

## Variable Documentation

fileDescriptor* fdTable = 0x0

Definition at line 45 of file file.c.

Referenced by fclose(), and fopen().

spinLock_t fdTable_lock = SPIN_LOCK_INITIALIZER`[static]`

Definition at line 42 of file file.c.

Referenced by fclose(), and fopen().