add lab answers
This commit is contained in:
12
labcodes_answer/lab5_result/kern/fs/fs.h
Normal file
12
labcodes_answer/lab5_result/kern/fs/fs.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __KERN_FS_FS_H__
|
||||
#define __KERN_FS_FS_H__
|
||||
|
||||
#include <mmu.h>
|
||||
|
||||
#define SECTSIZE 512
|
||||
#define PAGE_NSECT (PGSIZE / SECTSIZE)
|
||||
|
||||
#define SWAP_DEV_NO 1
|
||||
|
||||
#endif /* !__KERN_FS_FS_H__ */
|
||||
|
||||
27
labcodes_answer/lab5_result/kern/fs/swapfs.c
Normal file
27
labcodes_answer/lab5_result/kern/fs/swapfs.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <swap.h>
|
||||
#include <swapfs.h>
|
||||
#include <mmu.h>
|
||||
#include <fs.h>
|
||||
#include <ide.h>
|
||||
#include <pmm.h>
|
||||
#include <assert.h>
|
||||
|
||||
void
|
||||
swapfs_init(void) {
|
||||
static_assert((PGSIZE % SECTSIZE) == 0);
|
||||
if (!ide_device_valid(SWAP_DEV_NO)) {
|
||||
panic("swap fs isn't available.\n");
|
||||
}
|
||||
max_swap_offset = ide_device_size(SWAP_DEV_NO) / (PGSIZE / SECTSIZE);
|
||||
}
|
||||
|
||||
int
|
||||
swapfs_read(swap_entry_t entry, struct Page *page) {
|
||||
return ide_read_secs(SWAP_DEV_NO, swap_offset(entry) * PAGE_NSECT, page2kva(page), PAGE_NSECT);
|
||||
}
|
||||
|
||||
int
|
||||
swapfs_write(swap_entry_t entry, struct Page *page) {
|
||||
return ide_write_secs(SWAP_DEV_NO, swap_offset(entry) * PAGE_NSECT, page2kva(page), PAGE_NSECT);
|
||||
}
|
||||
|
||||
12
labcodes_answer/lab5_result/kern/fs/swapfs.h
Normal file
12
labcodes_answer/lab5_result/kern/fs/swapfs.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __KERN_FS_SWAPFS_H__
|
||||
#define __KERN_FS_SWAPFS_H__
|
||||
|
||||
#include <memlayout.h>
|
||||
#include <swap.h>
|
||||
|
||||
void swapfs_init(void);
|
||||
int swapfs_read(swap_entry_t entry, struct Page *page);
|
||||
int swapfs_write(swap_entry_t entry, struct Page *page);
|
||||
|
||||
#endif /* !__KERN_FS_SWAPFS_H__ */
|
||||
|
||||
Reference in New Issue
Block a user