rwdisk.c
来自「用于汇编领域的,运用于OS的MAIN函数.基于硬件基础的源代码」· C语言 代码 · 共 57 行
C
57 行
// 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 + =
减小字号Ctrl + -
显示快捷键?