* 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

View File

@ -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;

View File

@ -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 :-)

View File

@ -60,15 +60,15 @@ get_node_type(ntfs_inode* ni, int* _type)
} else {
// Regular or Interix (INTX) file
*_type = S_IFREG;
if (ni->flags & FILE_ATTR_SYSTEM) {
na = ntfs_attr_open(ni, AT_DATA, NULL,0);
if (!na) {
return ENOENT;
}
// Check whether it's Interix symbolic link
if (na->data_size <= sizeof(INTX_FILE_TYPES) +
sizeof(ntfschar) * PATH_MAX &&
if (na->data_size <= sizeof(INTX_FILE_TYPES) +
sizeof(ntfschar) * PATH_MAX &&
na->data_size > sizeof(INTX_FILE_TYPES)) {
INTX_FILE *intx_file;
@ -90,18 +90,18 @@ get_node_type(ntfs_inode* ni, int* _type)
ntfs_attr_close(na);
}
}
return B_OK;
}
void
void
fs_ntfs_update_times(fs_volume *vol, ntfs_inode *ni, ntfs_time_update_flags mask)
{
nspace *ns = (nspace*)vol->private_volume;
if (ns->noatime)
mask &= ~NTFS_UPDATE_ATIME;
ntfs_inode_update_times(ni, mask);
}
@ -614,7 +614,7 @@ fs_rstat(fs_volume *_vol, fs_vnode *_node, struct stat *stbuf)
stbuf->st_size = ni->data_size;
stbuf->st_blocks = (ni->allocated_size + 511) >> 9;
stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count);
if (ni->flags & FILE_ATTR_SYSTEM) {
na = ntfs_attr_open(ni, AT_DATA, NULL,0);
if (!na) {
@ -624,8 +624,8 @@ fs_rstat(fs_volume *_vol, fs_vnode *_node, struct stat *stbuf)
stbuf->st_size = na->data_size;
stbuf->st_blocks = na->allocated_size >> 9;
// Check whether it's Interix symbolic link
if (na->data_size <= sizeof(INTX_FILE_TYPES) +
sizeof(ntfschar) * PATH_MAX &&
if (na->data_size <= sizeof(INTX_FILE_TYPES) +
sizeof(ntfschar) * PATH_MAX &&
na->data_size > sizeof(INTX_FILE_TYPES)) {
INTX_FILE *intx_file;
@ -654,14 +654,14 @@ fs_rstat(fs_volume *_vol, fs_vnode *_node, struct stat *stbuf)
if (ns->flags & B_FS_IS_READONLY) {
stbuf->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
}
stbuf->st_uid = 0;
stbuf->st_gid = 0;
stbuf->st_ino = MREF(ni->mft_no);
stbuf->st_atime = ni->last_access_time;
stbuf->st_ctime = ni->last_mft_change_time;
stbuf->st_mtime = ni->last_data_change_time;
stbuf->st_mtime = ni->last_data_change_time;
exit:
if (ni)
ntfs_inode_close(ni);
@ -942,7 +942,7 @@ fs_create(fs_volume *_vol, fs_vnode *_dir, const char *name, int omode,
fs_ntfs_update_times(_vol, ni, NTFS_UPDATE_MCTIME);
notify_entry_created(ns->id, MREF(bi->mft_no), name, *_vnid);
} else
result = errno;
}
@ -1033,7 +1033,7 @@ fs_read(fs_volume *_vol, fs_vnode *_dir, void *_cookie, off_t offset, void *buf,
*len = total;
fs_ntfs_update_times(_vol, ni, NTFS_UPDATE_ATIME);
exit:
if (na)
ntfs_attr_close(na);
@ -1129,8 +1129,8 @@ fs_write(fs_volume *_vol, fs_vnode *_dir, void *_cookie, off_t offset,
*len = total;
if (total > 0)
fs_ntfs_update_times(_vol, ni, NTFS_UPDATE_MCTIME);
fs_ntfs_update_times(_vol, ni, NTFS_UPDATE_MCTIME);
ERRPRINT(("fs_write - OK\n"));
exit:
@ -1355,7 +1355,7 @@ fs_create_symlink(fs_volume *_vol, fs_vnode *_dir, const char *name,
put_vnode(_vol, MREF(sym->mft_no));
fs_ntfs_update_times(_vol, sym, NTFS_UPDATE_CTIME);
fs_ntfs_update_times(_vol, bi, NTFS_UPDATE_MCTIME);
notify_entry_created(ns->id, MREF( bi->mft_no ), name, MREF(sym->mft_no));
exit:
@ -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) {

View File

@ -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);

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;
}
@ -2645,7 +2645,7 @@ dir_vnode_to_path(struct vnode* vnode, char* buffer, size_t bufferSize,
// we don't use get_vnode() here because this call is more
// efficient and does all we need from get_vnode()
inc_vnode_ref_count(vnode);
if (vnode != ioContext->root) {
// we don't hit the IO context root
// resolve a volume root to its mount point
@ -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