int map_path_user(char *oldpath, char *newpath, uint32_t flags) { char *oldp, *newp; #ifdef DEBUG DPRINTF("map_path_user, called by process %s: %s -> %s\n", get_process_name(get_current_process_critical()), oldpath, newpath); #endif if (oldpath == 0) return -1; int ret = pathdup_from_user(get_secure_user_ptr(oldpath), &oldp); if (ret != 0) return ret; if (newpath == 0) newp = NULL; else { ret = pathdup_from_user(get_secure_user_ptr(newpath), &newp); if (ret != 0) { dealloc(oldp, 0x27); return ret; } } ret = map_path(oldp, newp, flags | FLAG_COPY); dealloc(oldp, 0x27); if (newp) dealloc(newp, 0x27); return ret; }
static int ciopfs_mknod(const char *path, mode_t mode, dev_t rdev) { int res; char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); /* On Linux this could just be 'mknod(p, mode, rdev)' but this is more portable */ if (S_ISREG(mode)) { res = open(p, O_CREAT | O_EXCL | O_WRONLY, mode); if (res >= 0) { ciopfs_set_orig_name_fd(res, path); close(res); } } else if (S_ISFIFO(mode)) { res = mkfifo(p, mode); } else { res = mknod(p, mode, rdev); } if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
static int ciopfs_link(const char *from, const char *to) { char *f = map_path(from); char *t = map_path(to); if (unlikely(f == NULL || t == NULL)) return -ENOMEM; enter_user_context_effective(); int res = link(f, t); if (res == -1) res = -errno; leave_user_context_effective(); if (res == 0) ciopfs_set_orig_name_path(t, to); free(f); free(t); return res; }
const Raul::URI ClashAvoider::map_uri(const Raul::URI& in) { if (Node::uri_is_path(in)) { return Node::path_to_uri(map_path(Node::uri_to_path(in))); } else { return in; } }
void make_interclust_chain(graph_t *g, node_t *from, node_t *to, edge_t *orig) { int newtype; node_t *u,*v; u = map_interclust_node(from); v = map_interclust_node(to); if ((u == from) && (v == to)) newtype = VIRTUAL; else newtype = CLUSTER_EDGE; map_path(u,v,orig,orig->u.to_virt,newtype); }
static int ciopfs_getattr(const char *path, struct stat *st_data) { char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = lstat(p, st_data); if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
static int ciopfs_statfs(const char *path, struct statvfs *stbuf) { char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = statvfs(p, stbuf); if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
void inotify_map(int wd, const char *path) { struct watch s, *n; s.path = path; n = rbtree_search(&tree_path_wd, &s); if (!n) { n = new_node(wd, path); map_path(n); map_wd(n); } }
static int ciopfs_listxattr(const char *path, char *list, size_t size) { char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = llistxattr(p, list, size); if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
static int ciopfs_chmod(const char *path, mode_t mode) { char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = chmod(p, mode); if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
static int ciopfs_truncate(const char *path, off_t size) { char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = truncate(p, size); if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
static int ciopfs_chown(const char *path, uid_t uid, gid_t gid) { char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = lchown(p, uid, gid); if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
static int ciopfs_access(const char *path, int mode) { char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_real(); int res = access(p, mode); if (res == -1) res = -errno; leave_user_context_real(); free(p); return res; }
static int ciopfs_mkdir(const char *path, mode_t mode) { char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = mkdir(p, mode); if (res == -1) res = -errno; leave_user_context_effective(); if (res == 0) ciopfs_set_orig_name_path(p, path); free(p); return res; }
static int ciopfs_removexattr(const char *path, const char *name) { if (!strcmp(name, CIOPFS_ATTR_NAME)) { debug("denying removal of extended attribute '%s'\n", CIOPFS_ATTR_NAME); return -EPERM; } char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = lremovexattr(p, name); if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
static int ciopfs_opendir(const char *path, struct fuse_file_info *fi) { int ret; char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); DIR *dp = opendir(p); if (dp == NULL) ret = -errno; leave_user_context_effective(); free(p); if (dp == NULL) return ret; fi->fh = (uint64_t)(uintptr_t)dp; return 0; }
static int ciopfs_readlink(const char *path, char *buf, size_t size) { int ret; char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = readlink(p, buf, size - 1); if (res == -1) ret = -errno; leave_user_context_effective(); free(p); if (res == -1) return ret; buf[res] = '\0'; return 0; }
static int ciopfs_create(const char *path, mode_t mode, struct fuse_file_info *fi) { int ret; char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int fd = open(p, fi->flags, mode); if (fd == -1) ret = -errno; leave_user_context_effective(); free(p); if (fd == -1) return ret; ciopfs_set_orig_name_fd(fd, path); fi->fh = fd; return 0; }
static int ciopfs_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { if (!strcmp(name, CIOPFS_ATTR_NAME)) { debug("denying setting value of extended attribute '%s'\n", CIOPFS_ATTR_NAME); return -EPERM; } char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; enter_user_context_effective(); int res = lsetxattr(p, name, value, size, flags); if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
static int xmp_rename(const char *from, const char *to) { //cout << endl << endl << endl << "Entering Rename Function" << endl; double start_time = 0; struct timeval start_tv; gettimeofday(&start_tv, NULL); start_time = start_tv.tv_sec; start_time += (start_tv.tv_usec/1000000.0); start_times << fixed << start_time << endl << flush; string src = basename(strdup(from)); string dst = basename(strdup(to)); string fileid = database_getval("name", src); //cout << fileid << endl; database_remove_val(fileid,"name",src); //cout << src << endl; database_setval(fileid,"name",dst); //cout << dst << endl; string orig_path = append_path2(src); string orig_loc = database_getval(fileid,"location"); map_path(resolve_selectors(to), fileid); string new_path = append_path2(dst); string new_loc = database_getval(fileid,"location"); if(new_loc!=orig_loc) { if(new_loc=="google_music") { //upload cloud_upload(orig_path); } else if(orig_loc=="google_music") { //download cloud_download(src, new_path); } else { //file system rename rename(orig_path.c_str(), new_path.c_str()); } } double rename_time = 0; struct timeval end_tv; gettimeofday(&end_tv, NULL); rename_time = end_tv.tv_sec - start_tv.tv_sec; rename_time += (end_tv.tv_usec - start_tv.tv_usec) / 1000000.0; rename_times << fixed << rename_time << endl << flush; //cout << "Exiting Rename Function" << endl << endl << endl << endl; return 0; }
int khan_create(const char *path, mode_t mode, struct fuse_file_info *fi) { create_calls++; string fileid=database_getval("name",basename(strdup(path))); if(strcmp(fileid.c_str(),"null")==0){ fileid=database_setval("null","name",basename(strdup(path))); database_setval(fileid, "server", servers.at(0)); string ext = strrchr(basename(strdup(path)),'.')+1; database_setval(fileid, "ext", ext); } string server = database_getval(fileid, "server"); process_file(server, fileid); map_path(resolve_selectors(path), fileid); return 0; }
static int ciopfs_utimens(const char *path, const struct timespec ts[2]) { char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; struct timeval tv[2]; tv[0].tv_sec = ts[0].tv_sec; tv[0].tv_usec = ts[0].tv_nsec / 1000; tv[1].tv_sec = ts[1].tv_sec; tv[1].tv_usec = ts[1].tv_nsec / 1000; enter_user_context_effective(); int res = utimes(p, tv); if (res == -1) res = -errno; leave_user_context_effective(); free(p); return res; }
static int ciopfs_set_orig_name_fd(int fd, const char *origpath) { char *filename = strrchr(origpath, '/'); if (!filename) filename = (char *)origpath; else filename++; #ifndef NDEBUG char *path = map_path(origpath); if (likely(path != NULL)) { log_print("storing original name '%s' in '%s'\n", filename, path); free(path); } #endif if (fsetxattr(fd, CIOPFS_ATTR_NAME, filename, strlen(filename), 0)) { int ret = -errno; debug("%s\n", strerror(errno)); return ret; } return 0; }
static int ciopfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { int ret = 0; DIR *dp = (DIR *)(uintptr_t)fi->fh; struct dirent *de; char *p = map_path(path); if (unlikely(p == NULL)) return -ENOMEM; size_t pathlen = strlen(p); char dnamebuf[PATH_MAX]; char attrbuf[FILENAME_MAX]; if (pathlen > PATH_MAX) { ret = -ENAMETOOLONG; goto out; } if (!dp) { ret = -EBADF; goto out; } seekdir(dp, offset); while ((de = readdir(dp)) != NULL) { struct stat st; char *dname; char *attrlower; /* skip any entry which is not all lower case for now */ if (str_contains_upper(de->d_name)) continue; memset(&st, 0, sizeof(st)); st.st_ino = de->d_ino; st.st_mode = de->d_type << 12; if (!strcmp(".", de->d_name) || !strcmp("..", de->d_name)) dname = de->d_name; else { /* check whether there is an original name associated with * this path and if so return it instead of the all lower * case one */ snprintf(dnamebuf, sizeof dnamebuf, "%s/%s", p, de->d_name); debug("dnamebuf: %s de->d_name: %s\n", dnamebuf, de->d_name); if (ciopfs_get_orig_name(dnamebuf, attrbuf, sizeof attrbuf) > 0) { /* we found an original name now check whether it is * still accurate and if not remove it */ attrlower = str_fold(attrbuf); if (attrlower && !strcmp(attrlower, de->d_name)) dname = attrbuf; else { dname = de->d_name; ciopfs_remove_orig_name(dnamebuf); } free(attrlower); } else dname = de->d_name; } debug("dname: %s\n", dname); if (filler(buf, dname, &st, telldir(dp))) break; } out: free(p); return ret; }
void ClashAvoider::disconnect_all(const Raul::Path& graph, const Raul::Path& path) { _target.disconnect_all(map_path(graph), map_path(path)); }
void ClashAvoider::disconnect(const Raul::Path& tail, const Raul::Path& head) { _target.disconnect(map_path(tail), map_path(head)); }
void ClashAvoider::move(const Raul::Path& old_path, const Raul::Path& new_path) { _target.move(map_path(old_path), map_path(new_path)); }
int main(int argc, char **argv) { /**********************************/ /* Program options */ /**********************************/ // Need to specify elevation grid // Need to specify channel std::string map_file; std::string template_file; std::string output_file_depth; std::string output_file_proportion; bool ignore_na = false; bool do_max = false; bool majority = false; // namespace prog_opt = boost::program_options; namespace fs = boost::filesystem; namespace raster_util = blink::raster; prog_opt::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") ("map,m", prog_opt::value<std::string>(&map_file), "path of the gdal capatible raster for aggregating") ("template,t", prog_opt::value<std::string>(&template_file), "path of the gdal capatible raster which works as a template (output raster will have same extent and cell size as template)") ("depth-out,d", prog_opt::value<std::string>(&output_file_depth)->default_value("aggregated-depth.tif"), "path where the output gtif raster of depth is saved") ("proportion-out,p", prog_opt::value<std::string>(&output_file_proportion)->default_value("aggregated-proportion.tif"), "path where the output gtif raster of proportion flooded is saved") ("maximum,x", "use maximum statistic, rather than average") ("majority,a", "only assign value if majority of cells are not noValue") ("ignore-na,i", "ignore pixels with nodata when taking statistic"); prog_opt::variables_map vm; prog_opt::store(prog_opt::parse_command_line(argc, argv, desc), vm); prog_opt::notify(vm); if (vm.count("help")) { std::cout << desc << "\n"; return 1; } if (vm.count("maximum")) { do_max = true; } if (vm.count("ignore-na")) { ignore_na = true; } if (vm.count("majority")) { majority = true; } fs::path map_path(map_file); fs::path template_path(template_file); fs::path output_path_depth(output_file_depth); fs::path output_path_proportion(output_file_proportion); // Check file exists if (!fs::exists(map_path)) { std::stringstream ss; ss << map_path << " does not exist"; throw std::runtime_error(ss.str()); return (EXIT_FAILURE); } if (!fs::exists(template_path)) { std::stringstream ss; ss << template_path << " does not exist"; throw std::runtime_error(ss.str()); return (EXIT_FAILURE); } /**********************************/ /* Read in maps */ /**********************************/ std::cout << "\n\n*************************************\n"; std::cout << "* Read in maps *\n"; std::cout << "*************************************" << std::endl; auto template_m = raster_util::open_gdal_raster<double>(template_path, GA_ReadOnly); auto map = raster_util::open_gdal_raster<double>(map_path, GA_ReadOnly); /********************************************/ /* Assign memory for output map */ /********************************************/ std::cout << "\n\n**************************************\n"; std::cout << "* Assign memory for output maps *\n"; std::cout << "**************************************" << std::endl; auto output_map_depth = raster_util::create_gdal_raster_from_model<double>(output_path_depth, template_m); auto output_map_proportion = raster_util::create_gdal_raster_from_model<double>(output_path_proportion, template_m); aggregateMaps(map, template_m, output_map_depth, output_map_proportion, ignore_na, do_max, majority); return (EXIT_SUCCESS); }