blob: 661f714d304194eab8f1d82374a4c13cd239d272 [file] [log] [blame]
The Android Open Source Project8ac3a132009-01-20 14:04:01 -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
29static char FSCK_MSDOS_PATH[] = "/system/bin/dosfsck";
30
31int vfat_identify(blkdev_t *dev)
32{
33#if VFAT_DEBUG
34 LOG_VOL("vfat_identify(%s):\n", dev->dev_fspath);
35#endif
36 return 0; // XXX: Implement
37}
38
39int vfat_check(blkdev_t *dev)
40{
41 int rc;
42
43#if VFAT_DEBUG
44 LOG_VOL("vfat_check(%s):\n", dev->dev_fspath);
45#endif
46
47 if (access(FSCK_MSDOS_PATH, X_OK)) {
48 LOGE("vfat_check(%s): %s not found (skipping checks)\n",
49 FSCK_MSDOS_PATH, dev->dev_fspath);
50 return 0;
51 }
52
53#ifdef VERIFY_PASS
54 char *args[7];
55 args[0] = FSCK_MSDOS_PATH;
56 args[1] = "-v";
57 args[2] = "-V";
58 args[3] = "-w";
59 args[4] = "-p";
60 args[5] = dev->dev_fspath;
61 args[6] = NULL;
62 rc = logwrap(6, args);
63#else
64 char *args[6];
65 args[0] = FSCK_MSDOS_PATH;
66 args[1] = "-v";
67 args[2] = "-w";
68 args[3] = "-p";
69 args[4] = dev->dev_fspath;
70 args[5] = NULL;
71 rc = logwrap(5, args);
72#endif
73
74 if (rc == 0) {
75 LOG_VOL("Filesystem check completed OK\n");
76 return 0;
77 } else if (rc == 1) {
78 LOG_VOL("Filesystem check failed (general failure)\n");
79 return -EINVAL;
80 } else if (rc == 2) {
81 LOG_VOL("Filesystem check failed (invalid usage)\n");
82 return -EIO;
83 } else if (rc == 4) {
84 LOG_VOL("Filesystem check completed (errors fixed)\n");
85 } else {
86 LOG_VOL("Filesystem check failed (unknown exit code %d)\n", rc);
87 return -EIO;
88 }
89 return 0;
90}
91
92int vfat_mount(blkdev_t *dev, volume_t *vol)
93{
94 int flags, rc;
95
96#if VFAT_DEBUG
97 LOG_VOL("vfat_mount(%s, %s):\n", dev->dev_fspath, vol->mount_point);
98#endif
99
100 flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC;
101 rc = mount(dev->dev_fspath, vol->mount_point, "vfat", flags,
102 "utf8,uid=1000,gid=1000,fmask=711,dmask=700");
103
104 if (rc && errno == EROFS) {
105 LOGE("vfat_mount(%s, %s): Read only filesystem - retrying mount RO\n",
106 dev->dev_fspath, vol->mount_point);
107 flags |= MS_RDONLY;
108 rc = mount(dev->dev_fspath, vol->mount_point, "vfat", flags,
109 "utf8,uid=1000,gid=1000,fmask=711,dmask=700");
110 }
111
112#if VFAT_DEBUG
113 LOG_VOL("vfat_mount(%s, %s): mount rc = %d\n", dev->dev_fspath,
114 vol->mount_point, rc);
115#endif
116 return rc;
117}