레이블이 external인 게시물을 표시합니다. 모든 게시물 표시
레이블이 external인 게시물을 표시합니다. 모든 게시물 표시

2013년 7월 4일 목요일

How to support NTFS fs with External Storage.

안드로이드의 external storage(USB Mass Storage)에 NTFS 파일 시스템을 지원하기

android_4.2.2 (BUILD_ID=JDQ39E)

storage_list.xml에 item을 추가한다.
device/hardkernel/odroid/overlay/frameworks/base/core/res/res/xml/storage_list.xml

<storage android:mountPoint="/storage/usb1"

             android:storageDescription="@string/storage_usb"
             android:primary="false"
             android:removable="true" />

USB Mass Storage를 연결 하면 발생하는 노드를 vold.fstab에 추가 한다.
device/hardkernel/odroid/conf/vold.fstab

dev_mount usb /storage/usb1 auto /devices/platform/xxx

init.odroid.rc에 node를 만든다.
device/hardkernel/odroid/conf/init.odroid.rc

mkdir /storage/usb1 0000 system system

system/vold를 수정 한다.

$ svn diff
Index: Volume.cpp
===================================================================
--- Volume.cpp (revision 21)
+++ Volume.cpp (working copy)
@@ -44,6 +44,7 @@
 #include "VolumeManager.h"
 #include "ResponseCode.h"
 #include "Fat.h"
+#include "Ntfs.h"
 #include "Process.h"
 #include "cryptfs.h"

@@ -401,7 +402,13 @@
         if (Fat::check(devicePath)) {
             if (errno == ENODATA) {
                 SLOGW("%s does not contain a FAT filesystem\n", devicePath);
-                continue;
+ if (Ntfs::doMount(devicePath, getMountpoint(), false, false, false,
+ 1000, 1015, 0702, false)) {
+ SLOGE("%s failed to mount via NTFS (%s)\n", devicePath, strerror(errno));
+ } else {
+ SLOGE("NTFS mounted");
+                 continue;
+ }
             }
             errno = EIO;
             /* Badness - abort the mount */
Index: Android.mk
===================================================================
--- Android.mk (revision 21)
+++ Android.mk (working copy)
@@ -12,6 +12,7 @@
  Process.cpp \
  Ext4.cpp \
  Fat.cpp \
+ Ntfs.cpp \
  Loop.cpp \
  Devmapper.cpp \
  ResponseCode.cpp \



Ntfs.h


  1 /*
  2  * Copyright (C) 2008 The Android Open Source Project
  3  *
  4  * Licensed under the Apache License, Version 2.0 (the "License");
  5  * you may not use this file except in compliance with the License.
  6  * You may obtain a copy of the License at
  7  *
  8  *      http://www.apache.org/licenses/LICENSE-2.0
  9  *
 10  * Unless required by applicable law or agreed to in writing, software
 11  * distributed under the License is distributed on an "AS IS" BASIS,
 12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  * See the License for the specific language governing permissions and
 14  * limitations under the License.
 15  */
 16
 17 #ifndef _NTFS_H
 18 #define _NTFS_H
 19
 20 #include <unistd.h>
 21
 22 class Ntfs {
 23 public:
 24     static int doMount(const char *fsPath, const char *mountPoint,
 25                        bool ro, bool remount, bool executable,
 26                        int ownerUid, int ownerGid, int permMask,
 27                        bool createLost);
 28 };
 29
 30 #endif


Ntfs.cpp


  1 /*
  2  * Copyright (C) 2008 The Android Open Source Project
  3  *
  4  * Licensed under the Apache License, Version 2.0 (the "License");
  5  * you may not use this file except in compliance with the License.
  6  * You may obtain a copy of the License at
  7  *
  8  *      http://www.apache.org/licenses/LICENSE-2.0
  9  *
 10  * Unless required by applicable law or agreed to in writing, software
 11  * distributed under the License is distributed on an "AS IS" BASIS,
 12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  * See the License for the specific language governing permissions and
 14  * limitations under the License.
 15  */
 16
 17 #include <stdio.h>
 18 #include <fcntl.h>
 19 #include <unistd.h>
 20 #include <errno.h>
 21 #include <string.h>
 22 #include <dirent.h>
 23 #include <errno.h>
 24 #include <fcntl.h>
 25
 26 #include <sys/types.h>
 27 #include <sys/stat.h>
 28 #include <sys/types.h>
 29 #include <sys/mman.h>
 30 #include <sys/mount.h>
 31
 32 #include <linux/kdev_t.h>
 33
 34 #define LOG_TAG "Vold"
 35
 36 #include <cutils/log.h>
 37 #include <cutils/properties.h>
 38
 39 #include "Ntfs.h"
 40
 41 static char FSCK_MSDOS_PATH[] = "/system/bin/fsck_msdos";
 42 static char MKDOSFS_PATH[] = "/system/bin/newfs_msdos";
 43 extern "C" int logwrap(int argc, const char **argv, int background);
 44 extern "C" int mount(const char *, const char *, const char *, unsigned long, const void *);
 45
 46 int Ntfs::doMount(const char *fsPath, const char *mountPoint,
 47                  bool ro, bool remount, bool executable,
 48                  int ownerUid, int ownerGid, int permMask, bool createLost) {
 49     int rc;
 50     unsigned long flags;
 51     char mountData[255];
 52
 53     flags = MS_NODEV | MS_NOSUID | MS_DIRSYNC;
54 
 55     flags |= (executable ? 0 : MS_NOEXEC);
 56     flags |= (ro ? MS_RDONLY : 0);
 57     flags |= (remount ? MS_REMOUNT : 0);
 58 
 59     /*
 60      * Note: This is a temporary hack. If the sampling profiler is enabled,
 61      * we make the SD card world-writable so any process can write snapshots.
 62      *
 63      * TODO: Remove this code once we have a drop box in system_server.
 64      */
 65     char value[PROPERTY_VALUE_MAX];
 66     property_get("persist.sampling_profiler", value, "");
 67     if (value[0] == '1') {
 68         SLOGW("The SD card is world-writable because the"
 69             " 'persist.sampling_profiler' system property is set to '1'.");
 70         permMask = 0;
 71     }
 72 
 73     sprintf(mountData,
 74             "utf8,uid=%d,gid=%d,fmask=%o,dmask=%o",
 75             ownerUid, ownerGid, permMask, permMask);
 76 
 77     rc = mount(fsPath, mountPoint, "ntfs", flags, mountData);
 78 
 79     if (rc && errno == EROFS) {
 80         SLOGE("%s appears to be a read only filesystem - retrying mount RO", fsPath);
 81         flags |= MS_RDONLY;
 82         rc = mount(fsPath, mountPoint, "ntfs", flags, mountData);
 83     }
 84 
 85     if (rc == 0 && createLost) {
 86         char *lost_path;
 87         asprintf(&lost_path, "%s/LOST.DIR", mountPoint);
 88         if (access(lost_path, F_OK)) {
 89             /*
 90              * Create a LOST.DIR in the root so we have somewhere to put
 91              * lost cluster chains (fsck_msdos doesn't currently do this)
 92              */
 93             if (mkdir(lost_path, 0755)) {
 94                 SLOGE("Unable to create LOST.DIR (%s)", strerror(errno));
 95             }
 96         }
 97         free(lost_path);
 98     }
 99 
100     return rc;
101 }


Ntfs는 read-only만 지원 됩니다.

shell@android:/ $ mount
rootfs / rootfs ro,relatime 0 0
tmpfs /dev tmpfs rw,nosuid,relatime,mode=755 0 0
devpts /dev/pts devpts rw,relatime,mode=600 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
none /acct cgroup rw,relatime,cpuacct 0 0
tmpfs /mnt/secure tmpfs rw,relatime,mode=700 0 0
tmpfs /mnt/asec tmpfs rw,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0
none /dev/cpuctl cgroup rw,relatime,cpu 0 0
/dev/block/mmcblk0p2 /system ext4 ro,relatime,data=ordered 0 0
/dev/block/mmcblk0p4 /cache ext4 rw,nosuid,nodev,noatime,nomblk_io_submit,errors=panic,data=ordered 0 0
/dev/block/mmcblk0p3 /data ext4 rw,nosuid,nodev,noatime,nomblk_io_submit,discard,noauto_da_alloc,errors=panic,data=ordered 0 0
/sys/kernel/debug /sys/kernel/debug debugfs rw,relatime 0 0
/dev/block/vold/179:1 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 00
/dev/block/vold/179:1 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount0
tmpfs /mnt/sdcard/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0
/dev/block/vold/179:9 /mnt/ext_sd vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 00
/dev/block/vold/8:1 /storage/usb1 ntfs ro,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,umask=0702,nls=utf8,errors=continue,mft_zone_multiplier=1 0 0
shell@android:/ $