int vfat_check(blkdev_t *dev) { int rc; #if VFAT_DEBUG LOG_VOL("vfat_check(%s):\n", dev->dev_fspath); #endif if (access(FSCK_MSDOS_PATH, X_OK)) { LOGE("vfat_check(%s): %s not found (skipping checks)\n", FSCK_MSDOS_PATH, dev->dev_fspath); return 0; } #ifdef VERIFY_PASS char *args[7]; args[0] = FSCK_MSDOS_PATH; args[1] = "-v"; args[2] = "-V"; args[3] = "-w"; args[4] = "-p"; args[5] = dev->dev_fspath; args[6] = NULL; rc = logwrap(6, args); #else char *args[6]; args[0] = FSCK_MSDOS_PATH; args[1] = "-v"; args[2] = "-w"; args[3] = "-p"; args[4] = dev->dev_fspath; args[5] = NULL; rc = logwrap(5, args); #endif if (rc == 0) { LOG_VOL("Filesystem check completed OK\n"); return 0; } else if (rc == 1) { LOG_VOL("Filesystem check failed (general failure)\n"); return -EINVAL; } else if (rc == 2) { LOG_VOL("Filesystem check failed (invalid usage)\n"); return -EIO; } else if (rc == 4) { LOG_VOL("Filesystem check completed (errors fixed)\n"); } else { LOG_VOL("Filesystem check failed (unknown exit code %d)\n", rc); return -EIO; } return 0; }
int Fat::check(const char *fsPath) { bool rw = true; if (access(FSCK_MSDOS_PATH, X_OK)) { SLOGW("Skipping fs checks\n"); return 0; } //return 0; int pass = 1; int rc = 0; do { const char *args[5]; args[0] = FSCK_MSDOS_PATH; args[1] = "-p"; args[2] = "-f"; args[3] = fsPath; args[4] = NULL; rc = logwrap(4, args, 1); switch(rc) { case 0: SLOGI("Filesystem check completed OK"); return 0; case 2: SLOGE("Filesystem check failed (not a FAT filesystem)"); errno = ENODATA; return -1; case 4: if (pass++ <= 3) { SLOGW("Filesystem modified - rechecking (pass %d)", pass); continue; } SLOGE("Failing check after too many rechecks"); errno = EIO; return -1; case 16: SLOGE("Too large SD card with too small cluster size"); errno = ENOMEM; return -1; default: SLOGE("Filesystem check failed (unknown exit code %d)", rc); errno = EIO; return -1; } } while (0); return 0; }
int vfat_check(blkdev_t *dev) { int rc; boolean rw = true; #if VFAT_DEBUG LOG_VOL("vfat_check(%d:%d):", dev->major, dev->minor); #endif if (access(FSCK_MSDOS_PATH, X_OK)) { LOGE("vfat_check(%d:%d): %s not found (skipping checks)", dev->major, dev->minor, FSCK_MSDOS_PATH); return 0; } int pass = 1; do { char *args[5]; args[0] = FSCK_MSDOS_PATH; args[1] = "-p"; args[2] = "-f"; args[3] = blkdev_get_devpath(dev); args[4] = NULL; rc = logwrap(4, args, 1); free(args[3]); if (rc == 0) { LOG_VOL("Filesystem check completed OK"); return 0; } else if (rc == 2) { LOG_VOL("Filesystem check failed (not a FAT filesystem)"); return -ENODATA; } else if (rc == 4) { if (pass++ <= 3) { LOG_VOL("Filesystem modified - rechecking (pass %d)", pass); continue; } else { LOG_VOL("Failing check after too many rechecks"); return -EIO; } } else if (rc == -11) { LOG_VOL("Filesystem check crashed"); return -EIO; } else { LOG_VOL("Filesystem check failed (unknown exit code %d)", rc); return -EIO; } } while (0); return 0; }
int BandwidthController::runIptablesCmd(const char *cmd, IptRejectOp rejectHandling, IptIpVer iptVer, IptFailureLog failureHandling) { char buffer[MAX_CMD_LEN]; const char *argv[MAX_CMD_ARGS]; int argc = 0; char *next = buffer; char *tmp; int res; std::string fullCmd = cmd; if (rejectHandling == IptRejectAdd) { fullCmd += " --jump REJECT --reject-with"; switch (iptVer) { case IptIpV4: fullCmd += " icmp-net-prohibited"; break; case IptIpV6: fullCmd += " icmp6-adm-prohibited"; break; } } fullCmd.insert(0, " "); fullCmd.insert(0, iptVer == IptIpV4 ? IPTABLES_PATH : IP6TABLES_PATH); if (!useLogwrapCall) { res = system_nosh(fullCmd.c_str()); } else { if (StrncpyAndCheck(buffer, fullCmd.c_str(), sizeof(buffer))) { ALOGE("iptables command too long"); return -1; } argc = 0; while ((tmp = strsep(&next, " "))) { argv[argc++] = tmp; if (argc >= MAX_CMD_ARGS) { ALOGE("iptables argument overflow"); return -1; } } argv[argc] = NULL; res = logwrap(argc, argv); } if (res && failureHandling == IptFailShow) { ALOGE("runIptablesCmd(): failed %s res=%d", fullCmd.c_str(), res); } return res; }
int Fat::format(const char *fsPath, unsigned int numSectors) { int fd; const char *args[11]; int rc; args[0] = MKDOSFS_PATH; args[1] = "-F"; args[2] = "32"; args[3] = "-O"; args[4] = "android"; args[5] = "-c"; args[6] = "64"; if (numSectors) { char tmp[32]; snprintf(tmp, sizeof(tmp), "%u", numSectors); const char *size = tmp; args[7] = "-s"; args[8] = size; args[9] = fsPath; args[10] = NULL; rc = logwrap(11, args, 1); } else { args[7] = fsPath; args[8] = NULL; rc = logwrap(9, args, 1); } if (rc == 0) { SLOGI("Filesystem formatted OK"); return 0; } else { SLOGE("Format failed (unknown exit code %d)", rc); errno = EIO; return -1; } return 0; }
int Ext::check(const char *fsPath) { bool rw = true; if (access(FSCK_EXT_PATH, X_OK)) { SLOGW("Skipping fs checks\n"); return 0; } int pass = 1; int rc = 0; do { const char *args[5]; args[0] = FSCK_EXT_PATH; args[1] = "-p"; args[2] = "-f"; args[3] = fsPath; args[4] = NULL; rc = logwrap(4, args, 1); switch(rc) { case 0: case 1: SLOGI("Filesystem check completed OK"); return 0; case 2: SLOGE("Filesystem check completed, system should be rebooted"); errno = ENODATA; return -1; case 4: SLOGE("Filesystem errors left uncorrected"); errno = EIO; return -1; default: SLOGE("Filesystem check failed (exit code %d)", rc); errno = EIO; return -1; } } while (0); return 0; }
int ext_check(const char *devpath) { ERROR("ext_check(%s):\n", devpath); if (access(E2FSCK_PATH, X_OK)) { ERROR("ext_check(%s): %s not found (skipping checks)\n", devpath, E2FSCK_PATH); return 0; } char *args[5]; args[0] = E2FSCK_PATH; args[1] = "-v"; args[2] = "-y"; args[3] = devpath; args[4] = NULL; int rc = logwrap(4, args); if (rc == 0) { ERROR("filesystem '%s' had no errors\n", devpath); } else if (rc == 1) { ERROR("filesystem '%s' had corrected errors\n", devpath); rc = 0; } else if (rc == 2) { ERROR("VOL volume '%s' had corrected errors (system should be rebooted)\n", devpath); rc = -EIO; } else if (rc == 4) { ERROR("VOL volume '%s' had uncorrectable errors\n", devpath); rc = -EIO; } else if (rc == 8) { ERROR("Operational error while checking volume '%s'\n", devpath); rc = -EIO; } else { ERROR("Unknown e2fsck exit code (%d)\n", rc); rc = -EIO; } return rc; }
int Ext::format(const char *fsPath) { int fd; const char *args[3]; int rc; args[0] = MKEXTFS_PATH; args[1] = fsPath; args[2] = NULL; rc = logwrap(3, args, 1); if (rc == 0) { SLOGI("Filesystem formatted OK"); return 0; } else { SLOGE("Format failed (unknown exit code %d)", rc); errno = EIO; return -1; } return 0; }
int usbset(int index,int cmd) { bool rw = true; if (access(USBPOWER_PATH, X_OK)) { SLOGW("No USBPOWER_PATH file\n"); return -1; } int rc = 0; do { const char *args[4]; args[0] = USBPOWER_PATH; args[1] = usb_index_str[index]; args[2] = usb_state_str[cmd]; args[3] = NULL; rc = logwrap(3, args, 1); } while (0); return rc; }
int Fat::format(const char *fsPath, unsigned int numSectors) { int fd; const char *args[11]; int rc; unsigned int nr_sec, Indx; args[0] = MKDOSFS_PATH; args[1] = "-F"; args[2] = "32"; args[3] = "-O"; args[4] = "android"; Indx = 5; if (numSectors) { nr_sec = numSectors; } else { if ((fd = open(fsPath, O_RDWR)) < 0) { LOGE("Error opening disk file (%s)", strerror(errno)); return -1; } if (ioctl(fd, BLKGETSIZE, &nr_sec)) { LOGE("Unable to get device size (%s)", strerror(errno)); close(fd); return -1; } close(fd); } /* * < 8GB -> cluster size = 4KB * 8GB ~ 16GB -> cluster size = 8KB * 16GB ~ 32GB -> cluster size = 16KB * 32GB ~ 2TB -> cluster size = 32KB * > 2TB -> Not supported */ if ((nr_sec / 2) < ((unsigned int) (1024 * 1024) * 8)) /* < 8GB */ { args[Indx++] = "-c"; args[Indx++] = "8"; SLOGI("Format the disk with cluster size: 4KB\n"); } else if ((nr_sec / 2) < ((unsigned int) (1024 * 1024) * 16)) /* 8GB ~ 16GB */ { args[Indx++] = "-c"; args[Indx++] = "16"; SLOGI("Format the disk with cluster size: 8KB\n"); } else if ((nr_sec / 2) < ((unsigned int) (1024 * 1024) * 32)) /* 16GB ~ 32GB */ { args[Indx++] = "-c"; args[Indx++] = "32"; SLOGI("Format the disk with cluster size: 16KB\n"); } else if ((nr_sec / 2) < ((unsigned int) (1024 * 1024 * 1024) * 2)) /* 32GB ~ 2TB */ { args[Indx++] = "-c"; args[Indx++] = "64"; SLOGI("Format the disk with cluster size: 32KB\n"); } else /* > 2TB */ { SLOGE("Unsupported disk\n"); return -1; } if (numSectors) { char tmp[32]; snprintf(tmp, sizeof(tmp), "%u", numSectors); const char *size = tmp; args[Indx++] = "-s"; args[Indx++] = size; args[Indx++] = fsPath; args[Indx++] = NULL; rc = logwrap(Indx, args, 1); } else { args[Indx++] = fsPath; args[Indx++] = NULL; rc = logwrap(Indx, args, 1); } if (rc == 0) { SLOGI("Filesystem formatted OK"); return 0; } else { SLOGE("Format failed (unknown exit code %d)", rc); errno = EIO; return -1; } return 0; }
int Fat::format(const char *fsPath, unsigned int numSectors) { int fd; const char *args[11]; int rc; #ifndef MTK_FORMAT_NOT_PARAM_CLUSTER unsigned int bps; unsigned int bsize; #endif if (-1 == (fd = open(fsPath, O_RDONLY, 0644)) ) { SLOGE("failed to open %s\n", fsPath); errno = EIO; return -1; } args[0] = MKDOSFS_PATH; #ifdef MTK_FORMAT_NOT_PARAM_CLUSTER args[1] = "-O"; args[2] = "android"; close(fd); if (numSectors) { char tmp[32]; snprintf(tmp, sizeof(tmp), "%u", numSectors); const char *size = tmp; args[3] = "-s"; args[4] = size; args[5] = fsPath; args[6] = NULL; SLOGD("%s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5]); rc = logwrap(7, args, 1); } else { args[3] = fsPath; args[4] = NULL; SLOGD("%s %s %s %s", args[0], args[1], args[2], args[3]); rc = logwrap(5, args, 1); } #else args[1] = "-F"; // args[2] = "32"; if (ioctl(fd, BLKSSZGET, &bps)) { bps = 0; SLOGE("failed to get %s bytes/sector\n", fsPath); } if (ioctl(fd, BLKGETSIZE, &bsize)) { bsize = 0; SLOGE("failed to get %s device size\n", fsPath); } close(fd); SLOGD("total cluster is %d", ( (unsigned long long)bsize * 512) / (bps * 8)); if (!numSectors && bps && bsize) { if ( (((unsigned long long)bsize * 512) / (bps * 8)) > 65536 ) args[2] = "32"; else args[2] = "16"; } else args[2] = "32"; args[3] = "-O"; args[4] = "android"; args[5] = "-c"; args[6] = "8"; SLOGD("%s %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5], args[6]); if (numSectors) { char tmp[32]; snprintf(tmp, sizeof(tmp), "%u", numSectors); const char *size = tmp; args[7] = "-s"; args[8] = size; args[9] = fsPath; args[10] = NULL; rc = logwrap(11, args, 1); } else { args[7] = fsPath; args[8] = NULL; rc = logwrap(9, args, 1); } #endif if (rc == 0) { SLOGI("Filesystem formatted OK"); return 0; } else { SLOGE("Format failed (unknown exit code %d)", rc); errno = EIO; return -1; } return 0; }
int Fat::check(const char *fsPath) { bool rw = true; if (access(FSCK_MSDOS_PATH, X_OK)) { SLOGW("Skipping fs checks\n"); return 0; } #ifdef FSCK_MSDOS_MTK SLOGI("-- MTK_FSCK_MSDOS_MTK enabled--"); int fsck_enhanced = 0 ; // 0 : original ver(fsck_msdos), 1 : enhanced ver(fsck_msdos_mtk) if (access(FSCK_MSDOS_MTK_PATH, X_OK)) { SLOGW("Because %s does not exist, we just use fsck_msdos (original ver.)", FSCK_MSDOS_MTK_PATH) ; fsck_enhanced = 0 ; } else { SLOGI("vold:fat:check fs = %s\n", fsPath) ; int fd = open(fsPath, O_RDONLY); if(fd < 0) { SLOGW("Because cannot read dev, we just use fsck_msdos (original ver.)") ; fsck_enhanced = 0 ; } else { struct bootblock boot ; if(readboot(fd, &boot) == 0) { if(boot.ClustMask == 0xfff) { SLOGW("Because fsck_msdos_mtk only supports FAT32, but this is FAT12!") ; SLOGW("We still use fsck_msdos for FAT12!") ; fsck_enhanced = 0 ; } else if(boot.ClustMask == 0xffff) { SLOGW("Because fsck_msdos_mtk only supports FAT32, but this is FAT16!") ; SLOGW("We still use fsck_msdos for FAT16!") ; fsck_enhanced = 0 ; } else { SLOGW("We always use fsck_msdos_mtk for FAT32 now!") ; fsck_enhanced = 1 ; } /*if(boot.NumClusters * 16 > 8*1024*1024) { SLOGI("It may need %d bytes ! It is too much ! Try enhanced fsck -- fsck_msdos_mtk !", boot.NumClusters * 16) ; fsck_enhanced = 1 ; } else SLOGW("Use fsck_msdos (original ver.)") ; */ } close(fd) ; } } #endif int pass = 1; int rc = 0; do { const char *args[5]; #ifdef FSCK_MSDOS_MTK if(fsck_enhanced) args[0] = FSCK_MSDOS_MTK_PATH; else #endif args[0] = FSCK_MSDOS_PATH; args[1] = "-p"; args[2] = "-f"; args[3] = fsPath; args[4] = NULL; rc = logwrap(4, args, 1); switch(rc) { case 0: SLOGI("Filesystem check completed OK"); return 0; case 2: SLOGE("Filesystem check failed (not a FAT filesystem)"); errno = ENODATA; return -1; case 4: if (pass++ <= 3) { SLOGW("Filesystem modified - rechecking (pass %d)", pass); continue; } SLOGE("Failing check after too many rechecks"); errno = EIO; return -1; default: SLOGE("Filesystem check failed (unknown exit code %d)", rc); errno = EIO; return -1; } } while (1); return 0; }