/* The function is NOT SCHEDULE-SAFE! */ int search_by_entry_key(struct super_block *sb, const struct cpu_key *key, struct treepath *path, struct reiserfs_dir_entry *de) { int retval; retval = search_item(sb, key, path); switch (retval) { case ITEM_NOT_FOUND: if (!PATH_LAST_POSITION(path)) { reiserfs_error(sb, "vs-7000", "search_by_key " "returned item position == 0"); pathrelse(path); return IO_ERROR; } PATH_LAST_POSITION(path)--; case ITEM_FOUND: break; case IO_ERROR: return retval; default: pathrelse(path); reiserfs_error(sb, "vs-7002", "no path to here"); return IO_ERROR; } set_de_item_location(de, path); #ifdef CONFIG_REISERFS_CHECK if (!is_direntry_le_ih(de->de_ih) || COMP_SHORT_KEYS(&de->de_ih->ih_key, key)) { print_block(de->de_bh, 0, -1, -1); reiserfs_panic(sb, "vs-7005", "found item %h is not directory " "item or does not belong to the same directory " "as key %K", de->de_ih, key); } #endif /* CONFIG_REISERFS_CHECK */ /* * binary search in directory item by third component of the * key. sets de->de_entry_num of de */ retval = bin_search_in_dir_item(de, cpu_key_k_offset(key)); path->pos_in_item = de->de_entry_num; if (retval != NAME_NOT_FOUND) { /* * ugly, but rename needs de_bh, de_deh, de_name, * de_namelen, de_objectid set */ set_de_name_and_namelen(de); set_de_object_key(de); } return retval; }
/* * We assign a key to each directory item, and place multiple entries in * a single directory item. A directory item has a key equal to the key * of the first directory entry in it. * * This function first calls search_by_key, then, if item whose first * entry matches is not found it looks for the entry inside directory * item found by search_by_key. Fills the path to the entry, and to the * entry position in the item */ int search_by_entry_key(struct reiserfs_sb_info *sbi, const struct cpu_key *key, struct path *path, struct reiserfs_dir_entry *de) { int retval; reiserfs_log(LOG_DEBUG, "searching in (objectid=%d,dirid=%d)\n", key->on_disk_key.k_objectid, key->on_disk_key.k_dir_id); retval = search_item(sbi, key, path); switch (retval) { case ITEM_NOT_FOUND: if (!PATH_LAST_POSITION(path)) { reiserfs_log(LOG_DEBUG, "search_by_key returned item position == 0"); pathrelse(path); return (IO_ERROR); } PATH_LAST_POSITION(path)--; reiserfs_log(LOG_DEBUG, "search_by_key did not found it\n"); break; case ITEM_FOUND: reiserfs_log(LOG_DEBUG, "search_by_key found it\n"); break; case IO_ERROR: return (retval); default: pathrelse(path); reiserfs_log(LOG_DEBUG, "no path to here"); return (IO_ERROR); } reiserfs_log(LOG_DEBUG, "set item location\n"); set_de_item_location(de, path); /* * Binary search in directory item by third component of the * key. Sets de->de_entry_num of de */ reiserfs_log(LOG_DEBUG, "bin_search_in_dir_item\n"); retval = bin_search_in_dir_item(de, cpu_key_k_offset(key)); path->pos_in_item = de->de_entry_num; if (retval != NAME_NOT_FOUND) { /* * Ugly, but rename needs de_bp, de_deh, de_name, de_namelen, * de_objectid set */ set_de_name_and_namelen(de); set_de_object_key(de); reiserfs_log(LOG_DEBUG, "set (objectid=%d,dirid=%d)\n", de->de_objectid, de->de_dir_id); } return (retval); }