2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
|
|
|
*
|
|
|
|
* Trivial changes by Alan Cox to remove EHASHCOLLISION for compatibility
|
|
|
|
*
|
|
|
|
* Trivial Changes:
|
|
|
|
* Rights granted to Hans Reiser to redistribute under other terms providing
|
|
|
|
* he accepts all liability including but not limited to patent, fitness
|
|
|
|
* for purpose, and direct or indirect claims arising from failure to perform.
|
|
|
|
*
|
|
|
|
* NO WARRANTY
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/bitops.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2012-03-17 09:16:43 +04:00
|
|
|
#include "reiserfs.h"
|
2012-03-17 09:03:10 +04:00
|
|
|
#include "acl.h"
|
2012-03-17 08:59:06 +04:00
|
|
|
#include "xattr.h"
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/quotaops.h>
|
|
|
|
|
2011-10-28 16:13:29 +04:00
|
|
|
#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); }
|
2006-10-01 10:29:03 +04:00
|
|
|
#define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* directory item contains array of entry headers. This performs
|
|
|
|
* binary search through that array
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
static int bin_search_in_dir_item(struct reiserfs_dir_entry *de, loff_t off)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
struct item_head *ih = de->de_ih;
|
|
|
|
struct reiserfs_de_head *deh = de->de_deh;
|
|
|
|
int rbound, lbound, j;
|
|
|
|
|
|
|
|
lbound = 0;
|
2014-04-23 18:00:35 +04:00
|
|
|
rbound = ih_entry_count(ih) - 1;
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
for (j = (rbound + lbound) / 2; lbound <= rbound;
|
|
|
|
j = (rbound + lbound) / 2) {
|
|
|
|
if (off < deh_offset(deh + j)) {
|
|
|
|
rbound = j - 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (off > deh_offset(deh + j)) {
|
|
|
|
lbound = j + 1;
|
|
|
|
continue;
|
|
|
|
}
|
2014-04-23 18:00:36 +04:00
|
|
|
/* this is not name found, but matched third key component */
|
2005-07-13 07:21:28 +04:00
|
|
|
de->de_entry_num = j;
|
|
|
|
return NAME_FOUND;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
de->de_entry_num = lbound;
|
|
|
|
return NAME_NOT_FOUND;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* comment? maybe something like set de to point to what the path points to?
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
static inline void set_de_item_location(struct reiserfs_dir_entry *de,
|
2006-12-08 13:36:32 +03:00
|
|
|
struct treepath *path)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
de->de_bh = get_last_bh(path);
|
2014-04-23 18:00:35 +04:00
|
|
|
de->de_ih = tp_item_head(path);
|
2005-07-13 07:21:28 +04:00
|
|
|
de->de_deh = B_I_DEH(de->de_bh, de->de_ih);
|
|
|
|
de->de_item_num = PATH_LAST_POSITION(path);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* de_bh, de_ih, de_deh (points to first element of array), de_item_num is set
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-10-04 01:36:38 +04:00
|
|
|
BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
de->de_entrylen = entry_length(de->de_bh, de->de_ih, de->de_entry_num);
|
|
|
|
de->de_namelen = de->de_entrylen - (de_with_sd(deh) ? SD_SIZE : 0);
|
2014-04-23 18:00:35 +04:00
|
|
|
de->de_name = ih_item_body(de->de_bh, de->de_ih) + deh_location(deh);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (de->de_name[de->de_namelen - 1] == 0)
|
|
|
|
de->de_namelen = strlen(de->de_name);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* what entry points to */
|
2005-07-13 07:21:28 +04:00
|
|
|
static inline void set_de_object_key(struct reiserfs_dir_entry *de)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2006-10-04 01:36:38 +04:00
|
|
|
BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
|
2014-04-23 18:00:42 +04:00
|
|
|
de->de_dir_id = deh_dir_id(&de->de_deh[de->de_entry_num]);
|
|
|
|
de->de_objectid = deh_objectid(&de->de_deh[de->de_entry_num]);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static inline void store_de_entry_key(struct reiserfs_dir_entry *de)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
|
|
|
|
|
2006-10-04 01:36:38 +04:00
|
|
|
BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
/* store key of the found entry */
|
|
|
|
de->de_entry_key.version = KEY_FORMAT_3_5;
|
|
|
|
de->de_entry_key.on_disk_key.k_dir_id =
|
|
|
|
le32_to_cpu(de->de_ih->ih_key.k_dir_id);
|
|
|
|
de->de_entry_key.on_disk_key.k_objectid =
|
|
|
|
le32_to_cpu(de->de_ih->ih_key.k_objectid);
|
2014-04-23 18:00:42 +04:00
|
|
|
set_cpu_key_k_offset(&de->de_entry_key, deh_offset(deh));
|
|
|
|
set_cpu_key_k_type(&de->de_entry_key, TYPE_DIRENTRY);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
/* The function is NOT SCHEDULE-SAFE! */
|
2005-07-13 07:21:28 +04:00
|
|
|
int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
|
2006-12-08 13:36:32 +03:00
|
|
|
struct treepath *path, struct reiserfs_dir_entry *de)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = search_item(sb, key, path);
|
|
|
|
switch (retval) {
|
|
|
|
case ITEM_NOT_FOUND:
|
|
|
|
if (!PATH_LAST_POSITION(path)) {
|
2009-03-30 22:02:28 +04:00
|
|
|
reiserfs_error(sb, "vs-7000", "search_by_key "
|
|
|
|
"returned item position == 0");
|
2005-07-13 07:21:28 +04:00
|
|
|
pathrelse(path);
|
|
|
|
return IO_ERROR;
|
|
|
|
}
|
|
|
|
PATH_LAST_POSITION(path)--;
|
|
|
|
|
|
|
|
case ITEM_FOUND:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IO_ERROR:
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
default:
|
|
|
|
pathrelse(path);
|
2009-03-30 22:02:28 +04:00
|
|
|
reiserfs_error(sb, "vs-7002", "no path to here");
|
2005-07-13 07:21:28 +04:00
|
|
|
return IO_ERROR;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
set_de_item_location(de, path);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_REISERFS_CHECK
|
2005-07-13 07:21:28 +04:00
|
|
|
if (!is_direntry_le_ih(de->de_ih) ||
|
2014-04-23 18:00:42 +04:00
|
|
|
COMP_SHORT_KEYS(&de->de_ih->ih_key, key)) {
|
2005-07-13 07:21:28 +04:00
|
|
|
print_block(de->de_bh, 0, -1, -1);
|
2009-03-30 22:02:25 +04:00
|
|
|
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);
|
2005-07-13 07:21:28 +04:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_REISERFS_CHECK */
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* binary search in directory item by third component of the
|
|
|
|
* key. sets de->de_entry_num of de
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
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) {
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* ugly, but rename needs de_bh, de_deh, de_name,
|
|
|
|
* de_namelen, de_objectid set
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
set_de_name_and_namelen(de);
|
|
|
|
set_de_object_key(de);
|
|
|
|
}
|
|
|
|
return retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Keyed 32-bit hash function using TEA in a Davis-Meyer function */
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* The third component is hashed, and you can choose from more than
|
|
|
|
* one hash function. Per directory hashes are not yet implemented
|
|
|
|
* but are thought about. This function should be moved to hashes.c
|
|
|
|
* Jedi, please do so. -Hans
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
static __u32 get_third_component(struct super_block *s,
|
|
|
|
const char *name, int len)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
__u32 res;
|
|
|
|
|
|
|
|
if (!len || (len == 1 && name[0] == '.'))
|
|
|
|
return DOT_OFFSET;
|
|
|
|
if (len == 2 && name[0] == '.' && name[1] == '.')
|
|
|
|
return DOT_DOT_OFFSET;
|
|
|
|
|
|
|
|
res = REISERFS_SB(s)->s_hash_function(name, len);
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* take bits from 7-th to 30-th including both bounds */
|
2005-07-13 07:21:28 +04:00
|
|
|
res = GET_HASH_VALUE(res);
|
|
|
|
if (res == 0)
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* needed to have no names before "." and ".." those have hash
|
|
|
|
* value == 0 and generation conters 1 and 2 accordingly
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
res = 128;
|
|
|
|
return res + MAX_GENERATION_NUMBER;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static int reiserfs_match(struct reiserfs_dir_entry *de,
|
|
|
|
const char *name, int namelen)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval = NAME_NOT_FOUND;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
if ((namelen == de->de_namelen) &&
|
|
|
|
!memcmp(de->de_name, name, de->de_namelen))
|
|
|
|
retval =
|
|
|
|
(de_visible(de->de_deh + de->de_entry_num) ? NAME_FOUND :
|
|
|
|
NAME_FOUND_INVISIBLE);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
return retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* de's de_bh, de_ih, de_deh, de_item_num, de_entry_num are set already */
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* used when hash collisions exist */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static int linear_search_in_dir_item(struct cpu_key *key,
|
|
|
|
struct reiserfs_dir_entry *de,
|
|
|
|
const char *name, int namelen)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
struct reiserfs_de_head *deh = de->de_deh;
|
|
|
|
int retval;
|
|
|
|
int i;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
i = de->de_entry_num;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:35 +04:00
|
|
|
if (i == ih_entry_count(de->de_ih) ||
|
2005-07-13 07:21:28 +04:00
|
|
|
GET_HASH_VALUE(deh_offset(deh + i)) !=
|
|
|
|
GET_HASH_VALUE(cpu_key_k_offset(key))) {
|
|
|
|
i--;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
RFALSE(de->de_deh != B_I_DEH(de->de_bh, de->de_ih),
|
|
|
|
"vs-7010: array of entry headers not found");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
deh += i;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
for (; i >= 0; i--, deh--) {
|
2014-04-23 18:00:36 +04:00
|
|
|
/* hash value does not match, no need to check whole name */
|
2005-07-13 07:21:28 +04:00
|
|
|
if (GET_HASH_VALUE(deh_offset(deh)) !=
|
|
|
|
GET_HASH_VALUE(cpu_key_k_offset(key))) {
|
|
|
|
return NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* mark that this generation number is used */
|
2005-07-13 07:21:28 +04:00
|
|
|
if (de->de_gen_number_bit_string)
|
|
|
|
set_bit(GET_GENERATION_NUMBER(deh_offset(deh)),
|
2006-03-02 21:25:26 +03:00
|
|
|
de->de_gen_number_bit_string);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* calculate pointer to name and namelen */
|
2005-07-13 07:21:28 +04:00
|
|
|
de->de_entry_num = i;
|
|
|
|
set_de_name_and_namelen(de);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* de's de_name, de_namelen, de_recordlen are set.
|
|
|
|
* Fill the rest.
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
if ((retval =
|
|
|
|
reiserfs_match(de, name, namelen)) != NAME_NOT_FOUND) {
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* key of pointed object */
|
2005-07-13 07:21:28 +04:00
|
|
|
set_de_object_key(de);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
store_de_entry_key(de);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* retval can be NAME_FOUND or NAME_FOUND_INVISIBLE */
|
2005-07-13 07:21:28 +04:00
|
|
|
return retval;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
if (GET_GENERATION_NUMBER(le_ih_k_offset(de->de_ih)) == 0)
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* we have reached left most entry in the node. In common we
|
|
|
|
* have to go to the left neighbor, but if generation counter
|
|
|
|
* is 0 already, we know for sure, that there is no name with
|
|
|
|
* the same hash value
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* FIXME: this work correctly only because hash value can not
|
|
|
|
* be 0. Btw, in case of Yura's hash it is probably possible,
|
|
|
|
* so, this is a bug
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
return NAME_NOT_FOUND;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
RFALSE(de->de_item_num,
|
|
|
|
"vs-7015: two diritems of the same directory in one node?");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
return GOTO_PREVIOUS_ITEM;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* may return NAME_FOUND, NAME_FOUND_INVISIBLE, NAME_NOT_FOUND
|
|
|
|
* FIXME: should add something like IOERROR
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
static int reiserfs_find_entry(struct inode *dir, const char *name, int namelen,
|
2006-12-08 13:36:32 +03:00
|
|
|
struct treepath *path_to_entry,
|
2005-07-13 07:21:28 +04:00
|
|
|
struct reiserfs_dir_entry *de)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
struct cpu_key key_to_search;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize))
|
|
|
|
return NAME_NOT_FOUND;
|
|
|
|
|
|
|
|
/* we will search for this key in the tree */
|
|
|
|
make_cpu_key(&key_to_search, dir,
|
|
|
|
get_third_component(dir->i_sb, name, namelen),
|
|
|
|
TYPE_DIRENTRY, 3);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
retval =
|
|
|
|
search_by_entry_key(dir->i_sb, &key_to_search,
|
|
|
|
path_to_entry, de);
|
|
|
|
if (retval == IO_ERROR) {
|
2009-03-30 22:02:28 +04:00
|
|
|
reiserfs_error(dir->i_sb, "zam-7001", "io error");
|
2005-07-13 07:21:28 +04:00
|
|
|
return IO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compare names for all entries having given hash value */
|
|
|
|
retval =
|
|
|
|
linear_search_in_dir_item(&key_to_search, de, name,
|
|
|
|
namelen);
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* there is no need to scan directory anymore.
|
|
|
|
* Given entry found or does not exist
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
if (retval != GOTO_PREVIOUS_ITEM) {
|
|
|
|
path_to_entry->pos_in_item = de->de_entry_num;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* there is left neighboring item of this directory
|
|
|
|
* and given entry can be there
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
set_cpu_key_k_offset(&key_to_search,
|
|
|
|
le_ih_k_offset(de->de_ih) - 1);
|
|
|
|
pathrelse(path_to_entry);
|
|
|
|
|
|
|
|
} /* while (1) */
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,
|
2012-06-11 01:13:09 +04:00
|
|
|
unsigned int flags)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval;
|
|
|
|
struct inode *inode = NULL;
|
|
|
|
struct reiserfs_dir_entry de;
|
|
|
|
INITIALIZE_PATH(path_to_entry);
|
|
|
|
|
|
|
|
if (REISERFS_MAX_NAME(dir->i_sb->s_blocksize) < dentry->d_name.len)
|
|
|
|
return ERR_PTR(-ENAMETOOLONG);
|
|
|
|
|
2013-08-09 01:34:46 +04:00
|
|
|
reiserfs_write_lock(dir->i_sb);
|
2009-05-08 03:05:06 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
de.de_gen_number_bit_string = NULL;
|
|
|
|
retval =
|
|
|
|
reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
|
|
|
|
&path_to_entry, &de);
|
|
|
|
pathrelse(&path_to_entry);
|
|
|
|
if (retval == NAME_FOUND) {
|
2009-05-05 23:30:17 +04:00
|
|
|
inode = reiserfs_iget(dir->i_sb,
|
2014-04-23 18:00:42 +04:00
|
|
|
(struct cpu_key *)&de.de_dir_id);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (!inode || IS_ERR(inode)) {
|
2013-08-09 01:34:46 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
2005-07-13 07:21:28 +04:00
|
|
|
return ERR_PTR(-EACCES);
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* Propagate the private flag so we know we're
|
|
|
|
* in the priv tree
|
|
|
|
*/
|
2009-03-30 22:02:32 +04:00
|
|
|
if (IS_PRIVATE(dir))
|
|
|
|
inode->i_flags |= S_PRIVATE;
|
2005-07-13 07:21:28 +04:00
|
|
|
}
|
2013-08-09 01:34:46 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (retval == IO_ERROR) {
|
|
|
|
return ERR_PTR(-EIO);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2006-01-15 00:21:09 +03:00
|
|
|
return d_splice_alias(inode, dentry);
|
2005-07-13 07:21:28 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-03-30 22:02:44 +04:00
|
|
|
/*
|
2014-04-23 18:00:36 +04:00
|
|
|
* looks up the dentry of the parent directory for child.
|
|
|
|
* taken from ext2_get_parent
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
struct dentry *reiserfs_get_parent(struct dentry *child)
|
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval;
|
|
|
|
struct inode *inode = NULL;
|
|
|
|
struct reiserfs_dir_entry de;
|
|
|
|
INITIALIZE_PATH(path_to_entry);
|
2015-03-18 01:25:59 +03:00
|
|
|
struct inode *dir = d_inode(child);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
if (dir->i_nlink == 0) {
|
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
}
|
|
|
|
de.de_gen_number_bit_string = NULL;
|
|
|
|
|
|
|
|
reiserfs_write_lock(dir->i_sb);
|
|
|
|
retval = reiserfs_find_entry(dir, "..", 2, &path_to_entry, &de);
|
|
|
|
pathrelse(&path_to_entry);
|
|
|
|
if (retval != NAME_FOUND) {
|
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
}
|
2014-04-23 18:00:42 +04:00
|
|
|
inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&de.de_dir_id);
|
2005-04-17 02:20:36 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
|
2008-08-11 17:49:04 +04:00
|
|
|
return d_obtain_alias(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-03-30 22:02:44 +04:00
|
|
|
/* add entry to the directory (entry can be hidden).
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
insert definition of when hidden directories are used here -Hans
|
|
|
|
|
|
|
|
Does not mark dir inode dirty, do it after successesfull call to it */
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
|
|
|
|
struct inode *dir, const char *name, int namelen,
|
|
|
|
struct inode *inode, int visible)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
struct cpu_key entry_key;
|
|
|
|
struct reiserfs_de_head *deh;
|
|
|
|
INITIALIZE_PATH(path);
|
|
|
|
struct reiserfs_dir_entry de;
|
2006-03-02 21:25:26 +03:00
|
|
|
DECLARE_BITMAP(bit_string, MAX_GENERATION_NUMBER + 1);
|
2005-07-13 07:21:28 +04:00
|
|
|
int gen_number;
|
2014-04-23 18:00:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 48 bytes now and we avoid kmalloc if we
|
|
|
|
* create file with short name
|
|
|
|
*/
|
|
|
|
char small_buf[32 + DEH_SIZE];
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
char *buffer;
|
|
|
|
int buflen, paste_size;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
BUG_ON(!th->t_trans_id);
|
|
|
|
|
|
|
|
/* cannot allow items to be added into a busy deleted directory */
|
|
|
|
if (!namelen)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize))
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
|
|
|
/* each entry has unique key. compose it */
|
|
|
|
make_cpu_key(&entry_key, dir,
|
|
|
|
get_third_component(dir->i_sb, name, namelen),
|
|
|
|
TYPE_DIRENTRY, 3);
|
|
|
|
|
|
|
|
/* get memory for composing the entry */
|
|
|
|
buflen = DEH_SIZE + ROUND_UP(namelen);
|
|
|
|
if (buflen > sizeof(small_buf)) {
|
2006-02-01 14:06:43 +03:00
|
|
|
buffer = kmalloc(buflen, GFP_NOFS);
|
2008-03-29 06:07:28 +03:00
|
|
|
if (!buffer)
|
2005-07-13 07:21:28 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
} else
|
|
|
|
buffer = small_buf;
|
|
|
|
|
|
|
|
paste_size =
|
|
|
|
(get_inode_sd_version(dir) ==
|
|
|
|
STAT_DATA_V1) ? (DEH_SIZE + namelen) : buflen;
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* fill buffer : directory entry head, name[, dir objectid | ,
|
|
|
|
* stat data | ,stat data, dir objectid ]
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
deh = (struct reiserfs_de_head *)buffer;
|
|
|
|
deh->deh_location = 0; /* JDM Endian safe if 0 */
|
|
|
|
put_deh_offset(deh, cpu_key_k_offset(&entry_key));
|
|
|
|
deh->deh_state = 0; /* JDM Endian safe if 0 */
|
|
|
|
/* put key (ino analog) to de */
|
2014-04-23 18:00:36 +04:00
|
|
|
|
|
|
|
/* safe: k_dir_id is le */
|
|
|
|
deh->deh_dir_id = INODE_PKEY(inode)->k_dir_id;
|
|
|
|
/* safe: k_objectid is le */
|
|
|
|
deh->deh_objectid = INODE_PKEY(inode)->k_objectid;
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
/* copy name */
|
|
|
|
memcpy((char *)(deh + 1), name, namelen);
|
|
|
|
/* padd by 0s to the 4 byte boundary */
|
|
|
|
padd_item((char *)(deh + 1), ROUND_UP(namelen), namelen);
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* entry is ready to be pasted into tree, set 'visibility'
|
|
|
|
* and 'stat data in entry' attributes
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
mark_de_without_sd(deh);
|
|
|
|
visible ? mark_de_visible(deh) : mark_de_hidden(deh);
|
|
|
|
|
|
|
|
/* find the proper place for the new entry */
|
|
|
|
memset(bit_string, 0, sizeof(bit_string));
|
2006-03-02 21:25:26 +03:00
|
|
|
de.de_gen_number_bit_string = bit_string;
|
2005-07-13 07:21:28 +04:00
|
|
|
retval = reiserfs_find_entry(dir, name, namelen, &path, &de);
|
|
|
|
if (retval != NAME_NOT_FOUND) {
|
|
|
|
if (buffer != small_buf)
|
2006-02-01 14:06:43 +03:00
|
|
|
kfree(buffer);
|
2005-07-13 07:21:28 +04:00
|
|
|
pathrelse(&path);
|
|
|
|
|
|
|
|
if (retval == IO_ERROR) {
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval != NAME_FOUND) {
|
2009-03-30 22:02:28 +04:00
|
|
|
reiserfs_error(dir->i_sb, "zam-7002",
|
|
|
|
"reiserfs_find_entry() returned "
|
|
|
|
"unexpected value (%d)", retval);
|
2005-07-13 07:21:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
gen_number =
|
2006-03-02 21:25:26 +03:00
|
|
|
find_first_zero_bit(bit_string,
|
2005-07-13 07:21:28 +04:00
|
|
|
MAX_GENERATION_NUMBER + 1);
|
|
|
|
if (gen_number > MAX_GENERATION_NUMBER) {
|
|
|
|
/* there is no free generation number */
|
2009-03-30 22:02:21 +04:00
|
|
|
reiserfs_warning(dir->i_sb, "reiserfs-7010",
|
|
|
|
"Congratulations! we have got hash function "
|
|
|
|
"screwed up");
|
2005-07-13 07:21:28 +04:00
|
|
|
if (buffer != small_buf)
|
2006-02-01 14:06:43 +03:00
|
|
|
kfree(buffer);
|
2005-07-13 07:21:28 +04:00
|
|
|
pathrelse(&path);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
/* adjust offset of directory enrty */
|
|
|
|
put_deh_offset(deh, SET_GENERATION_NUMBER(deh_offset(deh), gen_number));
|
|
|
|
set_cpu_key_k_offset(&entry_key, deh_offset(deh));
|
|
|
|
|
|
|
|
/* update max-hash-collisions counter in reiserfs_sb_info */
|
|
|
|
PROC_INFO_MAX(th->t_super, max_hash_collisions, gen_number);
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* we need to re-search for the insertion point */
|
|
|
|
if (gen_number != 0) {
|
2005-07-13 07:21:28 +04:00
|
|
|
if (search_by_entry_key(dir->i_sb, &entry_key, &path, &de) !=
|
|
|
|
NAME_NOT_FOUND) {
|
2009-03-30 22:02:21 +04:00
|
|
|
reiserfs_warning(dir->i_sb, "vs-7032",
|
|
|
|
"entry with this key (%K) already "
|
|
|
|
"exists", &entry_key);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
if (buffer != small_buf)
|
2006-02-01 14:06:43 +03:00
|
|
|
kfree(buffer);
|
2005-07-13 07:21:28 +04:00
|
|
|
pathrelse(&path);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
/* perform the insertion of the entry that we have prepared */
|
|
|
|
retval =
|
|
|
|
reiserfs_paste_into_item(th, &path, &entry_key, dir, buffer,
|
|
|
|
paste_size);
|
|
|
|
if (buffer != small_buf)
|
2006-02-01 14:06:43 +03:00
|
|
|
kfree(buffer);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (retval) {
|
|
|
|
reiserfs_check_path(&path);
|
|
|
|
return retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
dir->i_size += paste_size;
|
2016-09-14 17:48:05 +03:00
|
|
|
dir->i_mtime = dir->i_ctime = current_time(dir);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (!S_ISDIR(inode->i_mode) && visible)
|
2014-04-23 18:00:36 +04:00
|
|
|
/* reiserfs_mkdir or reiserfs_rename will do that by itself */
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(th, dir);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_check_path(&path);
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* quota utility function, call if you've had to abort after calling
|
|
|
|
* new_inode_init, and have not called reiserfs_new_inode yet.
|
|
|
|
* This should only be called on inodes that do not have stat data
|
|
|
|
* inserted into the tree yet.
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
static int drop_new_inode(struct inode *inode)
|
|
|
|
{
|
2010-03-03 17:05:05 +03:00
|
|
|
dquot_drop(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
make_bad_inode(inode);
|
|
|
|
inode->i_flags |= S_NOQUOTA;
|
|
|
|
iput(inode);
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* utility function that does setup for reiserfs_new_inode.
|
|
|
|
* dquot_initialize needs lots of credits so it's better to have it
|
|
|
|
* outside of a transaction, so we had to pull some bits of
|
|
|
|
* reiserfs_new_inode out into this func.
|
|
|
|
*/
|
2011-07-26 10:50:53 +04:00
|
|
|
static int new_inode_init(struct inode *inode, struct inode *dir, umode_t mode)
|
2005-07-13 07:21:28 +04:00
|
|
|
{
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* Make inode invalid - just in case we are going to drop it before
|
|
|
|
* the initialization happens
|
|
|
|
*/
|
2005-08-13 15:15:34 +04:00
|
|
|
INODE_PKEY(inode)->k_objectid = 0;
|
2014-04-23 18:00:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the quota init calls have to know who to charge the quota to, so
|
|
|
|
* we have to set uid and gid here
|
2010-03-04 17:32:19 +03:00
|
|
|
*/
|
|
|
|
inode_init_owner(inode, dir, mode);
|
2015-07-14 14:51:55 +03:00
|
|
|
return dquot_initialize(inode);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2011-07-26 09:42:34 +04:00
|
|
|
static int reiserfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
2012-06-11 02:05:36 +04:00
|
|
|
bool excl)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval;
|
|
|
|
struct inode *inode;
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* We need blocks for transaction + (user+group)*(quotas
|
|
|
|
* for new inode + update of quota for directory owner)
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
int jbegin_count =
|
|
|
|
JOURNAL_PER_BALANCE_CNT * 2 +
|
|
|
|
2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
|
|
|
|
REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
|
|
|
|
struct reiserfs_transaction_handle th;
|
2009-03-30 22:02:41 +04:00
|
|
|
struct reiserfs_security_handle security;
|
2005-07-13 07:21:28 +04:00
|
|
|
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = dquot_initialize(dir);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2010-03-03 17:05:06 +03:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
if (!(inode = new_inode(dir->i_sb))) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = new_inode_init(inode, dir, mode);
|
|
|
|
if (retval) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
return retval;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-03-30 22:02:39 +04:00
|
|
|
jbegin_count += reiserfs_cache_default_acl(dir);
|
2011-02-01 19:05:39 +03:00
|
|
|
retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security);
|
2009-03-30 22:02:41 +04:00
|
|
|
if (retval < 0) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
jbegin_count += retval;
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_lock(dir->i_sb);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
retval = journal_begin(&th, dir->i_sb, jbegin_count);
|
|
|
|
if (retval) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval =
|
|
|
|
reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
|
2009-03-30 22:02:41 +04:00
|
|
|
inode, &security);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (retval)
|
|
|
|
goto out_failed;
|
|
|
|
|
|
|
|
inode->i_op = &reiserfs_file_inode_operations;
|
|
|
|
inode->i_fop = &reiserfs_file_operations;
|
|
|
|
inode->i_mapping->a_ops = &reiserfs_address_space_operations;
|
|
|
|
|
|
|
|
retval =
|
|
|
|
reiserfs_add_entry(&th, dir, dentry->d_name.name,
|
|
|
|
dentry->d_name.len, inode, 1 /*visible */ );
|
|
|
|
if (retval) {
|
|
|
|
int err;
|
2011-10-28 16:13:28 +04:00
|
|
|
drop_nlink(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(&th, inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
err = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (err)
|
|
|
|
retval = err;
|
2008-12-30 10:03:58 +03:00
|
|
|
unlock_new_inode(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
iput(inode);
|
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
reiserfs_update_inode_transaction(inode);
|
|
|
|
reiserfs_update_inode_transaction(dir);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-12-30 10:03:58 +03:00
|
|
|
unlock_new_inode(inode);
|
2012-07-19 09:18:15 +04:00
|
|
|
d_instantiate(dentry, inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
retval = journal_end(&th);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:41 +04:00
|
|
|
out_failed:
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
return retval;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-07-26 09:52:52 +04:00
|
|
|
static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
|
2005-07-13 07:21:28 +04:00
|
|
|
dev_t rdev)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
struct inode *inode;
|
|
|
|
struct reiserfs_transaction_handle th;
|
2009-03-30 22:02:41 +04:00
|
|
|
struct reiserfs_security_handle security;
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* We need blocks for transaction + (user+group)*(quotas
|
|
|
|
* for new inode + update of quota for directory owner)
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
int jbegin_count =
|
|
|
|
JOURNAL_PER_BALANCE_CNT * 3 +
|
|
|
|
2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
|
|
|
|
REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
|
|
|
|
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = dquot_initialize(dir);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2010-03-03 17:05:06 +03:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
if (!(inode = new_inode(dir->i_sb))) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = new_inode_init(inode, dir, mode);
|
|
|
|
if (retval) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
return retval;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-03-30 22:02:39 +04:00
|
|
|
jbegin_count += reiserfs_cache_default_acl(dir);
|
2011-02-01 19:05:39 +03:00
|
|
|
retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security);
|
2009-03-30 22:02:41 +04:00
|
|
|
if (retval < 0) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
jbegin_count += retval;
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_lock(dir->i_sb);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
retval = journal_begin(&th, dir->i_sb, jbegin_count);
|
|
|
|
if (retval) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
goto out_failed;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
retval =
|
|
|
|
reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
|
2009-03-30 22:02:41 +04:00
|
|
|
inode, &security);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (retval) {
|
|
|
|
goto out_failed;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
inode->i_op = &reiserfs_special_inode_operations;
|
|
|
|
init_special_inode(inode, inode->i_mode, rdev);
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* FIXME: needed for block and char devices only */
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(&th, inode);
|
|
|
|
|
|
|
|
reiserfs_update_inode_transaction(inode);
|
|
|
|
reiserfs_update_inode_transaction(dir);
|
|
|
|
|
|
|
|
retval =
|
|
|
|
reiserfs_add_entry(&th, dir, dentry->d_name.name,
|
|
|
|
dentry->d_name.len, inode, 1 /*visible */ );
|
|
|
|
if (retval) {
|
|
|
|
int err;
|
2011-10-28 16:13:28 +04:00
|
|
|
drop_nlink(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(&th, inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
err = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (err)
|
|
|
|
retval = err;
|
2008-12-30 10:03:58 +03:00
|
|
|
unlock_new_inode(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
iput(inode);
|
|
|
|
goto out_failed;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-12-30 10:03:58 +03:00
|
|
|
unlock_new_inode(inode);
|
2012-07-19 09:18:15 +04:00
|
|
|
d_instantiate(dentry, inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
retval = journal_end(&th);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:41 +04:00
|
|
|
out_failed:
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
return retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2011-07-26 09:41:39 +04:00
|
|
|
static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval;
|
|
|
|
struct inode *inode;
|
|
|
|
struct reiserfs_transaction_handle th;
|
2009-03-30 22:02:41 +04:00
|
|
|
struct reiserfs_security_handle security;
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* We need blocks for transaction + (user+group)*(quotas
|
|
|
|
* for new inode + update of quota for directory owner)
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
int jbegin_count =
|
|
|
|
JOURNAL_PER_BALANCE_CNT * 3 +
|
|
|
|
2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
|
|
|
|
REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = dquot_initialize(dir);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2010-03-03 17:05:06 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef DISPLACE_NEW_PACKING_LOCALITIES
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* set flag that new packing locality created and new blocks
|
|
|
|
* for the content of that directory are not displaced yet
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
REISERFS_I(dir)->new_packing_locality = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
2005-07-13 07:21:28 +04:00
|
|
|
mode = S_IFDIR | mode;
|
|
|
|
if (!(inode = new_inode(dir->i_sb))) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = new_inode_init(inode, dir, mode);
|
|
|
|
if (retval) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
return retval;
|
|
|
|
}
|
2005-07-13 07:21:28 +04:00
|
|
|
|
2009-03-30 22:02:39 +04:00
|
|
|
jbegin_count += reiserfs_cache_default_acl(dir);
|
2011-02-01 19:05:39 +03:00
|
|
|
retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security);
|
2009-03-30 22:02:41 +04:00
|
|
|
if (retval < 0) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
jbegin_count += retval;
|
2013-08-09 01:34:46 +04:00
|
|
|
reiserfs_write_lock(dir->i_sb);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
retval = journal_begin(&th, dir->i_sb, jbegin_count);
|
|
|
|
if (retval) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
goto out_failed;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* inc the link count now, so another writer doesn't overflow
|
|
|
|
* it while we sleep later on.
|
2005-07-13 07:21:28 +04:00
|
|
|
*/
|
|
|
|
INC_DIR_INODE_NLINK(dir)
|
|
|
|
|
|
|
|
retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ ,
|
|
|
|
old_format_only(dir->i_sb) ?
|
|
|
|
EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
|
2009-03-30 22:02:41 +04:00
|
|
|
dentry, inode, &security);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (retval) {
|
2011-03-02 17:35:13 +03:00
|
|
|
DEC_DIR_INODE_NLINK(dir)
|
2005-07-13 07:21:28 +04:00
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
reiserfs_update_inode_transaction(inode);
|
|
|
|
reiserfs_update_inode_transaction(dir);
|
|
|
|
|
|
|
|
inode->i_op = &reiserfs_dir_inode_operations;
|
|
|
|
inode->i_fop = &reiserfs_dir_operations;
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* note, _this_ add_entry will not update dir's stat data */
|
2005-07-13 07:21:28 +04:00
|
|
|
retval =
|
|
|
|
reiserfs_add_entry(&th, dir, dentry->d_name.name,
|
|
|
|
dentry->d_name.len, inode, 1 /*visible */ );
|
|
|
|
if (retval) {
|
|
|
|
int err;
|
2011-10-28 16:13:28 +04:00
|
|
|
clear_nlink(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
DEC_DIR_INODE_NLINK(dir);
|
|
|
|
reiserfs_update_sd(&th, inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
err = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (err)
|
|
|
|
retval = err;
|
2008-12-30 10:03:58 +03:00
|
|
|
unlock_new_inode(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
iput(inode);
|
|
|
|
goto out_failed;
|
|
|
|
}
|
2014-04-23 18:00:36 +04:00
|
|
|
/* the above add_entry did not update dir's stat data */
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(&th, dir);
|
|
|
|
|
2008-12-30 10:03:58 +03:00
|
|
|
unlock_new_inode(inode);
|
2012-07-19 09:18:15 +04:00
|
|
|
d_instantiate(dentry, inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
retval = journal_end(&th);
|
2009-08-25 04:44:21 +04:00
|
|
|
out_failed:
|
2013-08-09 01:34:46 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
2005-07-13 07:21:28 +04:00
|
|
|
return retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static inline int reiserfs_empty_dir(struct inode *inode)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* we can cheat because an old format dir cannot have
|
|
|
|
* EMPTY_DIR_SIZE, and a new format dir cannot have
|
|
|
|
* EMPTY_DIR_SIZE_V1. So, if the inode is either size,
|
|
|
|
* regardless of disk format version, the directory is empty.
|
2005-07-13 07:21:28 +04:00
|
|
|
*/
|
|
|
|
if (inode->i_size != EMPTY_DIR_SIZE &&
|
|
|
|
inode->i_size != EMPTY_DIR_SIZE_V1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval, err;
|
|
|
|
struct inode *inode;
|
|
|
|
struct reiserfs_transaction_handle th;
|
|
|
|
int jbegin_count;
|
|
|
|
INITIALIZE_PATH(path);
|
|
|
|
struct reiserfs_dir_entry de;
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* we will be doing 2 balancings and update 2 stat data, we
|
|
|
|
* change quotas of the owner of the directory and of the owner
|
|
|
|
* of the parent directory. The quota structure is possibly
|
|
|
|
* deleted only on last iput => outside of this transaction
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
jbegin_count =
|
|
|
|
JOURNAL_PER_BALANCE_CNT * 2 + 2 +
|
|
|
|
4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
|
|
|
|
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = dquot_initialize(dir);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2010-03-03 17:05:06 +03:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_lock(dir->i_sb);
|
|
|
|
retval = journal_begin(&th, dir->i_sb, jbegin_count);
|
|
|
|
if (retval)
|
|
|
|
goto out_rmdir;
|
|
|
|
|
|
|
|
de.de_gen_number_bit_string = NULL;
|
|
|
|
if ((retval =
|
|
|
|
reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
|
|
|
|
&path, &de)) == NAME_NOT_FOUND) {
|
|
|
|
retval = -ENOENT;
|
|
|
|
goto end_rmdir;
|
|
|
|
} else if (retval == IO_ERROR) {
|
|
|
|
retval = -EIO;
|
|
|
|
goto end_rmdir;
|
|
|
|
}
|
|
|
|
|
2015-03-18 01:25:59 +03:00
|
|
|
inode = d_inode(dentry);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
reiserfs_update_inode_transaction(inode);
|
|
|
|
reiserfs_update_inode_transaction(dir);
|
|
|
|
|
|
|
|
if (de.de_objectid != inode->i_ino) {
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* FIXME: compare key of an object and a key found in the entry
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
retval = -EIO;
|
|
|
|
goto end_rmdir;
|
|
|
|
}
|
|
|
|
if (!reiserfs_empty_dir(inode)) {
|
|
|
|
retval = -ENOTEMPTY;
|
|
|
|
goto end_rmdir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cut entry from dir directory */
|
2014-04-23 18:00:42 +04:00
|
|
|
retval = reiserfs_cut_from_item(&th, &path, &de.de_entry_key,
|
|
|
|
dir, NULL, /* page */
|
2005-07-13 07:21:28 +04:00
|
|
|
0 /*new file size - not used here */ );
|
|
|
|
if (retval < 0)
|
|
|
|
goto end_rmdir;
|
|
|
|
|
|
|
|
if (inode->i_nlink != 2 && inode->i_nlink != 1)
|
2009-03-30 22:02:28 +04:00
|
|
|
reiserfs_error(inode->i_sb, "reiserfs-7040",
|
|
|
|
"empty directory has nlink != 2 (%d)",
|
|
|
|
inode->i_nlink);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
2006-10-01 10:29:06 +04:00
|
|
|
clear_nlink(inode);
|
2016-09-14 17:48:05 +03:00
|
|
|
inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(dir);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(&th, inode);
|
|
|
|
|
|
|
|
DEC_DIR_INODE_NLINK(dir)
|
|
|
|
dir->i_size -= (DEH_SIZE + de.de_entrylen);
|
|
|
|
reiserfs_update_sd(&th, dir);
|
|
|
|
|
|
|
|
/* prevent empty directory from getting lost */
|
|
|
|
add_save_link(&th, inode, 0 /* not truncate */ );
|
|
|
|
|
2014-04-23 18:00:38 +04:00
|
|
|
retval = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_check_path(&path);
|
2014-04-23 18:00:41 +04:00
|
|
|
out_rmdir:
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
return retval;
|
|
|
|
|
2014-04-23 18:00:41 +04:00
|
|
|
end_rmdir:
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* we must release path, because we did not call
|
|
|
|
* reiserfs_cut_from_item, or reiserfs_cut_from_item does not
|
|
|
|
* release path if operation was not complete
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
pathrelse(&path);
|
2014-04-23 18:00:38 +04:00
|
|
|
err = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
return err ? err : retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval, err;
|
|
|
|
struct inode *inode;
|
|
|
|
struct reiserfs_dir_entry de;
|
|
|
|
INITIALIZE_PATH(path);
|
|
|
|
struct reiserfs_transaction_handle th;
|
|
|
|
int jbegin_count;
|
|
|
|
unsigned long savelink;
|
|
|
|
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = dquot_initialize(dir);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2010-03-03 17:05:06 +03:00
|
|
|
|
2015-03-18 01:25:59 +03:00
|
|
|
inode = d_inode(dentry);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* in this transaction we can be doing at max two balancings and
|
|
|
|
* update two stat datas, we change quotas of the owner of the
|
|
|
|
* directory and of the owner of the parent directory. The quota
|
|
|
|
* structure is possibly deleted only on iput => outside of
|
|
|
|
* this transaction
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
jbegin_count =
|
|
|
|
JOURNAL_PER_BALANCE_CNT * 2 + 2 +
|
|
|
|
4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
|
|
|
|
|
2013-08-09 01:34:46 +04:00
|
|
|
reiserfs_write_lock(dir->i_sb);
|
2005-07-13 07:21:28 +04:00
|
|
|
retval = journal_begin(&th, dir->i_sb, jbegin_count);
|
|
|
|
if (retval)
|
|
|
|
goto out_unlink;
|
|
|
|
|
|
|
|
de.de_gen_number_bit_string = NULL;
|
|
|
|
if ((retval =
|
|
|
|
reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
|
|
|
|
&path, &de)) == NAME_NOT_FOUND) {
|
|
|
|
retval = -ENOENT;
|
|
|
|
goto end_unlink;
|
|
|
|
} else if (retval == IO_ERROR) {
|
|
|
|
retval = -EIO;
|
|
|
|
goto end_unlink;
|
|
|
|
}
|
|
|
|
|
|
|
|
reiserfs_update_inode_transaction(inode);
|
|
|
|
reiserfs_update_inode_transaction(dir);
|
|
|
|
|
|
|
|
if (de.de_objectid != inode->i_ino) {
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* FIXME: compare key of an object and a key found in the entry
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
retval = -EIO;
|
|
|
|
goto end_unlink;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inode->i_nlink) {
|
2009-03-30 22:02:21 +04:00
|
|
|
reiserfs_warning(inode->i_sb, "reiserfs-7042",
|
|
|
|
"deleting nonexistent file (%lu), %d",
|
|
|
|
inode->i_ino, inode->i_nlink);
|
2011-10-28 16:13:29 +04:00
|
|
|
set_nlink(inode, 1);
|
2005-07-13 07:21:28 +04:00
|
|
|
}
|
|
|
|
|
2006-10-01 10:29:03 +04:00
|
|
|
drop_nlink(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we schedule before doing the add_save_link call, save the link
|
|
|
|
* count so we don't race
|
|
|
|
*/
|
|
|
|
savelink = inode->i_nlink;
|
|
|
|
|
|
|
|
retval =
|
2014-04-23 18:00:42 +04:00
|
|
|
reiserfs_cut_from_item(&th, &path, &de.de_entry_key, dir, NULL,
|
2005-07-13 07:21:28 +04:00
|
|
|
0);
|
|
|
|
if (retval < 0) {
|
2006-10-01 10:29:04 +04:00
|
|
|
inc_nlink(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
goto end_unlink;
|
|
|
|
}
|
2016-09-14 17:48:05 +03:00
|
|
|
inode->i_ctime = current_time(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(&th, inode);
|
|
|
|
|
|
|
|
dir->i_size -= (de.de_entrylen + DEH_SIZE);
|
2016-09-14 17:48:05 +03:00
|
|
|
dir->i_ctime = dir->i_mtime = current_time(dir);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(&th, dir);
|
|
|
|
|
|
|
|
if (!savelink)
|
|
|
|
/* prevent file from getting lost */
|
|
|
|
add_save_link(&th, inode, 0 /* not truncate */ );
|
|
|
|
|
2014-04-23 18:00:38 +04:00
|
|
|
retval = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_check_path(&path);
|
2013-08-09 01:34:46 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
2005-07-13 07:21:28 +04:00
|
|
|
return retval;
|
|
|
|
|
2014-04-23 18:00:41 +04:00
|
|
|
end_unlink:
|
2005-07-13 07:21:28 +04:00
|
|
|
pathrelse(&path);
|
2014-04-23 18:00:38 +04:00
|
|
|
err = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_check_path(&path);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (err)
|
2005-07-13 07:21:28 +04:00
|
|
|
retval = err;
|
2014-04-23 18:00:41 +04:00
|
|
|
out_unlink:
|
2013-08-09 01:34:46 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
2005-07-13 07:21:28 +04:00
|
|
|
return retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static int reiserfs_symlink(struct inode *parent_dir,
|
|
|
|
struct dentry *dentry, const char *symname)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval;
|
|
|
|
struct inode *inode;
|
|
|
|
char *name;
|
|
|
|
int item_len;
|
|
|
|
struct reiserfs_transaction_handle th;
|
2009-03-30 22:02:41 +04:00
|
|
|
struct reiserfs_security_handle security;
|
2005-07-13 07:21:28 +04:00
|
|
|
int mode = S_IFLNK | S_IRWXUGO;
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* We need blocks for transaction + (user+group)*(quotas for
|
|
|
|
* new inode + update of quota for directory owner)
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
int jbegin_count =
|
|
|
|
JOURNAL_PER_BALANCE_CNT * 3 +
|
|
|
|
2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir->i_sb) +
|
|
|
|
REISERFS_QUOTA_TRANS_BLOCKS(parent_dir->i_sb));
|
|
|
|
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = dquot_initialize(parent_dir);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2010-03-03 17:05:06 +03:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
if (!(inode = new_inode(parent_dir->i_sb))) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = new_inode_init(inode, parent_dir, mode);
|
|
|
|
if (retval) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
return retval;
|
|
|
|
}
|
2005-07-13 07:21:28 +04:00
|
|
|
|
2011-02-01 19:05:39 +03:00
|
|
|
retval = reiserfs_security_init(parent_dir, inode, &dentry->d_name,
|
|
|
|
&security);
|
2009-03-30 22:02:41 +04:00
|
|
|
if (retval < 0) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
jbegin_count += retval;
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_lock(parent_dir->i_sb);
|
|
|
|
item_len = ROUND_UP(strlen(symname));
|
|
|
|
if (item_len > MAX_DIRECT_ITEM_LEN(parent_dir->i_sb->s_blocksize)) {
|
|
|
|
retval = -ENAMETOOLONG;
|
|
|
|
drop_new_inode(inode);
|
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
|
2006-02-01 14:06:43 +03:00
|
|
|
name = kmalloc(item_len, GFP_NOFS);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (!name) {
|
|
|
|
drop_new_inode(inode);
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
memcpy(name, symname, strlen(symname));
|
|
|
|
padd_item(name, item_len, strlen(symname));
|
|
|
|
|
|
|
|
retval = journal_begin(&th, parent_dir->i_sb, jbegin_count);
|
|
|
|
if (retval) {
|
|
|
|
drop_new_inode(inode);
|
2006-02-01 14:06:43 +03:00
|
|
|
kfree(name);
|
2005-07-13 07:21:28 +04:00
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval =
|
|
|
|
reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname),
|
2009-03-30 22:02:41 +04:00
|
|
|
dentry, inode, &security);
|
2006-02-01 14:06:43 +03:00
|
|
|
kfree(name);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (retval) { /* reiserfs_new_inode iputs for us */
|
|
|
|
goto out_failed;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_inode_transaction(inode);
|
|
|
|
reiserfs_update_inode_transaction(parent_dir);
|
|
|
|
|
|
|
|
inode->i_op = &reiserfs_symlink_inode_operations;
|
2015-11-17 09:07:57 +03:00
|
|
|
inode_nohighmem(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
inode->i_mapping->a_ops = &reiserfs_address_space_operations;
|
|
|
|
|
|
|
|
retval = reiserfs_add_entry(&th, parent_dir, dentry->d_name.name,
|
|
|
|
dentry->d_name.len, inode, 1 /*visible */ );
|
|
|
|
if (retval) {
|
|
|
|
int err;
|
2011-10-28 16:13:28 +04:00
|
|
|
drop_nlink(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(&th, inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
err = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
if (err)
|
|
|
|
retval = err;
|
2008-12-30 10:03:58 +03:00
|
|
|
unlock_new_inode(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
iput(inode);
|
|
|
|
goto out_failed;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-12-30 10:03:58 +03:00
|
|
|
unlock_new_inode(inode);
|
2012-07-19 09:18:15 +04:00
|
|
|
d_instantiate(dentry, inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
retval = journal_end(&th);
|
2014-04-23 18:00:41 +04:00
|
|
|
out_failed:
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(parent_dir->i_sb);
|
|
|
|
return retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static int reiserfs_link(struct dentry *old_dentry, struct inode *dir,
|
|
|
|
struct dentry *dentry)
|
|
|
|
{
|
|
|
|
int retval;
|
2015-03-18 01:25:59 +03:00
|
|
|
struct inode *inode = d_inode(old_dentry);
|
2005-07-13 07:21:28 +04:00
|
|
|
struct reiserfs_transaction_handle th;
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* We need blocks for transaction + update of quotas for
|
|
|
|
* the owners of the directory
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
int jbegin_count =
|
|
|
|
JOURNAL_PER_BALANCE_CNT * 3 +
|
|
|
|
2 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
|
|
|
|
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = dquot_initialize(dir);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2010-03-03 17:05:06 +03:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_lock(dir->i_sb);
|
|
|
|
if (inode->i_nlink >= REISERFS_LINK_MAX) {
|
2014-04-23 18:00:36 +04:00
|
|
|
/* FIXME: sd_nlink is 32 bit for new files */
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
return -EMLINK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inc before scheduling so reiserfs_unlink knows we are here */
|
2006-10-01 10:29:04 +04:00
|
|
|
inc_nlink(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
retval = journal_begin(&th, dir->i_sb, jbegin_count);
|
|
|
|
if (retval) {
|
2011-10-28 16:13:28 +04:00
|
|
|
drop_nlink(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create new entry */
|
|
|
|
retval =
|
|
|
|
reiserfs_add_entry(&th, dir, dentry->d_name.name,
|
|
|
|
dentry->d_name.len, inode, 1 /*visible */ );
|
|
|
|
|
|
|
|
reiserfs_update_inode_transaction(inode);
|
|
|
|
reiserfs_update_inode_transaction(dir);
|
|
|
|
|
|
|
|
if (retval) {
|
|
|
|
int err;
|
2011-10-28 16:13:28 +04:00
|
|
|
drop_nlink(inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
err = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
return err ? err : retval;
|
|
|
|
}
|
|
|
|
|
2016-09-14 17:48:05 +03:00
|
|
|
inode->i_ctime = current_time(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_sd(&th, inode);
|
|
|
|
|
2010-10-23 19:11:40 +04:00
|
|
|
ihold(inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
d_instantiate(dentry, inode);
|
2014-04-23 18:00:38 +04:00
|
|
|
retval = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(dir->i_sb);
|
|
|
|
return retval;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-03-30 22:02:44 +04:00
|
|
|
/* de contains information pointing to an entry which */
|
2005-07-13 07:21:28 +04:00
|
|
|
static int de_still_valid(const char *name, int len,
|
|
|
|
struct reiserfs_dir_entry *de)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
struct reiserfs_dir_entry tmp = *de;
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* recalculate pointer to name and name length */
|
2005-07-13 07:21:28 +04:00
|
|
|
set_de_name_and_namelen(&tmp);
|
2014-04-23 18:00:36 +04:00
|
|
|
/* FIXME: could check more */
|
2005-07-13 07:21:28 +04:00
|
|
|
if (tmp.de_namelen != len || memcmp(name, de->de_name, len))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
static int entry_points_to_object(const char *name, int len,
|
|
|
|
struct reiserfs_dir_entry *de,
|
|
|
|
struct inode *inode)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
if (!de_still_valid(name, len, de))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (inode) {
|
|
|
|
if (!de_visible(de->de_deh + de->de_entry_num))
|
2009-03-30 22:02:25 +04:00
|
|
|
reiserfs_panic(inode->i_sb, "vs-7042",
|
|
|
|
"entry must be visible");
|
2005-07-13 07:21:28 +04:00
|
|
|
return (de->de_objectid == inode->i_ino) ? 1 : 0;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
/* this must be added hidden entry */
|
|
|
|
if (de_visible(de->de_deh + de->de_entry_num))
|
2009-03-30 22:02:25 +04:00
|
|
|
reiserfs_panic(NULL, "vs-7043", "entry must be visible");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
return 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sets key of objectid the entry has to point to */
|
2005-07-13 07:21:28 +04:00
|
|
|
static void set_ino_in_dir_entry(struct reiserfs_dir_entry *de,
|
|
|
|
struct reiserfs_key *key)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
/* JDM These operations are endian safe - both are le */
|
|
|
|
de->de_deh[de->de_entry_num].deh_dir_id = key->k_dir_id;
|
|
|
|
de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2009-03-30 22:02:44 +04:00
|
|
|
/*
|
2005-04-17 02:20:36 +04:00
|
|
|
* process, that is going to call fix_nodes/do_balance must hold only
|
|
|
|
* one path. If it holds 2 or more, it can get into endless waiting in
|
2009-03-30 22:02:44 +04:00
|
|
|
* get_empty_nodes or its clones
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
fs: support RENAME_NOREPLACE for local filesystems
This is trivial to do:
- add flags argument to foo_rename()
- check if flags doesn't have any other than RENAME_NOREPLACE
- assign foo_rename() to .rename2 instead of .rename
Filesystems converted:
affs, bfs, exofs, ext2, hfs, hfsplus, jffs2, jfs, logfs, minix, msdos,
nilfs2, omfs, reiserfs, sysvfs, ubifs, udf, ufs, vfat.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Acked-by: Boaz Harrosh <ooo@electrozaur.com>
Acked-by: Richard Weinberger <richard@nod.at>
Acked-by: Bob Copeland <me@bobcopeland.com>
Acked-by: Jan Kara <jack@suse.cz>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Dave Kleikamp <shaggy@kernel.org>
Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: Christoph Hellwig <hch@infradead.org>
2016-09-27 12:03:57 +03:00
|
|
|
struct inode *new_dir, struct dentry *new_dentry,
|
|
|
|
unsigned int flags)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-13 07:21:28 +04:00
|
|
|
int retval;
|
|
|
|
INITIALIZE_PATH(old_entry_path);
|
|
|
|
INITIALIZE_PATH(new_entry_path);
|
|
|
|
INITIALIZE_PATH(dot_dot_entry_path);
|
|
|
|
struct item_head new_entry_ih, old_entry_ih, dot_dot_ih;
|
|
|
|
struct reiserfs_dir_entry old_de, new_de, dot_dot_de;
|
|
|
|
struct inode *old_inode, *new_dentry_inode;
|
|
|
|
struct reiserfs_transaction_handle th;
|
|
|
|
int jbegin_count;
|
|
|
|
umode_t old_inode_mode;
|
|
|
|
unsigned long savelink = 1;
|
|
|
|
struct timespec ctime;
|
|
|
|
|
fs: support RENAME_NOREPLACE for local filesystems
This is trivial to do:
- add flags argument to foo_rename()
- check if flags doesn't have any other than RENAME_NOREPLACE
- assign foo_rename() to .rename2 instead of .rename
Filesystems converted:
affs, bfs, exofs, ext2, hfs, hfsplus, jffs2, jfs, logfs, minix, msdos,
nilfs2, omfs, reiserfs, sysvfs, ubifs, udf, ufs, vfat.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Acked-by: Boaz Harrosh <ooo@electrozaur.com>
Acked-by: Richard Weinberger <richard@nod.at>
Acked-by: Bob Copeland <me@bobcopeland.com>
Acked-by: Jan Kara <jack@suse.cz>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Dave Kleikamp <shaggy@kernel.org>
Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: Christoph Hellwig <hch@infradead.org>
2016-09-27 12:03:57 +03:00
|
|
|
if (flags & ~RENAME_NOREPLACE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* three balancings: (1) old name removal, (2) new name insertion
|
|
|
|
* and (3) maybe "save" link insertion
|
|
|
|
* stat data updates: (1) old directory,
|
|
|
|
* (2) new directory and (3) maybe old object stat data (when it is
|
|
|
|
* directory) and (4) maybe stat data of object to which new entry
|
|
|
|
* pointed initially and (5) maybe block containing ".." of
|
|
|
|
* renamed directory
|
|
|
|
* quota updates: two parent directories
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
jbegin_count =
|
|
|
|
JOURNAL_PER_BALANCE_CNT * 3 + 5 +
|
|
|
|
4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir->i_sb);
|
|
|
|
|
2015-07-14 14:51:55 +03:00
|
|
|
retval = dquot_initialize(old_dir);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
retval = dquot_initialize(new_dir);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
2010-03-03 17:05:06 +03:00
|
|
|
|
2015-03-18 01:25:59 +03:00
|
|
|
old_inode = d_inode(old_dentry);
|
|
|
|
new_dentry_inode = d_inode(new_dentry);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* make sure that oldname still exists and points to an object we
|
|
|
|
* are going to rename
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
old_de.de_gen_number_bit_string = NULL;
|
|
|
|
reiserfs_write_lock(old_dir->i_sb);
|
|
|
|
retval =
|
|
|
|
reiserfs_find_entry(old_dir, old_dentry->d_name.name,
|
|
|
|
old_dentry->d_name.len, &old_entry_path,
|
|
|
|
&old_de);
|
|
|
|
pathrelse(&old_entry_path);
|
|
|
|
if (retval == IO_ERROR) {
|
2005-04-17 02:20:36 +04:00
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
2005-07-13 07:21:28 +04:00
|
|
|
return -EIO;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
if (retval != NAME_FOUND || old_de.de_objectid != old_inode->i_ino) {
|
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return -ENOENT;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
old_inode_mode = old_inode->i_mode;
|
|
|
|
if (S_ISDIR(old_inode_mode)) {
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* make sure that directory being renamed has correct ".."
|
|
|
|
* and that its new parent directory has not too many links
|
|
|
|
* already
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
if (new_dentry_inode) {
|
|
|
|
if (!reiserfs_empty_dir(new_dentry_inode)) {
|
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return -ENOTEMPTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* directory is renamed, its parent directory will be changed,
|
|
|
|
* so find ".." entry
|
2005-07-13 07:21:28 +04:00
|
|
|
*/
|
|
|
|
dot_dot_de.de_gen_number_bit_string = NULL;
|
|
|
|
retval =
|
|
|
|
reiserfs_find_entry(old_inode, "..", 2, &dot_dot_entry_path,
|
|
|
|
&dot_dot_de);
|
|
|
|
pathrelse(&dot_dot_entry_path);
|
|
|
|
if (retval != NAME_FOUND) {
|
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inode number of .. must equal old_dir->i_ino */
|
|
|
|
if (dot_dot_de.de_objectid != old_dir->i_ino) {
|
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return -EIO;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
retval = journal_begin(&th, old_dir->i_sb, jbegin_count);
|
|
|
|
if (retval) {
|
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
/* add new entry (or find the existing one) */
|
|
|
|
retval =
|
|
|
|
reiserfs_add_entry(&th, new_dir, new_dentry->d_name.name,
|
|
|
|
new_dentry->d_name.len, old_inode, 0);
|
|
|
|
if (retval == -EEXIST) {
|
|
|
|
if (!new_dentry_inode) {
|
2009-03-30 22:02:25 +04:00
|
|
|
reiserfs_panic(old_dir->i_sb, "vs-7050",
|
|
|
|
"new entry is found, new inode == 0");
|
2005-07-13 07:21:28 +04:00
|
|
|
}
|
|
|
|
} else if (retval) {
|
2014-04-23 18:00:38 +04:00
|
|
|
int err = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return err ? err : retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_update_inode_transaction(old_dir);
|
|
|
|
reiserfs_update_inode_transaction(new_dir);
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* this makes it so an fsync on an open fd for the old name will
|
|
|
|
* commit the rename operation
|
2005-07-13 07:21:28 +04:00
|
|
|
*/
|
|
|
|
reiserfs_update_inode_transaction(old_inode);
|
|
|
|
|
|
|
|
if (new_dentry_inode)
|
|
|
|
reiserfs_update_inode_transaction(new_dentry_inode);
|
|
|
|
|
|
|
|
while (1) {
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* look for old name using corresponding entry key
|
|
|
|
* (found by reiserfs_find_entry)
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
if ((retval =
|
|
|
|
search_by_entry_key(new_dir->i_sb, &old_de.de_entry_key,
|
|
|
|
&old_entry_path,
|
|
|
|
&old_de)) != NAME_FOUND) {
|
|
|
|
pathrelse(&old_entry_path);
|
2014-04-23 18:00:38 +04:00
|
|
|
journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:35 +04:00
|
|
|
copy_item_head(&old_entry_ih, tp_item_head(&old_entry_path));
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
reiserfs_prepare_for_journal(old_inode->i_sb, old_de.de_bh, 1);
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* look for new name by reiserfs_find_entry */
|
2005-07-13 07:21:28 +04:00
|
|
|
new_de.de_gen_number_bit_string = NULL;
|
|
|
|
retval =
|
|
|
|
reiserfs_find_entry(new_dir, new_dentry->d_name.name,
|
|
|
|
new_dentry->d_name.len, &new_entry_path,
|
|
|
|
&new_de);
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* reiserfs_add_entry should not return IO_ERROR,
|
|
|
|
* because it is called with essentially same parameters from
|
|
|
|
* reiserfs_add_entry above, and we'll catch any i/o errors
|
|
|
|
* before we get here.
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
if (retval != NAME_FOUND_INVISIBLE && retval != NAME_FOUND) {
|
|
|
|
pathrelse(&new_entry_path);
|
|
|
|
pathrelse(&old_entry_path);
|
2014-04-23 18:00:38 +04:00
|
|
|
journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:35 +04:00
|
|
|
copy_item_head(&new_entry_ih, tp_item_head(&new_entry_path));
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
reiserfs_prepare_for_journal(old_inode->i_sb, new_de.de_bh, 1);
|
|
|
|
|
|
|
|
if (S_ISDIR(old_inode->i_mode)) {
|
|
|
|
if ((retval =
|
|
|
|
search_by_entry_key(new_dir->i_sb,
|
|
|
|
&dot_dot_de.de_entry_key,
|
|
|
|
&dot_dot_entry_path,
|
|
|
|
&dot_dot_de)) != NAME_FOUND) {
|
|
|
|
pathrelse(&dot_dot_entry_path);
|
|
|
|
pathrelse(&new_entry_path);
|
|
|
|
pathrelse(&old_entry_path);
|
2014-04-23 18:00:38 +04:00
|
|
|
journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
copy_item_head(&dot_dot_ih,
|
2014-04-23 18:00:35 +04:00
|
|
|
tp_item_head(&dot_dot_entry_path));
|
2014-04-23 18:00:36 +04:00
|
|
|
/* node containing ".." gets into transaction */
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_prepare_for_journal(old_inode->i_sb,
|
|
|
|
dot_dot_de.de_bh, 1);
|
|
|
|
}
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* we should check seals here, not do
|
|
|
|
* this stuff, yes? Then, having
|
|
|
|
* gathered everything into RAM we
|
|
|
|
* should lock the buffers, yes? -Hans
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* probably. our rename needs to hold more
|
|
|
|
* than one path at once. The seals would
|
|
|
|
* have to be written to deal with multi-path
|
|
|
|
* issues -chris
|
2005-07-13 07:21:28 +04:00
|
|
|
*/
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* sanity checking before doing the rename - avoid races many
|
|
|
|
* of the above checks could have scheduled. We have to be
|
|
|
|
* sure our items haven't been shifted by another process.
|
2005-07-13 07:21:28 +04:00
|
|
|
*/
|
|
|
|
if (item_moved(&new_entry_ih, &new_entry_path) ||
|
|
|
|
!entry_points_to_object(new_dentry->d_name.name,
|
|
|
|
new_dentry->d_name.len,
|
|
|
|
&new_de, new_dentry_inode) ||
|
|
|
|
item_moved(&old_entry_ih, &old_entry_path) ||
|
|
|
|
!entry_points_to_object(old_dentry->d_name.name,
|
|
|
|
old_dentry->d_name.len,
|
|
|
|
&old_de, old_inode)) {
|
|
|
|
reiserfs_restore_prepared_buffer(old_inode->i_sb,
|
|
|
|
new_de.de_bh);
|
|
|
|
reiserfs_restore_prepared_buffer(old_inode->i_sb,
|
|
|
|
old_de.de_bh);
|
|
|
|
if (S_ISDIR(old_inode_mode))
|
|
|
|
reiserfs_restore_prepared_buffer(old_inode->
|
|
|
|
i_sb,
|
|
|
|
dot_dot_de.
|
|
|
|
de_bh);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (S_ISDIR(old_inode_mode)) {
|
|
|
|
if (item_moved(&dot_dot_ih, &dot_dot_entry_path) ||
|
|
|
|
!entry_points_to_object("..", 2, &dot_dot_de,
|
|
|
|
old_dir)) {
|
|
|
|
reiserfs_restore_prepared_buffer(old_inode->
|
|
|
|
i_sb,
|
|
|
|
old_de.de_bh);
|
|
|
|
reiserfs_restore_prepared_buffer(old_inode->
|
|
|
|
i_sb,
|
|
|
|
new_de.de_bh);
|
|
|
|
reiserfs_restore_prepared_buffer(old_inode->
|
|
|
|
i_sb,
|
|
|
|
dot_dot_de.
|
|
|
|
de_bh);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RFALSE(S_ISDIR(old_inode_mode) &&
|
|
|
|
!buffer_journal_prepared(dot_dot_de.de_bh), "");
|
|
|
|
|
|
|
|
break;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* ok, all the changes can be done in one fell swoop when we
|
|
|
|
* have claimed all the buffers needed.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
mark_de_visible(new_de.de_deh + new_de.de_entry_num);
|
|
|
|
set_ino_in_dir_entry(&new_de, INODE_PKEY(old_inode));
|
2014-04-23 18:00:39 +04:00
|
|
|
journal_mark_dirty(&th, new_de.de_bh);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-13 07:21:28 +04:00
|
|
|
mark_de_hidden(old_de.de_deh + old_de.de_entry_num);
|
2014-04-23 18:00:39 +04:00
|
|
|
journal_mark_dirty(&th, old_de.de_bh);
|
2016-09-14 17:48:05 +03:00
|
|
|
ctime = current_time(old_dir);
|
2005-07-13 07:21:28 +04:00
|
|
|
old_dir->i_ctime = old_dir->i_mtime = ctime;
|
|
|
|
new_dir->i_ctime = new_dir->i_mtime = ctime;
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* thanks to Alex Adriaanse <alex_a@caltech.edu> for patch
|
|
|
|
* which adds ctime update of renamed object
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
old_inode->i_ctime = ctime;
|
|
|
|
|
|
|
|
if (new_dentry_inode) {
|
2014-04-23 18:00:36 +04:00
|
|
|
/* adjust link number of the victim */
|
2005-07-13 07:21:28 +04:00
|
|
|
if (S_ISDIR(new_dentry_inode->i_mode)) {
|
2006-10-01 10:29:06 +04:00
|
|
|
clear_nlink(new_dentry_inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
} else {
|
2006-10-01 10:29:03 +04:00
|
|
|
drop_nlink(new_dentry_inode);
|
2005-07-13 07:21:28 +04:00
|
|
|
}
|
|
|
|
new_dentry_inode->i_ctime = ctime;
|
|
|
|
savelink = new_dentry_inode->i_nlink;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-07-13 07:21:28 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (S_ISDIR(old_inode_mode)) {
|
2009-03-30 22:02:44 +04:00
|
|
|
/* adjust ".." of renamed directory */
|
2005-07-13 07:21:28 +04:00
|
|
|
set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir));
|
2014-04-23 18:00:39 +04:00
|
|
|
journal_mark_dirty(&th, dot_dot_de.de_bh);
|
2005-07-13 07:21:28 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* there (in new_dir) was no directory, so it got new link
|
|
|
|
* (".." of renamed directory)
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
if (!new_dentry_inode)
|
|
|
|
INC_DIR_INODE_NLINK(new_dir);
|
|
|
|
|
|
|
|
/* old directory lost one link - ".. " of renamed directory */
|
|
|
|
DEC_DIR_INODE_NLINK(old_dir);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* looks like in 2.3.99pre3 brelse is atomic.
|
|
|
|
* so we can use pathrelse
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
pathrelse(&new_entry_path);
|
|
|
|
pathrelse(&dot_dot_entry_path);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/*
|
|
|
|
* FIXME: this reiserfs_cut_from_item's return value may screw up
|
|
|
|
* anybody, but it will panic if will not be able to find the
|
|
|
|
* entry. This needs one more clean up
|
|
|
|
*/
|
2005-07-13 07:21:28 +04:00
|
|
|
if (reiserfs_cut_from_item
|
2014-04-23 18:00:42 +04:00
|
|
|
(&th, &old_entry_path, &old_de.de_entry_key, old_dir, NULL,
|
2005-07-13 07:21:28 +04:00
|
|
|
0) < 0)
|
2009-03-30 22:02:28 +04:00
|
|
|
reiserfs_error(old_dir->i_sb, "vs-7060",
|
|
|
|
"couldn't not cut old name. Fsck later?");
|
2005-07-13 07:21:28 +04:00
|
|
|
|
|
|
|
old_dir->i_size -= DEH_SIZE + old_de.de_entrylen;
|
|
|
|
|
|
|
|
reiserfs_update_sd(&th, old_dir);
|
|
|
|
reiserfs_update_sd(&th, new_dir);
|
|
|
|
reiserfs_update_sd(&th, old_inode);
|
|
|
|
|
|
|
|
if (new_dentry_inode) {
|
|
|
|
if (savelink == 0)
|
|
|
|
add_save_link(&th, new_dentry_inode,
|
|
|
|
0 /* not truncate */ );
|
|
|
|
reiserfs_update_sd(&th, new_dentry_inode);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-07-13 07:21:28 +04:00
|
|
|
|
2014-04-23 18:00:38 +04:00
|
|
|
retval = journal_end(&th);
|
2005-07-13 07:21:28 +04:00
|
|
|
reiserfs_write_unlock(old_dir->i_sb);
|
|
|
|
return retval;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 18:00:36 +04:00
|
|
|
/* directories can handle most operations... */
|
2007-02-12 11:55:40 +03:00
|
|
|
const struct inode_operations reiserfs_dir_inode_operations = {
|
2005-07-13 07:21:28 +04:00
|
|
|
.create = reiserfs_create,
|
|
|
|
.lookup = reiserfs_lookup,
|
|
|
|
.link = reiserfs_link,
|
|
|
|
.unlink = reiserfs_unlink,
|
|
|
|
.symlink = reiserfs_symlink,
|
|
|
|
.mkdir = reiserfs_mkdir,
|
|
|
|
.rmdir = reiserfs_rmdir,
|
|
|
|
.mknod = reiserfs_mknod,
|
|
|
|
.rename = reiserfs_rename,
|
|
|
|
.setattr = reiserfs_setattr,
|
|
|
|
.listxattr = reiserfs_listxattr,
|
|
|
|
.permission = reiserfs_permission,
|
2011-07-23 19:37:31 +04:00
|
|
|
.get_acl = reiserfs_get_acl,
|
2013-12-20 17:16:49 +04:00
|
|
|
.set_acl = reiserfs_set_acl,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* symlink operations.. same as page_symlink_inode_operations, with xattr
|
|
|
|
* stuff added
|
|
|
|
*/
|
2007-02-12 11:55:40 +03:00
|
|
|
const struct inode_operations reiserfs_symlink_inode_operations = {
|
2015-11-17 18:20:54 +03:00
|
|
|
.get_link = page_get_link,
|
2005-07-13 07:21:28 +04:00
|
|
|
.setattr = reiserfs_setattr,
|
|
|
|
.listxattr = reiserfs_listxattr,
|
|
|
|
.permission = reiserfs_permission,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* special file operations.. just xattr/acl stuff
|
|
|
|
*/
|
2007-02-12 11:55:40 +03:00
|
|
|
const struct inode_operations reiserfs_special_inode_operations = {
|
2005-07-13 07:21:28 +04:00
|
|
|
.setattr = reiserfs_setattr,
|
|
|
|
.listxattr = reiserfs_listxattr,
|
|
|
|
.permission = reiserfs_permission,
|
2011-07-23 19:37:31 +04:00
|
|
|
.get_acl = reiserfs_get_acl,
|
2013-12-20 17:16:49 +04:00
|
|
|
.set_acl = reiserfs_set_acl,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|