diff options
author | David Woodhouse <David.Woodhouse@intel.com> | 2008-08-17 12:08:36 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:04:06 -0400 |
commit | 49593bfa575b7e3fda073b6d1033ee273bdaf97c (patch) | |
tree | c83b590a520ca5bd466d05a70c85de15a97b574d /fs/btrfs/inode.c | |
parent | 5ecc7e5d1d58731b3a6a69303d69aca7fb0fe1f5 (diff) |
Minor cleanup of btrfs_real_readdir()
Date: Sun, 17 Aug 2008 17:08:36 +0100
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 4520a0e86e70..c7b7095634da 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -1920,34 +1920,34 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, | |||
1920 | return 0; | 1920 | return 0; |
1921 | filp->f_pos = 1; | 1921 | filp->f_pos = 1; |
1922 | } | 1922 | } |
1923 | |||
1924 | key.objectid = inode->i_ino; | ||
1925 | path = btrfs_alloc_path(); | ||
1926 | path->reada = 2; | ||
1927 | |||
1928 | /* special case for .., just use the back ref */ | 1923 | /* special case for .., just use the back ref */ |
1929 | if (filp->f_pos == 1) { | 1924 | if (filp->f_pos == 1) { |
1930 | u64 pino = parent_ino(filp->f_path.dentry); | 1925 | u64 pino = parent_ino(filp->f_path.dentry); |
1931 | over = filldir(dirent, "..", 2, | 1926 | over = filldir(dirent, "..", 2, |
1932 | 2, pino, DT_DIR); | 1927 | 2, pino, DT_DIR); |
1933 | if (over) | 1928 | if (over) |
1934 | goto nopos; | 1929 | return 0; |
1935 | filp->f_pos = 2; | 1930 | filp->f_pos = 2; |
1936 | } | 1931 | } |
1937 | 1932 | ||
1933 | path = btrfs_alloc_path(); | ||
1934 | path->reada = 2; | ||
1935 | |||
1938 | btrfs_set_key_type(&key, key_type); | 1936 | btrfs_set_key_type(&key, key_type); |
1939 | key.offset = filp->f_pos; | 1937 | key.offset = filp->f_pos; |
1938 | key.objectid = inode->i_ino; | ||
1940 | 1939 | ||
1941 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); | 1940 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); |
1942 | if (ret < 0) | 1941 | if (ret < 0) |
1943 | goto err; | 1942 | goto err; |
1944 | advance = 0; | 1943 | advance = 0; |
1945 | while(1) { | 1944 | |
1945 | while (1) { | ||
1946 | leaf = path->nodes[0]; | 1946 | leaf = path->nodes[0]; |
1947 | nritems = btrfs_header_nritems(leaf); | 1947 | nritems = btrfs_header_nritems(leaf); |
1948 | slot = path->slots[0]; | 1948 | slot = path->slots[0]; |
1949 | if (advance || slot >= nritems) { | 1949 | if (advance || slot >= nritems) { |
1950 | if (slot >= nritems -1) { | 1950 | if (slot >= nritems - 1) { |
1951 | ret = btrfs_next_leaf(root, path); | 1951 | ret = btrfs_next_leaf(root, path); |
1952 | if (ret) | 1952 | if (ret) |
1953 | break; | 1953 | break; |
@@ -1971,19 +1971,23 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, | |||
1971 | continue; | 1971 | continue; |
1972 | 1972 | ||
1973 | filp->f_pos = found_key.offset; | 1973 | filp->f_pos = found_key.offset; |
1974 | advance = 1; | 1974 | |
1975 | di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); | 1975 | di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); |
1976 | di_cur = 0; | 1976 | di_cur = 0; |
1977 | di_total = btrfs_item_size(leaf, item); | 1977 | di_total = btrfs_item_size(leaf, item); |
1978 | while(di_cur < di_total) { | 1978 | |
1979 | while (di_cur < di_total) { | ||
1979 | struct btrfs_key location; | 1980 | struct btrfs_key location; |
1980 | 1981 | ||
1981 | name_len = btrfs_dir_name_len(leaf, di); | 1982 | name_len = btrfs_dir_name_len(leaf, di); |
1982 | if (name_len < 32) { | 1983 | if (name_len <= sizeof(tmp_name)) { |
1983 | name_ptr = tmp_name; | 1984 | name_ptr = tmp_name; |
1984 | } else { | 1985 | } else { |
1985 | name_ptr = kmalloc(name_len, GFP_NOFS); | 1986 | name_ptr = kmalloc(name_len, GFP_NOFS); |
1986 | BUG_ON(!name_ptr); | 1987 | if (!name_ptr) { |
1988 | ret = -ENOMEM; | ||
1989 | goto err; | ||
1990 | } | ||
1987 | } | 1991 | } |
1988 | read_extent_buffer(leaf, name_ptr, | 1992 | read_extent_buffer(leaf, name_ptr, |
1989 | (unsigned long)(di + 1), name_len); | 1993 | (unsigned long)(di + 1), name_len); |
@@ -1991,8 +1995,7 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, | |||
1991 | d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)]; | 1995 | d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)]; |
1992 | btrfs_dir_item_key_to_cpu(leaf, di, &location); | 1996 | btrfs_dir_item_key_to_cpu(leaf, di, &location); |
1993 | over = filldir(dirent, name_ptr, name_len, | 1997 | over = filldir(dirent, name_ptr, name_len, |
1994 | found_key.offset, | 1998 | found_key.offset, location.objectid, |
1995 | location.objectid, | ||
1996 | d_type); | 1999 | d_type); |
1997 | 2000 | ||
1998 | if (name_ptr != tmp_name) | 2001 | if (name_ptr != tmp_name) |
@@ -2000,12 +2003,15 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, | |||
2000 | 2003 | ||
2001 | if (over) | 2004 | if (over) |
2002 | goto nopos; | 2005 | goto nopos; |
2006 | |||
2003 | di_len = btrfs_dir_name_len(leaf, di) + | 2007 | di_len = btrfs_dir_name_len(leaf, di) + |
2004 | btrfs_dir_data_len(leaf, di) +sizeof(*di); | 2008 | btrfs_dir_data_len(leaf, di) + sizeof(*di); |
2005 | di_cur += di_len; | 2009 | di_cur += di_len; |
2006 | di = (struct btrfs_dir_item *)((char *)di + di_len); | 2010 | di = (struct btrfs_dir_item *)((char *)di + di_len); |
2007 | } | 2011 | } |
2008 | } | 2012 | } |
2013 | |||
2014 | /* Reached end of directory/root. Bump pos past the last item. */ | ||
2009 | if (key_type == BTRFS_DIR_INDEX_KEY) | 2015 | if (key_type == BTRFS_DIR_INDEX_KEY) |
2010 | filp->f_pos = INT_LIMIT(typeof(filp->f_pos)); | 2016 | filp->f_pos = INT_LIMIT(typeof(filp->f_pos)); |
2011 | else | 2017 | else |