[haiku-commits] haiku: hrev50983 - src/add-ons/kernel/file_systems/ntfs src/add-ons/kernel/file_systems/userlandfs/server/fuse src/add-ons/kernel/file_systems/shared src/add-ons/kernel/file_systems/fat headers/private

  • From: julian.harnath@xxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 27 Feb 2017 20:00:00 +0100 (CET)

hrev50983 adds 6 changesets to branch 'master'
old head: 94d84091502bae16229be113ae42d8334178c8c4
new head: 5d9f944f0a72c5a82be2611c00395d95335f1dc5
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=5d9f944f0a72+%5E94d84091502b

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

1263be8fc411: FUSE compat: add Haiku extension
  
  * Add a way for a FUSE module to supply Haiku-specific extensions.
    This allows it to integrate better with Haiku while only requiring
    minimal changes on the FUSE module itself.
  
  * For now, there is only one extension: another function pointer for
    "get_fs_info", which lets the FUSE module fill in an fs_info struct.
    FUSE provides no good way to otherwise communicate extra information,
    such as the volume flags (e.g. B_FS_IS_SHARED).
  
  * A FUSE module can signal that it supports the Haiku extensions by
      a) defining HAS_HAIKU_FUSE_EXTENSIONS before including the fuse
         headers
      b) setting the global variable gHasHaikuFuseExtensions to 1 in
         its initialization
    Otherwise, the Haiku extensions are completely invisible to the
    FUSE module.

6297d6c73b68: FUSE compat: fill in some stat infos for getattr
  
  * Prefill struct stat with some information which the FUSE module
    doesn't necessarily fill in

1b4f5f9b9462: FUSE compat: fall back to truncate if no ftruncate
  
  * As defined by the FUSE interface: if the FUSE module doesn't
    implement ftruncate(), fall back to using truncate() instead

5adf34b0d591: FUSE compat: add support for attribute reading
  
  * Implement reading extended file attributes in FUSE modules,
    using getxattr()
  
    getxattr() is a quite limited API, not allowing to specify a read
    offset. So we read in the entire attribute value into a buffer and
    store in the cookie. This shouldn't be a problem memory-wise, since
    xattr implementions usually have limitations regarding attribute size
    anyway, so it'll rarely be more than a few kilobytes.
  
  * Writing, renaming, and removing attributes is not yet implemented

6ced92452c27: FUSE compat: add MIME type faking
  
  * Add special handling for reading the BEOS:TYPE attribute to supply
    on-the-fly fake MIME types for FUSE module filesystems, the same
    way it's done in our FAT and NTFS FS modules
  
  * Reuse the mime_ext_table which we already have and put it into a
    shared location so we don't get further extra copies of it

5d9f944f0a72: Use common MIME table in FAT and NTFS, too
  
  * Last commit put the file-extension-to-MIME-type table and associated
    code into a shared location. So now we can remove it from the FAT
    and NTFS FS add-ons (they both had their own copy) and use the shared
    one there as well, removing the code duplication.

                          [ Julian Harnath <julian.harnath@xxxxxxxxxxxxxx> ]

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

19 files changed, 411 insertions(+), 267 deletions(-)
headers/private/file_systems/mime_ext_table.h    |  24 ++
headers/private/userlandfs/fuse/fuse.h           |  13 ++
src/add-ons/kernel/file_systems/fat/Jamfile      |   5 +-
src/add-ons/kernel/file_systems/fat/attr.c       |  28 +--
src/add-ons/kernel/file_systems/fat/mime_table.c | 105 ---------
src/add-ons/kernel/file_systems/fat/mime_table.h |  16 --
src/add-ons/kernel/file_systems/ntfs/Jamfile     |   7 +-
.../kernel/file_systems/ntfs/fake_attributes.c   | 128 ++++-------
.../kernel/file_systems/ntfs/fake_attributes.h   |   4 +-
src/add-ons/kernel/file_systems/ntfs/fs_func.c   |  12 +-
.../kernel/file_systems/ntfs/mime_table.h        |  16 --
.../mime_table.c => shared/mime_ext_table.c}     |  58 ++++-
.../userlandfs/server/fuse/FUSEFileSystem.cpp    |  12 +-
.../userlandfs/server/fuse/FUSEVolume.cpp        | 217 +++++++++++++++++++
.../userlandfs/server/fuse/FUSEVolume.h          |  12 +
.../file_systems/userlandfs/server/fuse/Jamfile  |   5 +-
.../userlandfs/server/fuse/fuse_api.h            |   2 +
.../userlandfs/server/fuse/fuse_fs.cpp           |   9 +
.../userlandfs/server/fuse/fuse_main.cpp         |   5 +

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

Commit:      1263be8fc411a0ae7e5418ffb509790bcfe4287c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1263be8fc411
Author:      Julian Harnath <julian.harnath@xxxxxxxxxxxxxx>
Date:        Sat Feb 11 10:32:21 2017 UTC

FUSE compat: add Haiku extension

* Add a way for a FUSE module to supply Haiku-specific extensions.
  This allows it to integrate better with Haiku while only requiring
  minimal changes on the FUSE module itself.

* For now, there is only one extension: another function pointer for
  "get_fs_info", which lets the FUSE module fill in an fs_info struct.
  FUSE provides no good way to otherwise communicate extra information,
  such as the volume flags (e.g. B_FS_IS_SHARED).

* A FUSE module can signal that it supports the Haiku extensions by
    a) defining HAS_HAIKU_FUSE_EXTENSIONS before including the fuse
       headers
    b) setting the global variable gHasHaikuFuseExtensions to 1 in
       its initialization
  Otherwise, the Haiku extensions are completely invisible to the
  FUSE module.

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

diff --git a/headers/private/userlandfs/fuse/fuse.h 
b/headers/private/userlandfs/fuse/fuse.h
index b7708c7..0758bab 100644
--- a/headers/private/userlandfs/fuse/fuse.h
+++ b/headers/private/userlandfs/fuse/fuse.h
@@ -36,6 +36,11 @@
 extern "C" {
 #endif
 
+#ifdef HAS_FUSE_HAIKU_EXTENSIONS
+struct fs_info;
+extern int gHasHaikuFuseExtensions;
+#endif
+
 /* ----------------------------------------------------------- *
  * Basic FUSE API                                             *
  * ----------------------------------------------------------- */
@@ -423,6 +428,10 @@ struct fuse_operations {
         * Introduced in version 2.6
         */
        int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
+
+#ifdef HAS_FUSE_HAIKU_EXTENSIONS
+       int (*get_fs_info) (struct fs_info*);
+#endif
 };
 
 /** Extra context that may be needed by some filesystems
@@ -658,6 +667,10 @@ int fuse_fs_bmap(struct fuse_fs *fs, const char *path, 
size_t blocksize,
 void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn);
 void fuse_fs_destroy(struct fuse_fs *fs);
 
+#ifdef HAS_FUSE_HAIKU_EXTENSIONS
+int fuse_fs_get_fs_info(struct fuse_fs* fs, struct fs_info* info);
+#endif
+
 /**
  * Create a new fuse filesystem object
  *
diff --git 
a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
index 570afae..ea9cc42 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
@@ -783,6 +783,15 @@ FUSEVolume::Sync()
 status_t
 FUSEVolume::ReadFSInfo(fs_info* info)
 {
+       if (gHasHaikuFuseExtensions == 1 && fFS->ops.get_fs_info != NULL) {
+               int fuseError = fuse_fs_get_fs_info(fFS, info);
+               if (fuseError != 0)
+                       return fuseError;
+               return B_OK;
+       }
+
+       // No Haiku FUSE extensions, so our knowledge is limited: use some 
values
+       // from statfs and make reasonable guesses for the rest of them.
        if (fFS->ops.statfs == NULL)
                return B_UNSUPPORTED;
 
@@ -791,6 +800,7 @@ FUSEVolume::ReadFSInfo(fs_info* info)
        if (fuseError != 0)
                return fuseError;
 
+       memset(info, 0, sizeof(*info));
        info->flags = B_FS_IS_PERSISTENT;       // assume the FS is persistent
        info->block_size = st.f_bsize;
        info->io_size = 64 * 1024;                      // some value
diff --git a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_api.h 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_api.h
index dca679f..750e43e 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_api.h
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_api.h
@@ -7,6 +7,8 @@
 
 #define FUSE_USE_VERSION FUSE_VERSION
 
+#define HAS_FUSE_HAIKU_EXTENSIONS
+
 #include <fuse.h>
 #include <fuse_lowlevel.h>
 #include <fuse_opt.h>
diff --git a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_fs.cpp 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_fs.cpp
index 62831b1..d0959fa 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_fs.cpp
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_fs.cpp
@@ -380,3 +380,12 @@ fuse_fs_new(const struct fuse_operations* ops, size_t 
opSize, void* userData)
 
        return fs;
 }
+
+
+int
+fuse_fs_get_fs_info(struct fuse_fs* fs, struct fs_info* info)
+{
+       if (fs->ops.get_fs_info == NULL)
+               return ENOSYS;
+       return fs->ops.get_fs_info(info);
+}
diff --git 
a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_main.cpp 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_main.cpp
index 7dc318d..2633970 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_main.cpp
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/fuse_main.cpp
@@ -17,6 +17,11 @@
 #include "../RequestThread.h"
 
 
+int gHasHaikuFuseExtensions = 0;
+       // This global can be set to 1 by a Haiku-aware FUSE add-on to signal
+       // that it implements the Haiku-specific functions in struct
+       // fuse_operations (those which are guarded by 
HAS_FUSE_HAIKU_EXTENSIONS).
+
 int
 fuse_main_real(int argc, char* argv[], const struct fuse_operations* op,
        size_t opSize, void* userData)

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

Commit:      6297d6c73b684f1f7f1d9cb1deb2a38495be177c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6297d6c73b68
Author:      Julian Harnath <julian.harnath@xxxxxxxxxxxxxx>
Date:        Sat Feb 11 10:40:32 2017 UTC

FUSE compat: fill in some stat infos for getattr

* Prefill struct stat with some information which the FUSE module
  doesn't necessarily fill in

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

diff --git 
a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
index ea9cc42..b916346 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
@@ -1260,6 +1260,11 @@ FUSEVolume::ReadStat(void* _node, struct stat* st)
 
        locker.Unlock();
 
+       st->st_dev = GetID();
+       st->st_ino = node->id;
+       st->st_blksize = 2048;
+       st->st_type = 0;
+
        // stat the path
        int fuseError = fuse_fs_getattr(fFS, path, st);
        if (fuseError != 0)

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

Commit:      1b4f5f9b946266b5979266a608d659a07285531f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1b4f5f9b9462
Author:      Julian Harnath <julian.harnath@xxxxxxxxxxxxxx>
Date:        Sat Feb 11 10:43:08 2017 UTC

FUSE compat: fall back to truncate if no ftruncate

* As defined by the FUSE interface: if the FUSE module doesn't
  implement ftruncate(), fall back to using truncate() instead

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

diff --git 
a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
index b916346..9b12a59 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
@@ -1474,6 +1474,10 @@ FUSEVolume::Open(void* _node, int openMode, void** 
_cookie)
        // truncate the file, if requested
        if (truncate) {
                fuseError = fuse_fs_ftruncate(fFS, path, 0, cookie);
+               if (fuseError == ENOSYS) {
+                       // Fallback to truncate if ftruncate is not implemented
+                       fuseError = fuse_fs_truncate(fFS, path, 0);
+               }
                if (fuseError != 0) {
                        fuse_fs_flush(fFS, path, cookie);
                        fuse_fs_release(fFS, path, cookie);

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

Commit:      5adf34b0d5917e689ce670cb4f39759ec64c6b6d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=5adf34b0d591
Author:      Julian Harnath <julian.harnath@xxxxxxxxxxxxxx>
Date:        Sat Feb 11 11:29:09 2017 UTC

FUSE compat: add support for attribute reading

* Implement reading extended file attributes in FUSE modules,
  using getxattr()

  getxattr() is a quite limited API, not allowing to specify a read
  offset. So we read in the entire attribute value into a buffer and
  store in the cookie. This shouldn't be a problem memory-wise, since
  xattr implementions usually have limitations regarding attribute size
  anyway, so it'll rarely be more than a few kilobytes.

* Writing, renaming, and removing attributes is not yet implemented

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

diff --git 
a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEFileSystem.cpp 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEFileSystem.cpp
index 2852a9c..fa5e825 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEFileSystem.cpp
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEFileSystem.cpp
@@ -472,14 +472,14 @@ FUSEFileSystem::_InitCapabilities()
 //     // or write_attr() is present
 //     bool hasAttributes = (fFS->ops.read_attr || fFS->ops.write_attr);
 //     fNodeCapabilities.Set(FS_VNODE_CAPABILITY_CREATE_ATTR, hasAttributes);
-//     fNodeCapabilities.Set(FS_VNODE_CAPABILITY_OPEN_ATTR, hasAttributes);
-//     fNodeCapabilities.Set(FS_VNODE_CAPABILITY_CLOSE_ATTR, false);
-//     fNodeCapabilities.Set(FS_VNODE_CAPABILITY_FREE_ATTR_COOKIE, 
hasAttributes);
-//     fNodeCapabilities.Set(FS_VNODE_CAPABILITY_READ_ATTR, 
fFS->ops.read_attr);
+       fNodeCapabilities.Set(FS_VNODE_CAPABILITY_OPEN_ATTR, hasAttributes);
+       fNodeCapabilities.Set(FS_VNODE_CAPABILITY_CLOSE_ATTR, false);
+       fNodeCapabilities.Set(FS_VNODE_CAPABILITY_FREE_ATTR_COOKIE, 
hasAttributes);
+       fNodeCapabilities.Set(FS_VNODE_CAPABILITY_READ_ATTR, fFS->ops.getxattr);
 //     fNodeCapabilities.Set(FS_VNODE_CAPABILITY_WRITE_ATTR, 
fFS->ops.write_attr);
 
-//     fNodeCapabilities.Set(FS_VNODE_CAPABILITY_READ_ATTR_STAT,
-//             fFS->ops.stat_attr);
+       fNodeCapabilities.Set(FS_VNODE_CAPABILITY_READ_ATTR_STAT,
+               fFS->ops.getxattr);
 //     // missing: FS_VNODE_CAPABILITY_WRITE_ATTR_STAT
 //     fNodeCapabilities.Set(FS_VNODE_CAPABILITY_RENAME_ATTR, 
fFS->ops.rename_attr);
 //     fNodeCapabilities.Set(FS_VNODE_CAPABILITY_REMOVE_ATTR, 
fFS->ops.remove_attr);
diff --git 
a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
index 9b12a59..df8c883 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
@@ -280,6 +280,73 @@ private:
 };
 
 
+struct FUSEVolume::AttrCookie : RWLockable {
+public:
+       AttrCookie()
+               :
+               fValue(NULL),
+               fSize(0)
+       {
+       }
+
+       AttrCookie(const char* value)
+               :
+               fValue(strdup(value)),
+               fSize(strlen(value) + 1)
+       {
+       }
+
+       ~AttrCookie()
+       {
+               free(fValue);
+       }
+
+       bool IsValid() const
+       {
+               return fValue != NULL;
+       }
+
+       status_t Allocate(size_t size)
+       {
+               fValue = (char*)malloc(size);
+               if (fValue == NULL) {
+                       fSize = 0;
+                       return B_NO_MEMORY;
+               }
+               fSize = size;
+               return B_OK;
+       }
+
+       void Read(void* buffer, size_t bufferSize, off_t pos,
+               size_t* bytesRead) const
+       {
+               if (pos < 0 || (uint64)pos > SIZE_MAX || (size_t)pos > fSize - 
1) {
+                       *bytesRead = 0;
+                       return;
+               }
+               size_t copySize = fSize - pos;
+               if (copySize > bufferSize)
+                       copySize = bufferSize;
+               strlcpy((char*)buffer, &fValue[pos], bufferSize);
+               *bytesRead = copySize;
+       }
+
+       char* Buffer()
+       {
+               return fValue;
+       }
+
+       size_t Size() const
+       {
+               return fSize;
+       }
+
+private:
+       char*   fValue;
+       size_t  fSize;
+};
+
+
 struct FUSEVolume::ReadDirBuffer {
        FUSEVolume*     volume;
        FUSENode*       directory;
@@ -2067,6 +2134,105 @@ FUSEVolume::RewindAttrDir(void* _node, void* _cookie)
 }
 
 
+// #pragma mark - attributes
+
+
+status_t
+FUSEVolume::OpenAttr(void* _node, const char* name, int openMode,
+       void** _cookie)
+{
+       FUSENode* node = (FUSENode*)_node;
+
+       // lock the node
+       NodeReadLocker nodeLocker(this, node, true);
+       if (nodeLocker.Status() != B_OK)
+               RETURN_ERROR(nodeLocker.Status());
+
+       if (openMode != O_RDONLY) {
+               // Write support currently not implemented
+               RETURN_ERROR(B_UNSUPPORTED);
+       }
+
+       AutoLocker<Locker> locker(fLock);
+
+       // get a path for the node
+       char path[B_PATH_NAME_LENGTH];
+       size_t pathLen;
+       status_t error = _BuildPath(node, path, pathLen);
+       if (error != B_OK)
+               RETURN_ERROR(error);
+
+       locker.Unlock();
+
+       int attrSize = fuse_fs_getxattr(fFS, path, name, NULL, 0);
+       if (attrSize < 0)
+               return attrSize;
+
+       AttrCookie* cookie = new(std::nothrow)AttrCookie();
+       error = cookie->Allocate(attrSize);
+       if (error != B_OK)
+               RETURN_ERROR(error);
+
+       int bytesRead = fuse_fs_getxattr(fFS, path, name, cookie->Buffer(),
+               attrSize);
+       if (bytesRead < 0)
+               return bytesRead;
+
+       *_cookie = cookie;
+
+       return B_OK;
+}
+
+
+status_t
+FUSEVolume::CloseAttr(void* _node, void* _cookie)
+{
+       return B_OK;
+}
+
+
+status_t
+FUSEVolume::FreeAttrCookie(void* _node, void* _cookie)
+{
+       delete (AttrCookie*)_cookie;
+       return B_OK;
+}
+
+
+status_t
+FUSEVolume::ReadAttr(void* _node, void* _cookie, off_t pos, void* buffer,
+       size_t bufferSize, size_t* bytesRead)
+{
+       AttrCookie* cookie = (AttrCookie*)_cookie;
+
+       RWLockableWriteLocker cookieLocker(this, cookie);
+
+       if (!cookie->IsValid())
+               RETURN_ERROR(B_BAD_VALUE);
+
+       cookie->Read(buffer, bufferSize, pos, bytesRead);
+
+       return B_OK;
+}
+
+
+status_t
+FUSEVolume::ReadAttrStat(void* _node, void* _cookie, struct stat* st)
+{
+       AttrCookie* cookie = (AttrCookie*)_cookie;
+
+       RWLockableWriteLocker cookieLocker(this, cookie);
+
+       if (!cookie->IsValid())
+               RETURN_ERROR(B_BAD_VALUE);
+
+       st->st_size = cookie->Size();
+       st->st_type = B_RAW_TYPE;
+
+       return B_OK;
+}
+
+
 // #pragma mark -
 
 
diff --git 
a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.h 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.h
index 6ec6b8e..89abd73 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.h
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.h
@@ -108,11 +108,23 @@ public:
                                                                        uint32 
count, uint32* countRead);
        virtual status_t                        RewindAttrDir(void* node, void* 
cookie);
 
+       // attributes
+       virtual status_t                        OpenAttr(void* node, const 
char* name,
+                                                                       int 
openMode, void** cookie);
+       virtual status_t                        CloseAttr(void* node, void* 
cookie);
+       virtual status_t                        FreeAttrCookie(void* node, 
void* cookie);
+       virtual status_t                        ReadAttr(void* node, void* 
cookie,
+                                                                       off_t 
pos, void* buffer, size_t bufferSize,
+                                                                       size_t* 
bytesRead);
+       virtual status_t                        ReadAttrStat(void* node, void* 
cookie,
+                                                                       struct 
stat* st);
+
 private:
        struct DirEntryCache;
        struct DirCookie;
        struct FileCookie;
        struct AttrDirCookie;
+       struct AttrCookie;
        struct ReadDirBuffer;
        struct LockIterator;
        struct RWLockableReadLocking;

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

Commit:      6ced92452c2712c91e850d1012332cfb6704f3da
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6ced92452c27
Author:      Julian Harnath <julian.harnath@xxxxxxxxxxxxxx>
Date:        Sat Feb 11 22:34:11 2017 UTC

FUSE compat: add MIME type faking

* Add special handling for reading the BEOS:TYPE attribute to supply
  on-the-fly fake MIME types for FUSE module filesystems, the same
  way it's done in our FAT and NTFS FS modules

* Reuse the mime_ext_table which we already have and put it into a
  shared location so we don't get further extra copies of it

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

diff --git a/headers/private/file_systems/mime_ext_table.h 
b/headers/private/file_systems/mime_ext_table.h
new file mode 100644
index 0000000..4b9b316
--- /dev/null
+++ b/headers/private/file_systems/mime_ext_table.h
@@ -0,0 +1,24 @@
+/*
+       Copyright 1999-2001, Be Incorporated.   All Rights Reserved.
+       This file may be used under the terms of the Be Sample Code License.
+*/
+
+#ifndef MIME_TYPES_H
+#define MIME_TYPES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern const char* kAttrMimeTypeName;
+
+extern status_t set_mime(const char** mime, const char* filename);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
diff --git a/src/add-ons/kernel/file_systems/shared/mime_ext_table.c 
b/src/add-ons/kernel/file_systems/shared/mime_ext_table.c
new file mode 100644
index 0000000..6c6e926
--- /dev/null
+++ b/src/add-ons/kernel/file_systems/shared/mime_ext_table.c
@@ -0,0 +1,156 @@
+/*
+       Copyright 1999-2001, Be Incorporated.   All Rights Reserved.
+       This file may be used under the terms of the Be Sample Code License.
+*/
+
+#include <SupportDefs.h>
+
+#include <string.h>
+
+#include <file_systems/mime_ext_table.h>
+
+
+struct ext_mime {
+       char *extension;
+       char *mime;
+};
+
+static struct ext_mime mimes[] = {
+       { "gz", "application/x-gzip" },
+       { "hqx", "application/x-binhex40" },
+       { "lha", "application/x-lharc" },
+       { "pcl", "application/x-pcl" },
+       { "pdf", "application/pdf" },
+       { "ps", "application/postscript" },
+       { "sit", "application/x-stuff-it" },
+       { "tar", "application/x-tar" },
+       { "tgz", "application/x-gzip" },
+       { "uue", "application/x-uuencode" },
+       { "z", "application/x-compress" },
+       { "zip", "application/zip" },
+       { "zoo", "application/x-zoo" },
+       { "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" },
+       { "au", "audio/basic" },
+       { "mid", "audio/x-midi" },
+       { "midi", "audio/x-midi" },
+       { "mod", "audio/mod" },
+       { "ra", "audio/x-real-audio" },
+       { "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" },
+       { "gif", "image/gif" },
+       { "iff", "image/x-iff" },
+       { "jpg", "image/jpeg" },
+       { "jpeg", "image/jpeg" },
+       { "pbm", "image/x-portable-bitmap" },
+       { "pcx", "image/x-pcx" },
+       { "pgm", "image/x-portable-graymap" },
+       { "png", "image/png" },
+       { "ppm", "image/x-portable-pixmap" },
+       { "rgb", "image/x-rgb" },
+       { "tga", "image/x-targa" },
+       { "tif", "image/tiff" },
+       { "tiff", "image/tiff" },
+       { "xbm", "image/x-xbitmap" },
+       { "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" },
+       { "htm", "text/html" },
+       { "html", "text/html" },
+       { "rtf", "text/rtf" },
+       { "c", "text/x-source-code" },
+       { "cc", "text/x-source-code" },
+       { "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" },
+       { "ini", "text/plain" },
+       { "inf", "text/plain" },
+
+       { "ttf", "application/x-truetype" },
+
+       { NULL, NULL }
+};
+
+
+const char* kAttrMimeTypeName = "BEOS:TYPE";
+
+static const char* kFailBackMime = "application/octet-stream";
+static const char* kDirectoryMime = "application/x-vnd.Be-directory";
+
+
+status_t
+set_mime(const char** mime, const char* filename)
+{
+       struct ext_mime *p;
+       int32 namelen;
+       int32 ext_len;
+       *mime = NULL;
+
+       if (filename == NULL) {
+               *mime = kDirectoryMime;
+               return B_NO_ERROR;
+       }
+       namelen = strlen(filename);
+
+       for (p = mimes; p->extension; p++) {
+               ext_len = strlen(p->extension);
+
+               if (namelen <= ext_len)
+                       continue;
+
+               if (filename[namelen-ext_len-1] != '.')
+                       continue;
+
+               if (!strcasecmp(filename + namelen - ext_len, p->extension))
+                       break;
+       }
+       if(p->mime == NULL)
+               *mime = kFailBackMime;
+       else
+               *mime = p->mime;
+
+       return B_NO_ERROR;
+}
diff --git 
a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
index df8c883..1318096 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/FUSEVolume.cpp
@@ -6,6 +6,7 @@
 #include "FUSEVolume.h"
 
 #include <dirent.h>
+#include <file_systems/mime_ext_table.h>
 
 #include <algorithm>
 
@@ -282,18 +283,22 @@ private:
 
 struct FUSEVolume::AttrCookie : RWLockable {
 public:
-       AttrCookie()
+       AttrCookie(const char* name)
                :
                fValue(NULL),
-               fSize(0)
+               fSize(0),
+               fType(0)
        {
+               _SetType(name);
        }
 
-       AttrCookie(const char* value)
+       AttrCookie(const char* name, const char* value)
                :
                fValue(strdup(value)),
-               fSize(strlen(value) + 1)
+               fSize(strlen(value) + 1),
+               fType(0)
        {
+               _SetType(name);
        }
 
        ~AttrCookie()
@@ -306,6 +311,11 @@ public:
                return fValue != NULL;
        }
 
+       uint32 Type() const
+       {
+               return fType;
+       }
+
        status_t Allocate(size_t size)
        {
                fValue = (char*)malloc(size);
@@ -342,8 +352,18 @@ public:
        }
 
 private:
+       void _SetType(const char* name)
+       {
+               if (strcmp(name, kAttrMimeTypeName) == 0)
+                       fType = B_MIME_STRING_TYPE;
+               else
+                       fType = B_RAW_TYPE;
+       }
+
+private:
        char*   fValue;
        size_t  fSize;
+       uint32  fType;
 };
 
 
@@ -2165,10 +2185,22 @@ FUSEVolume::OpenAttr(void* _node, const char* name, int 
openMode,
        locker.Unlock();
 
        int attrSize = fuse_fs_getxattr(fFS, path, name, NULL, 0);
-       if (attrSize < 0)
+       if (attrSize < 0) {
+               if (strcmp(name, kAttrMimeTypeName) == 0) {
+                       // Return a fake MIME type attribute based on the file 
extension
+                       const char* mimeType = NULL;
+                       error = set_mime(&mimeType, S_ISDIR(node->type) ? NULL 
: &path[0]);
+                       if (error != B_OK)
+                               return error;
+                       *_cookie = new(std::nothrow)AttrCookie(name, mimeType);
+                       return B_OK;
+               }
+
+               // Reading attribute failed
                return attrSize;
+       }
 
-       AttrCookie* cookie = new(std::nothrow)AttrCookie();
+       AttrCookie* cookie = new(std::nothrow)AttrCookie(name);
        error = cookie->Allocate(attrSize);
        if (error != B_OK)
                RETURN_ERROR(error);
@@ -2227,7 +2259,7 @@ FUSEVolume::ReadAttrStat(void* _node, void* _cookie, 
struct stat* st)
                RETURN_ERROR(B_BAD_VALUE);
 
        st->st_size = cookie->Size();
-       st->st_type = B_RAW_TYPE;
+       st->st_type = cookie->Type();
 
        return B_OK;
 }
diff --git a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/Jamfile 
b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/Jamfile
index dff8682..628ccdc 100644
--- a/src/add-ons/kernel/file_systems/userlandfs/server/fuse/Jamfile
+++ b/src/add-ons/kernel/file_systems/userlandfs/server/fuse/Jamfile
@@ -27,7 +27,10 @@ SharedLibrary libuserlandfs_fuse.so
        fuse_opt.c
        FUSEFileSystem.cpp
        FUSEVolume.cpp
-
+       mime_ext_table.c
        :
        <nogrist>userlandfs_server shared be [ TargetLibsupc++ ]
 ;
+
+SEARCH on [ FGristFiles mime_ext_table.c ]
+       += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems shared ] ;

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

Revision:    hrev50983
Commit:      5d9f944f0a72c5a82be2611c00395d95335f1dc5
URL:         http://cgit.haiku-os.org/haiku/commit/?id=5d9f944f0a72
Author:      Julian Harnath <julian.harnath@xxxxxxxxxxxxxx>
Date:        Sat Feb 11 22:51:36 2017 UTC

Use common MIME table in FAT and NTFS, too

* Last commit put the file-extension-to-MIME-type table and associated
  code into a shared location. So now we can remove it from the FAT
  and NTFS FS add-ons (they both had their own copy) and use the shared
  one there as well, removing the code duplication.

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

diff --git a/src/add-ons/kernel/file_systems/fat/Jamfile 
b/src/add-ons/kernel/file_systems/fat/Jamfile
index 822901c..5eb79ea 100644
--- a/src/add-ons/kernel/file_systems/fat/Jamfile
+++ b/src/add-ons/kernel/file_systems/fat/Jamfile
@@ -13,9 +13,12 @@ KernelAddon fat :
        fat.c
        file.c
        iter.c
-       mime_table.c
+       mime_ext_table.c
        mkdos.cpp
        util.c
        vcache.c
        version.c
 ;
+
+SEARCH on [ FGristFiles mime_ext_table.c ]
+       += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems shared ] ;
diff --git a/src/add-ons/kernel/file_systems/fat/attr.c 
b/src/add-ons/kernel/file_systems/fat/attr.c
index 36c30da..6f0bf71 100644
--- a/src/add-ons/kernel/file_systems/fat/attr.c
+++ b/src/add-ons/kernel/file_systems/fat/attr.c
@@ -15,13 +15,13 @@
 #include <KernelExport.h>
 
 #include <dirent.h>
+#include <file_systems/mime_ext_table.h>
 #include <fs_attr.h>
 #include <string.h>
 #include <malloc.h>
 
 #include "dosfs.h"
 #include "attr.h"
-#include "mime_table.h"
 
 int32 kBeOSTypeCookie = 0x1234;
 
@@ -29,31 +29,7 @@ int32 kBeOSTypeCookie = 0x1234;
 
 status_t set_mime_type(vnode *node, const char *filename)
 {
-       struct ext_mime *p;
-       int32 namelen, ext_len;
-
-       DPRINTF(0, ("get_mime_type of (%s)\n", filename));
-
-       node->mime = NULL;
-
-       namelen = strlen(filename);
-
-       for (p=mimes;p->extension;p++) {
-               ext_len = strlen(p->extension);
-
-               if (namelen <= ext_len)
-                       continue;
-
-               if (filename[namelen-ext_len-1] != '.')
-                       continue;
-
-               if (!strcasecmp(filename + namelen - ext_len, p->extension))
-                       break;
-       }
-
-       node->mime = p->mime;
-
-       return B_OK;
+       return set_mime(&node->mime, filename);
 }
 
 
diff --git a/src/add-ons/kernel/file_systems/fat/mime_table.c 
b/src/add-ons/kernel/file_systems/fat/mime_table.c
deleted file mode 100644
index 85f9a58..0000000
--- a/src/add-ons/kernel/file_systems/fat/mime_table.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
-       Copyright 1999-2001, Be Incorporated.   All Rights Reserved.
-       This file may be used under the terms of the Be Sample Code License.
-
-       extended: 2001-12-11 by Marcus Overhagen
-*/
-
-struct ext_mime {
-       char *extension;
-       char *mime;
-};
-
-struct ext_mime mimes[] = {
-       { "gz", "application/x-gzip" },
-       { "hqx", "application/x-binhex40" },
-       { "lha", "application/x-lharc" },
-       { "lzh", "application/x-lharc" },
-       { "pcl", "application/x-pcl" },
-       { "pdf", "application/pdf" },
-       { "ps", "application/postscript" },
-       { "sit", "application/x-stuff-it" },
-       { "tar", "application/x-tar" },
-       { "tgz", "application/x-gzip" },
-       { "uue", "application/x-uuencode" },
-       { "z", "application/x-compress" },
-       { "zip", "application/zip" },
-       { "zoo", "application/x-zoo" },
-       { "pkg", "application/x-scode-UPkg" },
-       { "vdwn", "application/x-scode-UPkg" },
-       { "proj", "application/x-mw-project" },
-       { "swf", "application/x-shockwave-flash" },
-       { "clp", "application/x-codeliege-project" },
-
-       { "aif", "audio/x-aiff" },
-       { "aifc", "audio/x-aifc" },
-       { "aiff", "audio/x-aiff" },
-       { "au", "audio/basic" },
-       { "mid", "audio/x-midi" },
-       { "midi", "audio/x-midi" },
-       { "mod", "audio/mod" },
-       { "ra", "audio/x-real-audio" },
-       { "wav", "audio/x-wav" },
-       { "mp2", "audio/x-mpeg" },
-       { "mp3", "audio/x-mpeg" },
-       { "ogg", "audio/x-vorbis" },
-       { "mpc", "audio/x-mpc" },
-       { "asf", "application/x-asf" },
-       { "riff", "application/x-riff" },
-       { "wma", "audio/x-ms-wma" },
-
-       { "bmp", "image/x-bmp" },
-       { "fax", "image/g3fax" },
-       { "gif", "image/gif" },
-       { "iff", "image/x-iff" },
-       { "jpg", "image/jpeg" },
-       { "jpeg", "image/jpeg" },
-       { "pbm", "image/x-portable-bitmap" },
-       { "pcx", "image/x-pcx" },
-       { "pgm", "image/x-portable-graymap" },
-       { "png", "image/png" },
-       { "ppm", "image/x-portable-pixmap" },
-       { "rgb", "image/x-rgb" },
-       { "tga", "image/x-targa" },
-       { "tif", "image/tiff" },
-       { "tiff", "image/tiff" },
-       { "xbm", "image/x-xbitmap" },
-
-       { "txt", "text/plain" },
-       { "ini", "text/plain" },
-       { "log", "text/plain" },
-       { "bat", "text/plain" },
-       { "doc", "text/plain" },
-       { "cfg", "text/plain" },
-       { "inf", "text/plain" },
-       { "htm", "text/html" },
-       { "html", "text/html" },
-       { "rtf", "text/rtf" },
-       { "c", "text/x-source-code" },
-       { "cc", "text/x-source-code" },
-       { "c++", "text/x-source-code" },
-       { "h", "text/x-source-code" },
-       { "h++", "text/x-source-code" },
-       { "hh", "text/x-source-code" },
-       { "hpp", "text/x-source-code" },
-       { "pl", "text/x-source-code" },
-       { "py", "text/x-source-code" },
-       { "cxx", "text/x-source-code" },
-       { "cpp", "text/x-source-code" },
-       { "S", "text/x-source-code" },
-       { "asm", "text/x-source-code" },
-       { "bas", "text/x-source-code" },
-       { "pas", "text/x-source-code" },
-       { "java", "text/x-source-code" },
-
-       { "avi", "video/x-msvideo" },
-       { "mov", "video/quicktime" },
-       { "mpg", "video/mpeg" },
-       { "mpeg", "video/mpeg" },
-       { "ogm", "video/x-ogm" },
-       { "wmv", "video/x-ms-wmv" },
-       { "rm", "application/vnd.rn-realmedia" },
-       { "rn", "application/vnd.rn-realmedia" },
-
-       { 0, 0 }
-};
diff --git a/src/add-ons/kernel/file_systems/fat/mime_table.h 
b/src/add-ons/kernel/file_systems/fat/mime_table.h
deleted file mode 100644
index 1a88823..0000000
--- a/src/add-ons/kernel/file_systems/fat/mime_table.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
-       Copyright 1999-2001, Be Incorporated.   All Rights Reserved.
-       This file may be used under the terms of the Be Sample Code License.
-*/
-
-#ifndef MIME_TYPES_H
-#define MIME_TYPES_H
-
-struct ext_mime {
-       char *extension;
-       char *mime;
-};
-
-extern struct ext_mime mimes[];
-
-#endif
diff --git a/src/add-ons/kernel/file_systems/ntfs/Jamfile 
b/src/add-ons/kernel/file_systems/ntfs/Jamfile
index cc8febd..315370d 100644
--- a/src/add-ons/kernel/file_systems/ntfs/Jamfile
+++ b/src/add-ons/kernel/file_systems/ntfs/Jamfile
@@ -13,7 +13,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) utils ] ;
 KernelAddon ntfs :
        attributes.c
        fake_attributes.c
-       mime_table.c
+       mime_ext_table.c
        utils.c
        ntfsdir.c
        volume_util.c
@@ -22,7 +22,7 @@ KernelAddon ntfs :
        attrdef.c
        sd.c
        boot.c
-       mkntfs.c        
+       mkntfs.c
        :
        libntfs.a
        ;
@@ -31,5 +31,8 @@ SEARCH on [ FGristFiles
                kernel_cpp.cpp
        ] = [ FDirName $(HAIKU_TOP) src system kernel util ] ;
 
+SEARCH on [ FGristFiles mime_ext_table.c ]
+       += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems shared ] ;
+
 SubInclude HAIKU_TOP src add-ons kernel file_systems ntfs libntfs ;
 
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 ebc02f4..1fc00f7 100644
--- a/src/add-ons/kernel/file_systems/ntfs/fake_attributes.c
+++ b/src/add-ons/kernel/file_systems/ntfs/fake_attributes.c
@@ -13,63 +13,31 @@
 #include <KernelExport.h>
 
 #include <dirent.h>
+#include <file_systems/mime_ext_table.h>
 #include <fs_attr.h>
 #include <string.h>
 #include <malloc.h>
 
 #include "ntfs.h"
 #include "fake_attributes.h"
-#include "mime_table.h"
 
 int32 kOpenTypeCookie = 0;
 int32 kCloseTypeCookie = 1;
 int32 kSetTypeCookie = 0x1234;
 int32 kFreeTypeCookie = 0x87654321;
 
-char *kFailBackMime = {"application/octet-stream"};
-char *kDirectoryMime = {"application/x-vnd.Be-directory"};
-char *kAttrTypeName = {"BEOS:TYPE"};
 
-
-status_t set_mime(vnode *node, const char *filename)
+status_t set_mime_type(vnode *node, const char *filename)
 {
-       struct ext_mime *p;
-       int32 namelen;
-       int32 ext_len;
-       node->mime = NULL;
-       
-       if (filename == NULL)
-        {
-               node->mime = kDirectoryMime;
-               return B_NO_ERROR;
-        }
-       namelen = strlen(filename);
-
-       for (p=mimes; p->extension; p++) {
-               ext_len = strlen(p->extension);
-
-               if (namelen <= ext_len)
-                       continue;
-
-               if (filename[namelen-ext_len-1] != '.')
-                       continue;
-               
-               if (!strcasecmp(filename + namelen - ext_len, p->extension))
-                       break;
-       }
-       if(p->mime == NULL)
-               node->mime = kFailBackMime;
-       else
-               node->mime = p->mime;
-       return B_NO_ERROR;
+       return set_mime(&node->mime, filename);
 }
 
 
-status_t 
+status_t
 fake_open_attrib_dir(fs_volume *_vol, fs_vnode *_node, void **_cookie)
 {
        nspace *ns = (nspace *)_vol->private_volume;
-               
+
        int     result = B_NO_ERROR;
 
        TRACE("fake_open_attrdir - ENTER\n");
@@ -80,39 +48,39 @@ fake_open_attrib_dir(fs_volume *_vol, fs_vnode *_node, void 
**_cookie)
                result = ENOMEM;
                goto    exit;
        }
-       
+
        *(int32 *)(*_cookie) = kOpenTypeCookie;
-       
+
 exit:
 
        TRACE("fake_open_attrdir - EXIT, result is %s\n", strerror(result));
-       
+
        UNLOCK_VOL(ns);
-       
+
        return result;
 }
 
 
-status_t 
+status_t
 fake_close_attrib_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie)
 {
        nspace *ns = (nspace *)_vol->private_volume;
-       
+
        TRACE("fake_close_attrdir - ENTER\n");
 
        LOCK_VOL(ns);
 
        *(int32 *)_cookie = kCloseTypeCookie;
-       
+
        TRACE("fake_close_attrdir - EXIT\n");
-       
+
        UNLOCK_VOL(ns);
-       
+
        return B_NO_ERROR;
 }
 
 
-status_t 
+status_t
 fake_free_attrib_dir_cookie(fs_volume *_vol, fs_vnode *_node, void *_cookie)
 {
        nspace *ns = (nspace *)_vol->private_volume;
@@ -120,7 +88,7 @@ fake_free_attrib_dir_cookie(fs_volume *_vol, fs_vnode 
*_node, void *_cookie)
        int     result = B_NO_ERROR;
 
        LOCK_VOL(ns);
-               
+
        TRACE("fake_free_attrib_dir_cookie - ENTER\n");
 
        if (_cookie == NULL) {
@@ -128,7 +96,7 @@ fake_free_attrib_dir_cookie(fs_volume *_vol, fs_vnode 
*_node, void *_cookie)
                result =  EINVAL;
                goto    exit;
        }
-       
+
        *(int32 *)_cookie = kFreeTypeCookie;
        free(_cookie);
 
@@ -138,12 +106,12 @@ exit:
                strerror(result));
 
        UNLOCK_VOL(ns);
-       
+
        return result;
 }
 
 
-status_t 
+status_t
 fake_rewind_attrib_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie)
 {
        nspace *ns = (nspace *)_vol->private_volume;
@@ -151,7 +119,7 @@ fake_rewind_attrib_dir(fs_volume *_vol, fs_vnode *_node, 
void *_cookie)
        int     result = B_NO_ERROR;
 
        LOCK_VOL(ns);
-       
+
        TRACE("fake_rewind_attrcookie  - ENTER\n");
 
        if (_cookie == NULL) {
@@ -160,7 +128,7 @@ fake_rewind_attrib_dir(fs_volume *_vol, fs_vnode *_node, 
void *_cookie)
                result =  EINVAL;
                goto    exit;
        }
-       
+
        *(uint32 *)_cookie = kOpenTypeCookie;
 
 exit:
@@ -168,12 +136,12 @@ exit:
        TRACE("fake_rewind_attrcookie - EXIT, result is %s\n", 
strerror(result));
 
        UNLOCK_VOL(ns);
-       
+
        return result;
 }
 
 
-status_t 
+status_t
 fake_read_attrib_dir(fs_volume *_vol, fs_vnode *_node, void *_cookie,
        struct dirent *entry, size_t bufsize, uint32 *num)
 {
@@ -190,11 +158,11 @@ fake_read_attrib_dir(fs_volume *_vol, fs_vnode *_node, 
void *_cookie,
 
        if ((*cookie == kOpenTypeCookie) && (node->mime)) {
                *num = 1;
-               
+
                entry->d_ino = node->vnid;
                entry->d_dev = ns->id;
-               entry->d_reclen = sizeof(struct dirent) + strlen(kAttrTypeName);
-               strcpy(entry->d_name, kAttrTypeName);
+               entry->d_reclen = sizeof(struct dirent) + 
strlen(kAttrMimeTypeName);
+               strcpy(entry->d_name, kAttrMimeTypeName);
        }
 
        *cookie = kCloseTypeCookie;
@@ -202,7 +170,7 @@ fake_read_attrib_dir(fs_volume *_vol, fs_vnode *_node, void 
*_cookie,
        TRACE("fake_read_attrdir - EXIT\n");
 
        UNLOCK_VOL(ns);
-       
+
        return B_NO_ERROR;
 }
 
@@ -211,19 +179,19 @@ fake_create_attrib(fs_volume *_vol, fs_vnode *_node, 
const char* name,
        uint32 type, int openMode, void** _cookie)
 {
        nspace *ns = (nspace *)_vol->private_volume;
-               
+
        LOCK_VOL(ns);
-       
+
        TRACE("fake_create_attrib - ENTER (name = [%s])\n",name);
 
-       if (strcmp(name, kAttrTypeName) == 0)
+       if (strcmp(name, kAttrMimeTypeName) == 0)
                *_cookie = &kSetTypeCookie;
-       
+
        TRACE("fake_create_attrib - EXIT\n");
 
        UNLOCK_VOL(ns);
-               
-       return B_NO_ERROR;      
+
+       return B_NO_ERROR;
 }
 
 status_t
@@ -232,12 +200,12 @@ fake_open_attrib(fs_volume *_vol, fs_vnode *_node, const 
char *name,
 {
        nspace *ns = (nspace *)_vol->private_volume;
        status_t result = B_NO_ERROR;
-               
+
        LOCK_VOL(ns);
-       
+
        TRACE("fake_open_attrib - ENTER (name = [%s])\n",name);
 
-       if (strcmp(name, kAttrTypeName) == 0)
+       if (strcmp(name, kAttrMimeTypeName) == 0)
                *_cookie = &kSetTypeCookie;
        else
                result = ENOENT;
@@ -245,7 +213,7 @@ fake_open_attrib(fs_volume *_vol, fs_vnode *_node, const 
char *name,
        TRACE("fake_open_attrib - EXIT, result is %s\n", strerror(result));
 
        UNLOCK_VOL(ns);
-               
+
        return result;
 }
 
@@ -264,12 +232,12 @@ fake_free_attrib_cookie(fs_volume *_vol, fs_vnode *_node, 
void *cookie)
 }
 
 
-status_t 
+status_t
 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);
@@ -280,7 +248,7 @@ fake_read_attrib_stat(fs_volume *_vol, fs_vnode *_node, 
void *_cookie,
                result = ENOENT;
                goto    exit;
        }
-       
+
        stat->st_type = MIME_STRING_TYPE;
        if (node->mime == NULL)
                stat->st_size = 0;
@@ -293,17 +261,17 @@ exit:
                strerror(result));
 
        UNLOCK_VOL(ns);
-       
+
        return B_NO_ERROR;
 }
 
 
-status_t 
+status_t
 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;
 
@@ -315,12 +283,12 @@ fake_read_attrib(fs_volume *_vol, fs_vnode *_node, void 
*_cookie,
                result = ENOENT;
                goto    exit;
        }
-                       
+
        if (node->mime == NULL) {
                result = ENOENT;
                goto    exit;
        }
-       
+
        if ((pos < 0) || (pos > strlen(node->mime))) {
                result = EINVAL;
                goto    exit;
@@ -329,13 +297,13 @@ fake_read_attrib(fs_volume *_vol, fs_vnode *_node, void 
*_cookie,
        strncpy(buffer, node->mime + pos, *_length - 1);
        ((char *)buffer)[*_length - 1] = 0;
        *_length = strlen(buffer) + 1;
-       
+
 exit:
-       
+
        TRACE("fake_read_attr - EXIT, result is %s\n", strerror(result));
 
        UNLOCK_VOL(ns);
-       
+
        return result;
 }
 
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 f121f0f..5c00d33 100644
--- a/src/add-ons/kernel/file_systems/ntfs/fake_attributes.h
+++ b/src/add-ons/kernel/file_systems/ntfs/fake_attributes.h
@@ -12,7 +12,7 @@
 
 #include <fs_attr.h>
 
-status_t set_mime(vnode *node, const char *filename);
+status_t set_mime_type(vnode *node, const char *filename);
 
 status_t fake_open_attrib_dir(fs_volume *_vol, fs_vnode *_node,
        void **_cookie);
@@ -37,5 +37,5 @@ status_t fake_read_attrib(fs_volume *_vol, fs_vnode *_node, 
void *cookie,
        off_t pos,void *buffer, size_t *_length);
 status_t fake_write_attrib(fs_volume *_vol, fs_vnode *_node, void *cookie,
        off_t pos,      const void *buffer, size_t *_length);
-       
+
 #endif //NTFS_FAKE_ATTR_H_
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 3b89268..0c7db53 100644
--- a/src/add-ons/kernel/file_systems/ntfs/fs_func.c
+++ b/src/add-ons/kernel/file_systems/ntfs/fs_func.c
@@ -689,12 +689,12 @@ 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, NULL);
+                               set_mime_type(newNode, NULL);
                        else {
                                name = (char*)malloc(MAX_PATH);
                                if (name != NULL) {
                                        if (utils_inode_get_name(ni, name, 
MAX_PATH) == 1)
-                                               set_mime(newNode, name);
+                                               set_mime_type(newNode, name);
                                        free(name);
                                }
                        }
@@ -1146,9 +1146,9 @@ fs_create(fs_volume *_vol, fs_vnode *_dir, const char 
*name, int omode,
 
                        if (ns->fake_attrib) {
                                if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
-                                       set_mime(newNode, NULL);
+                                       set_mime_type(newNode, NULL);
                                else
-                                       set_mime(newNode, name);
+                                       set_mime_type(newNode, name);
                        }
 
                        ntfs_mark_free_space_outdated(ns);
@@ -1750,9 +1750,9 @@ 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, NULL);
+                               set_mime_type(file, NULL);
                        else
-                               set_mime(file, newname);
+                               set_mime_type(file, newname);
                        notify_attribute_changed(ns->id, -1, file->vnid, 
"BEOS:TYPE",
                                B_ATTR_CHANGED);
                }
diff --git a/src/add-ons/kernel/file_systems/ntfs/mime_table.c 
b/src/add-ons/kernel/file_systems/ntfs/mime_table.c
deleted file mode 100644
index 649dbf6..0000000
--- a/src/add-ons/kernel/file_systems/ntfs/mime_table.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
-       Copyright 1999-2001, Be Incorporated.   All Rights Reserved.
-       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[] = {
-       { "gz", "application/x-gzip" },
-       { "hqx", "application/x-binhex40" },
-       { "lha", "application/x-lharc" },
-       { "pcl", "application/x-pcl" },
-       { "pdf", "application/pdf" },
-       { "ps", "application/postscript" },
-       { "sit", "application/x-stuff-it" },
-       { "tar", "application/x-tar" },
-       { "tgz", "application/x-gzip" },
-       { "uue", "application/x-uuencode" },
-       { "z", "application/x-compress" },
-       { "zip", "application/zip" },
-       { "zoo", "application/x-zoo" },
-       { "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" },
-       { "au", "audio/basic" },
-       { "mid", "audio/x-midi" },
-       { "midi", "audio/x-midi" },
-       { "mod", "audio/mod" },
-       { "ra", "audio/x-real-audio" },
-       { "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" },
-       { "gif", "image/gif" },
-       { "iff", "image/x-iff" },
-       { "jpg", "image/jpeg" },
-       { "jpeg", "image/jpeg" },
-       { "pbm", "image/x-portable-bitmap" },
-       { "pcx", "image/x-pcx" },
-       { "pgm", "image/x-portable-graymap" },
-       { "png", "image/png" },
-       { "ppm", "image/x-portable-pixmap" },
-       { "rgb", "image/x-rgb" },
-       { "tga", "image/x-targa" },
-       { "tif", "image/tiff" },
-       { "tiff", "image/tiff" },
-       { "xbm", "image/x-xbitmap" },
-       { "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" },
-       { "htm", "text/html" },
-       { "html", "text/html" },
-       { "rtf", "text/rtf" },
-       { "c", "text/x-source-code" },
-       { "cc", "text/x-source-code" },
-       { "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" },
-       { "ini", "text/plain" },
-       { "inf", "text/plain" },
-               
-       { "ttf", "application/x-truetype" },
-
-       { NULL, NULL }
-};
diff --git a/src/add-ons/kernel/file_systems/ntfs/mime_table.h 
b/src/add-ons/kernel/file_systems/ntfs/mime_table.h
deleted file mode 100644
index f62978d..0000000
--- a/src/add-ons/kernel/file_systems/ntfs/mime_table.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
-       Copyright 1999-2001, Be Incorporated.   All Rights Reserved.
-       This file may be used under the terms of the Be Sample Code License.
-*/
-
-#ifndef MIME_TYPES_H
-#define MIME_TYPES_H
-
-struct ext_mime {
-       char *extension;
-       char *mime;
-};
-
-extern struct ext_mime mimes[];
-
-#endif


Other related posts:

  • » [haiku-commits] haiku: hrev50983 - src/add-ons/kernel/file_systems/ntfs src/add-ons/kernel/file_systems/userlandfs/server/fuse src/add-ons/kernel/file_systems/shared src/add-ons/kernel/file_systems/fat headers/private - julian . harnath