^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "reiserfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) extern const struct reiserfs_key MIN_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static int reiserfs_readdir(struct file *, struct dir_context *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static int reiserfs_dir_fsync(struct file *filp, loff_t start, loff_t end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) int datasync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) const struct file_operations reiserfs_dir_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) .llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .read = generic_read_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) .iterate_shared = reiserfs_readdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .fsync = reiserfs_dir_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .unlocked_ioctl = reiserfs_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .compat_ioctl = reiserfs_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int reiserfs_dir_fsync(struct file *filp, loff_t start, loff_t end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int datasync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct inode *inode = filp->f_mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) err = file_write_and_wait_range(filp, start, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) err = reiserfs_commit_for_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define store_ih(where,what) copy_item_head (where, what)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static inline bool is_privroot_deh(struct inode *dir, struct reiserfs_de_head *deh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct dentry *privroot = REISERFS_SB(dir->i_sb)->priv_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return (d_really_is_positive(privroot) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) deh->deh_objectid == INODE_PKEY(d_inode(privroot))->k_objectid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int reiserfs_readdir_inode(struct inode *inode, struct dir_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* key of current position in the directory (key of directory entry) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct cpu_key pos_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) INITIALIZE_PATH(path_to_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int item_num, entry_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) const struct reiserfs_key *rkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct item_head *ih, tmp_ih;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int search_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) char *local_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) loff_t next_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) char small_buf[32]; /* avoid kmalloc if we can */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct reiserfs_dir_entry de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) reiserfs_check_lock_depth(inode->i_sb, "readdir");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * form key for search the next directory entry using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * f_pos field of file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) make_cpu_key(&pos_key, inode, ctx->pos ?: DOT_OFFSET, TYPE_DIRENTRY, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) next_pos = cpu_key_k_offset(&pos_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) path_to_entry.reada = PATH_READA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) research:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * search the directory item, containing entry with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * specified key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) search_res =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) &de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (search_res == IO_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * FIXME: we could just skip part of directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * which could not be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) entry_num = de.de_entry_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) bh = de.de_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) item_num = de.de_item_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ih = de.de_ih;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) store_ih(&tmp_ih, ih);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* we must have found item, that is item of this directory, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) RFALSE(COMP_SHORT_KEYS(&ih->ih_key, &pos_key),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) "vs-9000: found item %h does not match to dir we readdir %K",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ih, &pos_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) RFALSE(item_num > B_NR_ITEMS(bh) - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) "vs-9005 item_num == %d, item amount == %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) item_num, B_NR_ITEMS(bh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * and entry must be not more than number of entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * in the item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) RFALSE(ih_entry_count(ih) < entry_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) "vs-9010: entry number is too big %d (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) entry_num, ih_entry_count(ih));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * go through all entries in the directory item beginning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * from the entry, that has been found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (search_res == POSITION_FOUND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) || entry_num < ih_entry_count(ih)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct reiserfs_de_head *deh =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) B_I_DEH(bh, ih) + entry_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) for (; entry_num < ih_entry_count(ih);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) entry_num++, deh++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int d_reclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) char *d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ino_t d_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) loff_t cur_pos = deh_offset(deh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* it is hidden entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!de_visible(deh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) d_reclen = entry_length(bh, ih, entry_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (d_reclen <= 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) d_name + d_reclen > bh->b_data + bh->b_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * There is corrupted data in entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * We'd better stop here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) pathrelse(&path_to_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (!d_name[d_reclen - 1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) d_reclen = strlen(d_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* too big to send back to VFS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (d_reclen >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) REISERFS_MAX_NAME(inode->i_sb->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) s_blocksize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* Ignore the .reiserfs_priv entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (is_privroot_deh(inode, deh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ctx->pos = deh_offset(deh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) d_ino = deh_objectid(deh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (d_reclen <= 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) local_buf = small_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) local_buf = kmalloc(d_reclen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!local_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) pathrelse(&path_to_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (item_moved(&tmp_ih, &path_to_entry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) kfree(local_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) goto research;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * Note, that we copy name to user space via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * temporary buffer (local_buf) because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * filldir will block if user space buffer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * swapped out. At that time entry can move to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * somewhere else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) memcpy(local_buf, d_name, d_reclen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * Since filldir might sleep, we can release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * the write lock here for other waiters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) depth = reiserfs_write_unlock_nested(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!dir_emit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) (ctx, local_buf, d_reclen, d_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) DT_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) reiserfs_write_lock_nested(inode->i_sb, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (local_buf != small_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) kfree(local_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) reiserfs_write_lock_nested(inode->i_sb, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (local_buf != small_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) kfree(local_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* deh_offset(deh) may be invalid now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) next_pos = cur_pos + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (item_moved(&tmp_ih, &path_to_entry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) set_cpu_key_k_offset(&pos_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) next_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) goto research;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) } /* for */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* end of directory has been reached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (item_num != B_NR_ITEMS(bh) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * item we went through is last item of node. Using right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * delimiting key check is it directory end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) rkey = get_rkey(&path_to_entry, inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (!comp_le_keys(rkey, &MIN_KEY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * set pos_key to key, that is the smallest and greater
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * that key of the last entry in the item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) set_cpu_key_k_offset(&pos_key, next_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* end of directory has been reached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (COMP_SHORT_KEYS(rkey, &pos_key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* directory continues in the right neighboring block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) set_cpu_key_k_offset(&pos_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) le_key_k_offset(KEY_FORMAT_3_5, rkey));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) } /* while */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ctx->pos = next_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) pathrelse(&path_to_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) reiserfs_check_path(&path_to_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static int reiserfs_readdir(struct file *file, struct dir_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return reiserfs_readdir_inode(file_inode(file), ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * compose directory item containing "." and ".." entries (entries are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * not aligned to 4 byte boundary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) __le32 par_dirid, __le32 par_objid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct reiserfs_de_head *dot, *dotdot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) memset(body, 0, EMPTY_DIR_SIZE_V1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) dot = (struct reiserfs_de_head *)body;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) dotdot = dot + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* direntry header of "." */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) put_deh_offset(dot, DOT_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* these two are from make_le_item_head, and are LE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) dot->deh_dir_id = dirid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) dot->deh_objectid = objid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) dot->deh_state = 0; /* Endian safe if 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) put_deh_location(dot, EMPTY_DIR_SIZE_V1 - strlen("."));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) mark_de_visible(dot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* direntry header of ".." */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) put_deh_offset(dotdot, DOT_DOT_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /* key of ".." for the root directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /* these two are from the inode, and are LE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) dotdot->deh_dir_id = par_dirid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) dotdot->deh_objectid = par_objid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) dotdot->deh_state = 0; /* Endian safe if 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) put_deh_location(dotdot, deh_location(dot) - strlen(".."));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) mark_de_visible(dotdot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* copy ".." and "." */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) memcpy(body + deh_location(dot), ".", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) memcpy(body + deh_location(dotdot), "..", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /* compose directory item containing "." and ".." entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) void make_empty_dir_item(char *body, __le32 dirid, __le32 objid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) __le32 par_dirid, __le32 par_objid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct reiserfs_de_head *dot, *dotdot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) memset(body, 0, EMPTY_DIR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) dot = (struct reiserfs_de_head *)body;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) dotdot = dot + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* direntry header of "." */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) put_deh_offset(dot, DOT_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /* these two are from make_le_item_head, and are LE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) dot->deh_dir_id = dirid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) dot->deh_objectid = objid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) dot->deh_state = 0; /* Endian safe if 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) put_deh_location(dot, EMPTY_DIR_SIZE - ROUND_UP(strlen(".")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) mark_de_visible(dot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* direntry header of ".." */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) put_deh_offset(dotdot, DOT_DOT_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* key of ".." for the root directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* these two are from the inode, and are LE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) dotdot->deh_dir_id = par_dirid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) dotdot->deh_objectid = par_objid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) dotdot->deh_state = 0; /* Endian safe if 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) put_deh_location(dotdot, deh_location(dot) - ROUND_UP(strlen("..")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) mark_de_visible(dotdot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /* copy ".." and "." */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) memcpy(body + deh_location(dot), ".", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) memcpy(body + deh_location(dotdot), "..", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }