blob: 835b71df8f194337320618f7af0b1da13dbb837a [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;
69 } else {
70 LOG_VOL("Filesystem check failed (unknown exit code %d)", rc);
71 return -EIO;
72 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080073 return 0;
74}
75
76int vfat_mount(blkdev_t *dev, volume_t *vol, boolean safe_mode)
77{
78 int flags, rc;
79 char *devpath;
80
81 devpath = blkdev_get_devpath(dev);
82
83#if VFAT_DEBUG
84 LOG_VOL("vfat_mount(%d:%d, %s, %d):", dev->major, dev->minor, vol->mount_point, safe_mode);
85#endif
86
San Mehatf754f742009-06-02 10:27:52 -070087 flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080088
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080089 if (vol->state == volstate_mounted) {
90 LOG_VOL("Remounting %d:%d on %s, safe mode %d", dev->major,
91 dev->minor, vol->mount_point, safe_mode);
92 flags |= MS_REMOUNT;
93 }
94
San Mehatb76a63b2009-05-18 12:59:13 -070095 /*
96 * The mount masks restrict access so that:
97 * 1. The 'system' user cannot access the SD card at all -
98 * (protects system_server from grabbing file references)
99 * 2. Group users can RWX
100 * 3. Others can only RX
101 */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800102 rc = mount(devpath, vol->mount_point, "vfat", flags,
San Mehatb76a63b2009-05-18 12:59:13 -0700103 "utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800104
105 if (rc && errno == EROFS) {
106 LOGE("vfat_mount(%d:%d, %s): Read only filesystem - retrying mount RO",
107 dev->major, dev->minor, vol->mount_point);
108 flags |= MS_RDONLY;
109 rc = mount(devpath, vol->mount_point, "vfat", flags,
San Mehatb76a63b2009-05-18 12:59:13 -0700110 "utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800111 }
112
113#if VFAT_DEBUG
114 LOG_VOL("vfat_mount(%s, %d:%d): mount rc = %d", dev->major,k dev->minor,
115 vol->mount_point, rc);
116#endif
117 free (devpath);
118 return rc;
119}