-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathfile.h
59 lines (46 loc) · 1.49 KB
/
file.h
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
/*
* Declarations for file handle and file table management.
* New for SOL2.
*/
#ifndef _FILE_H_
#define _FILE_H_
#include <limits.h>
struct lock;
struct vnode;
/*** openfile section ***/
/*
* openfile struct
* note that there's not too much to keep track of, since the vnode does most
* of that. note that it does require synchronization, because a single
* openfile can be shared between processes (filetable inheritance).
*/
struct openfile {
struct vnode *of_vnode;
struct lock *of_lock;
off_t of_offset;
int of_accmode; /* from open: O_RDONLY, O_WRONLY, or O_RDWR */
int of_refcount;
};
/* opens a file (must be kernel pointers in the args) */
int file_open(char *filename, int flags, int mode, int *retfd);
/* closes a file */
int file_close(int fd);
/*** file table section ***/
/*
* filetable struct
* just an array of open files. nice and simple. doesn't require
* synchronization, because a table can only be owned by a single process (on
* inheritance in fork, the table is copied).
*/
struct filetable {
struct openfile *ft_openfiles[OPEN_MAX];
};
/* these all have an implicit arg of the curthread's filetable */
int filetable_init(const char *inpath, const char *outpath,
const char *errpath);
int filetable_copy(struct filetable **copy);
int filetable_placefile(struct openfile *file, int *fd);
int filetable_findfile(int fd, struct openfile **file);
int filetable_dup2file(int oldfd, int newfd);
void filetable_destroy(struct filetable *ft);
#endif /* _FILE_H_ */