xv6-riscv-kernel/kernel/file.h

41 lines
987 B
C
Raw Normal View History

2006-09-06 20:38:56 +02:00
struct file {
2019-06-13 16:29:27 +02:00
enum { FD_NONE, FD_PIPE, FD_INODE, FD_DEVICE } type;
2006-07-16 04:04:58 +02:00
int ref; // reference count
2006-06-27 16:35:53 +02:00
char readable;
2006-09-06 20:06:04 +02:00
char writable;
2019-06-13 16:29:27 +02:00
struct pipe *pipe; // FD_PIPE
struct inode *ip; // FD_INODE and FD_DEVICE
2024-05-24 11:26:40 +02:00
u32 off; // FD_INODE
2019-06-13 16:29:27 +02:00
short major; // FD_DEVICE
2006-06-27 16:35:53 +02:00
};
#define major(dev) ((dev) >> 16 & 0xFFFF)
#define minor(dev) ((dev) & 0xFFFF)
2024-05-24 11:26:40 +02:00
#define mkdev(m,n) ((u32)((m)<<16| (n)))
2011-10-11 12:41:37 +02:00
// in-memory copy of an inode
struct inode {
2024-05-24 11:26:40 +02:00
u32 dev; // Device number
u32 inum; // Inode number
int ref; // Reference count
struct sleeplock lock; // protects everything below here
int valid; // inode has been read from disk?
short type; // copy of disk inode
short major;
short minor;
short nlink;
2024-05-24 11:26:40 +02:00
u32 size;
u32 addrs[NDIRECT+1];
};
2019-06-13 16:29:27 +02:00
// map major device number to device functions.
struct devsw {
2024-05-24 11:26:40 +02:00
int (*read)(int, u64, int);
int (*write)(int, u64, int);
};
extern struct devsw devsw[];
#define CONSOLE 1