1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/* VTreeFS - stadir.c - file and file system status management */
#include "inc.h"
/*
* Retrieve file status.
*/
int
fs_stat(ino_t ino_nr, struct stat * buf)
{
char path[PATH_MAX];
time_t cur_time;
struct inode *node;
int r;
if ((node = find_inode(ino_nr)) == NULL)
return EINVAL;
/* Fill in the basic info. */
buf->st_mode = node->i_stat.mode;
buf->st_nlink = !is_inode_deleted(node);
buf->st_uid = node->i_stat.uid;
buf->st_gid = node->i_stat.gid;
buf->st_rdev = (dev_t) node->i_stat.dev;
buf->st_size = node->i_stat.size;
/* If it is a symbolic link, return the size of the link target. */
if (S_ISLNK(node->i_stat.mode) && vtreefs_hooks->rdlink_hook != NULL) {
r = vtreefs_hooks->rdlink_hook(node, path, sizeof(path),
get_inode_cbdata(node));
if (r == OK)
buf->st_size = strlen(path);
}
/* Take the current time as file time for all files. */
cur_time = clock_time(NULL);
buf->st_atime = cur_time;
buf->st_mtime = cur_time;
buf->st_ctime = cur_time;
return OK;
}
/*
* Change file mode.
*/
int
fs_chmod(ino_t ino_nr, mode_t * mode)
{
struct inode *node;
struct inode_stat istat;
int r;
if ((node = find_inode(ino_nr)) == NULL)
return EINVAL;
if (vtreefs_hooks->chstat_hook == NULL)
return ENOSYS;
get_inode_stat(node, &istat);
istat.mode = (istat.mode & ~ALL_MODES) | (*mode & ALL_MODES);
r = vtreefs_hooks->chstat_hook(node, &istat, get_inode_cbdata(node));
if (r != OK)
return r;
get_inode_stat(node, &istat);
*mode = istat.mode;
return OK;
}
/*
* Change file ownership.
*/
int
fs_chown(ino_t ino_nr, uid_t uid, gid_t gid, mode_t * mode)
{
struct inode *node;
struct inode_stat istat;
int r;
if ((node = find_inode(ino_nr)) == NULL)
return EINVAL;
if (vtreefs_hooks->chstat_hook == NULL)
return ENOSYS;
get_inode_stat(node, &istat);
istat.uid = uid;
istat.gid = gid;
istat.mode &= ~(S_ISUID | S_ISGID);
r = vtreefs_hooks->chstat_hook(node, &istat, get_inode_cbdata(node));
if (r != OK)
return r;
get_inode_stat(node, &istat);
*mode = istat.mode;
return OK;
}
/*
* Retrieve file system statistics.
*/
int
fs_statvfs(struct statvfs * buf)
{
buf->f_flag = ST_NOTRUNC;
buf->f_namemax = NAME_MAX;
return OK;
}
|