forked from Bananymous/banan-os
Kernel/LibC: Add SYS_TRUNCATE
This commit is contained in:
parent
f5987b68ff
commit
18e2559b1e
|
@ -36,6 +36,8 @@ namespace Kernel
|
|||
BAN::ErrorOr<off_t> seek(int fd, off_t offset, int whence);
|
||||
BAN::ErrorOr<off_t> tell(int) const;
|
||||
|
||||
BAN::ErrorOr<void> truncate(int fd, off_t length);
|
||||
|
||||
BAN::ErrorOr<void> fstat(int fd, struct stat*) const;
|
||||
BAN::ErrorOr<void> fstatat(int fd, BAN::StringView path, struct stat* buf, int flag);
|
||||
BAN::ErrorOr<void> stat(BAN::StringView absolute_path, struct stat* buf, int flag);
|
||||
|
|
|
@ -138,6 +138,8 @@ namespace Kernel
|
|||
BAN::ErrorOr<long> sys_seek(int fd, off_t offset, int whence);
|
||||
BAN::ErrorOr<long> sys_tell(int fd);
|
||||
|
||||
BAN::ErrorOr<long> sys_truncate(int fd, off_t length);
|
||||
|
||||
BAN::ErrorOr<long> sys_fstat(int fd, struct stat*);
|
||||
BAN::ErrorOr<long> sys_fstatat(int fd, const char* path, struct stat* buf, int flag);
|
||||
BAN::ErrorOr<long> sys_stat(const char* path, struct stat* buf, int flag);
|
||||
|
|
|
@ -242,6 +242,12 @@ namespace Kernel
|
|||
return m_open_files[fd]->offset;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> OpenFileDescriptorSet::truncate(int fd, off_t length)
|
||||
{
|
||||
TRY(validate_fd(fd));
|
||||
return m_open_files[fd]->inode->truncate(length);
|
||||
}
|
||||
|
||||
static void read_stat_from_inode(BAN::RefPtr<Inode> inode, struct stat* out)
|
||||
{
|
||||
out->st_dev = inode->dev();
|
||||
|
|
|
@ -1145,6 +1145,13 @@ namespace Kernel
|
|||
return TRY(m_open_file_descriptors.tell(fd));
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_truncate(int fd, off_t length)
|
||||
{
|
||||
LockGuard _(m_process_lock);
|
||||
TRY(m_open_file_descriptors.truncate(fd, length));
|
||||
return 0;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Process::mount(BAN::StringView source, BAN::StringView target)
|
||||
{
|
||||
BAN::String absolute_source, absolute_target;
|
||||
|
|
|
@ -73,6 +73,7 @@ __BEGIN_DECLS
|
|||
O(SYS_CONNECT, connect) \
|
||||
O(SYS_LISTEN, listen) \
|
||||
O(SYS_PSELECT, pselect) \
|
||||
O(SYS_TRUNCATE, truncate) \
|
||||
|
||||
enum Syscall
|
||||
{
|
||||
|
|
|
@ -99,6 +99,11 @@ off_t lseek(int fildes, off_t offset, int whence)
|
|||
return syscall(SYS_SEEK, fildes, offset, whence);
|
||||
}
|
||||
|
||||
int ftruncate(int fildes, off_t length)
|
||||
{
|
||||
return syscall(SYS_TRUNCATE, fildes, length);
|
||||
}
|
||||
|
||||
int dup(int fildes)
|
||||
{
|
||||
return syscall(SYS_DUP, fildes);
|
||||
|
|
Loading…
Reference in New Issue