Exemple #1
0
int
affs_rename(struct inode *old_dir, struct dentry *old_dentry,
	    struct inode *new_dir, struct dentry *new_dentry)
{
	struct super_block *sb = old_dir->i_sb;
	struct buffer_head *bh = NULL;
	int retval;

	pr_debug("%s(old=%lu,\"%pd\" to new=%lu,\"%pd\")\n", __func__,
		 old_dir->i_ino, old_dentry, new_dir->i_ino, new_dentry);

	retval = affs_check_name(new_dentry->d_name.name,
				 new_dentry->d_name.len,
				 affs_nofilenametruncate(old_dentry));

	if (retval)
		return retval;

	/* Unlink destination if it already exists */
	if (new_dentry->d_inode) {
		retval = affs_remove_header(new_dentry);
		if (retval)
			return retval;
	}

	bh = affs_bread(sb, old_dentry->d_inode->i_ino);
	if (!bh)
		return -EIO;

	/* Remove header from its parent directory. */
	affs_lock_dir(old_dir);
	retval = affs_remove_hash(old_dir, bh);
	affs_unlock_dir(old_dir);
	if (retval)
		goto done;

	/* And insert it into the new directory with the new name. */
	affs_copy_name(AFFS_TAIL(sb, bh)->name, new_dentry);
	affs_fix_checksum(sb, bh);
	affs_lock_dir(new_dir);
	retval = affs_insert_hash(new_dir, bh);
	affs_unlock_dir(new_dir);
	/* TODO: move it back to old_dir, if error? */

done:
	mark_buffer_dirty_inode(bh, retval ? old_dir : new_dir);
	affs_brelse(bh);
	return retval;
}
Exemple #2
0
int
affs_add_entry(struct inode *dir, struct inode *inode, struct dentry *dentry, s32 type)
{
    struct super_block *sb = dir->i_sb;
    struct buffer_head *inode_bh = NULL;
    struct buffer_head *bh = NULL;
    u32 block = 0;
    int retval;

    pr_debug("AFFS: add_entry(dir=%u, inode=%u, \"%*s\", type=%d)\n", (u32)dir->i_ino,
             (u32)inode->i_ino, (int)dentry->d_name.len, dentry->d_name.name, type);

    retval = -EIO;
    bh = affs_bread(sb, inode->i_ino);
    if (!bh)
        goto done;

    affs_lock_link(inode);
    switch (type) {
    case ST_LINKFILE:
    case ST_LINKDIR:
        retval = -ENOSPC;
        block = affs_alloc_block(dir, dir->i_ino);
        if (!block)
            goto err;
        retval = -EIO;
        inode_bh = bh;
        bh = affs_getzeroblk(sb, block);
        if (!bh)
            goto err;
        break;
    default:
        break;
    }

    AFFS_HEAD(bh)->ptype = cpu_to_be32(T_SHORT);
    AFFS_HEAD(bh)->key = cpu_to_be32(bh->b_blocknr);
    affs_copy_name(AFFS_TAIL(sb, bh)->name, dentry);
    AFFS_TAIL(sb, bh)->stype = cpu_to_be32(type);
    AFFS_TAIL(sb, bh)->parent = cpu_to_be32(dir->i_ino);

    if (inode_bh) {
        __be32 chain;
        chain = AFFS_TAIL(sb, inode_bh)->link_chain;
        AFFS_TAIL(sb, bh)->original = cpu_to_be32(inode->i_ino);
        AFFS_TAIL(sb, bh)->link_chain = chain;
        AFFS_TAIL(sb, inode_bh)->link_chain = cpu_to_be32(block);
        affs_adjust_checksum(inode_bh, block - be32_to_cpu(chain));
        mark_buffer_dirty_inode(inode_bh, inode);
        inode->i_nlink = 2;
        atomic_inc(&inode->i_count);
    }
    affs_fix_checksum(sb, bh);
    mark_buffer_dirty_inode(bh, inode);
    dentry->d_fsdata = (void *)(long)bh->b_blocknr;

    affs_lock_dir(dir);
    retval = affs_insert_hash(dir, bh);
    mark_buffer_dirty_inode(bh, inode);
    affs_unlock_dir(dir);
    affs_unlock_link(inode);

    d_instantiate(dentry, inode);
done:
    affs_brelse(inode_bh);
    affs_brelse(bh);
    return retval;
err:
    if (block)
        affs_free_block(sb, block);
    affs_unlock_link(inode);
    goto done;
}
Exemple #3
0
int
affs_rename(struct inode *old_dir, struct dentry *old_dentry,
	    struct inode *new_dir, struct dentry *new_dentry)
{
	struct inode		*old_inode = old_dentry->d_inode;
	struct inode		*new_inode = new_dentry->d_inode;
	struct buffer_head	*old_bh;
	struct buffer_head	*new_bh;
	unsigned long		 old_ino;
	unsigned long		 new_ino;
	int			 retval;

	pr_debug("AFFS: rename(old=%lu,\"%*s\" (inode=%p) to new=%lu,\"%*s\" (inode=%p))\n",
		 old_dir->i_ino,old_dentry->d_name.len,old_dentry->d_name.name,old_inode,
		 new_dir->i_ino,new_dentry->d_name.len,new_dentry->d_name.name,new_inode);
	
	if ((retval = affs_check_name(new_dentry->d_name.name,new_dentry->d_name.len)))
		goto out;

	new_bh = NULL;
	retval = -ENOENT;
	old_bh = affs_find_entry(old_dir,old_dentry,&old_ino);
	if (!old_bh)
		goto end_rename;

	new_bh = affs_find_entry(new_dir,new_dentry,&new_ino);
	if (new_bh && !new_inode) {
		affs_error(old_inode->i_sb,"affs_rename",
			   "No inode for entry found (key=%lu)\n",new_ino);
		goto end_rename;
	}
	if (S_ISDIR(old_inode->i_mode)) {
		if (new_inode) {
			retval = -ENOTEMPTY;
			if (!empty_dir(new_bh,AFFS_I2HSIZE(new_inode)))
				goto end_rename;
		}

		retval = -ENOENT;
		if (affs_parent_ino(old_inode) != old_dir->i_ino)
			goto end_rename;
	}
	/* Unlink destination if it already exists */
	if (new_inode) {
		if ((retval = affs_remove_header(new_bh,new_dir)) < 0)
			goto end_rename;
		new_inode->i_nlink = retval;
		mark_inode_dirty(new_inode);
		if (new_inode->i_ino == new_ino)
			new_inode->i_nlink = 0;
	}
	/* Remove header from its parent directory. */
	if ((retval = affs_remove_hash(old_bh,old_dir)))
		goto end_rename;
	/* And insert it into the new directory with the new name. */
	affs_copy_name(FILE_END(old_bh->b_data,old_inode)->file_name,new_dentry->d_name.name);
	if ((retval = affs_insert_hash(new_dir->i_ino,old_bh,new_dir)))
		goto end_rename;
	affs_fix_checksum(AFFS_I2BSIZE(new_dir),old_bh->b_data,5);

	new_dir->i_ctime   = new_dir->i_mtime = old_dir->i_ctime
			   = old_dir->i_mtime = CURRENT_TIME;
	new_dir->i_version = ++event;
	old_dir->i_version = ++event;
	retval             = 0;
	mark_inode_dirty(new_dir);
	mark_inode_dirty(old_dir);
	mark_buffer_dirty(old_bh,1);
	
end_rename:
	affs_brelse(old_bh);
	affs_brelse(new_bh);
out:
	return retval;
}