kernels/linux-2.4.0/fs/minix/namei.c
/*
 *	minix_add_entry()
 *
 * adds a file entry to the specified directory, returning a possible
 * error value if it fails.
 *
 * NOTE!! The inode part of 'de' is left at 0 - which means you
 * may not sleep between calling this and putting something into
 * the entry, as someone else might have used it while you slept.
 */
minix_add_entry()
adds a file entry to the specified directory, returning a possible
error value if it fails.

NOTE!. The inode part of 'de' is left at 0 - which means you
may not sleep between calling this and putting something into
the entry, as someone else might have used it while you slept.
minix_add_entry () adds a file entry to the specified directory returning a possible error value if it fails . NOTE! . The inode part of ' de ' is left at 0 - which means you may not sleep between calling this and putting something into the entry as someone else might have used it while you slept .
static int minix_add_entry(struct inode * dir,
	const char * name, int namelen,
	struct buffer_head ** res_buf,
	struct minix_dir_entry ** res_dir)
{
	int i;
	unsigned long block, offset;
	struct buffer_head * bh;
	struct minix_dir_entry * de;
	struct minix_sb_info * info;
	*res_buf = NULL;
	*res_dir = NULL;
	info = &dir->i_sb->u.minix_sb;
	if (namelen > info->s_namelen) {
#ifdef NO_TRUNCATE
		return -ENAMETOOLONG;
#else
		namelen = info->s_namelen;
#endif
	}
	if (!namelen)
		return -ENOENT;
	bh = NULL;
	block = offset = 0;
	while (1) {
		if (!bh) {
			bh = minix_bread(dir,block,1);
			if (!bh)
				return -ENOSPC;
		}
		de = (struct minix_dir_entry *) (bh->b_data + offset);
		offset += info->s_dirsize;
		if (block*bh->b_size + offset > dir->i_size) {
			de->inode = 0;
			dir->i_size = block*bh->b_size + offset;
			mark_inode_dirty(dir);
		}
		if (!de->inode) {
			dir->i_mtime = dir->i_ctime = CURRENT_TIME;
			mark_inode_dirty(dir);
			for (i = 0; i < info->s_namelen ; i++)
				de->name[i] = (i < namelen) ? name[i] : 0;
			dir->i_version = ++event;
			mark_buffer_dirty(bh);
			*res_dir = de;
			break;
		}
		if (offset < bh->b_size)
			continue;
		brelse(bh);
		bh = NULL;
		offset = 0;
		block++;
	}
	*res_buf = bh;
	return 0;
}
static int minix_add_entry ( struct inode * dir , const char * name , int namelen , struct buffer_head * * res_buf , struct minix_dir_entry * * res_dir ) { int i ; unsigned long block , offset ; struct buffer_head * bh ; struct minix_dir_entry * de ; struct minix_sb_info * info ; * res_buf = NULL ; * res_dir = NULL ; info = & dir -> i_sb -> u . minix_sb ; if ( namelen > info -> s_namelen ) { #ifdef NO_TRUNCATE return - ENAMETOOLONG ; #else namelen = info -> s_namelen ; #endif } if ( ! namelen ) return - ENOENT ; bh = NULL ; block = offset = 0 ; while ( 1 ) { if ( ! bh ) { bh = minix_bread ( dir , block , 1 ) ; if ( ! bh ) return - ENOSPC ; } de = ( struct minix_dir_entry * ) ( bh -> b_data + offset ) ; offset += info -> s_dirsize ; if ( block * bh -> b_size + offset > dir -> i_size ) { de -> inode = 0 ; dir -> i_size = block * bh -> b_size + offset ; mark_inode_dirty ( dir ) ; } if ( ! de -> inode ) { dir -> i_mtime = dir -> i_ctime = CURRENT_TIME ; mark_inode_dirty ( dir ) ; for ( i = 0 ; i < info -> s_namelen ; i ++ ) de -> name [ i ] = ( i < namelen ) ? name [ i ] : 0 ; dir -> i_version = ++ event ; mark_buffer_dirty ( bh ) ; * res_dir = de ; break ; } if ( offset < bh -> b_size ) continue ; brelse ( bh ) ; bh = NULL ; offset = 0 ; block ++ ; } * res_buf = bh ; return 0 ; }
minix_add_entry()
 adds a file entry to the specified directory, returning a possible
 error value if it fails.
minix_add_entry () adds a file entry to the specified directory returning a possible error value if it fails .