Пример #1
0
/*
 * Free a double indirect block.
 */
int fs_double_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_indirect_block_free (fs, nb);
	}
	fs_block_free (fs, bno);
	return 1;
}
Пример #2
0
/*
 * Free a double indirect block.
 */
int fs_double_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 * BSDFS_BSIZE/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_indirect_block_free (fs, nb,
                nblk - i/4 * BSDFS_BSIZE/4);
    }
    fs_block_free (fs, bno);
    return 1;
}