14 #include <linux/time.h>
15 #include <linux/bitops.h>
16 #include <linux/slab.h>
22 #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) set_nlink(i, 1); }
23 #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
31 int rbound, lbound,
j;
36 for (j = (rbound + lbound) / 2; lbound <= rbound;
37 j = (rbound + lbound) / 2) {
125 "returned item position == 0");
143 set_de_item_location(de, path);
145 #ifdef CONFIG_REISERFS_CHECK
146 if (!is_direntry_le_ih(de->
de_ih) ||
150 "item or does not belong to the same directory "
151 "as key %K", de->
de_ih, key);
157 retval = bin_search_in_dir_item(de, cpu_key_k_offset(key));
162 set_de_object_key(de);
175 const char *
name,
int len)
179 if (!len || (len == 1 && name[0] ==
'.'))
181 if (len == 2 && name[0] ==
'.' && name[1] ==
'.')
184 res = REISERFS_SB(s)->s_hash_function(name, len);
213 static int linear_search_in_dir_item(
struct cpu_key *
key,
215 const char *name,
int namelen)
230 "vs-7010: array of entry headers not found");
234 for (; i >= 0; i--, deh--) {
255 set_de_object_key(de);
257 store_de_entry_key(de);
275 "vs-7015: two diritems of the same directory in one node?");
282 static int reiserfs_find_entry(
struct inode *dir,
const char *name,
int namelen,
294 get_third_component(dir->
i_sb, name, namelen),
308 linear_search_in_dir_item(&key_to_search, de, name,
317 set_cpu_key_k_offset(&key_to_search,
318 le_ih_k_offset(de->
de_ih) - 1);
345 reiserfs_find_entry(dir, dentry->
d_name.name, dentry->
d_name.len,
346 &path_to_entry, &de);
351 if (!inode || IS_ERR(inode)) {
363 return ERR_PTR(-
EIO);
376 struct inode *inode =
NULL;
379 struct inode *dir = child->
d_inode;
387 retval = reiserfs_find_entry(dir,
"..", 2, &path_to_entry, &de);
406 struct inode *dir,
const char *name,
int namelen,
407 struct inode *inode,
int visible)
432 get_third_component(dir->
i_sb, name, namelen),
437 if (buflen >
sizeof(small_buf)) {
458 memcpy((
char *)(deh + 1), name, namelen);
467 memset(bit_string, 0,
sizeof(bit_string));
469 retval = reiserfs_find_entry(dir, name, namelen, &
path, &de);
471 if (buffer != small_buf)
481 "reiserfs_find_entry() returned "
482 "unexpected value (%d)", retval);
494 "Congratulations! we have got hash function "
496 if (buffer != small_buf)
503 set_cpu_key_k_offset(&entry_key,
deh_offset(deh));
508 if (gen_number != 0) {
512 "entry with this key (%K) already "
513 "exists", &entry_key);
515 if (buffer != small_buf)
526 if (buffer != small_buf)
533 dir->
i_size += paste_size;
537 reiserfs_update_sd(th, dir);
548 static int drop_new_inode(
struct inode *inode)
562 static int new_inode_init(
struct inode *inode,
struct inode *dir,
umode_t mode)
575 static int reiserfs_create(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
593 new_inode_init(inode, dir, mode);
598 drop_new_inode(inode);
606 drop_new_inode(inode);
621 reiserfs_add_entry(&th, dir, dentry->
d_name.name,
622 dentry->
d_name.len, inode, 1 );
626 reiserfs_update_sd(&th, inode);
646 static int reiserfs_mknod(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
659 if (!new_valid_dev(rdev))
667 new_inode_init(inode, dir, mode);
672 drop_new_inode(inode);
680 drop_new_inode(inode);
695 reiserfs_update_sd(&th, inode);
701 reiserfs_add_entry(&th, dir, dentry->
d_name.name,
702 dentry->
d_name.len, inode, 1 );
706 reiserfs_update_sd(&th, inode);
724 static int reiserfs_mkdir(
struct inode *dir,
struct dentry *dentry,
umode_t mode)
739 #ifdef DISPLACE_NEW_PACKING_LOCALITIES
741 REISERFS_I(dir)->new_packing_locality = 1;
747 new_inode_init(inode, dir, mode);
752 drop_new_inode(inode);
760 drop_new_inode(inode);
786 reiserfs_add_entry(&th, dir, dentry->d_name.name,
787 dentry->d_name.len, inode, 1 );
792 reiserfs_update_sd(&th, inode);
801 reiserfs_update_sd(&th, dir);
805 retval =
journal_end(&th, dir->i_sb, jbegin_count);
811 static inline int reiserfs_empty_dir(
struct inode *inode)
818 if (inode->
i_size != EMPTY_DIR_SIZE &&
825 static int reiserfs_rmdir(
struct inode *dir,
struct dentry *dentry)
851 reiserfs_find_entry(dir, dentry->
d_name.name, dentry->
d_name.len,
871 if (!reiserfs_empty_dir(inode)) {
884 "empty directory has nlink != 2 (%d)",
889 reiserfs_update_sd(&th, inode);
893 reiserfs_update_sd(&th, dir);
898 retval =
journal_end(&th, dir->i_sb, jbegin_count);
911 return err ? err : retval;
914 static
int reiserfs_unlink(
struct inode *dir,
struct dentry *dentry)
922 unsigned long savelink;
927 inode = dentry->d_inode;
944 reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
965 "deleting nonexistent file (%lu), %d",
986 reiserfs_update_sd(&th, inode);
990 reiserfs_update_sd(&th, dir);
996 retval =
journal_end(&th, dir->i_sb, jbegin_count);
1012 static int reiserfs_symlink(
struct inode *parent_dir,
1013 struct dentry *dentry,
const char *symname)
1016 struct inode *
inode;
1033 new_inode_init(inode, parent_dir, mode);
1038 drop_new_inode(inode);
1047 drop_new_inode(inode);
1053 drop_new_inode(inode);
1062 drop_new_inode(inode);
1069 dentry, inode, &security);
1085 retval = reiserfs_add_entry(&th, parent_dir, dentry->
d_name.name,
1086 dentry->
d_name.len, inode, 1 );
1090 reiserfs_update_sd(&th, inode);
1107 static int reiserfs_link(
struct dentry *old_dentry,
struct inode *dir,
1108 struct dentry *dentry)
1111 struct inode *inode = old_dentry->
d_inode;
1139 reiserfs_add_entry(&th, dir, dentry->
d_name.name,
1140 dentry->
d_name.len, inode, 1 );
1150 return err ? err :
retval;
1154 reiserfs_update_sd(&th, inode);
1164 static int de_still_valid(
const char *name,
int len,
1177 static int entry_points_to_object(
const char *name,
int len,
1179 struct inode *inode)
1181 if (!de_still_valid(name, len, de))
1187 "entry must be visible");
1212 static int reiserfs_rename(
struct inode *old_dir,
struct dentry *old_dentry,
1213 struct inode *new_dir,
struct dentry *new_dentry)
1219 struct item_head new_entry_ih, old_entry_ih, dot_dot_ih;
1221 struct inode *old_inode, *new_dentry_inode;
1225 unsigned long savelink = 1;
1243 old_inode = old_dentry->
d_inode;
1244 new_dentry_inode = new_dentry->
d_inode;
1248 old_de.de_gen_number_bit_string =
NULL;
1251 reiserfs_find_entry(old_dir, old_dentry->
d_name.name,
1252 old_dentry->
d_name.len, &old_entry_path,
1265 old_inode_mode = old_inode->
i_mode;
1266 if (
S_ISDIR(old_inode_mode)) {
1271 if (new_dentry_inode) {
1272 if (!reiserfs_empty_dir(new_dentry_inode)) {
1281 dot_dot_de.de_gen_number_bit_string =
NULL;
1283 reiserfs_find_entry(old_inode,
"..", 2, &dot_dot_entry_path,
1292 if (dot_dot_de.de_objectid != old_dir->
i_ino) {
1306 reiserfs_add_entry(&th, new_dir, new_dentry->
d_name.name,
1307 new_dentry->
d_name.len, old_inode, 0);
1309 if (!new_dentry_inode) {
1311 "new entry is found, new inode == 0");
1313 }
else if (retval) {
1316 return err ? err :
retval;
1327 if (new_dentry_inode)
1347 new_de.de_gen_number_bit_string =
NULL;
1349 reiserfs_find_entry(new_dir, new_dentry->
d_name.name,
1350 new_dentry->
d_name.len, &new_entry_path,
1369 &dot_dot_de.de_entry_key,
1370 &dot_dot_entry_path,
1380 get_ih(&dot_dot_entry_path));
1383 dot_dot_de.de_bh, 1);
1398 if (
item_moved(&new_entry_ih, &new_entry_path) ||
1399 !entry_points_to_object(new_dentry->
d_name.name,
1401 &new_de, new_dentry_inode) ||
1402 item_moved(&old_entry_ih, &old_entry_path) ||
1403 !entry_points_to_object(old_dentry->
d_name.name,
1405 &old_de, old_inode)) {
1417 if (
S_ISDIR(old_inode_mode)) {
1418 if (
item_moved(&dot_dot_ih, &dot_dot_entry_path) ||
1419 !entry_points_to_object(
"..", 2, &dot_dot_de,
1436 !buffer_journal_prepared(dot_dot_de.de_bh),
"");
1445 set_ino_in_dir_entry(&new_de,
INODE_PKEY(old_inode));
1457 if (new_dentry_inode) {
1465 savelink = new_dentry_inode->
i_nlink;
1468 if (
S_ISDIR(old_inode_mode)) {
1470 set_ino_in_dir_entry(&dot_dot_de,
INODE_PKEY(new_dir));
1473 if (!new_dentry_inode)
1489 (&th, &old_entry_path, &(old_de.de_entry_key), old_dir, NULL,
1492 "couldn't not cut old name. Fsck later?");
1496 reiserfs_update_sd(&th, old_dir);
1497 reiserfs_update_sd(&th, new_dir);
1498 reiserfs_update_sd(&th, old_inode);
1500 if (new_dentry_inode) {
1504 reiserfs_update_sd(&th, new_dentry_inode);
1517 .create = reiserfs_create,
1518 .lookup = reiserfs_lookup,
1519 .link = reiserfs_link,
1520 .unlink = reiserfs_unlink,
1521 .symlink = reiserfs_symlink,
1522 .mkdir = reiserfs_mkdir,
1523 .rmdir = reiserfs_rmdir,
1524 .mknod = reiserfs_mknod,
1525 .rename = reiserfs_rename,