文件系统低级API之往内存inode结构中写文件数据
#define NINDIRECT (BSIZE/sizeof(uint))
#define MAXFILE (NDIRECT+NINDIRECT)
int
writei(struct inode *ip, char *src, uint off, uint n)
{
uint tot, m;
struct buf *bp;
if (off>ip->size || off+n<off)
return -1;
if (off+n > MAXFILE*BSIZE)
return -1;
for (tot=0; tot<n; tot+=m, off+=m, src+=m)
{
bp = bread(ip->dev, bmap(ip, off/BSZIE));
m=min(n-tot, BSIZE-off%BSIZE);
memmove(bp->data+off%BSIZE, src, m);
}
return n;
}