diff options
Diffstat (limited to 'fs/reiserfs/dir.c')
| -rw-r--r-- | fs/reiserfs/dir.c | 488 |
1 files changed, 255 insertions, 233 deletions
diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c index fbde4b01a325..9dd71e807034 100644 --- a/fs/reiserfs/dir.c +++ b/fs/reiserfs/dir.c | |||
| @@ -12,264 +12,286 @@ | |||
| 12 | #include <linux/buffer_head.h> | 12 | #include <linux/buffer_head.h> |
| 13 | #include <asm/uaccess.h> | 13 | #include <asm/uaccess.h> |
| 14 | 14 | ||
| 15 | extern struct reiserfs_key MIN_KEY; | 15 | extern struct reiserfs_key MIN_KEY; |
| 16 | 16 | ||
| 17 | static int reiserfs_readdir (struct file *, void *, filldir_t); | 17 | static int reiserfs_readdir(struct file *, void *, filldir_t); |
| 18 | static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, int datasync) ; | 18 | static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, |
| 19 | int datasync); | ||
| 19 | 20 | ||
| 20 | struct file_operations reiserfs_dir_operations = { | 21 | struct file_operations reiserfs_dir_operations = { |
| 21 | .read = generic_read_dir, | 22 | .read = generic_read_dir, |
| 22 | .readdir = reiserfs_readdir, | 23 | .readdir = reiserfs_readdir, |
| 23 | .fsync = reiserfs_dir_fsync, | 24 | .fsync = reiserfs_dir_fsync, |
| 24 | .ioctl = reiserfs_ioctl, | 25 | .ioctl = reiserfs_ioctl, |
| 25 | }; | 26 | }; |
| 26 | 27 | ||
| 27 | static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, int datasync) { | 28 | static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, |
| 28 | struct inode *inode = dentry->d_inode; | 29 | int datasync) |
| 29 | int err; | 30 | { |
| 30 | reiserfs_write_lock(inode->i_sb); | 31 | struct inode *inode = dentry->d_inode; |
| 31 | err = reiserfs_commit_for_inode(inode) ; | 32 | int err; |
| 32 | reiserfs_write_unlock(inode->i_sb) ; | 33 | reiserfs_write_lock(inode->i_sb); |
| 33 | if (err < 0) | 34 | err = reiserfs_commit_for_inode(inode); |
| 34 | return err; | 35 | reiserfs_write_unlock(inode->i_sb); |
| 35 | return 0; | 36 | if (err < 0) |
| 37 | return err; | ||
| 38 | return 0; | ||
| 36 | } | 39 | } |
| 37 | 40 | ||
| 38 | |||
| 39 | #define store_ih(where,what) copy_item_head (where, what) | 41 | #define store_ih(where,what) copy_item_head (where, what) |
| 40 | 42 | ||
| 41 | // | 43 | // |
| 42 | static int reiserfs_readdir (struct file * filp, void * dirent, filldir_t filldir) | 44 | static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir) |
| 43 | { | 45 | { |
| 44 | struct inode *inode = filp->f_dentry->d_inode; | 46 | struct inode *inode = filp->f_dentry->d_inode; |
| 45 | struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ | 47 | struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ |
| 46 | INITIALIZE_PATH (path_to_entry); | 48 | INITIALIZE_PATH(path_to_entry); |
| 47 | struct buffer_head * bh; | 49 | struct buffer_head *bh; |
| 48 | int item_num, entry_num; | 50 | int item_num, entry_num; |
| 49 | const struct reiserfs_key * rkey; | 51 | const struct reiserfs_key *rkey; |
| 50 | struct item_head * ih, tmp_ih; | 52 | struct item_head *ih, tmp_ih; |
| 51 | int search_res; | 53 | int search_res; |
| 52 | char * local_buf; | 54 | char *local_buf; |
| 53 | loff_t next_pos; | 55 | loff_t next_pos; |
| 54 | char small_buf[32] ; /* avoid kmalloc if we can */ | 56 | char small_buf[32]; /* avoid kmalloc if we can */ |
| 55 | struct reiserfs_dir_entry de; | 57 | struct reiserfs_dir_entry de; |
| 56 | int ret = 0; | 58 | int ret = 0; |
| 57 | 59 | ||
| 58 | reiserfs_write_lock(inode->i_sb); | 60 | reiserfs_write_lock(inode->i_sb); |
| 59 | 61 | ||
| 60 | reiserfs_check_lock_depth(inode->i_sb, "readdir") ; | 62 | reiserfs_check_lock_depth(inode->i_sb, "readdir"); |
| 61 | 63 | ||
| 62 | /* form key for search the next directory entry using f_pos field of | 64 | /* form key for search the next directory entry using f_pos field of |
| 63 | file structure */ | 65 | file structure */ |
| 64 | make_cpu_key (&pos_key, inode, (filp->f_pos) ? (filp->f_pos) : DOT_OFFSET, | 66 | make_cpu_key(&pos_key, inode, |
| 65 | TYPE_DIRENTRY, 3); | 67 | (filp->f_pos) ? (filp->f_pos) : DOT_OFFSET, TYPE_DIRENTRY, |
| 66 | next_pos = cpu_key_k_offset (&pos_key); | 68 | 3); |
| 67 | 69 | next_pos = cpu_key_k_offset(&pos_key); | |
| 68 | /* reiserfs_warning (inode->i_sb, "reiserfs_readdir 1: f_pos = %Ld", filp->f_pos);*/ | 70 | |
| 69 | 71 | /* reiserfs_warning (inode->i_sb, "reiserfs_readdir 1: f_pos = %Ld", filp->f_pos); */ | |
| 70 | path_to_entry.reada = PATH_READA; | 72 | |
| 71 | while (1) { | 73 | path_to_entry.reada = PATH_READA; |
| 72 | research: | 74 | while (1) { |
| 73 | /* search the directory item, containing entry with specified key */ | 75 | research: |
| 74 | search_res = search_by_entry_key (inode->i_sb, &pos_key, &path_to_entry, &de); | 76 | /* search the directory item, containing entry with specified key */ |
| 75 | if (search_res == IO_ERROR) { | 77 | search_res = |
| 76 | // FIXME: we could just skip part of directory which could | 78 | search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry, |
| 77 | // not be read | 79 | &de); |
| 78 | ret = -EIO; | 80 | if (search_res == IO_ERROR) { |
| 79 | goto out; | 81 | // FIXME: we could just skip part of directory which could |
| 80 | } | 82 | // not be read |
| 81 | entry_num = de.de_entry_num; | 83 | ret = -EIO; |
| 82 | bh = de.de_bh; | ||
| 83 | item_num = de.de_item_num; | ||
| 84 | ih = de.de_ih; | ||
| 85 | store_ih (&tmp_ih, ih); | ||
| 86 | |||
| 87 | /* we must have found item, that is item of this directory, */ | ||
| 88 | RFALSE( COMP_SHORT_KEYS (&(ih->ih_key), &pos_key), | ||
| 89 | "vs-9000: found item %h does not match to dir we readdir %K", | ||
| 90 | ih, &pos_key); | ||
| 91 | RFALSE( item_num > B_NR_ITEMS (bh) - 1, | ||
| 92 | "vs-9005 item_num == %d, item amount == %d", | ||
| 93 | item_num, B_NR_ITEMS (bh)); | ||
| 94 | |||
| 95 | /* and entry must be not more than number of entries in the item */ | ||
| 96 | RFALSE( I_ENTRY_COUNT (ih) < entry_num, | ||
| 97 | "vs-9010: entry number is too big %d (%d)", | ||
| 98 | entry_num, I_ENTRY_COUNT (ih)); | ||
| 99 | |||
| 100 | if (search_res == POSITION_FOUND || entry_num < I_ENTRY_COUNT (ih)) { | ||
| 101 | /* go through all entries in the directory item beginning from the entry, that has been found */ | ||
| 102 | struct reiserfs_de_head * deh = B_I_DEH (bh, ih) + entry_num; | ||
| 103 | |||
| 104 | for (; entry_num < I_ENTRY_COUNT (ih); entry_num ++, deh ++) { | ||
| 105 | int d_reclen; | ||
| 106 | char * d_name; | ||
| 107 | off_t d_off; | ||
| 108 | ino_t d_ino; | ||
| 109 | |||
| 110 | if (!de_visible (deh)) | ||
| 111 | /* it is hidden entry */ | ||
| 112 | continue; | ||
| 113 | d_reclen = entry_length (bh, ih, entry_num); | ||
| 114 | d_name = B_I_DEH_ENTRY_FILE_NAME (bh, ih, deh); | ||
| 115 | if (!d_name[d_reclen - 1]) | ||
| 116 | d_reclen = strlen (d_name); | ||
| 117 | |||
| 118 | if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)){ | ||
| 119 | /* too big to send back to VFS */ | ||
| 120 | continue ; | ||
| 121 | } | ||
| 122 | |||
| 123 | /* Ignore the .reiserfs_priv entry */ | ||
| 124 | if (reiserfs_xattrs (inode->i_sb) && | ||
| 125 | !old_format_only(inode->i_sb) && | ||
| 126 | filp->f_dentry == inode->i_sb->s_root && | ||
| 127 | REISERFS_SB(inode->i_sb)->priv_root && | ||
| 128 | REISERFS_SB(inode->i_sb)->priv_root->d_inode && | ||
| 129 | deh_objectid(deh) == le32_to_cpu (INODE_PKEY(REISERFS_SB(inode->i_sb)->priv_root->d_inode)->k_objectid)) { | ||
| 130 | continue; | ||
| 131 | } | ||
| 132 | |||
| 133 | d_off = deh_offset (deh); | ||
| 134 | filp->f_pos = d_off ; | ||
| 135 | d_ino = deh_objectid (deh); | ||
| 136 | if (d_reclen <= 32) { | ||
| 137 | local_buf = small_buf ; | ||
| 138 | } else { | ||
| 139 | local_buf = reiserfs_kmalloc(d_reclen, GFP_NOFS, inode->i_sb) ; | ||
| 140 | if (!local_buf) { | ||
| 141 | pathrelse (&path_to_entry); | ||
| 142 | ret = -ENOMEM ; | ||
| 143 | goto out; | 84 | goto out; |
| 144 | } | ||
| 145 | if (item_moved (&tmp_ih, &path_to_entry)) { | ||
| 146 | reiserfs_kfree(local_buf, d_reclen, inode->i_sb) ; | ||
| 147 | goto research; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | // Note, that we copy name to user space via temporary | ||
| 151 | // buffer (local_buf) because filldir will block if | ||
| 152 | // user space buffer is swapped out. At that time | ||
| 153 | // entry can move to somewhere else | ||
| 154 | memcpy (local_buf, d_name, d_reclen); | ||
| 155 | if (filldir (dirent, local_buf, d_reclen, d_off, d_ino, | ||
| 156 | DT_UNKNOWN) < 0) { | ||
| 157 | if (local_buf != small_buf) { | ||
| 158 | reiserfs_kfree(local_buf, d_reclen, inode->i_sb) ; | ||
| 159 | } | ||
| 160 | goto end; | ||
| 161 | } | 85 | } |
| 162 | if (local_buf != small_buf) { | 86 | entry_num = de.de_entry_num; |
| 163 | reiserfs_kfree(local_buf, d_reclen, inode->i_sb) ; | 87 | bh = de.de_bh; |
| 88 | item_num = de.de_item_num; | ||
| 89 | ih = de.de_ih; | ||
| 90 | store_ih(&tmp_ih, ih); | ||
| 91 | |||
| 92 | /* we must have found item, that is item of this directory, */ | ||
| 93 | RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key), | ||
| 94 | "vs-9000: found item %h does not match to dir we readdir %K", | ||
| 95 | ih, &pos_key); | ||
| 96 | RFALSE(item_num > B_NR_ITEMS(bh) - 1, | ||
| 97 | "vs-9005 item_num == %d, item amount == %d", | ||
| 98 | item_num, B_NR_ITEMS(bh)); | ||
| 99 | |||
| 100 | /* and entry must be not more than number of entries in the item */ | ||
| 101 | RFALSE(I_ENTRY_COUNT(ih) < entry_num, | ||
| 102 | "vs-9010: entry number is too big %d (%d)", | ||
| 103 | entry_num, I_ENTRY_COUNT(ih)); | ||
| 104 | |||
| 105 | if (search_res == POSITION_FOUND | ||
| 106 | || entry_num < I_ENTRY_COUNT(ih)) { | ||
| 107 | /* go through all entries in the directory item beginning from the entry, that has been found */ | ||
| 108 | struct reiserfs_de_head *deh = | ||
| 109 | B_I_DEH(bh, ih) + entry_num; | ||
| 110 | |||
| 111 | for (; entry_num < I_ENTRY_COUNT(ih); | ||
| 112 | entry_num++, deh++) { | ||
| 113 | int d_reclen; | ||
| 114 | char *d_name; | ||
| 115 | off_t d_off; | ||
| 116 | ino_t d_ino; | ||
| 117 | |||
| 118 | if (!de_visible(deh)) | ||
| 119 | /* it is hidden entry */ | ||
| 120 | continue; | ||
| 121 | d_reclen = entry_length(bh, ih, entry_num); | ||
| 122 | d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh); | ||
| 123 | if (!d_name[d_reclen - 1]) | ||
| 124 | d_reclen = strlen(d_name); | ||
| 125 | |||
| 126 | if (d_reclen > | ||
| 127 | REISERFS_MAX_NAME(inode->i_sb-> | ||
| 128 | s_blocksize)) { | ||
| 129 | /* too big to send back to VFS */ | ||
| 130 | continue; | ||
| 131 | } | ||
| 132 | |||
| 133 | /* Ignore the .reiserfs_priv entry */ | ||
| 134 | if (reiserfs_xattrs(inode->i_sb) && | ||
| 135 | !old_format_only(inode->i_sb) && | ||
| 136 | filp->f_dentry == inode->i_sb->s_root && | ||
| 137 | REISERFS_SB(inode->i_sb)->priv_root && | ||
| 138 | REISERFS_SB(inode->i_sb)->priv_root->d_inode | ||
| 139 | && deh_objectid(deh) == | ||
| 140 | le32_to_cpu(INODE_PKEY | ||
| 141 | (REISERFS_SB(inode->i_sb)-> | ||
| 142 | priv_root->d_inode)-> | ||
| 143 | k_objectid)) { | ||
| 144 | continue; | ||
| 145 | } | ||
| 146 | |||
| 147 | d_off = deh_offset(deh); | ||
| 148 | filp->f_pos = d_off; | ||
| 149 | d_ino = deh_objectid(deh); | ||
| 150 | if (d_reclen <= 32) { | ||
| 151 | local_buf = small_buf; | ||
| 152 | } else { | ||
| 153 | local_buf = | ||
| 154 | reiserfs_kmalloc(d_reclen, GFP_NOFS, | ||
| 155 | inode->i_sb); | ||
| 156 | if (!local_buf) { | ||
| 157 | pathrelse(&path_to_entry); | ||
| 158 | ret = -ENOMEM; | ||
| 159 | goto out; | ||
| 160 | } | ||
| 161 | if (item_moved(&tmp_ih, &path_to_entry)) { | ||
| 162 | reiserfs_kfree(local_buf, | ||
| 163 | d_reclen, | ||
| 164 | inode->i_sb); | ||
| 165 | goto research; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | // Note, that we copy name to user space via temporary | ||
| 169 | // buffer (local_buf) because filldir will block if | ||
| 170 | // user space buffer is swapped out. At that time | ||
| 171 | // entry can move to somewhere else | ||
| 172 | memcpy(local_buf, d_name, d_reclen); | ||
| 173 | if (filldir | ||
| 174 | (dirent, local_buf, d_reclen, d_off, d_ino, | ||
| 175 | DT_UNKNOWN) < 0) { | ||
| 176 | if (local_buf != small_buf) { | ||
| 177 | reiserfs_kfree(local_buf, | ||
| 178 | d_reclen, | ||
| 179 | inode->i_sb); | ||
| 180 | } | ||
| 181 | goto end; | ||
| 182 | } | ||
| 183 | if (local_buf != small_buf) { | ||
| 184 | reiserfs_kfree(local_buf, d_reclen, | ||
| 185 | inode->i_sb); | ||
| 186 | } | ||
| 187 | // next entry should be looked for with such offset | ||
| 188 | next_pos = deh_offset(deh) + 1; | ||
| 189 | |||
| 190 | if (item_moved(&tmp_ih, &path_to_entry)) { | ||
| 191 | goto research; | ||
| 192 | } | ||
| 193 | } /* for */ | ||
| 164 | } | 194 | } |
| 165 | 195 | ||
| 166 | // next entry should be looked for with such offset | 196 | if (item_num != B_NR_ITEMS(bh) - 1) |
| 167 | next_pos = deh_offset (deh) + 1; | 197 | // end of directory has been reached |
| 198 | goto end; | ||
| 199 | |||
| 200 | /* item we went through is last item of node. Using right | ||
| 201 | delimiting key check is it directory end */ | ||
| 202 | rkey = get_rkey(&path_to_entry, inode->i_sb); | ||
| 203 | if (!comp_le_keys(rkey, &MIN_KEY)) { | ||
| 204 | /* set pos_key to key, that is the smallest and greater | ||
| 205 | that key of the last entry in the item */ | ||
| 206 | set_cpu_key_k_offset(&pos_key, next_pos); | ||
| 207 | continue; | ||
| 208 | } | ||
| 168 | 209 | ||
| 169 | if (item_moved (&tmp_ih, &path_to_entry)) { | 210 | if (COMP_SHORT_KEYS(rkey, &pos_key)) { |
| 170 | goto research; | 211 | // end of directory has been reached |
| 212 | goto end; | ||
| 171 | } | 213 | } |
| 172 | } /* for */ | 214 | |
| 173 | } | 215 | /* directory continues in the right neighboring block */ |
| 174 | 216 | set_cpu_key_k_offset(&pos_key, | |
| 175 | if (item_num != B_NR_ITEMS (bh) - 1) | 217 | le_key_k_offset(KEY_FORMAT_3_5, rkey)); |
| 176 | // end of directory has been reached | 218 | |
| 177 | goto end; | 219 | } /* while */ |
| 178 | 220 | ||
| 179 | /* item we went through is last item of node. Using right | 221 | end: |
| 180 | delimiting key check is it directory end */ | 222 | filp->f_pos = next_pos; |
| 181 | rkey = get_rkey (&path_to_entry, inode->i_sb); | 223 | pathrelse(&path_to_entry); |
| 182 | if (! comp_le_keys (rkey, &MIN_KEY)) { | 224 | reiserfs_check_path(&path_to_entry); |
| 183 | /* set pos_key to key, that is the smallest and greater | 225 | out: |
| 184 | that key of the last entry in the item */ | 226 | reiserfs_write_unlock(inode->i_sb); |
| 185 | set_cpu_key_k_offset (&pos_key, next_pos); | 227 | return ret; |
| 186 | continue; | ||
| 187 | } | ||
| 188 | |||
| 189 | if ( COMP_SHORT_KEYS (rkey, &pos_key)) { | ||
| 190 | // end of directory has been reached | ||
| 191 | goto end; | ||
| 192 | } | ||
| 193 | |||
| 194 | /* directory continues in the right neighboring block */ | ||
| 195 | set_cpu_key_k_offset (&pos_key, le_key_k_offset (KEY_FORMAT_3_5, rkey)); | ||
| 196 | |||
| 197 | } /* while */ | ||
| 198 | |||
| 199 | |||
| 200 | end: | ||
| 201 | filp->f_pos = next_pos; | ||
| 202 | pathrelse (&path_to_entry); | ||
| 203 | reiserfs_check_path(&path_to_entry) ; | ||
| 204 | out: | ||
| 205 | reiserfs_write_unlock(inode->i_sb); | ||
| 206 | return ret; | ||
| 207 | } | 228 | } |
| 208 | 229 | ||
| 209 | /* compose directory item containing "." and ".." entries (entries are | 230 | /* compose directory item containing "." and ".." entries (entries are |
| 210 | not aligned to 4 byte boundary) */ | 231 | not aligned to 4 byte boundary) */ |
| 211 | /* the last four params are LE */ | 232 | /* the last four params are LE */ |
| 212 | void make_empty_dir_item_v1 (char * body, __le32 dirid, __le32 objid, | 233 | void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid, |
| 213 | __le32 par_dirid, __le32 par_objid) | 234 | __le32 par_dirid, __le32 par_objid) |
| 214 | { | 235 | { |
| 215 | struct reiserfs_de_head * deh; | 236 | struct reiserfs_de_head *deh; |
| 216 | 237 | ||
| 217 | memset (body, 0, EMPTY_DIR_SIZE_V1); | 238 | memset(body, 0, EMPTY_DIR_SIZE_V1); |
| 218 | deh = (struct reiserfs_de_head *)body; | 239 | deh = (struct reiserfs_de_head *)body; |
| 219 | 240 | ||
| 220 | /* direntry header of "." */ | 241 | /* direntry header of "." */ |
| 221 | put_deh_offset( &(deh[0]), DOT_OFFSET ); | 242 | put_deh_offset(&(deh[0]), DOT_OFFSET); |
| 222 | /* these two are from make_le_item_head, and are are LE */ | 243 | /* these two are from make_le_item_head, and are are LE */ |
| 223 | deh[0].deh_dir_id = dirid; | 244 | deh[0].deh_dir_id = dirid; |
| 224 | deh[0].deh_objectid = objid; | 245 | deh[0].deh_objectid = objid; |
| 225 | deh[0].deh_state = 0; /* Endian safe if 0 */ | 246 | deh[0].deh_state = 0; /* Endian safe if 0 */ |
| 226 | put_deh_location( &(deh[0]), EMPTY_DIR_SIZE_V1 - strlen( "." )); | 247 | put_deh_location(&(deh[0]), EMPTY_DIR_SIZE_V1 - strlen(".")); |
| 227 | mark_de_visible(&(deh[0])); | 248 | mark_de_visible(&(deh[0])); |
| 228 | 249 | ||
| 229 | /* direntry header of ".." */ | 250 | /* direntry header of ".." */ |
| 230 | put_deh_offset( &(deh[1]), DOT_DOT_OFFSET); | 251 | put_deh_offset(&(deh[1]), DOT_DOT_OFFSET); |
| 231 | /* key of ".." for the root directory */ | 252 | /* key of ".." for the root directory */ |
| 232 | /* these two are from the inode, and are are LE */ | 253 | /* these two are from the inode, and are are LE */ |
| 233 | deh[1].deh_dir_id = par_dirid; | 254 | deh[1].deh_dir_id = par_dirid; |
| 234 | deh[1].deh_objectid = par_objid; | 255 | deh[1].deh_objectid = par_objid; |
| 235 | deh[1].deh_state = 0; /* Endian safe if 0 */ | 256 | deh[1].deh_state = 0; /* Endian safe if 0 */ |
| 236 | put_deh_location( &(deh[1]), deh_location( &(deh[0]) ) - strlen( ".." ) ); | 257 | put_deh_location(&(deh[1]), deh_location(&(deh[0])) - strlen("..")); |
| 237 | mark_de_visible(&(deh[1])); | 258 | mark_de_visible(&(deh[1])); |
| 238 | 259 | ||
| 239 | /* copy ".." and "." */ | 260 | /* copy ".." and "." */ |
| 240 | memcpy (body + deh_location( &(deh[0]) ), ".", 1); | 261 | memcpy(body + deh_location(&(deh[0])), ".", 1); |
| 241 | memcpy (body + deh_location( &(deh[1]) ), "..", 2); | 262 | memcpy(body + deh_location(&(deh[1])), "..", 2); |
| 242 | } | 263 | } |
| 243 | 264 | ||
| 244 | /* compose directory item containing "." and ".." entries */ | 265 | /* compose directory item containing "." and ".." entries */ |
| 245 | void make_empty_dir_item (char * body, __le32 dirid, __le32 objid, | 266 | void make_empty_dir_item(char *body, __le32 dirid, __le32 objid, |
| 246 | __le32 par_dirid, __le32 par_objid) | 267 | __le32 par_dirid, __le32 par_objid) |
| 247 | { | 268 | { |
| 248 | struct reiserfs_de_head * deh; | 269 | struct reiserfs_de_head *deh; |
| 249 | 270 | ||
| 250 | memset (body, 0, EMPTY_DIR_SIZE); | 271 | memset(body, 0, EMPTY_DIR_SIZE); |
| 251 | deh = (struct reiserfs_de_head *)body; | 272 | deh = (struct reiserfs_de_head *)body; |
| 252 | 273 | ||
| 253 | /* direntry header of "." */ | 274 | /* direntry header of "." */ |
| 254 | put_deh_offset( &(deh[0]), DOT_OFFSET ); | 275 | put_deh_offset(&(deh[0]), DOT_OFFSET); |
| 255 | /* these two are from make_le_item_head, and are are LE */ | 276 | /* these two are from make_le_item_head, and are are LE */ |
| 256 | deh[0].deh_dir_id = dirid; | 277 | deh[0].deh_dir_id = dirid; |
| 257 | deh[0].deh_objectid = objid; | 278 | deh[0].deh_objectid = objid; |
| 258 | deh[0].deh_state = 0; /* Endian safe if 0 */ | 279 | deh[0].deh_state = 0; /* Endian safe if 0 */ |
| 259 | put_deh_location( &(deh[0]), EMPTY_DIR_SIZE - ROUND_UP( strlen( "." ) ) ); | 280 | put_deh_location(&(deh[0]), EMPTY_DIR_SIZE - ROUND_UP(strlen("."))); |
| 260 | mark_de_visible(&(deh[0])); | 281 | mark_de_visible(&(deh[0])); |
| 261 | 282 | ||
| 262 | /* direntry header of ".." */ | 283 | /* direntry header of ".." */ |
| 263 | put_deh_offset( &(deh[1]), DOT_DOT_OFFSET ); | 284 | put_deh_offset(&(deh[1]), DOT_DOT_OFFSET); |
| 264 | /* key of ".." for the root directory */ | 285 | /* key of ".." for the root directory */ |
| 265 | /* these two are from the inode, and are are LE */ | 286 | /* these two are from the inode, and are are LE */ |
| 266 | deh[1].deh_dir_id = par_dirid; | 287 | deh[1].deh_dir_id = par_dirid; |
| 267 | deh[1].deh_objectid = par_objid; | 288 | deh[1].deh_objectid = par_objid; |
| 268 | deh[1].deh_state = 0; /* Endian safe if 0 */ | 289 | deh[1].deh_state = 0; /* Endian safe if 0 */ |
| 269 | put_deh_location( &(deh[1]), deh_location( &(deh[0])) - ROUND_UP( strlen( ".." ) ) ); | 290 | put_deh_location(&(deh[1]), |
| 270 | mark_de_visible(&(deh[1])); | 291 | deh_location(&(deh[0])) - ROUND_UP(strlen(".."))); |
| 271 | 292 | mark_de_visible(&(deh[1])); | |
| 272 | /* copy ".." and "." */ | 293 | |
| 273 | memcpy (body + deh_location( &(deh[0]) ), ".", 1); | 294 | /* copy ".." and "." */ |
| 274 | memcpy (body + deh_location( &(deh[1]) ), "..", 2); | 295 | memcpy(body + deh_location(&(deh[0])), ".", 1); |
| 296 | memcpy(body + deh_location(&(deh[1])), "..", 2); | ||
| 275 | } | 297 | } |
