-
Notifications
You must be signed in to change notification settings - Fork 20
/
file.c
34 lines (28 loc) · 791 Bytes
/
file.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
#include "file.h"
struct file *file_open(const char *path, int flags, int rights) {
struct file *filp = NULL;
int err = 0;
filp = filp_open(path, flags, rights);
if (IS_ERR(filp)) {
err = PTR_ERR(filp);
return NULL;
}
return filp;
}
void file_close(struct file *file) {
filp_close(file, NULL);
}
int file_read(struct file *file, unsigned long long offset, unsigned char *data, unsigned int size) {
int ret;
ret = kernel_read(file, data, size, &offset);
return ret;
}
int file_write(struct file *file, unsigned long long offset, unsigned char *data, unsigned int size) {
int ret;
ret = kernel_write(file, data, size, &offset);
return ret;
}
int file_sync(struct file *file) {
vfs_fsync(file, 0);
return 0;
}