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