-
Notifications
You must be signed in to change notification settings - Fork 46
/
umask_access.c
45 lines (36 loc) · 970 Bytes
/
umask_access.c
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
//
// Created by bruce on 30/04/20.
//
#include <fs/fs.h>
#include <sys/unistd.h>
int sys_umask(struct proc* who, mode_t mask){
mode_t prev = who->umask;
who->umask = mask & 0777;
return prev;
}
int do_umask(struct proc* who, struct message* msg){
return sys_umask(who, msg->m1_i1);
}
int sys_access(struct proc* who, const char* pathname, int mode){
struct inode *ino = NULL;
int ret = 0;
bool has_access;
ret = get_inode_by_path(who, pathname, &ino);
if(mode == F_OK){
if(!ino)
return -ENOENT;
goto final;
}
has_access = has_file_access(who, ino, mode);
ret = has_access ? 0 : -EACCES;
final:
put_inode(ino, false);
return ret;
}
int do_access(struct proc* who, struct message* msg){
char *buf;
if(!is_vaddr_accessible(msg->m1_p1, who))
return -EFAULT;
buf = (char *) get_physical_addr(msg->m1_p1, who);
return sys_access(who, buf, msg->m1_i1);
}