meta name='generator' content='cgit v1.2.2'/>
aboutsummaryrefslogblamecommitdiffstats
path: root/fs/reiserfs/dir.c
blob: d71ac657928931e114ea0798342e501f27558a79 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                                                       
                                   
 


                                                                       

                                                  



                                    

  










                                                                       

 


                                                         
                                                                               
 





































                                                                                                       
                                 
                 


































































                                                                                                                        

                                                                      





                                                                                  
                                                                 











                                                                                      
                                                                 



                                                             
                                                         







                                                                                   

                 












                                                                               
 


                                                            
                 













                                                                            




                                                                      

                                                                   
 


























                                                                            


                                                            

                                                                
 



























                                                                            
 
/*
 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
 */

#include <linux/config.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/reiserfs_fs.h>
#include <linux/stat.h>
#include <linux/smp_lock.h>
#include <linux/buffer_head.h>
#include <asm/uaccess.h>

extern struct reiserfs_key MIN_KEY;

static int reiserfs_readdir(struct file *, void *, filldir_t);
static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry,
			      int datasync);

struct file_operations reiserfs_dir_operations = {
	.read = generic_read_dir,
	.readdir = reiserfs_readdir,
	.fsync = reiserfs_dir_fsync,
	.ioctl = reiserfs_ioctl,
};

static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry,
			      int datasync)
{
	struct inode *inode = dentry->d_inode;
	int err;
	reiserfs_write_lock(inode->i_sb);
	err = reiserfs_commit_for_inode(inode);
	reiserfs_write_unlock(inode->i_sb);
	if (err < 0)
		return err;
	return 0;
}

#define store_ih(where,what) copy_item_head (where, what)

//
static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
{
	struct inode *inode = filp->f_dentry->d_inode;
	struct cpu_key pos_key;	/* key of current position in the directory (key of directory entry) */
	INITIALIZE_PATH(path_to_entry);
	struct buffer_head *bh;
	int item_num, entry_num;
	const struct reiserfs_key *rkey;
	struct item_head *ih, tmp_ih;
	int search_res;
	char *local_buf;
	loff_t next_pos;
	char small_buf[32];	/* avoid kmalloc if we can */
	struct reiserfs_dir_entry de;
	int ret = 0;

	reiserfs_write_lock(inode->i_sb);

	reiserfs_check_lock_depth(inode->i_sb, "readdir");

	/* form key for search the next directory entry using f_pos field of
	   file structure */
	make_cpu_key(&pos_key, inode,
		     (filp->f_pos) ? (filp->f_pos) : DOT_OFFSET, TYPE_DIRENTRY,
		     3);
	next_pos = cpu_key_k_offset(&pos_key);

	/*  reiserfs_warning (inode->i_sb, "reiserfs_readdir 1: f_pos = %Ld", filp->f_pos); */

	path_to_entry.reada = PATH_READA;
	while (1) {
	      research:
		/* search the directory item, containing entry with specified key */
		search_res =
		    search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
					&de);
		if (search_res == IO_ERROR) {
			// FIXME: we could just skip part of directory which could
			// not be read
			ret = -EIO;
			goto out;