kernels/linux-2.4.0/fs/affs/inode.c
/*
 * Add an entry to a directory. Create the header block
 * and insert it into the hash table.
 */
Add an entry to a directory. Create the header block
and insert it into the hash table.
Add an entry to a directory . Create the header block and insert it into the hash table .
int
affs_add_entry(struct inode *dir, struct inode *link, struct inode *inode,
	       struct dentry *dentry, int type)
{
	struct buffer_head	*dir_bh;
	struct buffer_head	*inode_bh;
	struct buffer_head	*link_bh;
	int			 retval;
	const unsigned char	*name = dentry->d_name.name;
	int			 len  = dentry->d_name.len;
	pr_debug("AFFS: add_entry(dir=%lu,inode=%lu,\"%*s\",type=%d)\n",dir->i_ino,inode->i_ino,
		 len,name,type);
	if ((retval = affs_check_name(name,len)))
		return retval;
	if (len > 30)
		len = 30;
	dir_bh   = affs_bread(dir->i_dev,dir->i_ino,AFFS_I2BSIZE(dir));
	inode_bh = affs_bread(inode->i_dev,inode->i_ino,AFFS_I2BSIZE(inode));
	link_bh  = NULL;
	retval   = -EIO;
	if (!dir_bh || !inode_bh)
		goto addentry_done;
	if (link) {
		link_bh = affs_bread(link->i_dev,link->i_ino,AFFS_I2BSIZE(link));
		if (!link_bh)
			goto addentry_done;
	}
	((struct dir_front *)inode_bh->b_data)->primary_type = cpu_to_be32(T_SHORT);
	((struct dir_front *)inode_bh->b_data)->own_key      = cpu_to_be32(inode->i_ino);
	DIR_END(inode_bh->b_data,inode)->dir_name[0]         = len;
	strncpy(DIR_END(inode_bh->b_data,inode)->dir_name + 1,name,len);
	DIR_END(inode_bh->b_data,inode)->secondary_type = cpu_to_be32(type);
	DIR_END(inode_bh->b_data,inode)->parent         = cpu_to_be32(dir->i_ino);
	lock_super(inode->i_sb);
	retval = affs_insert_hash(dir->i_ino,inode_bh,dir);
	if (link_bh) {
		LINK_END(inode_bh->b_data,inode)->original   = cpu_to_be32(link->i_ino);
		LINK_END(inode_bh->b_data,inode)->link_chain =
						FILE_END(link_bh->b_data,link)->link_chain;
		FILE_END(link_bh->b_data,link)->link_chain   = cpu_to_be32(inode->i_ino);
		affs_fix_checksum(AFFS_I2BSIZE(link),link_bh->b_data,5);
		link->i_version = ++event;
		mark_inode_dirty(link);
		mark_buffer_dirty(link_bh);
	}
	affs_fix_checksum(AFFS_I2BSIZE(inode),inode_bh->b_data,5);
	affs_fix_checksum(AFFS_I2BSIZE(dir),dir_bh->b_data,5);
	dir->i_version = ++event;
	dir->i_mtime   = dir->i_atime = dir->i_ctime = CURRENT_TIME;
	unlock_super(inode->i_sb);
	mark_inode_dirty(dir);
	mark_inode_dirty(inode);
	mark_buffer_dirty(dir_bh);
	mark_buffer_dirty(inode_bh);
addentry_done:
	affs_brelse(dir_bh);
	affs_brelse(inode_bh);
	affs_brelse(link_bh);
	return retval;
}
int affs_add_entry ( struct inode * dir , struct inode * link , struct inode * inode , struct dentry * dentry , int type ) { struct buffer_head * dir_bh ; struct buffer_head * inode_bh ; struct buffer_head * link_bh ; int retval ; const unsigned char * name = dentry -> d_name . name ; int len = dentry -> d_name . len ; pr_debug ( " \" \" \n " , dir -> i_ino , inode -> i_ino , len , name , type ) ; if ( ( retval = affs_check_name ( name , len ) ) ) return retval ; if ( len > 30 ) len = 30 ; dir_bh = affs_bread ( dir -> i_dev , dir -> i_ino , AFFS_I2BSIZE ( dir ) ) ; inode_bh = affs_bread ( inode -> i_dev , inode -> i_ino , AFFS_I2BSIZE ( inode ) ) ; link_bh = NULL ; retval = - EIO ; if ( ! dir_bh || ! inode_bh ) goto addentry_done ; if ( link ) { link_bh = affs_bread ( link -> i_dev , link -> i_ino , AFFS_I2BSIZE ( link ) ) ; if ( ! link_bh ) goto addentry_done ; } ( ( struct dir_front * ) inode_bh -> b_data ) -> primary_type = cpu_to_be32 ( T_SHORT ) ; ( ( struct dir_front * ) inode_bh -> b_data ) -> own_key = cpu_to_be32 ( inode -> i_ino ) ; DIR_END ( inode_bh -> b_data , inode ) -> dir_name [ 0 ] = len ; strncpy ( DIR_END ( inode_bh -> b_data , inode ) -> dir_name + 1 , name , len ) ; DIR_END ( inode_bh -> b_data , inode ) -> secondary_type = cpu_to_be32 ( type ) ; DIR_END ( inode_bh -> b_data , inode ) -> parent = cpu_to_be32 ( dir -> i_ino ) ; lock_super ( inode -> i_sb ) ; retval = affs_insert_hash ( dir -> i_ino , inode_bh , dir ) ; if ( link_bh ) { LINK_END ( inode_bh -> b_data , inode ) -> original = cpu_to_be32 ( link -> i_ino ) ; LINK_END ( inode_bh -> b_data , inode ) -> link_chain = FILE_END ( link_bh -> b_data , link ) -> link_chain ; FILE_END ( link_bh -> b_data , link ) -> link_chain = cpu_to_be32 ( inode -> i_ino ) ; affs_fix_checksum ( AFFS_I2BSIZE ( link ) , link_bh -> b_data , 5 ) ; link -> i_version = ++ event ; mark_inode_dirty ( link ) ; mark_buffer_dirty ( link_bh ) ; } affs_fix_checksum ( AFFS_I2BSIZE ( inode ) , inode_bh -> b_data , 5 ) ; affs_fix_checksum ( AFFS_I2BSIZE ( dir ) , dir_bh -> b_data , 5 ) ; dir -> i_version = ++ event ; dir -> i_mtime = dir -> i_atime = dir -> i_ctime = CURRENT_TIME ; unlock_super ( inode -> i_sb ) ; mark_inode_dirty ( dir ) ; mark_inode_dirty ( inode ) ; mark_buffer_dirty ( dir_bh ) ; mark_buffer_dirty ( inode_bh ) ; addentry_done : affs_brelse ( dir_bh ) ; affs_brelse ( inode_bh ) ; affs_brelse ( link_bh ) ; return retval ; }
Add an entry to a directory.
Add an entry to a directory .