文件系统低级API之从内存inode数据结构中读文件数据
inode结构体本身是不包含磁盘数据的,它只是代表可某个文件的信息。它是一个内存的结构体
可以根据inode来从磁盘上读数据
struct buf*
bread(uint dev, uint blockno)
{
}
static uint
bmap(struct inode *ip, uint bn)
{
}
void*
memmove(void *dst, const void *src, uint n)
{
}
int
readi(struct inode *ip, char *dst, uint off, uint n)
{
uint tot, m;
struct buf *buf;
if (off>ip->size || off+n < off)
return -1;
for (tot=0; tot<n; tot+=m, off+=m, dst+=m)
{
bp = bread(ip->dec, bmap(ip, off/BSIZE)
m = min(n-tot,BSIZE-off%BSIZE);
memmove(dst, bp->data+off%BSIZE, n);
}
return 0;
}