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.
This commit is contained in:
Julian Harnath 2017-02-11 22:51:36 +00:00
parent 6ced92452c
commit 5d9f944f0a
10 changed files with 67 additions and 364 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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