namei.c (57fe60df62410f949da094d06ced1dda9575b69c) namei.c (0222e6571c332563a48d4cf5487b67feabe60b5e)
1/*
2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
3 *
4 * Trivial changes by Alan Cox to remove EHASHCOLLISION for compatibility
5 *
6 * Trivial Changes:
7 * Rights granted to Hans Reiser to redistribute under other terms providing
8 * he accepts all liability including but not limited to patent, fitness

--- 92 unchanged lines hidden (view full) ---

101
102/* We assign a key to each directory item, and place multiple entries
103in a single directory item. A directory item has a key equal to the
104key of the first directory entry in it.
105
106This function first calls search_by_key, then, if item whose first
107entry matches is not found it looks for the entry inside directory
108item found by search_by_key. Fills the path to the entry, and to the
1/*
2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
3 *
4 * Trivial changes by Alan Cox to remove EHASHCOLLISION for compatibility
5 *
6 * Trivial Changes:
7 * Rights granted to Hans Reiser to redistribute under other terms providing
8 * he accepts all liability including but not limited to patent, fitness

--- 92 unchanged lines hidden (view full) ---

101
102/* We assign a key to each directory item, and place multiple entries
103in a single directory item. A directory item has a key equal to the
104key of the first directory entry in it.
105
106This function first calls search_by_key, then, if item whose first
107entry matches is not found it looks for the entry inside directory
108item found by search_by_key. Fills the path to the entry, and to the
109entry position in the item
109entry position in the item
110
111*/
112
113/* The function is NOT SCHEDULE-SAFE! */
114int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
115 struct treepath *path, struct reiserfs_dir_entry *de)
116{
117 int retval;

--- 248 unchanged lines hidden (view full) ---

366 reiserfs_write_unlock(dir->i_sb);
367 if (retval == IO_ERROR) {
368 return ERR_PTR(-EIO);
369 }
370
371 return d_splice_alias(inode, dentry);
372}
373
110
111*/
112
113/* The function is NOT SCHEDULE-SAFE! */
114int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
115 struct treepath *path, struct reiserfs_dir_entry *de)
116{
117 int retval;

--- 248 unchanged lines hidden (view full) ---

366 reiserfs_write_unlock(dir->i_sb);
367 if (retval == IO_ERROR) {
368 return ERR_PTR(-EIO);
369 }
370
371 return d_splice_alias(inode, dentry);
372}
373
374/*
374/*
375** looks up the dentry of the parent directory for child.
376** taken from ext2_get_parent
377*/
378struct dentry *reiserfs_get_parent(struct dentry *child)
379{
380 int retval;
381 struct inode *inode = NULL;
382 struct reiserfs_dir_entry de;

--- 13 unchanged lines hidden (view full) ---

396 return ERR_PTR(-ENOENT);
397 }
398 inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
399 reiserfs_write_unlock(dir->i_sb);
400
401 return d_obtain_alias(inode);
402}
403
375** looks up the dentry of the parent directory for child.
376** taken from ext2_get_parent
377*/
378struct dentry *reiserfs_get_parent(struct dentry *child)
379{
380 int retval;
381 struct inode *inode = NULL;
382 struct reiserfs_dir_entry de;

--- 13 unchanged lines hidden (view full) ---

396 return ERR_PTR(-ENOENT);
397 }
398 inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
399 reiserfs_write_unlock(dir->i_sb);
400
401 return d_obtain_alias(inode);
402}
403
404/* add entry to the directory (entry can be hidden).
404/* add entry to the directory (entry can be hidden).
405
406insert definition of when hidden directories are used here -Hans
407
408 Does not mark dir inode dirty, do it after successesfull call to it */
409
410static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
411 struct inode *dir, const char *name, int namelen,
412 struct inode *inode, int visible)

--- 141 unchanged lines hidden (view full) ---

554{
555 DQUOT_DROP(inode);
556 make_bad_inode(inode);
557 inode->i_flags |= S_NOQUOTA;
558 iput(inode);
559 return 0;
560}
561
405
406insert definition of when hidden directories are used here -Hans
407
408 Does not mark dir inode dirty, do it after successesfull call to it */
409
410static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
411 struct inode *dir, const char *name, int namelen,
412 struct inode *inode, int visible)

--- 141 unchanged lines hidden (view full) ---

554{
555 DQUOT_DROP(inode);
556 make_bad_inode(inode);
557 inode->i_flags |= S_NOQUOTA;
558 iput(inode);
559 return 0;
560}
561
562/* utility function that does setup for reiserfs_new_inode.
562/* utility function that does setup for reiserfs_new_inode.
563** DQUOT_INIT needs lots of credits so it's better to have it
564** outside of a transaction, so we had to pull some bits of
565** reiserfs_new_inode out into this func.
566*/
567static int new_inode_init(struct inode *inode, struct inode *dir, int mode)
568{
569
570 /* the quota init calls have to know who to charge the quota to, so

--- 244 unchanged lines hidden (view full) ---

815 reiserfs_write_unlock(dir->i_sb);
816 return retval;
817}
818
819static inline int reiserfs_empty_dir(struct inode *inode)
820{
821 /* we can cheat because an old format dir cannot have
822 ** EMPTY_DIR_SIZE, and a new format dir cannot have
563** DQUOT_INIT needs lots of credits so it's better to have it
564** outside of a transaction, so we had to pull some bits of
565** reiserfs_new_inode out into this func.
566*/
567static int new_inode_init(struct inode *inode, struct inode *dir, int mode)
568{
569
570 /* the quota init calls have to know who to charge the quota to, so

--- 244 unchanged lines hidden (view full) ---

815 reiserfs_write_unlock(dir->i_sb);
816 return retval;
817}
818
819static inline int reiserfs_empty_dir(struct inode *inode)
820{
821 /* we can cheat because an old format dir cannot have
822 ** EMPTY_DIR_SIZE, and a new format dir cannot have
823 ** EMPTY_DIR_SIZE_V1. So, if the inode is either size,
823 ** EMPTY_DIR_SIZE_V1. So, if the inode is either size,
824 ** regardless of disk format version, the directory is empty.
825 */
826 if (inode->i_size != EMPTY_DIR_SIZE &&
827 inode->i_size != EMPTY_DIR_SIZE_V1) {
828 return 0;
829 }
830 return 1;
831}

--- 325 unchanged lines hidden (view full) ---

1157
1158 atomic_inc(&inode->i_count);
1159 d_instantiate(dentry, inode);
1160 retval = journal_end(&th, dir->i_sb, jbegin_count);
1161 reiserfs_write_unlock(dir->i_sb);
1162 return retval;
1163}
1164
824 ** regardless of disk format version, the directory is empty.
825 */
826 if (inode->i_size != EMPTY_DIR_SIZE &&
827 inode->i_size != EMPTY_DIR_SIZE_V1) {
828 return 0;
829 }
830 return 1;
831}

--- 325 unchanged lines hidden (view full) ---

1157
1158 atomic_inc(&inode->i_count);
1159 d_instantiate(dentry, inode);
1160 retval = journal_end(&th, dir->i_sb, jbegin_count);
1161 reiserfs_write_unlock(dir->i_sb);
1162 return retval;
1163}
1164
1165// de contains information pointing to an entry which
1165/* de contains information pointing to an entry which */
1166static int de_still_valid(const char *name, int len,
1167 struct reiserfs_dir_entry *de)
1168{
1169 struct reiserfs_dir_entry tmp = *de;
1170
1171 // recalculate pointer to name and name length
1172 set_de_name_and_namelen(&tmp);
1173 // FIXME: could check more

--- 27 unchanged lines hidden (view full) ---

1201static void set_ino_in_dir_entry(struct reiserfs_dir_entry *de,
1202 struct reiserfs_key *key)
1203{
1204 /* JDM These operations are endian safe - both are le */
1205 de->de_deh[de->de_entry_num].deh_dir_id = key->k_dir_id;
1206 de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid;
1207}
1208
1166static int de_still_valid(const char *name, int len,
1167 struct reiserfs_dir_entry *de)
1168{
1169 struct reiserfs_dir_entry tmp = *de;
1170
1171 // recalculate pointer to name and name length
1172 set_de_name_and_namelen(&tmp);
1173 // FIXME: could check more

--- 27 unchanged lines hidden (view full) ---

1201static void set_ino_in_dir_entry(struct reiserfs_dir_entry *de,
1202 struct reiserfs_key *key)
1203{
1204 /* JDM These operations are endian safe - both are le */
1205 de->de_deh[de->de_entry_num].deh_dir_id = key->k_dir_id;
1206 de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid;
1207}
1208
1209/*
1209/*
1210 * process, that is going to call fix_nodes/do_balance must hold only
1211 * one path. If it holds 2 or more, it can get into endless waiting in
1210 * process, that is going to call fix_nodes/do_balance must hold only
1211 * one path. If it holds 2 or more, it can get into endless waiting in
1212 * get_empty_nodes or its clones
1212 * get_empty_nodes or its clones
1213 */
1214static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1215 struct inode *new_dir, struct dentry *new_dentry)
1216{
1217 int retval;
1218 INITIALIZE_PATH(old_entry_path);
1219 INITIALIZE_PATH(new_entry_path);
1220 INITIALIZE_PATH(dot_dot_entry_path);

--- 37 unchanged lines hidden (view full) ---

1258
1259 if (retval != NAME_FOUND || old_de.de_objectid != old_inode->i_ino) {
1260 reiserfs_write_unlock(old_dir->i_sb);
1261 return -ENOENT;
1262 }
1263
1264 old_inode_mode = old_inode->i_mode;
1265 if (S_ISDIR(old_inode_mode)) {
1213 */
1214static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1215 struct inode *new_dir, struct dentry *new_dentry)
1216{
1217 int retval;
1218 INITIALIZE_PATH(old_entry_path);
1219 INITIALIZE_PATH(new_entry_path);
1220 INITIALIZE_PATH(dot_dot_entry_path);

--- 37 unchanged lines hidden (view full) ---

1258
1259 if (retval != NAME_FOUND || old_de.de_objectid != old_inode->i_ino) {
1260 reiserfs_write_unlock(old_dir->i_sb);
1261 return -ENOENT;
1262 }
1263
1264 old_inode_mode = old_inode->i_mode;
1265 if (S_ISDIR(old_inode_mode)) {
1266 // make sure, that directory being renamed has correct ".."
1266 // make sure, that directory being renamed has correct ".."
1267 // and that its new parent directory has not too many links
1268 // already
1269
1270 if (new_dentry_inode) {
1271 if (!reiserfs_empty_dir(new_dentry_inode)) {
1272 reiserfs_write_unlock(old_dir->i_sb);
1273 return -ENOTEMPTY;
1274 }
1275 }
1276
1267 // and that its new parent directory has not too many links
1268 // already
1269
1270 if (new_dentry_inode) {
1271 if (!reiserfs_empty_dir(new_dentry_inode)) {
1272 reiserfs_write_unlock(old_dir->i_sb);
1273 return -ENOTEMPTY;
1274 }
1275 }
1276
1277 /* directory is renamed, its parent directory will be changed,
1278 ** so find ".." entry
1277 /* directory is renamed, its parent directory will be changed,
1278 ** so find ".." entry
1279 */
1280 dot_dot_de.de_gen_number_bit_string = NULL;
1281 retval =
1282 reiserfs_find_entry(old_inode, "..", 2, &dot_dot_entry_path,
1283 &dot_dot_de);
1284 pathrelse(&dot_dot_entry_path);
1285 if (retval != NAME_FOUND) {
1286 reiserfs_write_unlock(old_dir->i_sb);

--- 93 unchanged lines hidden (view full) ---

1380 // node containing ".." gets into transaction
1381 reiserfs_prepare_for_journal(old_inode->i_sb,
1382 dot_dot_de.de_bh, 1);
1383 }
1384 /* we should check seals here, not do
1385 this stuff, yes? Then, having
1386 gathered everything into RAM we
1387 should lock the buffers, yes? -Hans */
1279 */
1280 dot_dot_de.de_gen_number_bit_string = NULL;
1281 retval =
1282 reiserfs_find_entry(old_inode, "..", 2, &dot_dot_entry_path,
1283 &dot_dot_de);
1284 pathrelse(&dot_dot_entry_path);
1285 if (retval != NAME_FOUND) {
1286 reiserfs_write_unlock(old_dir->i_sb);

--- 93 unchanged lines hidden (view full) ---

1380 // node containing ".." gets into transaction
1381 reiserfs_prepare_for_journal(old_inode->i_sb,
1382 dot_dot_de.de_bh, 1);
1383 }
1384 /* we should check seals here, not do
1385 this stuff, yes? Then, having
1386 gathered everything into RAM we
1387 should lock the buffers, yes? -Hans */
1388 /* probably. our rename needs to hold more
1389 ** than one path at once. The seals would
1390 ** have to be written to deal with multi-path
1388 /* probably. our rename needs to hold more
1389 ** than one path at once. The seals would
1390 ** have to be written to deal with multi-path
1391 ** issues -chris
1392 */
1393 /* sanity checking before doing the rename - avoid races many
1394 ** of the above checks could have scheduled. We have to be
1395 ** sure our items haven't been shifted by another process.
1396 */
1397 if (item_moved(&new_entry_ih, &new_entry_path) ||
1398 !entry_points_to_object(new_dentry->d_name.name,

--- 61 unchanged lines hidden (view full) ---

1460 } else {
1461 drop_nlink(new_dentry_inode);
1462 }
1463 new_dentry_inode->i_ctime = ctime;
1464 savelink = new_dentry_inode->i_nlink;
1465 }
1466
1467 if (S_ISDIR(old_inode_mode)) {
1391 ** issues -chris
1392 */
1393 /* sanity checking before doing the rename - avoid races many
1394 ** of the above checks could have scheduled. We have to be
1395 ** sure our items haven't been shifted by another process.
1396 */
1397 if (item_moved(&new_entry_ih, &new_entry_path) ||
1398 !entry_points_to_object(new_dentry->d_name.name,

--- 61 unchanged lines hidden (view full) ---

1460 } else {
1461 drop_nlink(new_dentry_inode);
1462 }
1463 new_dentry_inode->i_ctime = ctime;
1464 savelink = new_dentry_inode->i_nlink;
1465 }
1466
1467 if (S_ISDIR(old_inode_mode)) {
1468 // adjust ".." of renamed directory
1468 /* adjust ".." of renamed directory */
1469 set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir));
1470 journal_mark_dirty(&th, new_dir->i_sb, dot_dot_de.de_bh);
1471
1472 if (!new_dentry_inode)
1473 /* there (in new_dir) was no directory, so it got new link
1474 (".." of renamed directory) */
1475 INC_DIR_INODE_NLINK(new_dir);
1476

--- 85 unchanged lines hidden ---
1469 set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir));
1470 journal_mark_dirty(&th, new_dir->i_sb, dot_dot_de.de_bh);
1471
1472 if (!new_dentry_inode)
1473 /* there (in new_dir) was no directory, so it got new link
1474 (".." of renamed directory) */
1475 INC_DIR_INODE_NLINK(new_dir);
1476

--- 85 unchanged lines hidden ---