[haiku-commits] r33895 - in haiku/trunk/src: add-ons/kernel/file_systems/bfs add-ons/kernel/file_systems/cdda add-ons/kernel/file_systems/ntfs add-ons/kernel/file_systems/ramfs system/kernel/fs
- From: axeld@xxxxxxxxxxxxxxxx
- To: haiku-commits@xxxxxxxxxxxxx
- Date: Thu, 5 Nov 2009 14:03:06 +0100 (CET)
Author: axeld
Date: 2009-11-05 14:03:06 +0100 (Thu, 05 Nov 2009)
New Revision: 33895
Changeset: http://dev.haiku-os.org/changeset/33895/haiku
Modified:
haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp
haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp
haiku/trunk/src/add-ons/kernel/file_systems/ntfs/fs_func.c
haiku/trunk/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp
haiku/trunk/src/system/kernel/fs/vfs.cpp
Log:
* 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.
Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp
2009-11-05 12:37:43 UTC (rev 33894)
+++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp
2009-11-05 13:03:06 UTC (rev 33895)
@@ -1040,12 +1040,6 @@
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;
Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp
2009-11-05 12:37:43 UTC (rev 33894)
+++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp
2009-11-05 13:03:06 UTC (rev 33895)
@@ -1738,12 +1738,7 @@
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 :-)
Modified: haiku/trunk/src/add-ons/kernel/file_systems/ntfs/fs_func.c
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/ntfs/fs_func.c 2009-11-05
12:37:43 UTC (rev 33894)
+++ haiku/trunk/src/add-ons/kernel/file_systems/ntfs/fs_func.c 2009-11-05
13:03:06 UTC (rev 33895)
@@ -60,15 +60,15 @@
} 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 @@
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 @@
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 @@
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 @@
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_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 @@
*len = total;
fs_ntfs_update_times(_vol, ni, NTFS_UPDATE_ATIME);
-
+
exit:
if (na)
ntfs_attr_close(na);
@@ -1129,8 +1129,8 @@
*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 @@
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 @@
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 @@
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) {
Modified: haiku/trunk/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp
2009-11-05 12:37:43 UTC (rev 33894)
+++ haiku/trunk/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp
2009-11-05 13:03:06 UTC (rev 33895)
@@ -525,21 +525,7 @@
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);
Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp
===================================================================
--- haiku/trunk/src/system/kernel/fs/vfs.cpp 2009-11-05 12:37:43 UTC (rev
33894)
+++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2009-11-05 13:03:06 UTC (rev
33895)
@@ -2080,40 +2080,40 @@
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 @@
// 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 @@
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
Other related posts:
- » [haiku-commits] r33895 - in haiku/trunk/src: add-ons/kernel/file_systems/bfs add-ons/kernel/file_systems/cdda add-ons/kernel/file_systems/ntfs add-ons/kernel/file_systems/ramfs system/kernel/fs - axeld