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

27 lines
688 B

12 years ago
  1. #include <swap.h>
  2. #include <swapfs.h>
  3. #include <mmu.h>
  4. #include <fs.h>
  5. #include <ide.h>
  6. #include <pmm.h>
  7. #include <assert.h>
  8. void
  9. swapfs_init(void) {
  10. static_assert((PGSIZE % SECTSIZE) == 0);
  11. if (!ide_device_valid(SWAP_DEV_NO)) {
  12. panic("swap fs isn't available.\n");
  13. }
  14. max_swap_offset = ide_device_size(SWAP_DEV_NO) / (PGSIZE / SECTSIZE);
  15. }
  16. int
  17. swapfs_read(swap_entry_t entry, struct Page *page) {
  18. return ide_read_secs(SWAP_DEV_NO, swap_offset(entry) * PAGE_NSECT, page2kva(page), PAGE_NSECT);
  19. }
  20. int
  21. swapfs_write(swap_entry_t entry, struct Page *page) {
  22. return ide_write_secs(SWAP_DEV_NO, swap_offset(entry) * PAGE_NSECT, page2kva(page), PAGE_NSECT);
  23. }