-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathlink_unlink.c
More file actions
89 lines (68 loc) · 1.96 KB
/
Copy pathlink_unlink.c
File metadata and controls
89 lines (68 loc) · 1.96 KB
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
//
// Created by bruce on 28/04/20.
//
#include <fs/fs.h>
int sys_link(struct proc* who, char *oldpath, char *newpath){
struct inode* oldinode = NULL, *newinode = NULL, *lastdir = NULL;
char string[WINIX_NAME_LEN];
int ret;
if((ret = get_inode_by_path(who, oldpath, &oldinode)))
goto failed_1;
if((ret = eat_path(who, newpath, &lastdir, &newinode, string)))
goto final;
if(newinode){
ret = -EEXIST;
goto final;
}
ret = add_inode_to_directory(who, lastdir, oldinode, string);
final:
if(newinode)
put_inode(newinode, false);
if(lastdir)
put_inode(lastdir, ret == 0);
failed_1:
if(oldinode)
put_inode(oldinode, false);
return ret;
}
int sys_unlink(struct proc* who, const char* path, bool allow_dir){
char string[WINIX_NAME_LEN];
struct inode* lastdir = NULL, *ino = NULL;
int ret;
ret = eat_path(who, path, &lastdir, &ino, string);
if(ret)
goto final;
if(!ino){
ret = -ENOENT;
goto final;
}
if(!allow_dir && S_ISDIR(ino->i_mode)){
ret = -EISDIR;
goto inode_err;
}
ret = remove_inode_from_dir(who, lastdir, ino, string);
put_inode(ino, false);
if(ino->i_nlinks == 0 && ino->i_count == 0){
ret = release_inode(ino);
}
goto final;
inode_err:
put_inode(ino, false);
final:
put_inode(lastdir, false);
return ret;
}
int do_link(struct proc* who, struct message* msg){
if(!is_vaddr_accessible(msg->m1_p1, who)
|| !is_vaddr_accessible(msg->m1_p2, who)){
return -EFAULT;
}
return sys_link(who, (char*)get_physical_addr(msg->m1_p1, who),
(char*)get_physical_addr(msg->m1_p2, who));
}
int do_unlink(struct proc* who, struct message* msg){
if(!is_vaddr_accessible(msg->m1_p1, who) ){
return -EFAULT;
}
return sys_unlink(who, (char*)get_physical_addr(msg->m1_p1, who), false);
}