《操作系统》的实验代码。
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

61 Zeilen
1.5 KiB

vor 10 Jahren
  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__ */