- if (rwflg == B_READ) {
- if (nb == 0)
- return ((daddr_t)-1);
- goto gotit;
- }
- if (nb == 0 || ip->i_size < (bn + 1) * fs->fs_bsize) {
- if (nb != 0) {
- /* consider need to reallocate a frag */
- osize = fragroundup(fs, blkoff(fs, ip->i_size));
- nsize = fragroundup(fs, size);
- if (nsize <= osize)
- goto gotit;
- bp = realloccg(ip, nb,
- blkpref(ip, bn, (int)bn, &ip->i_db[0]),
- osize, nsize);
- } else {
- if (ip->i_size < (bn + 1) * fs->fs_bsize)
- nsize = fragroundup(fs, size);
- else
- nsize = fs->fs_bsize;
- bp = alloc(ip,
- blkpref(ip, bn, (int)bn, &ip->i_db[0]),
- nsize);
- }
- if (bp == NULL)
- return ((daddr_t)-1);
- nb = dbtofsb(fs, bp->b_blkno);
- if ((ip->i_mode&IFMT) == IFDIR)
- /*
- * Write directory blocks synchronously
- * so they never appear with garbage in
- * them on the disk.
- */
- bwrite(bp);
- else
- bdwrite(bp);
- ip->i_db[bn] = nb;
- ip->i_flag |= IUPD|ICHG;
- }
-gotit:
- if (bn < NDADDR - 1) {
- rablock = fsbtodb(fs, ip->i_db[bn + 1]);
- rasize = blksize(fs, ip, bn + 1);