embox

Форк
0
/
kfile_node.c 
93 строки · 2.0 Кб
1
/**
2
 * @file
3
 *
4
 * @date Oct 24, 2013
5
 * @author: Anton Bondarev
6
 */
7
#include <string.h>
8
#include <stdio.h>
9
#include <stdlib.h>
10
#include <errno.h>
11
#include <fcntl.h>
12
#include <unistd.h>
13
#include <sys/stat.h>
14

15
#include <fs/hlpr_path.h>
16
#include <fs/perm.h>
17
#include <security/security.h>
18
#include <fs/vfs.h>
19
#include <fs/inode.h>
20
#include <fs/inode_operation.h>
21
#include <fs/path.h>
22
#include <fs/fs_driver.h>
23
#include <fs/file_desc.h>
24
#include <sys/time.h>
25
#include <utime.h>
26
#include <drivers/block_dev.h>
27

28
int ktruncate(struct inode *node, off_t length) {
29
	int ret;
30

31
	if (S_ISDIR(node->i_mode)) {
32
		SET_ERRNO(EISDIR);
33
		return -1;
34
	}
35

36
	if (0 > (ret = fs_perm_check(node, S_IWOTH))) {
37
		SET_ERRNO(-ret);
38
		return -1;
39
	}
40

41
	if ((!node->i_sb->sb_iops) || (!node->i_sb->sb_iops->ino_truncate)) {
42
		//SET_ERRNO(ENOTSUP);
43
		//SET_ERRNO(EPERM); it may mean that file it's not possible to modify
44
		return 0;
45
	}
46

47
	if (0 > (ret = node->i_sb->sb_iops->ino_truncate(node, length))) {
48
		SET_ERRNO(-ret);
49
		return -1;
50
	}
51

52
	return ret;
53
}
54

55
int kfile_fill_stat(struct inode *node, struct stat *stat_buff) {
56
	memset(stat_buff, 0 , sizeof(struct stat));
57

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;
65

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);	
69
        }
70

71
	return 0;
72
}
73

74
int kfile_change_stat(struct inode *node, const struct utimbuf *times) {
75
	struct timeval now;
76

77
	if (node == NULL) {
78
		return -ENOENT;
79
	}
80

81
	if (times == NULL) {
82
		if (gettimeofday(&now, NULL) == -1) {
83
			return -EINVAL;
84
		}
85
		inode_ctime_set(node, now.tv_sec);
86
		return 0;
87
	}
88

89
	inode_ctime_set(node, times->actime);
90
	inode_mtime_set(node, times->modtime);
91

92
	return 0;
93
}
94

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.