/* * Free an indirect block. */ int fs_indirect_block_free (fs_t *fs, unsigned int bno) { unsigned nb; unsigned char data [BSDFS_BSIZE]; int i; if (! fs_read_block (fs, bno, data)) { fprintf (stderr, "inode_clear: read error at block %d\n", bno); return 0; } for (i=BSDFS_BSIZE-2; i>=0; i-=2) { nb = data [i+1] << 8 | data [i]; if (nb) fs_block_free (fs, nb); } fs_block_free (fs, bno); return 1; }
/* * Free an indirect block. */ int fs_indirect_block_free (fs_t *fs, unsigned int bno, int nblk) { unsigned nb; unsigned char data [BSDFS_BSIZE]; int i; if (! fs_read_block (fs, bno, data)) { fprintf (stderr, "inode_clear: read error at block %d\n", bno); return 0; } for (i=BSDFS_BSIZE-4; i>=0; i-=4) { if (i/4 < nblk) { /* Truncate up to required size. */ return 0; } nb = data [i+3] << 24 | data [i+2] << 16 | data [i+1] << 8 | data [i]; if (nb) fs_block_free (fs, nb); } fs_block_free (fs, bno); return 1; }