int rename_test() { int mount = try_mount(); if (!mount) { return 0; } char filename[] = "test_sandbox/test_file"; char new_filename[] = "test_sandbox/moved_file"; rename(filename, new_filename); char buffer[4096]; FILE* fp = fopen(new_filename, "r"); if (fp == NULL) { fprintf(stderr, "Can't open file %s!\n", new_filename); return 0; } bool fail = true; while (fscanf(fp, "%s", buffer) == 1) { if (!strcmp("helllooooo", buffer)) { fail = false; } } fclose(fp); int umount = (system("fusermount -u test_sandbox") == 0); if (fail) { return 0; } else { return 1; } }
int mount_test(){ int mount = try_mount(); if (!mount) { return 0; } int umount = (system("fusermount -u test_sandbox") == 0); return 1; }
int superblock_size_test(){ int mount = try_mount(); if (!mount) { return 0; } int fd = open("./.superblock", O_RDONLY); int size = lseek(fd, 0, SEEK_END); int umount = (system("fusermount -u test_sandbox") == 0); return size == SUPERBLOCK_SIZE; }
int write_test() { int mount = try_mount(); if (!mount) { return 0; } FILE *fp; char filename[] = "test_sandbox/test_file"; fp = fopen(filename, "w"); if (fp == NULL) { fprintf(stderr, "Can't open file %s!\n", filename); return 0; } fprintf(fp, "helllooooo"); fclose(fp); int umount = (system("fusermount -u test_sandbox") == 0); return 1; }
/** * Program entry point * * @param argc count of command line arguments * @param argv array of NUL-terminated C strings containing command line arguments * @return program exit status */ int main(int argc, char *argv[]) { char *source, *target, *text_options; int c, mnt_err; (void)setlocale(LC_ALL, ""); progname = basename(argv[0]); if (argv[1] && argv[1][0] == '-') { if(argv[1][1] == 'V') printf("%s ("PACKAGE_STRING")\n", progname); else mount_usage(); exit(EX_SUCCESS); } if (argc < 3) { mount_usage(); exit(EX_USAGE); } source = argv[1]; target = argv[2]; mnt_err = EX_USAGE; text_options = NULL; readonly = false; sloppy = false; fake = false; argv[2] = argv[0]; /* so that getopt error messages are correct */ while ((c = getopt_long(argc - 2, argv + 2, fedfs_opts, fedfs_longopts, NULL)) != -1) { switch (c) { case 'f': fake = true; break; case 'n': ++nomtab; break; case 'o': /* Ugh. */ if (text_options != NULL) text_options = xstrconcat3(text_options, ",", optarg); else text_options = strdup(optarg); if (text_options == NULL) { fprintf(stderr, _("%s: No memory\n"), progname); goto out; } break; case 'r': readonly = true; break; case 's': sloppy = true; break; case 'v': ++verbose; break; case 'V': printf("%s: ("PACKAGE_STRING")\n", progname); mnt_err = EX_SUCCESS; goto out; case 'w': readonly = false; break; case 'h': default: mount_usage(); goto out; } } /* Extra non-option words at the end are bogus... */ if (optind != argc - 2) { mount_usage(); goto out; } if (getuid() != 0 && geteuid() != 0) { fprintf(stderr, _("%s: Not installed setuid - " "\"user\" FedFS mounts are not supported\n"), progname); mnt_err = EX_FAIL; goto out; } mnt_err = try_mount(source, target, text_options); out: free(text_options); exit(mnt_err); }
int ensure_path_mounted(const char* path) { Volume* v = volume_for_path(path); if (v == NULL) { // no /sdcard? let's assume /data/media if (strstr(path, "/sdcard") == path && is_data_media()) { LOGW("using /data/media, no /sdcard found.\n"); int ret; if (0 != (ret = ensure_path_mounted("/data"))) return ret; setup_data_media(); return 0; } LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } const MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); if (mv) { // volume is already mounted return 0; } mkdir(v->mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, v->mount_point); return -1; } return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "rfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { if ((result = try_mount(v->device, v->mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device2, v->mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device, v->mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; if ((result = try_mount(v->device2, v->mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; return result; } else { // let's try mounting with the mount binary and hope for the best. char mount_cmd[PATH_MAX]; sprintf(mount_cmd, "mount %s", path); return __system(mount_cmd); } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); return -1; }
static int mount_main(struct libmnt_context *cxt, int argc, char **argv) { int rc, c; struct libmnt_fs *fs; char *spec = NULL, *mount_point = NULL, *opts = NULL; static const struct option longopts[] = { { "fake", 0, 0, 'f' }, { "help", 0, 0, 'h' }, { "no-mtab", 0, 0, 'n' }, { "read-only", 0, 0, 'r' }, { "ro", 0, 0, 'r' }, { "verbose", 0, 0, 'v' }, { "version", 0, 0, 'V' }, { "read-write", 0, 0, 'w' }, { "rw", 0, 0, 'w' }, { "options", 1, 0, 'o' }, { "sloppy", 0, 0, 's' }, { NULL, 0, 0, 0 } }; mount_config_init(progname); mnt_context_init_helper(cxt, MNT_ACT_MOUNT, 0); while ((c = getopt_long(argc, argv, "fhnrVvwo:s", longopts, NULL)) != -1) { rc = mnt_context_helper_setopt(cxt, c, optarg); if (rc == 0) /* valid option */ continue; if (rc < 0) /* error (probably ENOMEM) */ goto err; /* rc==1 means unknow option */ switch (c) { case 'V': printf("%s: ("PACKAGE_STRING")\n", progname); return EX_SUCCESS; case 'h': default: mount_usage(); return EX_USAGE; } } if (optind < argc) spec = argv[optind++]; if (optind < argc) mount_point = argv[optind++]; if (!mount_point) { nfs_error(_("%s: no mount point provided"), progname); goto err; } if (!spec) { nfs_error(_("%s: no mount spec provided"), progname); goto err; } if (geteuid() != 0) { nfs_error(_("%s: not installed setuid - " "\"user\" NFS mounts not supported."), progname); goto err; } verbose = mnt_context_is_verbose(cxt); sloppy = mnt_context_is_sloppy(cxt); nomtab = mnt_context_is_nomtab(cxt); if (strcmp(progname, "mount.nfs4") == 0) mnt_context_set_fstype(cxt, "nfs4"); else mnt_context_set_fstype(cxt, "nfs"); /* default */ rc = mnt_context_set_source(cxt, spec); if (!rc) mnt_context_set_target(cxt, mount_point); if (rc) { nfs_error(_("%s: failed to set spec or mountpoint: %s"), progname, strerror(errno)); goto err; } mount_point = mnt_resolve_path(mount_point, mnt_context_get_cache(cxt)); if (chk_mountpoint(mount_point)) goto err; /* * Concatenate mount options from the configuration file */ fs = mnt_context_get_fs(cxt); if (fs) { opts = mnt_fs_strdup_options(fs); opts = mount_config_opts(spec, mount_point, opts); mnt_fs_set_options(fs, opts); } rc = mnt_context_prepare_mount(cxt); if (rc) { nfs_error(_("%s: failed to prepare mount: %s\n"), progname, strerror(-rc)); goto err; } rc = try_mount(cxt, FOREGROUND); if (rc == EX_BG) { printf(_("%s: backgrounding \"%s\"\n"), progname, mnt_context_get_source(cxt)); printf(_("%s: mount options: \"%s\"\n"), progname, opts); fflush(stdout); if (daemon(0, 0)) { nfs_error(_("%s: failed to start " "background process: %s\n"), progname, strerror(errno)); exit(EX_FAIL); } rc = try_mount(cxt, BACKGROUND); if (verbose && rc) printf(_("%s: giving up \"%s\"\n"), progname, mnt_context_get_source(cxt)); } mnt_context_set_syscall_status(cxt, rc == EX_SUCCESS ? 0 : -1); mnt_context_finalize_mount(cxt); /* mtab update */ return rc; err: return EX_FAIL; }
int ensure_path_mounted_at_mount_point(const char* path, const char* mount_point) { if (is_data_media_volume_path(path)) { if (ui_should_log_stdout()) { LOGI("using /data/media for %s.\n", path); } int ret; if (0 != (ret = ensure_path_mounted("/data"))) return ret; setup_data_media(); return 0; } Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } if (NULL == mount_point) mount_point = v->mount_point; const MountedVolume* mv = find_mounted_volume_by_mount_point(mount_point); if (mv) { // volume is already mounted return 0; } mkdir(mount_point, 0755); // in case it doesn't already exist if (fs_mgr_is_voldmanaged(v)) { return vold_mount_volume(mount_point, 1) == CommandOkay ? 0 : -1; } else if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->blk_device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->blk_device, mount_point); return -1; } return mtd_mount_partition(partition, mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "rfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { if ((result = try_mount(v->blk_device, mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->blk_device, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; if ((result = try_mount(v->blk_device2, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; return result; } else { // let's try mounting with the mount binary and hope for the best. char mount_cmd[PATH_MAX]; sprintf(mount_cmd, "mount %s", mount_point); return __system(mount_cmd); } return -1; }
int ensure_path_mounted_at_mount_point(const char* path, const char* mount_point) { Volume* v = volume_for_path(path); if (v == NULL) { LOGE("unknown volume for path [%s]\n", path); return -1; } if (is_data_media_volume_path(path)) { LOGI("using /data/media for %s.\n", path); int ret; if (0 != (ret = ensure_path_mounted("/data"))) return ret; setup_data_media(); return 0; } if (strcmp(v->fs_type, "ramdisk") == 0) { // the ramdisk is always mounted. return 0; } int result; result = scan_mounted_volumes(); if (result < 0) { LOGE("failed to scan mounted volumes\n"); return -1; } if (NULL == mount_point) mount_point = v->mount_point; const MountedVolume* mv = find_mounted_volume_by_mount_point(mount_point); if (mv) { // volume is already mounted return 0; } mkdir(mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. mtd_scan_partitions(); const MtdPartition* partition; partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", v->device, mount_point); return -1; } return mtd_mount_partition(partition, mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "rfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { if ((result = try_mount(v->device, mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device2, mount_point, v->fs_type, v->fs_options)) == 0) return 0; if ((result = try_mount(v->device, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; if ((result = try_mount(v->device2, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; #ifdef KYLE_TOUCH_RECOVERY #include "/home/klaplante/recoverystuff/exfat2.c" #endif return result; } else { // let's try mounting with the mount binary and hope for the best. char mount_cmd[PATH_MAX]; sprintf(mount_cmd, "mount %s", path); return __system(mount_cmd); } LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, mount_point); return -1; }