comparison src/fs.c @ 33:7a63dacab7f8

fix cbc_read
author mir3636
date Tue, 22 Jan 2019 17:32:06 +0900
parents 96af12a50fdb
children
comparison
equal deleted inserted replaced
32:96af12a50fdb 33:7a63dacab7f8
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, struct file *f, __code (*next)(int ret)) 456 __code cbc_readi (struct inode *ip, char *dst, uint off, uint n, __code (*next)(int ret))
457 { 457 {
458 uint tot, m; 458 uint tot, m;
459 struct buf *bp; 459 struct buf *bp;
460 460
461 if (ip->type == T_DEV) { 461 if (ip->type == T_DEV) {
462 if (ip->major < 0 || ip->major >= NDEV || !cbc_devsw[ip->major].read) { 462 if (ip->major < 0 || ip->major >= NDEV || !cbc_devsw[ip->major].read) {
463 goto next(-1); 463 goto next(-1);
464 } 464 }
465 465
466 goto cbc_devsw[ip->major].read(ip, dst, n, f, next); 466 goto cbc_devsw[ip->major].read(ip, dst, n, next);
467 } 467 }
468 468
469 if (off > ip->size || off + n < off) { 469 if (off > ip->size || off + n < off) {
470 goto next(-1); 470 goto next(-1);
471 } 471 }
478 bp = bread(ip->dev, bmap(ip, off / BSIZE)); 478 bp = bread(ip->dev, bmap(ip, off / BSIZE));
479 m = min(n - tot, BSIZE - off%BSIZE); 479 m = min(n - tot, BSIZE - off%BSIZE);
480 memmove(dst, bp->data + off % BSIZE, m); 480 memmove(dst, bp->data + off % BSIZE, m);
481 brelse(bp); 481 brelse(bp);
482 } 482 }
483
484 if (n > 0)
485 f->off += n;
486 iunlock(f->ip);
487 483
488 goto next(n); 484 goto next(n);
489 } 485 }
490 486
491 //PAGEBREAK! 487 //PAGEBREAK!