xv6-riscv-kernel/kernel/file.h

47 lines
1.1 KiB
C
Raw Permalink Normal View History

#pragma once
#include "types.h"
#include "sleeplock.h"
#include "fs.h"
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;
2024-06-15 16:55:06 +02:00
int ref; // reference count
char readable;
char writable;
struct pipe *pipe; // FD_PIPE
struct inode *ip; // FD_INODE and FD_DEVICE
u32 off; // FD_INODE
short major; // FD_DEVICE
2006-06-27 16:35:53 +02:00
};
#define major(dev) ((dev) >> 16 & 0xFFFF)
#define minor(dev) ((dev) & 0xFFFF)
2024-06-15 16:55:06 +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-06-15 16:55:06 +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?
2024-06-15 16:55:06 +02:00
short type; // copy of disk inode
short major;
short minor;
short nlink;
2024-06-15 16:55:06 +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