📄 rwdisk.c
字号:
// read, write for disk#include "fs.h"int comp_sect_num(int n){// what is the starting sect num for block n? return n*SECT_PER_BLOCK;}void dump_sector(int s, char *buf){// dump sector s whose contents are in buf int i,j,k; unsigned long * temp=(unsigned long *)buf; printk("dumping sector %d\n",s); k=0; for(i=0;i<8;i++){ printk("%d-th portion\n",i); for(j=0;j<32;j++) printk("%x ",temp[k++]); printk("\n"); wait_for_anykey(); }}void test_disk(){// scan all sectors int i;char buf[512]; printk("dumping first 32 bytes of all sectors\n"); for(i=0;;i++){ ReadRelativeSector(i, buf, buf); dump_sector(i, buf); }} void ReadDiskBlock(int n, char * buf){// read blk no n from disk into buf. blk size is 4kB// 4kB is 8 sectors int s = comp_sect_num(n); int i; char *temp = buf; //test_disk(); for(i=0;i<SECT_PER_BLOCK;i++){ ReadRelativeSector(s, temp,temp); //dump_sector(s,temp); s=s++; temp = temp + 512; }}void WriteDiskBlock(int n, char * buf){// write the contents of buf into block n int s = comp_sect_num(n); int i; char *temp = buf; for(i=0;i<SECT_PER_BLOCK;i++){ WriteRelativeSector(s, temp, temp); s++; temp = temp + 512; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -