comparison src/fs.c @ 24:36bd61f5c847

rewrite sys_read cbc
author mir3636
date Thu, 17 Jan 2019 19:11:19 +0900
parents 83c23a36980d
children 1a64b5645cdd
comparison
equal deleted inserted replaced
23:ee58360d0e99 24:36bd61f5c847
451 st->type = ip->type; 451 st->type = ip->type;
452 st->nlink = ip->nlink; 452 st->nlink = ip->nlink;
453 st->size = ip->size; 453 st->size = ip->size;
454 } 454 }
455 455
456 __code cbc_readi (struct inode *ip, char *dst, uint off, uint n, __code (*next)(int ret))
457 {
458 uint tot, m;
459 struct buf *bp;
460
461 if (ip->type == T_DEV) {
462 if (ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].read) {
463 goto next(-1);
464 }
465
466 goto cbc_devsw[ip->major].read(ip, dst, n);
467 }
468
469 if (off > ip->size || off + n < off) {
470 goto next(-1);
471 }
472
473 if (off + n > ip->size) {
474 n = ip->size - off;
475 }
476
477 for (tot = 0; tot < n; tot += m, off += m, dst += m) {
478 bp = bread(ip->dev, bmap(ip, off / BSIZE));
479 m = min(n - tot, BSIZE - off%BSIZE);
480 memmove(dst, bp->data + off % BSIZE, m);
481 brelse(bp);
482 }
483
484 goto next(n);
485 }
486
456 //PAGEBREAK! 487 //PAGEBREAK!
457 // Read data from inode. 488 // Read data from inode.
458 int readi (struct inode *ip, char *dst, uint off, uint n) 489 int readi (struct inode *ip, char *dst, uint off, uint n)
459 { 490 {
460 uint tot, m; 491 uint tot, m;