os_kernel_lab/labcodes/lab8/kern/fs/file.h

63 lines
1.4 KiB
C
Raw Normal View History

2012-08-22 12:32:13 +08:00
#ifndef __KERN_FS_FILE_H__
#define __KERN_FS_FILE_H__
//#include <types.h>
#include <fs.h>
#include <proc.h>
#include <atomic.h>
#include <assert.h>
struct inode;
struct stat;
struct dirent;
struct file {
enum {
FD_NONE, FD_INIT, FD_OPENED, FD_CLOSED,
} status;
bool readable;
bool writable;
int fd;
off_t pos;
struct inode *node;
2012-09-14 21:36:57 +08:00
int open_count;
2012-08-22 12:32:13 +08:00
};
void fd_array_init(struct file *fd_array);
void fd_array_open(struct file *file);
void fd_array_close(struct file *file);
void fd_array_dup(struct file *to, struct file *from);
bool file_testfd(int fd, bool readable, bool writable);
int file_open(char *path, uint32_t open_flags);
int file_close(int fd);
int file_read(int fd, void *base, size_t len, size_t *copied_store);
int file_write(int fd, void *base, size_t len, size_t *copied_store);
int file_seek(int fd, off_t pos, int whence);
int file_fstat(int fd, struct stat *stat);
int file_fsync(int fd);
int file_getdirentry(int fd, struct dirent *dirent);
int file_dup(int fd1, int fd2);
int file_pipe(int fd[]);
int file_mkfifo(const char *name, uint32_t open_flags);
static inline int
fopen_count(struct file *file) {
2012-09-14 21:36:57 +08:00
return file->open_count;
2012-08-22 12:32:13 +08:00
}
static inline int
fopen_count_inc(struct file *file) {
2012-09-14 21:36:57 +08:00
file->open_count += 1;
return file->open_count;
2012-08-22 12:32:13 +08:00
}
static inline int
fopen_count_dec(struct file *file) {
2012-09-14 21:36:57 +08:00
file->open_count -= 1;
return file->open_count;
2012-08-22 12:32:13 +08:00
}
#endif /* !__KERN_FS_FILE_H__ */