[haiku-commits] haiku: hrev44728 - src/add-ons/kernel/file_systems/ntfs

  • From: Gerasim Troeglazov <3deyes@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 31 Oct 2012 04:08:18 +0100 (CET)

hrev44728 adds 4 changesets to branch 'master'
old head: 4107ac9cda4e76ce515596afebc11005b6e97534
new head: bd2b61fbd06cffef73193957057feb7f0bd8766d

----------------------------------------------------------------------------

157d826: NTFS: fake-attributes improvements
  
  * Fake-atributes enabled by default (Real attributes require optimization. 
Too slow with big and fragmented volumes.)
  * Upadted mime-table for file extension to mime-type mapping.
  * Fix for fake-attributes mode switching.

ba49a8d: NTFS: Fixes for Identify partition function.
  * Try to fix #8332

ef544e5: NTFS: Optimize for fs_walk function.

bd2b61f: NTFS: Code cleanup. No functional changes.

                                           [ threedeyes <3dEyes@xxxxxxxxx> ]

----------------------------------------------------------------------------

6 files changed, 166 insertions(+), 136 deletions(-)
.../kernel/file_systems/ntfs/attributes.c        |   3 +-
.../kernel/file_systems/ntfs/fake_attributes.c   | 110 ++++++++-------
.../kernel/file_systems/ntfs/fake_attributes.h   |   2 +
src/add-ons/kernel/file_systems/ntfs/fs_func.c   | 133 +++++++++----------
.../kernel/file_systems/ntfs/mime_table.c        |  42 ++++--
src/add-ons/kernel/file_systems/ntfs/ntfsdir.c   |  12 +-

############################################################################

Commit:      157d82668176fd86c627a4655565d7602ed3eb40
URL:         http://cgit.haiku-os.org/haiku/commit/?id=157d826
Author:      threedeyes <3dEyes@xxxxxxxxx>
Date:        Wed Oct 31 00:00:06 2012 UTC

NTFS: fake-attributes improvements

* Fake-atributes enabled by default (Real attributes require optimization. Too 
slow with big and fragmented volumes.)
* Upadted mime-table for file extension to mime-type mapping.
* Fix for fake-attributes mode switching.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/file_systems/ntfs/fake_attributes.c 
b/src/add-ons/kernel/file_systems/ntfs/fake_attributes.c
index a2fd096..be02952 100644
--- a/src/add-ons/kernel/file_systems/ntfs/fake_attributes.c
+++ b/src/add-ons/kernel/file_systems/ntfs/fake_attributes.c
@@ -21,14 +21,27 @@
 #include "fake_attributes.h"
 #include "mime_table.h"
 
-int32 kBeOSTypeCookie = 0x1234;
+int32 kOpenTypeCookie = 0;
+int32 kCloseTypeCookie = 1;
+int32 kSetTypeCookie = 0x1234;
+int32 kFreeTypeCookie = 0x87654321;
+
 char *kFailBackMime = {"application/octet-stream"};
+char *kDirectoryMime = {"application/x-vnd.Be-directory"};
+
 
 status_t set_mime(vnode *node, const char *filename)
 {
        struct ext_mime *p;
-       int32 namelen, ext_len;
+       int32 namelen;
+       int32 ext_len;
        node->mime = kFailBackMime;
+       
+       if (filename == NULL)
+        {
+               node->mime = kDirectoryMime;
+               return B_NO_ERROR;
+        }
        namelen = strlen(filename);
 
        for (p=mimes; p->extension; p++) {
@@ -64,7 +77,7 @@ fake_open_attrib_dir(fs_volume *_vol, fs_vnode *_node, void 
**_cookie)
                goto    exit;
        }
        
-       *(int32 *)(*_cookie) = 0;
+       *(int32 *)(*_cookie) = kOpenTypeCookie;
        
 exit:
 
@@ -75,6 +88,7 @@ exit:
        return result;
 }
 
+
 status_t 
 fake_close_attrib_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie)
 {
@@ -84,7 +98,7 @@ fake_close_attrib_dir(fs_volume *_vol, fs_vnode *_node, void 
*_cookie)
 
        LOCK_VOL(ns);
 
-       *(int32 *)_cookie = 1;
+       *(int32 *)_cookie = kCloseTypeCookie;
        
        TRACE("fake_close_attrdir - EXIT\n");
        
@@ -93,6 +107,7 @@ fake_close_attrib_dir(fs_volume *_vol, fs_vnode *_node, void 
*_cookie)
        return B_NO_ERROR;
 }
 
+
 status_t 
 fake_free_attrib_dir_cookie(fs_volume *_vol, fs_vnode *_node, void *_cookie)
 {
@@ -110,7 +125,7 @@ fake_free_attrib_dir_cookie(fs_volume *_vol, fs_vnode 
*_node, void *_cookie)
                goto    exit;
        }
        
-       *(int32 *)_cookie = 0x87654321;
+       *(int32 *)_cookie = kFreeTypeCookie;
        free(_cookie);
 
 exit:
@@ -123,6 +138,7 @@ exit:
        return result;
 }
 
+
 status_t 
 fake_rewind_attrib_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie)
 {
@@ -141,7 +157,7 @@ fake_rewind_attrib_dir(fs_volume *_vol, fs_vnode *_node, 
void *_cookie)
                goto    exit;
        }
        
-       *(uint32 *)_cookie = 0;
+       *(uint32 *)_cookie = kOpenTypeCookie;
 
 exit:
 
@@ -168,16 +184,16 @@ fake_read_attrib_dir(fs_volume *_vol, fs_vnode *_node, 
void *_cookie,
 
        *num = 0;
 
-       if ((*cookie == 0) && (node->mime)) {
+       if ((*cookie == kOpenTypeCookie) && (node->mime)) {
                *num = 1;
                
                entry->d_ino = node->vnid;
                entry->d_dev = ns->id;
-               entry->d_reclen = sizeof(struct dirent)+10;
+               entry->d_reclen = sizeof(struct dirent) + 10;
                strcpy(entry->d_name, "BEOS:TYPE");
        }
 
-       *cookie = 1;
+       *cookie = kCloseTypeCookie;
 
        TRACE("fake_read_attrdir - EXIT\n");
 
@@ -187,29 +203,45 @@ fake_read_attrib_dir(fs_volume *_vol, fs_vnode *_node, 
void *_cookie,
 }
 
 status_t
+fake_create_attrib(fs_volume *_vol, fs_vnode *_node, const char* name,
+       uint32 type, int openMode, void** _cookie)
+{
+       nspace *ns = (nspace *)_vol->private_volume;
+       int     result = B_NO_ERROR;
+
+       LOCK_VOL(ns);
+       
+       TRACE("fake_create_attrib - ENTER (name = [%s])\n",name);
+
+       if (strcmp(name, "BEOS:TYPE") != 0)
+               goto    exit;
+
+       *_cookie = &kSetTypeCookie;
+       
+exit:
+
+       TRACE("fake_create_attrib - EXIT, result is %s\n", strerror(result));
+
+       UNLOCK_VOL(ns);
+               
+       return result;  
+}
+
+status_t
 fake_open_attrib(fs_volume *_vol, fs_vnode *_node, const char *name,
        int openMode, void **_cookie)
 {
        nspace *ns = (nspace *)_vol->private_volume;
-       vnode *node = (vnode *)_node->private_node;     
        int     result = B_NO_ERROR;
 
        LOCK_VOL(ns);
        
        TRACE("fake_open_attrib - ENTER (name = [%s])\n",name);
 
-       if (strcmp(name, "BEOS:TYPE") != 0) {
-               result = ENOENT;
-               goto    exit;
-       }
-       
-       if (node->mime == NULL) {
-               TRACE("fake_open_attrib - MIME = NULL\n");
-               result = ENOENT;
+       if (strcmp(name, "BEOS:TYPE") != 0)
                goto    exit;
-       }
 
-       *_cookie = &kBeOSTypeCookie;
+       *_cookie = &kSetTypeCookie;
        
 exit:
 
@@ -240,25 +272,23 @@ fake_read_attrib_stat(fs_volume *_vol, fs_vnode *_node, 
void *_cookie,
        struct stat *stat)
 {
        nspace *ns = (nspace *)_vol->private_volume;
-       vnode *node = (vnode *)_node->private_node;
+       vnode *node = (vnode *)_node->private_node;     
        int     result = B_NO_ERROR;
 
        LOCK_VOL(ns);
 
        TRACE("fake_read_attr_stat - ENTER\n");
 
-       if (_cookie != &kBeOSTypeCookie) {
-               result = ENOENT;
-               goto    exit;
-       }
-
-       if (node->mime == NULL) {
+       if (_cookie != &kSetTypeCookie) {
                result = ENOENT;
                goto    exit;
        }
        
        stat->st_type = MIME_STRING_TYPE;
-       stat->st_size = strlen(node->mime) + 1;
+       if (node->mime == NULL)
+               stat->st_size = 0;
+       else
+               stat->st_size = strlen(node->mime) + 1;
 
 exit:
 
@@ -276,7 +306,7 @@ fake_read_attrib(fs_volume *_vol, fs_vnode *_node, void 
*_cookie,
        off_t pos,void *buffer, size_t *_length)
 {
        nspace *ns = (nspace *)_vol->private_volume;
-       vnode *node = (vnode *)_node->private_node;
+       vnode *node = (vnode *)_node->private_node;             
 
        int     result = B_NO_ERROR;
 
@@ -284,7 +314,7 @@ fake_read_attrib(fs_volume *_vol, fs_vnode *_node, void 
*_cookie,
 
        TRACE("fake_read_attr - ENTER\n");
 
-       if (_cookie != &kBeOSTypeCookie) {
+       if (_cookie != &kSetTypeCookie) {
                result = ENOENT;
                goto    exit;
        }
@@ -317,23 +347,5 @@ status_t
 fake_write_attrib(fs_volume *_vol, fs_vnode *_node, void *_cookie, off_t pos,
        const void *buffer, size_t *_length)
 {
-       nspace *ns = (nspace *)_vol->private_volume;
-
-       int     result = B_NO_ERROR;
-       
-       LOCK_VOL(ns);
-       
-       TRACE("fake_write_attr - ENTER\n");
-
-       *_length = 0;
-
-       if (_cookie != &kBeOSTypeCookie) {
-               result = ENOSYS;
-       }
-       
-       TRACE("fake_write_attrib - EXIT, result is %s\n", strerror(result));
-
-       UNLOCK_VOL(ns);
-               
-       return result;
+       return B_NO_ERROR;
 }
diff --git a/src/add-ons/kernel/file_systems/ntfs/fake_attributes.h 
b/src/add-ons/kernel/file_systems/ntfs/fake_attributes.h
index c127494..f121f0f 100644
--- a/src/add-ons/kernel/file_systems/ntfs/fake_attributes.h
+++ b/src/add-ons/kernel/file_systems/ntfs/fake_attributes.h
@@ -24,6 +24,8 @@ status_t fake_rewind_attrib_dir(fs_volume *_vol, fs_vnode 
*_node,
        void *_cookie);
 status_t fake_read_attrib_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie,
        struct dirent *buf, size_t bufsize, uint32 *num);
+status_t fake_create_attrib(fs_volume *_vol, fs_vnode *_node, const char *name,
+       uint32 type, int openMode, void** _cookie);
 status_t fake_open_attrib(fs_volume *_vol, fs_vnode *_node, const char *name,
        int openMode, void **_cookie);
 status_t fake_close_attrib(fs_volume *_vol, fs_vnode *_node, void *cookie);
diff --git a/src/add-ons/kernel/file_systems/ntfs/fs_func.c 
b/src/add-ons/kernel/file_systems/ntfs/fs_func.c
index a50c6f6..40bc4dd 100644
--- a/src/add-ons/kernel/file_systems/ntfs/fs_func.c
+++ b/src/add-ons/kernel/file_systems/ntfs/fs_func.c
@@ -346,7 +346,7 @@ fs_mount(fs_volume *_vol, const char *device, ulong flags, 
const char *args,
        ns->noatime = strcasecmp(get_driver_parameter(handle, "no_atime", 
"true",
                "true"), "true") == 0;
        ns->fake_attrib = strcasecmp(get_driver_parameter(handle, 
"fake_attributes",
-               "false", "false"), "false") != 0;
+               "true", "true"), "true") == 0;
        unload_driver_settings(handle);
 
        if (ns->ro || (flags & B_MOUNT_READ_ONLY) != 0
@@ -361,7 +361,7 @@ fs_mount(fs_volume *_vol, const char *device, ulong flags, 
const char *args,
                gNTFSVnodeOps.free_attr_dir_cookie = 
fake_free_attrib_dir_cookie;
                gNTFSVnodeOps.read_attr_dir = fake_read_attrib_dir;
                gNTFSVnodeOps.rewind_attr_dir = fake_rewind_attrib_dir;
-               gNTFSVnodeOps.create_attr = NULL;
+               gNTFSVnodeOps.create_attr = fake_create_attrib;
                gNTFSVnodeOps.open_attr = fake_open_attrib;
                gNTFSVnodeOps.close_attr = fake_close_attrib;
                gNTFSVnodeOps.free_attr_cookie = fake_free_attrib_cookie;
@@ -369,6 +369,20 @@ fs_mount(fs_volume *_vol, const char *device, ulong flags, 
const char *args,
                gNTFSVnodeOps.read_attr_stat = fake_read_attrib_stat;
                gNTFSVnodeOps.write_attr = fake_write_attrib;
                gNTFSVnodeOps.remove_attr = NULL;
+       } else {
+               gNTFSVnodeOps.open_attr_dir = fs_open_attrib_dir;
+               gNTFSVnodeOps.close_attr_dir = fs_close_attrib_dir;
+               gNTFSVnodeOps.free_attr_dir_cookie = fs_free_attrib_dir_cookie;
+               gNTFSVnodeOps.read_attr_dir = fs_read_attrib_dir;
+               gNTFSVnodeOps.rewind_attr_dir = fs_rewind_attrib_dir;
+               gNTFSVnodeOps.create_attr = fs_create_attrib;
+               gNTFSVnodeOps.open_attr = fs_open_attrib;
+               gNTFSVnodeOps.close_attr = fs_close_attrib;
+               gNTFSVnodeOps.free_attr_cookie = fs_free_attrib_cookie;
+               gNTFSVnodeOps.read_attr = fs_read_attrib;
+               gNTFSVnodeOps.read_attr_stat = fs_read_attrib_stat;
+               gNTFSVnodeOps.write_attr = fs_write_attrib;
+               gNTFSVnodeOps.remove_attr = fs_remove_attrib;           
        }
 
        ns->ntvol = utils_mount_volume(device, mountFlags | MS_RECOVER);
@@ -1088,7 +1102,7 @@ fs_create(fs_volume *_vol, fs_vnode *_dir, const char 
*name, int omode,
                        }
 
                        newNode->vnid = vnid;
-                       newNode->parent_vnid = MREF(dir_ni->mft_no);
+                       newNode->parent_vnid = dir->vnid;
                        
                        ni->flags |= FILE_ATTR_ARCHIVE;
                        NInoSetDirty(ni);
@@ -1102,10 +1116,17 @@ fs_create(fs_volume *_vol, fs_vnode *_dir, const char 
*name, int omode,
                        }                               
 
                        *_vnid = vnid;
-                                       
-                       ntfs_mark_free_space_outdated(ns);                      
                        
-                       fs_ntfs_update_times(_vol, dir_ni, NTFS_UPDATE_MCTIME); 
                
-                       notify_entry_created(ns->id, MREF(dir_ni->mft_no), 
name, *_vnid);                       
+
+                       if (ns->fake_attrib) {
+                               if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
+                                       set_mime(newNode, NULL);
+                               else
+                                       set_mime(newNode, name);
+                       }
+
+                       ntfs_mark_free_space_outdated(ns);      
+                       fs_ntfs_update_times(_vol, dir_ni, NTFS_UPDATE_MCTIME); 
+                       notify_entry_created(ns->id, dir->vnid, name, vnid);
                } else
                        result = errno;
        }
@@ -1703,13 +1724,13 @@ fs_rename(fs_volume *_vol, fs_vnode *_odir, const char 
*name,
 
                if (ns->fake_attrib) {
                        if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
-                               set_mime(file, ".***");
+                               set_mime(file, NULL);
                        else
                                set_mime(file, newname);
                        notify_attribute_changed(ns->id, file->vnid, 
"BEOS:TYPE",
                                B_ATTR_CHANGED);
                }
-                               
+
                ntfs_inode_close(dir_ni);             
                ntfs_inode_close(ni);
                
diff --git a/src/add-ons/kernel/file_systems/ntfs/mime_table.c 
b/src/add-ons/kernel/file_systems/ntfs/mime_table.c
index 5a92158..649dbf6 100644
--- a/src/add-ons/kernel/file_systems/ntfs/mime_table.c
+++ b/src/add-ons/kernel/file_systems/ntfs/mime_table.c
@@ -3,14 +3,14 @@
        This file may be used under the terms of the Be Sample Code License.
 */
 
+#include <sys/types.h>
+
 struct ext_mime {
        char *extension;
        char *mime;
 };
 
 struct ext_mime mimes[] = {
-       { "***", "application/x-vnd.Be-directory"},
-       
        { "gz", "application/x-gzip" },
        { "hqx", "application/x-binhex40" },
        { "lha", "application/x-lharc" },
@@ -24,8 +24,13 @@ struct ext_mime mimes[] = {
        { "z", "application/x-compress" },
        { "zip", "application/zip" },
        { "zoo", "application/x-zoo" },
-       { "rar", "application/x-rar-compressed" },
+       { "rar", "application/x-rar" },
        { "pkg", "application/x-scode-UPkg" },
+       { "7z", "application/x-7z-compressed" },
+       { "bz2", "application/x-bzip2" },
+       { "xz", "application/x-xz" },
+       
+       { "jar", "application/x-jar" },
 
        { "aif", "audio/x-aiff" },
        { "aiff", "audio/x-aiff" },
@@ -37,13 +42,20 @@ struct ext_mime mimes[] = {
        { "wav", "audio/x-wav" },
        { "mp3", "audio/x-mpeg" },
        { "ogg", "audio/x-vorbis" },
+       { "flac", "audio/x-flac" },
+       { "wma", "audio/x-ms-wma" },
 
        { "avi", "video/x-msvideo" },
        { "mov", "video/quicktime" },
+       { "qt", "video/quicktime" },
        { "mpg", "video/mpeg" },
        { "mpeg", "video/mpeg" },
+       { "flv", "video/x-flv" },
+       { "mp4", "video/mp4" },
+       { "mkv", "video/x-matroska" },  
        { "asf", "application/x-asf" },
        { "rm", "video/vnd.rn-realvideo" },
+       { "wmv", "video/x-ms-wmv" },
 
        { "bmp", "image/x-bmp" },
        { "fax", "image/g3fax" },
@@ -61,11 +73,21 @@ struct ext_mime mimes[] = {
        { "tif", "image/tiff" },
        { "tiff", "image/tiff" },
        { "xbm", "image/x-xbitmap" },
-       { "djvu", "image/x-djvu" },     
+       { "djvu", "image/x-djvu" },
+       { "svg", "image/svg+xml" },
+       { "ico", "image/vnd.microsoft.icon" },
 
+       { "doc", "application/msword" },
+       { "xls", "application/vnd.ms-excel" },
+       { "xls", "application/vnd.ms-excel" },
+       { "xlsx", 
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" },
+       { "docx", 
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
+       { "ppt", "application/vnd.ms-powerpoint" },
+       { "pptx", 
"application/vnd.openxmlformats-officedocument.presentationml.presentation" },
+       { "chm", "application/x-chm" },
+       
        { "txt", "text/plain" },
        { "xml", "text/plain" },
-       { "doc", "text/plain" },
        { "htm", "text/html" },
        { "html", "text/html" },
        { "rtf", "text/rtf" },
@@ -74,15 +96,15 @@ struct ext_mime mimes[] = {
        { "c++", "text/x-source-code" },
        { "h", "text/x-source-code" },
        { "hh", "text/x-source-code" },
+       { "hpp", "text/x-source-code" },
        { "cxx", "text/x-source-code" },
        { "cpp", "text/x-source-code" },
        { "S", "text/x-source-code" },
        { "java", "text/x-source-code" },
-       
-       { "exe", "application/x-vnd.Be-elfexecutable" },
-       { "dll", "application/x-vnd.Be.ELF-object" },   
-       
+       { "ini", "text/plain" },
+       { "inf", "text/plain" },
+               
        { "ttf", "application/x-truetype" },
 
-       { 0, 0 }
+       { NULL, NULL }
 };

############################################################################

Commit:      ba49a8daf71e10026837cfe64d80b2c39f233014
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ba49a8d
Author:      threedeyes <3dEyes@xxxxxxxxx>
Date:        Wed Oct 31 00:20:08 2012 UTC

Ticket:      https://dev.haiku-os.org/ticket/8332

NTFS: Fixes for Identify partition function.
* Try to fix #8332

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/file_systems/ntfs/fs_func.c 
b/src/add-ons/kernel/file_systems/ntfs/fs_func.c
index 40bc4dd..6f3af2c 100644
--- a/src/add-ons/kernel/file_systems/ntfs/fs_func.c
+++ b/src/add-ons/kernel/file_systems/ntfs/fs_func.c
@@ -43,6 +43,7 @@
 #include "ntfs.h"
 #include "volume_util.h"
 
+static const char* kNTFSUntitled = {"NTFS Untitled"};
 
 typedef struct identify_cookie {
        NTFS_BOOT_SECTOR boot;
@@ -225,10 +226,10 @@ float
 fs_identify_partition(int fd, partition_data *partition, void **_cookie)
 {
        NTFS_BOOT_SECTOR boot;
-       identify_cookie *cookie;
+       char devpath[MAX_PATH];
+       identify_cookie *cookie = NULL;
        ntfs_volume *ntVolume;
        uint8 *buf = (uint8*)&boot;
-       char devpath[256];
 
        // read in the boot sector
        TRACE("fs_identify_partition: read in the boot sector\n");
@@ -249,19 +250,6 @@ fs_identify_partition(int fd, partition_data *partition, 
void **_cookie)
                return -1;
        }
 
-       // get path for device
-       if (!ioctl(fd, B_GET_PATH_FOR_DEVICE, devpath)) {
-               ERROR("fs_identify_partition: couldn't get path for device\n");
-               return -1;
-       }
-
-       // try mount
-       ntVolume = utils_mount_volume(devpath, MS_RDONLY | MS_RECOVER);
-       if (!ntVolume) {
-               ERROR("fs_identify_partition: mount failed\n");
-               return -1;
-       }
-
        // allocate identify_cookie
        cookie = (identify_cookie *)malloc(sizeof(identify_cookie));
        if (!cookie) {
@@ -269,14 +257,20 @@ fs_identify_partition(int fd, partition_data *partition, 
void **_cookie)
                return -1;
        }
 
-       memcpy(&cookie->boot, &boot, 512);
-
-       strcpy(cookie->label, "NTFS Volume");
+       strcpy(cookie->label, kNTFSUntitled);
 
-       if (ntVolume->vol_name && ntVolume->vol_name[0] != '\0')
-               strcpy(cookie->label, ntVolume->vol_name);
+       // try get path for device
+       if (ioctl(fd, B_GET_PATH_FOR_DEVICE, devpath)) {
+               // try mount
+               ntVolume = utils_mount_volume(devpath, MS_RDONLY | MS_RECOVER);
+               if (ntVolume != NULL) {
+                       if (ntVolume->vol_name && ntVolume->vol_name[0] != '\0')
+                               strcpy(cookie->label, ntVolume->vol_name);
+                       ntfs_umount(ntVolume, true);
+               }       
+       }
 
-       ntfs_umount(ntVolume, true);
+       memcpy(&cookie->boot, &boot, 512);
 
        *_cookie = cookie;
 
@@ -474,7 +468,7 @@ fs_rfsstat(fs_volume *_vol, struct fs_info *fss)
                        break;
        }
        if (i < 0)
-               strcpy(fss->volume_name, "NTFS Untitled");
+               strcpy(fss->volume_name, kNTFSUntitled);
        else
                fss->volume_name[i + 1] = 0;
 
@@ -662,7 +656,7 @@ fs_read_vnode(fs_volume *_vol, ino_t vnid, fs_vnode *_node, 
int *_type,
                
                if (ns->fake_attrib) {
                        if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
-                               set_mime(newNode, ".***");
+                               set_mime(newNode, NULL);
                        else {
                                name = (char*)malloc(MAX_PATH);
                                if (name != NULL) {

############################################################################

Commit:      ef544e59f28e5392b37e1980f1b0f1d08f144182
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ef544e5
Author:      threedeyes <3dEyes@xxxxxxxxx>
Date:        Wed Oct 31 00:33:10 2012 UTC

NTFS: Optimize for fs_walk function.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/file_systems/ntfs/fs_func.c 
b/src/add-ons/kernel/file_systems/ntfs/fs_func.c
index 6f3af2c..2c948d0 100644
--- a/src/add-ons/kernel/file_systems/ntfs/fs_func.c
+++ b/src/add-ons/kernel/file_systems/ntfs/fs_func.c
@@ -508,70 +508,50 @@ exit:
 
 
 status_t
-fs_walk(fs_volume *_vol, fs_vnode *_dir, const char *file, ino_t *vnid)
+fs_walk(fs_volume *_vol, fs_vnode *_dir, const char *file, ino_t *_vnid)
 {
        nspace *ns = (nspace*)_vol->private_volume;
        vnode *baseNode = (vnode*)_dir->private_node;
        vnode *newNode = NULL;
-       ntfschar *uname = NULL;
-       ntfs_inode *dir_ni = NULL;
        status_t result = B_NO_ERROR;
-       int uname_len;
 
        LOCK_VOL(ns);
 
        TRACE("fs_walk - ENTER : find for \"%s\"\n",file);
 
-       if (ns == NULL || _dir == NULL || file == NULL || vnid == NULL) {
+       if (ns == NULL || _dir == NULL || file == NULL || _vnid == NULL) {
                result = EINVAL;
                goto exit;
        }
 
        if (!strcmp(file, ".")) {
-               *vnid = baseNode->vnid;
-               if (get_vnode(_vol, *vnid, (void**)&newNode) != 0)
+               *_vnid = baseNode->vnid;
+               if (get_vnode(_vol, *_vnid, (void**)&newNode) != 0)
                        result = ENOENT;
        } else if (!strcmp(file, "..") && baseNode->vnid != FILE_root) {
-               *vnid = baseNode->parent_vnid;
-               if (get_vnode(_vol, *vnid, (void**)&newNode) != 0)
+               *_vnid = baseNode->parent_vnid;
+               if (get_vnode(_vol, *_vnid, (void**)&newNode) != 0)
                        result = ENOENT;
        } else {
-               uname = ntfs_calloc(MAX_PATH);
-               uname_len = ntfs_mbstoucs(file, &uname);
-               if (uname_len < 0) {
-                       result = EILSEQ;
-                       goto exit;
-               }
-
-               dir_ni = ntfs_inode_open(ns->ntvol, baseNode->vnid);
-               if (dir_ni == NULL) {
-                       result = ENOENT;
-                       goto exit;
-               }
-
-               *vnid = MREF(ntfs_inode_lookup_by_name(dir_ni, uname, 
uname_len));
-               TRACE("fs_walk - VNID = %d\n",*vnid);
+               ino_t vnid = ntfs_inode_lookup(_vol, baseNode->vnid, file);
 
-               ntfs_inode_close(dir_ni);
-
-               if (*vnid == (u64)-1) {
-                       result = EINVAL;
+               if (vnid == (u64)-1) {
+                       result = errno;
                        goto exit;
                }
 
-               if (get_vnode(_vol, *vnid, (void**)&newNode) != 0)
+               if (get_vnode(_vol, vnid, (void**)&newNode) != 0)
                        result = ENOENT;
 
                if (newNode!=NULL)
                        newNode->parent_vnid = baseNode->vnid;
+                       
+               *_vnid = vnid;
        }
 
 exit:
        TRACE("fs_walk - EXIT, result is %s\n", strerror(result));
 
-       if (uname)
-               free(uname);
-
        UNLOCK_VOL(ns);
 
        return result;

############################################################################

Revision:    hrev44728
Commit:      bd2b61fbd06cffef73193957057feb7f0bd8766d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=bd2b61f
Author:      threedeyes <3dEyes@xxxxxxxxx>
Date:        Wed Oct 31 00:41:30 2012 UTC

NTFS: Code cleanup. No functional changes.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/file_systems/ntfs/attributes.c 
b/src/add-ons/kernel/file_systems/ntfs/attributes.c
index 727b6d6..0e10eba 100644
--- a/src/add-ons/kernel/file_systems/ntfs/attributes.c
+++ b/src/add-ons/kernel/file_systems/ntfs/attributes.c
@@ -422,8 +422,7 @@ exit:
 status_t
 fs_close_attrib(fs_volume *_vol, fs_vnode *_node, void *cookie)
 {
-       vnode *node = (vnode*)_node->private_node;
-       TRACE("%s vnid: %d\n", __FUNCTION__, node->vnid);
+       TRACE("%s vnid: %d\n", __FUNCTION__, 
((vnode*)_node->private_node)->vnid);
        return B_NO_ERROR;
 }
 
diff --git a/src/add-ons/kernel/file_systems/ntfs/fs_func.c 
b/src/add-ons/kernel/file_systems/ntfs/fs_func.c
index 2c948d0..8218828 100644
--- a/src/add-ons/kernel/file_systems/ntfs/fs_func.c
+++ b/src/add-ons/kernel/file_systems/ntfs/fs_func.c
@@ -1126,11 +1126,11 @@ exit:
 
 
 status_t
-fs_read(fs_volume *_vol, fs_vnode *_dir, void *_cookie, off_t offset, void 
*buf,
+fs_read(fs_volume *_vol, fs_vnode *_node, void *_cookie, off_t offset, void 
*buf,
        size_t *len)
 {
        nspace *ns = (nspace*)_vol->private_volume;
-       vnode *node = (vnode*)_dir->private_node;
+       vnode *node = (vnode*)_node->private_node;
        ntfs_inode *ni = NULL;
        ntfs_attr *na = NULL;
        size_t  size = *len;
@@ -1206,11 +1206,11 @@ exit2:
 
 
 status_t
-fs_write(fs_volume *_vol, fs_vnode *_dir, void *_cookie, off_t offset,
+fs_write(fs_volume *_vol, fs_vnode *_node, void *_cookie, off_t offset,
        const void *buf, size_t *len)
 {
        nspace *ns = (nspace*)_vol->private_volume;
-       vnode *node = (vnode*)_dir->private_node;
+       vnode *node = (vnode*)_node->private_node;
        filecookie *cookie = (filecookie*)_cookie;
        ntfs_inode *ni = NULL;
        ntfs_attr *na = NULL;
@@ -1264,7 +1264,7 @@ fs_write(fs_volume *_vol, fs_vnode *_dir, void *_cookie, 
off_t offset,
                if (ntfs_attr_truncate(na, offset + size))
                        size = na->data_size - offset;
                else
-                       notify_stat_changed(ns->id, MREF(ni->mft_no), 
B_STAT_SIZE);
+                       notify_stat_changed(ns->id, node->vnid, B_STAT_SIZE);
        }
 
        while (size) {
diff --git a/src/add-ons/kernel/file_systems/ntfs/ntfsdir.c 
b/src/add-ons/kernel/file_systems/ntfs/ntfsdir.c
index 46f5e0f..36a1aac 100644
--- a/src/add-ons/kernel/file_systems/ntfs/ntfsdir.c
+++ b/src/add-ons/kernel/file_systems/ntfs/ntfsdir.c
@@ -92,9 +92,9 @@ fs_free_dircookie(fs_volume *_vol, fs_vnode *vnode, void 
*_cookie)
        
        if (cookie != NULL) {
                cache_entry *entry = cookie->cache_root;
-               for(;entry!=NULL;) {
+               while (entry != NULL) {
                        cache_entry *next = entry->next;
-                       if(entry->ent != NULL)
+                       if (entry->ent != NULL)
                                free(entry->ent);
                        free(entry);
                        entry = next;
@@ -176,7 +176,7 @@ fs_readdir(fs_volume *_vol, fs_vnode *_node, void *_cookie, 
struct dirent *buf,
        LOCK_VOL(ns);
        TRACE("fs_readdir - ENTER (sizeof(buf)=%d, bufsize=%d, num=%d\n",
                sizeof(buf), bufsize, *num);
-
+               
        if (!ns || !node || !cookie || !num || bufsize < sizeof(*buf)) {
                result = EINVAL;
                goto exit;
@@ -241,7 +241,7 @@ exit:
 
 
 status_t
-fs_rewinddir(fs_volume *_vol, fs_vnode *vnode, void *_cookie)
+fs_rewinddir(fs_volume *_vol, fs_vnode *_node, void *_cookie)
 {
        nspace          *ns = (nspace*)_vol->private_volume;
        dircookie       *cookie = (dircookie*)_cookie;
@@ -252,9 +252,9 @@ fs_rewinddir(fs_volume *_vol, fs_vnode *vnode, void 
*_cookie)
        
        if (cookie != NULL) {
                cache_entry *entry = cookie->cache_root;
-               for(;entry!=NULL;) {
+               while (entry != NULL) {
                        cache_entry *next = entry->next;
-                       if(entry->ent != NULL)
+                       if (entry->ent != NULL)
                                free(entry->ent);
                        free(entry);
                        entry = next;


Other related posts: