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