The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 1 | |
| 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 | |
| 29 | static char FSCK_MSDOS_PATH[] = "/system/bin/dosfsck"; |
| 30 | |
| 31 | int vfat_identify(blkdev_t *dev) |
| 32 | { |
| 33 | #if VFAT_DEBUG |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 34 | LOG_VOL("vfat_identify(%d:%d):", dev->major, dev->minor); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 35 | #endif |
| 36 | return 0; // XXX: Implement |
| 37 | } |
| 38 | |
| 39 | int vfat_check(blkdev_t *dev) |
| 40 | { |
| 41 | int rc; |
| 42 | |
| 43 | #if VFAT_DEBUG |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 44 | LOG_VOL("vfat_check(%d:%d):", dev->major, dev->minor); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 45 | #endif |
| 46 | |
| 47 | if (access(FSCK_MSDOS_PATH, X_OK)) { |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 48 | LOGE("vfat_check(%d:%d): %s not found (skipping checks)", |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 49 | dev->major, dev->minor, FSCK_MSDOS_PATH); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 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"; |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 60 | args[5] = blkdev_get_devpath(dev); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 61 | args[6] = NULL; |
| 62 | rc = logwrap(6, args); |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 63 | free(args[5]); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 64 | #else |
| 65 | char *args[6]; |
| 66 | args[0] = FSCK_MSDOS_PATH; |
| 67 | args[1] = "-v"; |
| 68 | args[2] = "-w"; |
| 69 | args[3] = "-p"; |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 70 | args[4] = blkdev_get_devpath(dev); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 71 | args[5] = NULL; |
| 72 | rc = logwrap(5, args); |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 73 | free(args[4]); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 74 | #endif |
| 75 | |
| 76 | if (rc == 0) { |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 77 | LOG_VOL("Filesystem check completed OK"); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 78 | return 0; |
| 79 | } else if (rc == 1) { |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 80 | LOG_VOL("Filesystem check failed (general failure)"); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 81 | return -EINVAL; |
| 82 | } else if (rc == 2) { |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 83 | LOG_VOL("Filesystem check failed (invalid usage)"); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 84 | return -EIO; |
| 85 | } else if (rc == 4) { |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 86 | LOG_VOL("Filesystem check completed (errors fixed)"); |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 87 | } else if (rc == 8) { |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 88 | LOG_VOL("Filesystem check failed (not a FAT filesystem)"); |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 89 | return -ENODATA; |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 90 | } else { |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 91 | LOG_VOL("Filesystem check failed (unknown exit code %d)", rc); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 92 | return -EIO; |
| 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 97 | int vfat_mount(blkdev_t *dev, volume_t *vol, boolean safe_mode) |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 98 | { |
| 99 | int flags, rc; |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 100 | char *devpath; |
| 101 | |
| 102 | devpath = blkdev_get_devpath(dev); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 103 | |
| 104 | #if VFAT_DEBUG |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 105 | LOG_VOL("vfat_mount(%d:%d, %s, %d):", dev->major, dev->minor, vol->mount_point, safe_mode); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 106 | #endif |
| 107 | |
| 108 | flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC; |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 109 | |
| 110 | if (safe_mode) |
| 111 | flags |= MS_SYNCHRONOUS; |
| 112 | if (vol->state == volstate_mounted) { |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 113 | LOG_VOL("Remounting %d:%d on %s, safe mode %d", dev->major, |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 114 | dev->minor, vol->mount_point, safe_mode); |
| 115 | flags |= MS_REMOUNT; |
| 116 | } |
| 117 | |
| 118 | rc = mount(devpath, vol->mount_point, "vfat", flags, |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 119 | "utf8,uid=1000,gid=1000,fmask=711,dmask=700"); |
| 120 | |
| 121 | if (rc && errno == EROFS) { |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 122 | LOGE("vfat_mount(%d:%d, %s): Read only filesystem - retrying mount RO", |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 123 | dev->major, dev->minor, vol->mount_point); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 124 | flags |= MS_RDONLY; |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 125 | rc = mount(devpath, vol->mount_point, "vfat", flags, |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 126 | "utf8,uid=1000,gid=1000,fmask=711,dmask=700"); |
| 127 | } |
| 128 | |
| 129 | #if VFAT_DEBUG |
The Android Open Source Project | 1b8e5a6 | 2009-02-13 12:57:54 -0800 | [diff] [blame^] | 130 | LOG_VOL("vfat_mount(%s, %d:%d): mount rc = %d", dev->major,k dev->minor, |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 131 | vol->mount_point, rc); |
| 132 | #endif |
The Android Open Source Project | 13f797d | 2009-02-10 15:44:07 -0800 | [diff] [blame] | 133 | free (devpath); |
The Android Open Source Project | 8ac3a13 | 2009-01-20 14:04:01 -0800 | [diff] [blame] | 134 | return rc; |
| 135 | } |