kernels/linux-2.4.0/fs/cramfs/inode.c
/*
 * Read a cramfs directory entry.
 */
Read a cramfs directory entry.
Read a cramfs directory entry .
static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
{
	struct inode *inode = filp->f_dentry->d_inode;
	struct super_block *sb = inode->i_sb;
	unsigned int offset;
	int copied;
	offset = filp->f_pos;
	if (offset >= inode->i_size)
		return 0;
	if (offset & 3)
		return -EINVAL;
	copied = 0;
	while (offset < inode->i_size) {
		struct cramfs_inode *de;
		unsigned long nextoffset;
		char *name;
		int namelen, error;
		de = cramfs_read(sb, OFFSET(inode) + offset, sizeof(*de)+256);
		name = (char *)(de+1);
		namelen = de->namelen << 2;
		nextoffset = offset + sizeof(*de) + namelen;
		for (;;) {
			if (!namelen)
				return -EIO;
			if (name[namelen-1])
				break;
			namelen--;
		}
		error = filldir(dirent, name, namelen, offset, CRAMINO(de), de->mode >> 12);
		if (error)
			break;
		offset = nextoffset;
		filp->f_pos = offset;
		copied++;
	}
	return 0;
}
static int cramfs_readdir ( struct file * filp , void * dirent , filldir_t filldir ) { struct inode * inode = filp -> f_dentry -> d_inode ; struct super_block * sb = inode -> i_sb ; unsigned int offset ; int copied ; offset = filp -> f_pos ; if ( offset >= inode -> i_size ) return 0 ; if ( offset & 3 ) return - EINVAL ; copied = 0 ; while ( offset < inode -> i_size ) { struct cramfs_inode * de ; unsigned long nextoffset ; char * name ; int namelen , error ; de = cramfs_read ( sb , OFFSET ( inode ) + offset , sizeof ( * de ) + 256 ) ; name = ( char * ) ( de + 1 ) ; namelen = de -> namelen << 2 ; nextoffset = offset + sizeof ( * de ) + namelen ; for ( ; ; ) { if ( ! namelen ) return - EIO ; if ( name [ namelen - 1 ] ) break ; namelen -- ; } error = filldir ( dirent , name , namelen , offset , CRAMINO ( de ) , de -> mode >> 12 ) ; if ( error ) break ; offset = nextoffset ; filp -> f_pos = offset ; copied ++ ; } return 0 ; }
Read a cramfs directory entry.
Read a cramfs directory entry .
/* Offset within the thing. */ /* Directory entries are always 4-byte aligned */ /*
		 * Namelengths on disk are shifted by two
		 * and the name padded out to 4-byte boundaries
		 * with zeroes.
		 */