《操作系统》的实验代码。
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.

61 lines
1.5 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. #ifndef __KERN_FS_FS_H__
  2. #define __KERN_FS_FS_H__
  3. #include <defs.h>
  4. #include <mmu.h>
  5. #include <sem.h>
  6. #include <atomic.h>
  7. #define SECTSIZE 512
  8. #define PAGE_NSECT (PGSIZE / SECTSIZE)
  9. #define SWAP_DEV_NO 1
  10. #define DISK0_DEV_NO 2
  11. #define DISK1_DEV_NO 3
  12. void fs_init(void);
  13. void fs_cleanup(void);
  14. struct inode;
  15. struct file;
  16. /*
  17. * process's file related informaction
  18. */
  19. struct files_struct {
  20. struct inode *pwd; // inode of present working directory
  21. struct file *fd_array; // opened files array
  22. int files_count; // the number of opened files
  23. semaphore_t files_sem; // lock protect sem
  24. };
  25. #define FILES_STRUCT_BUFSIZE (PGSIZE - sizeof(struct files_struct))
  26. #define FILES_STRUCT_NENTRY (FILES_STRUCT_BUFSIZE / sizeof(struct file))
  27. void lock_files(struct files_struct *filesp);
  28. void unlock_files(struct files_struct *filesp);
  29. struct files_struct *files_create(void);
  30. void files_destroy(struct files_struct *filesp);
  31. void files_closeall(struct files_struct *filesp);
  32. int dup_files(struct files_struct *to, struct files_struct *from);
  33. static inline int
  34. files_count(struct files_struct *filesp) {
  35. return filesp->files_count;
  36. }
  37. static inline int
  38. files_count_inc(struct files_struct *filesp) {
  39. filesp->files_count += 1;
  40. return filesp->files_count;
  41. }
  42. static inline int
  43. files_count_dec(struct files_struct *filesp) {
  44. filesp->files_count -= 1;
  45. return filesp->files_count;
  46. }
  47. #endif /* !__KERN_FS_FS_H__ */