예제 #1
0
static int trunc_tindirect(struct inode * inode, unsigned long offset, sysv_zone_t * p, int convert, unsigned char * dirt)
{
	u32 indtmp, indblock;
	struct super_block * sb;
	struct buffer_head * indbh;
	unsigned int i;
	sysv_zone_t * ind;
	u32 tmp, block;
	int retry = 0;

	indblock = indtmp = *p;
	if (convert)
		indblock = from_coh_ulong(indblock);
	if (!indblock)
		return 0;
	sb = inode->i_sb;
	indbh = sv_bread(sb, inode->i_dev, indblock);
	if (indtmp != *p) {
		brelse(indbh);
		return 1;
	}
	if (!indbh) {
		*p = 0;
		*dirt = 1;
		return 0;
	}
	if (inode->i_size < offset)
		i = 0;
	else
		i = (inode->i_size - offset + sb->sv_ind_per_block_2_block_size_1) >> sb->sv_ind_per_block_2_block_size_bits;
	for (; i < sb->sv_ind_per_block; i++) {
		unsigned char dirty = 0;
		ind = ((sysv_zone_t *) indbh->b_data) + i;
		block = tmp = *ind;
		if (sb->sv_convert)
			block = from_coh_ulong(block);
		if (!block)
			continue;
		retry |= trunc_dindirect(inode,offset+(i<<sb->sv_ind_per_block_2_bits),ind,sb->sv_convert,&dirty);
		if (dirty)
			mark_buffer_dirty(indbh, 1);
	}
	for (i = 0; i < sb->sv_ind_per_block; i++)
		if (((sysv_zone_t *) indbh->b_data)[i])
			goto done;
	if ((indbh->b_count != 1) || (indtmp != *p)) {
		brelse(indbh);
		return 1;
	}
	*p = 0;
	*dirt = 1;
	sysv_free_block(sb,indblock);
done:
	brelse(indbh);
	return retry;
}
예제 #2
0
/* Leave at most `blocks' blocks out of an double indirect block whose number is
 * from_coh_ulong(*p) if convert=1, *p if convert=0.
 */
static int coh_trunc_dindirect (struct inode * inode, unsigned long blocks, unsigned long * p, int convert, unsigned char * dirt)
{
	struct super_block * sb = inode->i_sb;
	unsigned long tmp, block, dindblock;
	struct buffer_head * bh;
	char * bh_data;
	unsigned long i, j;
	sysv_zone_t * dind;
	int retry = 0;

	if (blocks >= sb->sv_ind_per_block_2)
		return 0;
	block = tmp = *p;
	if (convert)
		block = from_coh_ulong(block);
	if (!block)
		return 0;
	bh = sysv_bread(sb,inode->i_dev,block,&bh_data);
	if (tmp != *p) {
		brelse(bh);
		return 1;
	}
	if (!bh) {
		*p = 0;
		*dirt = 1;
		return 0;
	}
	for (i = blocks >> sb->sv_ind_per_block_bits, j = blocks & sb->sv_ind_per_block_1;
	     i < sb->sv_ind_per_block;
	     i++, j = 0) {
		/* j = max(blocks-i*ind_per_block,0) */
		dind = &((sysv_zone_t *) bh_data)[i];
		dindblock = *dind;
		if (sb->sv_convert)
			dindblock = from_coh_ulong(dindblock);
		if (!dindblock)
			continue;
		retry |= coh_trunc_indirect(inode,j,dind,sb->sv_convert,&bh->b_dirt);
	}
	for (i = 0; i < sb->sv_ind_per_block; i++)
		if (((sysv_zone_t *) bh_data)[i])
			goto done;
	if (tmp != *p) {
		brelse(bh);
		return 1;
	}
	*p = 0;
	*dirt = 1;
	sysv_free_block(sb,block);
done:
	brelse(bh);
	return retry;
}
예제 #3
0
static int trunc_tindirect(struct inode * inode, unsigned long offset, unsigned long * p, int convert, unsigned char * dirt)
{
	unsigned long indtmp, indblock;
	struct super_block * sb;
	struct buffer_head * indbh;
	unsigned int i;
	sysv_zone_t * ind;
	unsigned long tmp, block;
	int retry = 0;

	indblock = indtmp = *p;
	if (convert)
		indblock = from_coh_ulong(indblock);
	if (!indblock)
		return 0;
	sb = inode->i_sb;
	indbh = bread(inode->i_dev,indblock+sb->sv_block_base,BLOCK_SIZE);
	if (indtmp != *p) {
		brelse(indbh);
		return 1;
	}
	if (!indbh) {
		*p = 0;
		*dirt = 1;
		return 0;
	}
	if (inode->i_size < offset)
		i = 0;
	else
		i = (inode->i_size - offset + IND_PER_BLOCK*IND_PER_BLOCK*BLOCK_SIZE-1) / (IND_PER_BLOCK*IND_PER_BLOCK*BLOCK_SIZE);
	for (; i < IND_PER_BLOCK; i++) {
		ind = ((sysv_zone_t *) indbh->b_data) + i;
		block = tmp = *ind;
		if (sb->sv_convert)
			block = from_coh_ulong(block);
		if (!block)
			continue;
		retry |= trunc_dindirect(inode,offset+i*IND_PER_BLOCK*IND_PER_BLOCK,ind,sb->sv_convert,&indbh->b_dirt);
	}
	for (i = 0; i < IND_PER_BLOCK; i++)
		if (((sysv_zone_t *) indbh->b_data)[i])
			goto done;
	if ((indbh->b_count != 1) || (indtmp != *p)) {
		brelse(indbh);
		return 1;
	}
	*p = 0;
	*dirt = 1;
	sysv_free_block(sb,indblock);
done:
	brelse(indbh);
	return retry;
}
예제 #4
0
/* Leave at most `blocks' blocks out of an indirect block whose number is
 * from_coh_ulong(*p) if convert=1, *p if convert=0.
 */
static int coh_trunc_indirect (struct inode * inode, unsigned long blocks, unsigned long * p, int convert, unsigned char * dirt)
{
	struct super_block * sb = inode->i_sb;
	unsigned long tmp, block, indblock;
	struct buffer_head * bh;
	char * bh_data;
	unsigned long i;
	sysv_zone_t * ind;

	if (blocks >= sb->sv_ind_per_block)
		return 0;
	block = tmp = *p;
	if (convert)
		block = from_coh_ulong(block);
	if (!block)
		return 0;
	bh = sysv_bread(sb,inode->i_dev,block,&bh_data);
	if (tmp != *p) {
		brelse(bh);
		return 1;
	}
	if (!bh) {
		*p = 0;
		*dirt = 1;
		return 0;
	}
	for (i = blocks; i < sb->sv_ind_per_block; i++) {
		ind = &((sysv_zone_t *) bh_data)[i];
		indblock = *ind;
		if (sb->sv_convert)
			indblock = from_coh_ulong(indblock);
		if (!indblock)
			continue;
		*ind = 0;
		mark_buffer_dirty(bh, 1);
		sysv_free_block(sb,indblock);
	}
	for (i = 0; i < sb->sv_ind_per_block; i++)
		if (((sysv_zone_t *) bh_data)[i])
			goto done;
	if (tmp != *p) {
		brelse(bh);
		return 1;
	}
	*p = 0;
	*dirt = 1;
	sysv_free_block(sb,block);
done:
	brelse(bh);
	return 0;
}
예제 #5
0
static struct super_block * detected_coherent (struct super_block *sb, struct buffer_head *bh)
{
	struct coh_super_block * sbd;

	sbd = (struct coh_super_block *) bh->b_data;
	/* sanity check */
	if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
	    || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
		return NULL;

	sb->sv_convert = 1;
	sb->sv_kludge_symlinks = 1;
	sb->sv_truncate = 1;
	sb->sv_link_max = COH_LINK_MAX;
	sb->sv_fic_size = COH_NICINOD;
	sb->sv_flc_size = COH_NICFREE;
	sb->sv_bh1 = bh;
	sb->sv_bh2 = bh;
	sb->sv_sbd1 = (char *) sbd;
	sb->sv_sbd2 = (char *) sbd;
	sb->sv_sb_fic_count = &sbd->s_ninode;
	sb->sv_sb_fic_inodes = &sbd->s_inode[0];
	sb->sv_sb_total_free_inodes = &sbd->s_tinode;
	sb->sv_sb_flc_count = &sbd->s_nfree;
	sb->sv_sb_flc_blocks = &sbd->s_free[0];
	sb->sv_sb_total_free_blocks = &sbd->s_tfree;
	sb->sv_sb_time = &sbd->s_time;
	sb->sv_firstinodezone = 2;
	sb->sv_firstdatazone = sbd->s_isize;
	sb->sv_nzones = from_coh_ulong(sbd->s_fsize);
	sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
	return sb;
}
예제 #6
0
파일: fsync.c 프로젝트: dmgerman/original
/* Sync one block full of indirect pointers and read it because we'll need it. */
static int sync_iblock (struct inode * inode, u32 * iblockp, int convert,
			struct buffer_head * *bh, int wait)
{
	int rc;
	u32 tmp, block;

	*bh = NULL;
	block = tmp = *iblockp;
	if (convert)
		block = from_coh_ulong(block);
	if (!block)
		return 0;
	rc = sync_block (inode, iblockp, convert, wait);
	if (rc)
		return rc;
	*bh = sv_bread(inode->i_sb, inode->i_dev, block);
	if (tmp != *iblockp) {
		brelse(*bh);
		*bh = NULL;
		return 1;
	}
	if (!*bh)
		return -1;
	return 0;
}
예제 #7
0
파일: fsync.c 프로젝트: dmgerman/original
/* Sync one block. The block number is
 * from_coh_ulong(*blockp) if convert=1, *blockp if convert=0.
 */
static int sync_block (struct inode * inode, u32 *blockp, int convert, int wait)
{
	struct buffer_head * bh;
	u32 tmp, block;
	struct super_block * sb;

	block = tmp = *blockp;
	if (convert)
		block = from_coh_ulong(block);
	if (!block)
		return 0;
	sb = inode->i_sb;
	bh = sv_get_hash_table(sb, inode->i_dev, block);
	if (!bh)
		return 0;
	if (*blockp != tmp) {
		brelse (bh);
		return 1;
	}
	if (wait && buffer_req(bh) && !buffer_uptodate(bh)) {
		brelse(bh);
		return -1;
	}
	if (wait || !buffer_uptodate(bh) || !buffer_dirty(bh)) {
		brelse(bh);
		return 0;
	}
	ll_rw_block(WRITE, 1, &bh);
	atomic_dec(&bh->b_count);
	return 0;
}
예제 #8
0
static const char* detect_coherent (struct super_block *sb, struct buffer_head *bh)
{
    struct coh_super_block * sbd;

    sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2);
    if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
            || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
        return NULL;
    sb->sv_type = FSTYPE_COH;
    sb->sv_convert = 1;
    sb->sv_kludge_symlinks = 1;
    sb->sv_truncate = 1;
    sb->sv_link_max = COH_LINK_MAX;
    sb->sv_fic_size = COH_NICINOD;
    sb->sv_flc_size = COH_NICFREE;
    sb->sv_bh = bh;
    sb->sv_sbd = (char *) sbd;
    sb->sv_sb_fic_count = &sbd->s_ninode;
    sb->sv_sb_fic_inodes = &sbd->s_inode[0];
    sb->sv_sb_total_free_inodes = &sbd->s_tinode;
    sb->sv_sb_flc_count = &sbd->s_nfree;
    sb->sv_sb_flc_blocks = &sbd->s_free[0];
    sb->sv_sb_total_free_blocks = &sbd->s_tfree;
    sb->sv_sb_time = &sbd->s_time;
    sb->sv_block_base = 0;
    sb->sv_firstinodezone = 2;
    sb->sv_firstdatazone = sbd->s_isize;
    sb->sv_nzones = from_coh_ulong(sbd->s_fsize);
    sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
    detected_bs512(sb);
    return "Coherent";
}
예제 #9
0
static struct buffer_head * block_getblk(struct inode * inode,
        struct buffer_head * bh, int nr, int create, char * *start)
{
    struct super_block *sb;
    unsigned long tmp, block;
    sysv_zone_t *p;
    struct buffer_head * result;

    if (!bh)
        return NULL;
    if (!bh->b_uptodate) {
        ll_rw_block(READ, 1, &bh);
        wait_on_buffer(bh);
        if (!bh->b_uptodate) {
            brelse(bh);
            return NULL;
        }
    }
    sb = inode->i_sb;
    p = nr + (sysv_zone_t *) *start;
repeat:
    block = tmp = *p;
    if (sb->sv_convert)
        block = from_coh_ulong(block);
    if (tmp) {
        result = getblk(bh->b_dev, (block >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
        if (tmp == *p) {
            brelse(bh);
            *start = result->b_data + ((block & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
            return result;
        }
        brelse(result);
        goto repeat;
    }
    if (!create) {
        brelse(bh);
        return NULL;
    }
    block = sysv_new_block(sb);
    if (!block) {
        brelse(bh);
        return NULL;
    }
    result = getblk(bh->b_dev, (block >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
    if (*p) {
        sysv_free_block(sb,block);
        brelse(result);
        goto repeat;
    }
    *p = (sb->sv_convert ? to_coh_ulong(block) : block);
    mark_buffer_dirty(bh, 1);
    brelse(bh);
    *start = result->b_data + ((block & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
    return result;
}
예제 #10
0
static int block_bmap(struct super_block * sb, struct buffer_head * bh, int nr, int convert)
{
    int tmp;

    if (!bh)
        return 0;
    tmp = ((sysv_zone_t *) bh->b_data) [nr];
    if (convert)
        tmp = from_coh_ulong(tmp);
    brelse(bh);
    if (!tmp)
        return 0;
    return tmp + sb->sv_block_base;
}
예제 #11
0
static int trunc_indirect(struct inode * inode, unsigned long offset, sysv_zone_t * p, int convert, unsigned char * dirt)
{
	unsigned long indtmp, indblock;
	struct super_block * sb;
	struct buffer_head * indbh;
	unsigned int i;
	sysv_zone_t * ind;
	unsigned long tmp, block;
	struct buffer_head * bh;
	int retry = 0;

	indblock = indtmp = *p;
	if (convert)
		indblock = from_coh_ulong(indblock);
	if (!indblock)
		return 0;
	sb = inode->i_sb;
	indbh = sv_bread(sb, inode->i_dev, indblock);
	if (indtmp != *p) {
		brelse(indbh);
		return 1;
	}
	if (!indbh) {
		*p = 0;
		*dirt = 1;
		return 0;
	}
repeat:
	if (inode->i_size < offset)
		i = 0;
	else
		i = (inode->i_size - offset + sb->sv_block_size_1) >> sb->sv_block_size_bits;
	for (; i < sb->sv_ind_per_block; i++) {
		ind = ((sysv_zone_t *) indbh->b_data) + i;
		block = tmp = *ind;
		if (sb->sv_convert)
			block = from_coh_ulong(block);
		if (!block)
			continue;
		bh = sv_get_hash_table(sb, inode->i_dev, block);
		if ((i << sb->sv_block_size_bits) + offset < inode->i_size) {
			brelse(bh);
			goto repeat;
		}
		if ((bh && bh->b_count != 1) || (tmp != *ind)) {
			retry = 1;
			brelse(bh);
			continue;
		}
		*ind = 0;
		mark_buffer_dirty(indbh, 1);
		brelse(bh);
		sysv_free_block(sb,block);
	}
	for (i = 0; i < sb->sv_ind_per_block; i++)
		if (((sysv_zone_t *) indbh->b_data)[i])
			goto done;
	if ((indbh->b_count != 1) || (indtmp != *p)) {
		brelse(indbh);
		return 1;
	}
	*p = 0;
	*dirt = 1;
	sysv_free_block(sb,indblock);
done:
	brelse(indbh);
	return retry;
}