blob: 7a4e12f1906114762969e9ceb19df0fbf8a5fdd6 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001
2/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <errno.h>
19
20#include <sys/mount.h>
21
22#include "vold.h"
23#include "volmgr.h"
24#include "volmgr_vfat.h"
25#include "logwrapper.h"
26
27#define VFAT_DEBUG 0
28
San Mehate7f444f2009-06-24 17:56:03 -070029static char FSCK_MSDOS_PATH[] = "/system/bin/fsck_msdos";
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080030
31int vfat_identify(blkdev_t *dev)
32{
33#if VFAT_DEBUG
34 LOG_VOL("vfat_identify(%d:%d):", dev->major, dev->minor);
35#endif
36 return 0; // XXX: Implement
37}
38
39int vfat_check(blkdev_t *dev)
40{
41 int rc;
San Mehat7edc4f92009-05-18 09:55:21 -070042 boolean rw = true;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080043
44#if VFAT_DEBUG
45 LOG_VOL("vfat_check(%d:%d):", dev->major, dev->minor);
46#endif
47
48 if (access(FSCK_MSDOS_PATH, X_OK)) {
49 LOGE("vfat_check(%d:%d): %s not found (skipping checks)",
50 dev->major, dev->minor, FSCK_MSDOS_PATH);
51 return 0;
52 }
53
San Mehate7f444f2009-06-24 17:56:03 -070054 char *args[5];
55 args[0] = FSCK_MSDOS_PATH;
56 args[1] = "-p";
57 args[2] = "-f";
58 args[3] = blkdev_get_devpath(dev);
59 args[4] = NULL;
60 rc = logwrap(4, args, 1);
61 free(args[3]);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080062
San Mehate7f444f2009-06-24 17:56:03 -070063 if (rc == 0) {
64 LOG_VOL("Filesystem check completed OK");
65 return 0;
66 } else if (rc == 2) {
67 LOG_VOL("Filesystem check failed (not a FAT filesystem)");
68 return -ENODATA;
San Mehatc3115b92009-06-25 13:34:16 -070069 } else if (rc == -11) {
70 LOG_VOL("Filesystem check crashed");
71 return -EIO;
San Mehate7f444f2009-06-24 17:56:03 -070072 } else {
73 LOG_VOL("Filesystem check failed (unknown exit code %d)", rc);
74 return -EIO;
75 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080076 return 0;
77}
78
79int vfat_mount(blkdev_t *dev, volume_t *vol, boolean safe_mode)
80{
81 int flags, rc;
82 char *devpath;
83
84 devpath = blkdev_get_devpath(dev);
85
86#if VFAT_DEBUG
87 LOG_VOL("vfat_mount(%d:%d, %s, %d):", dev->major, dev->minor, vol->mount_point, safe_mode);
88#endif
89
San Mehatf754f742009-06-02 10:27:52 -070090 flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080091
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080092 if (vol->state == volstate_mounted) {
93 LOG_VOL("Remounting %d:%d on %s, safe mode %d", dev->major,
94 dev->minor, vol->mount_point, safe_mode);
95 flags |= MS_REMOUNT;
96 }
97
San Mehatb76a63b2009-05-18 12:59:13 -070098 /*
99 * The mount masks restrict access so that:
100 * 1. The 'system' user cannot access the SD card at all -
101 * (protects system_server from grabbing file references)
102 * 2. Group users can RWX
103 * 3. Others can only RX
104 */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800105 rc = mount(devpath, vol->mount_point, "vfat", flags,
San Mehatb76a63b2009-05-18 12:59:13 -0700106 "utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800107
108 if (rc && errno == EROFS) {
109 LOGE("vfat_mount(%d:%d, %s): Read only filesystem - retrying mount RO",
110 dev->major, dev->minor, vol->mount_point);
111 flags |= MS_RDONLY;
112 rc = mount(devpath, vol->mount_point, "vfat", flags,
San Mehatb76a63b2009-05-18 12:59:13 -0700113 "utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800114 }
115
116#if VFAT_DEBUG
117 LOG_VOL("vfat_mount(%s, %d:%d): mount rc = %d", dev->major,k dev->minor,
118 vol->mount_point, rc);
119#endif
120 free (devpath);
121 return rc;
122}