-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.h
51 lines (40 loc) · 1012 Bytes
/
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
#ifndef INCLUDE_KERNEL_H
#define INCLUDE_KERNEL_H
#include "spinlock.h"
#define NDIRECT 12
struct file {
enum { FD_NONE, FD_PIPE, FD_INODE } type;
int ref; // reference count
char readable;
char writable;
struct pipe *pipe;
struct inode *ip;
uint32_t off;
};
// in-memory copy of an inode
struct inode {
uint32_t dev; // Device number
uint32_t inum; // Inode number
int ref; // Reference count
int flags; // I_BUSY, I_VALID
uint16_t type; // copy of disk inode
uint16_t major;
uint16_t minor;
uint16_t nlink;
uint32_t size;
uint32_t addrs[NDIRECT+1];
};
struct pipe {
struct spinlock lock;
char data[128];
uint32_t nread; // number of bytes read
uint32_t nwrite; // number of bytes written
int readopen; // read fd is still open
int writeopen; // write fd is still open
};
typedef int fd_t;
#define O_RDONLY 0x000
#define O_WRONLY 0x001
#define O_RDWR 0x002
#define O_CREATE 0x200
#endif