int extract_iso(uniso_status_t *s, struct archive *iso, const char *dst, distro_filter_f filter, uniso_progress_t total, uniso_progress_cb cb, void *cb_data) { struct archive_entry *e; uniso_progress_t current = 0; make_dir_parents(dst); if(cb) cb(current, total, cb_data); while(archive_read_next_header(iso, &e) == ARCHIVE_OK) { char *name = unix_path(strdup2(archive_entry_pathname(e))); if(archive_entry_filetype(e) == AE_IFDIR || !filter(name)) { free(name); continue; } s->files = new_string_node_t(name, s->files); char *dest = unix_path(create_dest(dst, "/", name)); if(!extract_file(s, iso, dest)) { free(dest); return 0; } ++current; if(cb) cb(current, total, cb_data); free(dest); } return 1; }
int do_mount(char *src, char *dst, int flags, char *fstype, char *data) { unsigned long mountflags = 0; struct stat st; bool isdir = true; if (flags & CT_FS_BIND) { if (fstype || data) return -1; mountflags |= MS_BIND; if (stat(src, &st)) { pr_perror("Unable to stat %s", src); return -1; } isdir = S_ISDIR(st.st_mode); } if (create_dest(dst, 0755, isdir)) return -1; if (flags & CT_FS_RDONLY) mountflags |= MS_RDONLY; if (flags & CT_FS_NOEXEC) mountflags |= MS_NOEXEC; if (flags & CT_FS_NOSUID) mountflags |= MS_NOSUID; if (flags & CT_FS_NODEV) mountflags |= MS_NODEV; if (flags & CT_FS_STRICTATIME) mountflags |= MS_STRICTATIME; if (mount(src, dst, fstype, mountflags, data) == -1) { pr_perror("Unable to mount %s -> %s\n", src, dst); return -1; } if (flags & CT_FS_PRIVATE) { if (mount(NULL, dst, NULL, MS_PRIVATE, NULL) == -1) { pr_perror("Unable to mark %s as private", dst); umount(dst); return -1; } } return 0; }