mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-28 15:34:31 +00:00
kernel/syscalls: Implement sys_tell & sys_seek
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
parent
b208862de2
commit
1695418dcb
@ -232,6 +232,13 @@ typedef enum
|
|||||||
__SYS_SET_FS = 3,
|
__SYS_SET_FS = 3,
|
||||||
} prctl_options_t;
|
} prctl_options_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
__SYS_SEEK_SET = 0,
|
||||||
|
__SYS_SEEK_CUR = 1,
|
||||||
|
__SYS_SEEK_END = 2
|
||||||
|
} seek_whence_t;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
__SYS_SIGNULL = 0,
|
__SYS_SIGNULL = 0,
|
||||||
@ -685,6 +692,46 @@ typedef enum
|
|||||||
* - #EINVAL if `length` is invalid
|
* - #EINVAL if `length` is invalid
|
||||||
*/
|
*/
|
||||||
SYS_FTRUNCATE,
|
SYS_FTRUNCATE,
|
||||||
|
/**
|
||||||
|
* @brief Get the current file offset
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* off_t tell(int fd);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @details Returns the current file offset for the file referred to by `fd`.
|
||||||
|
*
|
||||||
|
* @param fd File descriptor
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - Current file offset on success
|
||||||
|
* - #EBADF if `fd` is not a valid file descriptor
|
||||||
|
*/
|
||||||
|
SYS_TELL,
|
||||||
|
/**
|
||||||
|
* @brief Set the file offset
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* off_t seek(int fd, off_t offset, int whence);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @details Sets the file offset for the file referred to by `fd` to the
|
||||||
|
* specified `offset` according to the directive `whence`.
|
||||||
|
*
|
||||||
|
* @param fd File descriptor
|
||||||
|
* @param offset Offset to set
|
||||||
|
* @param whence Directive for setting the offset\n
|
||||||
|
* Supported values:
|
||||||
|
* - #__SYS_SEEK_SET: Set the offset to `offset` bytes
|
||||||
|
* - #__SYS_SEEK_CUR: Set the offset to the current offset plus `offset`
|
||||||
|
* - #__SYS_SEEK_END: Set the offset to the size of the file plus `offset`
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - New file offset on success
|
||||||
|
* - #EBADF if `fd` is not a valid file descriptor
|
||||||
|
* - #EINVAL if `whence` is invalid
|
||||||
|
*/
|
||||||
|
SYS_SEEK,
|
||||||
|
|
||||||
/* Process Control */
|
/* Process Control */
|
||||||
|
|
||||||
@ -1376,6 +1423,12 @@ typedef enum
|
|||||||
/** @copydoc SYS_FTRUNCATE */
|
/** @copydoc SYS_FTRUNCATE */
|
||||||
#define call_ftruncate(fd, length) syscall2(SYS_FTRUNCATE, (scarg)fd, (scarg)length)
|
#define call_ftruncate(fd, length) syscall2(SYS_FTRUNCATE, (scarg)fd, (scarg)length)
|
||||||
|
|
||||||
|
/** @copydoc SYS_TELL */
|
||||||
|
#define call_tell(fd) syscall1(SYS_TELL, (scarg)fd)
|
||||||
|
|
||||||
|
/** @copydoc SYS_SEEK */
|
||||||
|
#define call_seek(fd, offset, whence) syscall3(SYS_SEEK, (scarg)fd, (scarg)offset, (scarg)whence)
|
||||||
|
|
||||||
/* Process Control */
|
/* Process Control */
|
||||||
|
|
||||||
/** @copydoc SYS_EXIT */
|
/** @copydoc SYS_EXIT */
|
||||||
|
@ -159,6 +159,22 @@ static int sys_access(SysFrm *Frame, const char *pathname, int mode)
|
|||||||
static int sys_truncate(SysFrm *Frame, const char *pathname, off_t length) { return -ENOSYS; }
|
static int sys_truncate(SysFrm *Frame, const char *pathname, off_t length) { return -ENOSYS; }
|
||||||
static int sys_ftruncate(SysFrm *Frame, int fd, off_t length) { return -ENOSYS; }
|
static int sys_ftruncate(SysFrm *Frame, int fd, off_t length) { return -ENOSYS; }
|
||||||
|
|
||||||
|
static int sys_tell(SysFrm *Frame, int fd)
|
||||||
|
{
|
||||||
|
PCB *pcb = thisProcess;
|
||||||
|
vfs::FileDescriptorTable *fdt = pcb->FileDescriptors;
|
||||||
|
|
||||||
|
return fdt->usr_lseek(fd, 0, SEEK_CUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
static off_t sys_seek(SysFrm *Frame, int fd, off_t offset, int whence)
|
||||||
|
{
|
||||||
|
PCB *pcb = thisProcess;
|
||||||
|
vfs::FileDescriptorTable *fdt = pcb->FileDescriptors;
|
||||||
|
|
||||||
|
return fdt->usr_lseek(fd, offset, whence);
|
||||||
|
}
|
||||||
|
|
||||||
static __noreturn void sys_exit(SysFrm *Frame, int status)
|
static __noreturn void sys_exit(SysFrm *Frame, int status)
|
||||||
{
|
{
|
||||||
TCB *t = thisThread;
|
TCB *t = thisThread;
|
||||||
@ -333,6 +349,8 @@ __constructor void __init_native_syscalls(void)
|
|||||||
scTbl[SYS_ACCESS] = {"SYS_ACCESS", (void *)sys_access};
|
scTbl[SYS_ACCESS] = {"SYS_ACCESS", (void *)sys_access};
|
||||||
scTbl[SYS_TRUNCATE] = {"SYS_TRUNCATE", (void *)sys_truncate};
|
scTbl[SYS_TRUNCATE] = {"SYS_TRUNCATE", (void *)sys_truncate};
|
||||||
scTbl[SYS_FTRUNCATE] = {"SYS_FTRUNCATE", (void *)sys_ftruncate};
|
scTbl[SYS_FTRUNCATE] = {"SYS_FTRUNCATE", (void *)sys_ftruncate};
|
||||||
|
scTbl[SYS_TELL] = {"SYS_TELL", (void *)sys_tell};
|
||||||
|
scTbl[SYS_SEEK] = {"SYS_SEEK", (void *)sys_seek};
|
||||||
|
|
||||||
/* Process Control */
|
/* Process Control */
|
||||||
scTbl[SYS_EXIT] = {"SYS_EXIT", (void *)sys_exit};
|
scTbl[SYS_EXIT] = {"SYS_EXIT", (void *)sys_exit};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user