《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

10 years ago
  1. #ifndef __KERN_FS_FILE_H__
  2. #define __KERN_FS_FILE_H__
  3. //#include <types.h>
  4. #include <fs.h>
  5. #include <proc.h>
  6. #include <atomic.h>
  7. #include <assert.h>
  8. struct inode;
  9. struct stat;
  10. struct dirent;
  11. struct file {
  12. enum {
  13. FD_NONE, FD_INIT, FD_OPENED, FD_CLOSED,
  14. } status;
  15. bool readable;
  16. bool writable;
  17. int fd;
  18. off_t pos;
  19. struct inode *node;
  20. int open_count;
  21. };
  22. void fd_array_init(struct file *fd_array);
  23. void fd_array_open(struct file *file);
  24. void fd_array_close(struct file *file);
  25. void fd_array_dup(struct file *to, struct file *from);
  26. bool file_testfd(int fd, bool readable, bool writable);
  27. int file_open(char *path, uint32_t open_flags);
  28. int file_close(int fd);
  29. int file_read(int fd, void *base, size_t len, size_t *copied_store);
  30. int file_write(int fd, void *base, size_t len, size_t *copied_store);
  31. int file_seek(int fd, off_t pos, int whence);
  32. int file_fstat(int fd, struct stat *stat);
  33. int file_fsync(int fd);
  34. int file_getdirentry(int fd, struct dirent *dirent);
  35. int file_dup(int fd1, int fd2);
  36. int file_pipe(int fd[]);
  37. int file_mkfifo(const char *name, uint32_t open_flags);
  38. static inline int
  39. fopen_count(struct file *file) {
  40. return file->open_count;
  41. }
  42. static inline int
  43. fopen_count_inc(struct file *file) {
  44. file->open_count += 1;
  45. return file->open_count;
  46. }
  47. static inline int
  48. fopen_count_dec(struct file *file) {
  49. file->open_count -= 1;
  50. return file->open_count;
  51. }
  52. #endif /* !__KERN_FS_FILE_H__ */