15
#include <fs/hlpr_path.h>
17
#include <security/security.h>
20
#include <fs/inode_operation.h>
22
#include <fs/fs_driver.h>
23
#include <fs/file_desc.h>
26
#include <drivers/block_dev.h>
28
int ktruncate(struct inode *node, off_t length) {
31
if (S_ISDIR(node->i_mode)) {
36
if (0 > (ret = fs_perm_check(node, S_IWOTH))) {
41
if ((!node->i_sb->sb_iops) || (!node->i_sb->sb_iops->ino_truncate)) {
47
if (0 > (ret = node->i_sb->sb_iops->ino_truncate(node, length))) {
55
int kfile_fill_stat(struct inode *node, struct stat *stat_buff) {
56
memset(stat_buff, 0 , sizeof(struct stat));
58
stat_buff->st_size = inode_size(node);
59
stat_buff->st_mode = node->i_mode;
60
stat_buff->st_uid = node->i_owner_id;
61
stat_buff->st_gid = node->i_group_id;
62
stat_buff->st_ctime = inode_ctime(node);
63
stat_buff->st_mtime = inode_mtime(node);
64
stat_buff->st_blocks = stat_buff->st_size;
66
if (node->i_sb->bdev) {
67
stat_buff->st_blocks /= block_dev_block_size(node->i_sb->bdev);
68
stat_buff->st_blocks += (stat_buff->st_blocks % block_dev_block_size(node->i_sb->bdev) != 0);
74
int kfile_change_stat(struct inode *node, const struct utimbuf *times) {
82
if (gettimeofday(&now, NULL) == -1) {
85
inode_ctime_set(node, now.tv_sec);
89
inode_ctime_set(node, times->actime);
90
inode_mtime_set(node, times->modtime);