* common_rename() now checks the name for validity before passing it on to the

file systems, so those checks don't have to be duplicated there, anymore.
* Minor cleanup, mostly automatic whitespace.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33895 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-11-05 13:03:06 +00:00
parent a63c61839e
commit f40c5e3211
5 changed files with 44 additions and 75 deletions
@@ -1040,12 +1040,6 @@ bfs_rename(fs_volume* _volume, fs_vnode* _oldDir, const char* oldName,
FUNCTION_START(("oldDir = %p, oldName = \"%s\", newDir = %p, newName = "
"\"%s\"\n", _oldDir, oldName, _newDir, newName));
// there might be some more tests needed?!
if (!strcmp(oldName, ".") || !strcmp(oldName, "..")
|| !strcmp(newName, ".") || !strcmp(newName, "..")
|| strchr(newName, '/') != NULL)
RETURN_ERROR(B_BAD_VALUE);
Volume* volume = (Volume*)_volume->private_volume;
Inode* oldDirectory = (Inode*)_oldDir->private_node;
Inode* newDirectory = (Inode*)_newDir->private_node;
@@ -1738,12 +1738,7 @@ status_t
cdda_rename(fs_volume* _volume, fs_vnode* _oldDir, const char* oldName,
fs_vnode* _newDir, const char* newName)
{
if (_oldDir != _newDir
|| oldName == NULL || oldName[0] == '\0'
|| newName == NULL || newName[0] == '\0'
|| !strcmp(oldName, ".") || !strcmp(oldName, "..")
|| !strcmp(newName, ".") || !strcmp(newName, "..")
|| strchr(newName, '/') != NULL)
if (_oldDir != _newDir)
return B_BAD_VALUE;
// we only have a single directory which simplifies things a bit :-)
+2 -16
View File
@@ -1457,8 +1457,8 @@ exit:
status_t
fs_rename(fs_volume *_vol, fs_vnode *_odir, const char *oldname, fs_vnode *_ndir,
const char *newname)
fs_rename(fs_volume *_vol, fs_vnode *_odir, const char *oldname,
fs_vnode *_ndir, const char *newname)
{
nspace *ns = (nspace*)_vol->private_volume;
vnode *odir = (vnode*)_odir->private_node;
@@ -1489,20 +1489,6 @@ fs_rename(fs_volume *_vol, fs_vnode *_odir, const char *oldname, fs_vnode *_ndir
ERRPRINT("fs_rename - oldname:%s newname:%s\n", oldname, newname);
if (_vol == NULL || _odir == NULL || _ndir == NULL
|| oldname == NULL || *oldname == '\0'
|| newname == NULL || *newname == '\0'
|| !strcmp(oldname, ".") || !strcmp(oldname, "..")
|| !strcmp(newname, ".") || !strcmp(newname, "..")
|| strchr(newname, '/') != NULL) {
result = EINVAL;
goto exit;
}
// stupid renaming check
if (odir == ndir && !strcmp(oldname, newname))
goto exit;
// convert names from utf8 to unicode string
unewnameLength = ntfs_mbstoucs(newname, &unewname);
if (unewnameLength < 0) {
@@ -525,21 +525,7 @@ ramfs_rename(fs_volume fs, fs_vnode _oldDir, const char *oldName,
Directory *newDir = dynamic_cast<Directory*>((Node*)_newDir);
status_t error = B_OK;
// check name
if (!oldName || *oldName == '\0'
|| !strcmp(oldName, ".") || !strcmp(oldName, "..")
|| !newName || *newName == '\0'
|| !strcmp(newName, ".") || !strcmp(newName, "..")) {
SET_ERROR(error, B_BAD_VALUE);
// check nodes
} else if (!oldDir || !newDir) {
SET_ERROR(error, B_BAD_VALUE);
// check if the entry isn't actually moved or renamed
} else if (oldDir == newDir && !strcmp(oldName, newName)) {
SET_ERROR(error, B_BAD_VALUE);
} else if (VolumeWriteLocker locker = volume) {
if (VolumeWriteLocker locker = volume) {
FUNCTION(("old dir: %Ld, old name: `%s', new dir: %Ld, new name: `%s'\n",
oldDir->GetID(), oldName, newDir->GetID(), newName));
NodeMTimeUpdater mTimeUpdater1(oldDir);
+21 -13
View File
@@ -2080,40 +2080,40 @@ get_dir_path_and_leaf(char* path, char* filename)
if (*path == '\0')
return B_ENTRY_NOT_FOUND;
char* p = strrchr(path, '/');
char* last = strrchr(path, '/');
// '/' are not allowed in file names!
FUNCTION(("get_dir_path_and_leaf(path = %s)\n", path));
if (!p) {
if (last == NULL) {
// this path is single segment with no '/' in it
// ex. "foo"
if (strlcpy(filename, path, B_FILE_NAME_LENGTH) >= B_FILE_NAME_LENGTH)
return B_NAME_TOO_LONG;
strcpy(path, ".");
} else {
p++;
if (p[0] == '\0') {
last++;
if (last[0] == '\0') {
// special case: the path ends in one or more '/' - remove them
while (*--p == '/' && p != path);
p[1] = '\0';
while (*--last == '/' && last != path);
last[1] = '\0';
if (p == path && p[0] == '/') {
if (last == path && last[0] == '/') {
// This path points to the root of the file system
strcpy(filename, ".");
return B_OK;
}
for (; p != path && *(p - 1) != '/'; p--);
for (; last != path && *(last - 1) != '/'; last--);
// rewind to the start of the leaf before the '/'
}
// normal leaf: replace the leaf portion of the path with a '.'
if (strlcpy(filename, p, B_FILE_NAME_LENGTH)
>= B_FILE_NAME_LENGTH) {
if (strlcpy(filename, last, B_FILE_NAME_LENGTH) >= B_FILE_NAME_LENGTH)
return B_NAME_TOO_LONG;
}
p[0] = '.';
p[1] = '\0';
last[0] = '.';
last[1] = '\0';
}
return B_OK;
}
@@ -6086,6 +6086,14 @@ common_rename(int fd, char* path, int newFD, char* newPath, bool kernel)
goto err2;
}
if (fromName[0] == '\0' || toName == '\0'
|| !strcmp(fromName, ".") || !strcmp(fromName, "..")
|| !strcmp(toName, ".") || !strcmp(toName, "..")
|| (fromVnode == toVnode && !strcmp(fromName, toName))) {
status = B_BAD_VALUE;
goto err2;
}
if (HAS_FS_CALL(fromVnode, rename))
status = FS_CALL(fromVnode, rename, fromName, toVnode, toName);
else