int cryptofs_link(Ctx *ctx, char *_target, char *_lnk) { gchar *target; gchar *lnk; gint ret; target = translate_path(ctx, _target); lnk = translate_path(ctx, _lnk); ret = link(target, lnk); g_free(target); g_free(lnk); return ret; }
int cryptofs_rename(Ctx *ctx, char *_old_name, char *_new_name) { gchar *old_name; gchar *new_name; int ret; old_name = translate_path(ctx, _old_name); new_name = translate_path(ctx, _new_name); ret = rename(old_name, new_name); g_free(new_name); g_free(old_name); return ret; }
static int fsys_open(const char *path, struct fuse_file_info *fi) { char* origpath; int fd; errno = 0; origpath = translate_path(path); if (!origpath) return -errno; //transcoder the file transcode(origpath); fd = open(origpath, fi->flags); /* File does exist, but can't be opened. */ if (fd == -1 && errno != ENOENT) { free(origpath); return -errno; } else /* Not really an error. */ errno = 0; /* File is real and can be opened. */ if (fd != -1) { close(fd); free(origpath); return -errno; } return -errno; }
static int callback_readdir(const char *path, void *buf, fuse_fill_dir_t filler,off_t offset, struct fuse_file_info *fi) { DIR *dp; struct dirent *de; int res; (void) offset; (void) fi; char *ipath; ipath=translate_path(path); dp = opendir(ipath); free(ipath); if(dp == NULL) { res = -errno; return res; } while((de = readdir(dp)) != NULL) { struct stat st; memset(&st, 0, sizeof(st)); st.st_ino = de->d_ino; st.st_mode = de->d_type << 12; if (filler(buf, de->d_name, &st, 0)) break; } closedir(dp); return 0; }
static int mp3fs_readlink(const char *path, char *buf, size_t size) { char* origpath; ssize_t len; mp3fs_debug("readlink %s", path); errno = 0; origpath = translate_path(path); if (!origpath) { goto translate_fail; } convert_path(origpath, 1); len = readlink(origpath, buf, size - 2); if (len == -1) { goto readlink_fail; } buf[len] = '\0'; convert_path(buf, 0); readlink_fail: free(origpath); translate_fail: return -errno; }
void CL_InputSource_File::open() { if (filehandle != NULL) return; #ifndef WIN32 // hate win32 non posix conform if (filename[0] == '!') { filehandle = popen(std::string(filename, 1).c_str(), "rb"); if (filehandle == NULL) { throw CL_Error("Could not open pipe: " + std::string(filename,1)); } filesize = 99999999; } else #endif { filename = translate_path(filename); filehandle = fopen(filename.c_str(), "rb"); if (filehandle == NULL) { std::cout << "Error: Could not open file: " << filename << std::endl; throw CL_Error("Could not open file: " + filename); } fseek(filehandle, 0, SEEK_END); filesize = ftell(filehandle); fseek(filehandle, 0, SEEK_SET); } // cl_assert(filehandle != NULL); }
int cryptofs_setattr(Ctx *ctx, char *_file, struct lufs_fattr *fattr) { struct stat stat; int res; gchar *file; file = translate_path(ctx, _file); if((res = lstat(file, &stat)) < 0) goto out; if(stat.st_size > fattr->f_size) { TRACE("truncating file to %Ld bytes", fattr->f_size); if((res = truncate(file, fattr->f_size)) < 0) goto out; } if(stat.st_mode != fattr->f_mode) { TRACE("set mode %o, old=%o", (unsigned)fattr->f_mode, (unsigned)stat.st_mode); if((res = chmod(file, fattr->f_mode)) < 0) goto out; } if((stat.st_atime != (time_t)fattr->f_atime) || (stat.st_mtime != (time_t)fattr->f_mtime)) { struct utimbuf utim = {fattr->f_atime, fattr->f_mtime}; if((res = utime(file, &utim)) < 0) goto out; } out: g_free(file); return res; }
int open(const char* path, int flags, int mode) { char* translated_path = translate_path(path); int retval = syscall(SYS_open, translated_path, flags, mode); free(translated_path); return retval; }
Status ObjectStorageManager::symlink(const string& fpath, const string&, ObjectId link_obj_id) { string local_path = translate_path(link_obj_id); int ret = ::symlink(fpath.c_str(), local_path.c_str()); if (ret == -1) { return Status::system_error(errno); } return Status::OK; }
int esp_vfs_rename(struct _reent *r, const char *src, const char *dst) { const vfs_entry_t* vfs = get_vfs_for_path(src); if (vfs == NULL) { __errno_r(r) = ENOENT; return -1; } const vfs_entry_t* vfs_dst = get_vfs_for_path(dst); if (vfs != vfs_dst) { __errno_r(r) = EXDEV; return -1; } const char* src_within_vfs = translate_path(vfs, src); const char* dst_within_vfs = translate_path(vfs, dst); int ret; CHECK_AND_CALL(ret, r, vfs, rename, src_within_vfs, dst_within_vfs); return ret; }
Status ObjectStorageManager::unlink(const string& path, ObjectId obj_id) { string local_path = translate_path(obj_id); int ret = ::unlink(local_path.c_str()); if (ret == -1) { LOG(ERROR) << "Failed to unlink " << path << " (Obj: " << obj_id << ")"; return Status::system_error(errno); } return Status::OK; }
int esp_vfs_link(struct _reent *r, const char* n1, const char* n2) { const vfs_entry_t* vfs = get_vfs_for_path(n1); if (vfs == NULL) { __errno_r(r) = ENOENT; return -1; } const vfs_entry_t* vfs2 = get_vfs_for_path(n2); if (vfs != vfs2) { __errno_r(r) = EXDEV; return -1; } const char* path1_within_vfs = translate_path(vfs, n1); const char* path2_within_vfs = translate_path(vfs, n2); int ret; CHECK_AND_CALL(ret, r, vfs, link, path1_within_vfs, path2_within_vfs); return ret; }
Status ObjectStorageManager::readlink( const string&, ObjectId oid, char* buf, size_t size, ssize_t* retlen) { string local_path = translate_path(oid); *retlen = ::readlink(local_path.c_str(), buf, size); if (*retlen < 0) { return Status::system_error(errno); } return Status::OK; }
Status ObjectStorageManager::getattr( const string&, ObjectId obj_id, struct stat* stbuf) { string local_path = translate_path(obj_id); int ret = ::stat(local_path.c_str(), stbuf); if (ret == -1) { return Status::system_error(errno); } return Status::OK; }
/** * Put in @host_path the canonicalized form of @path. In the nominal * case (@tracee == NULL), this function is barely equivalent to * realpath(), but when doing sub-reconfiguration, the path is * canonicalized relatively to the current @tracee's file-system * name-space. This function returns -errno on error, otherwise 0. */ int realpath2(Tracee *tracee, char host_path[PATH_MAX], const char *path, bool deref_final) { int status; if (tracee == NULL) status = (realpath(path, host_path) == NULL ? -errno : 0); else status = translate_path(tracee, host_path, AT_FDCWD, path, deref_final); return status; }
static int fsys_access(const char *path, int mode) { char* origpath; errno = 0; origpath = translate_path(path); if (!origpath) return -errno; return access(origpath, mode); }
int cryptofs_rmdir(Ctx *ctx, char *_dir, int mode) { gchar *dir; int ret; dir = translate_path(ctx, _dir); ret = rmdir(dir); g_free(dir); return ret; }
int cryptofs_create(Ctx *ctx, char *_file, int mode) { gchar *file; int ret; file = translate_path(ctx, _file); ret = mknod(file, mode, 0); g_free(file); return ret; }
int cryptofs_unlink(Ctx *ctx, char *_file) { gchar *file; int ret; file = translate_path(ctx, _file); ret = unlink(file); g_free(file); return ret; }
int esp_vfs_unlink(struct _reent *r, const char *path) { const vfs_entry_t* vfs = get_vfs_for_path(path); if (vfs == NULL) { __errno_r(r) = ENOENT; return -1; } const char* path_within_vfs = translate_path(vfs, path); int ret; CHECK_AND_CALL(ret, r, vfs, unlink, path_within_vfs); return ret; }
static int mp3fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { char* origpath; char* origfile; DIR *dp; struct dirent *de; mp3fs_debug("readdir %s", path); errno = 0; origpath = translate_path(path); if (!origpath) { goto translate_fail; } /* 2 for directory separator and NULL byte */ origfile = malloc(strlen(origpath) + NAME_MAX + 2); if (!origfile) { goto origfile_fail; } dp = opendir(origpath); if (!dp) { goto opendir_fail; } while ((de = readdir(dp))) { struct stat st; snprintf(origfile, strlen(origpath) + NAME_MAX + 2, "%s/%s", origpath, de->d_name); if (lstat(origfile, &st) == -1) { goto stat_fail; } else { if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { convert_path(de->d_name, 0); } } if (filler(buf, de->d_name, &st, 0)) break; } stat_fail: closedir(dp); opendir_fail: free(origfile); origfile_fail: free(origpath); translate_fail: return -errno; }
Status ObjectStorageManager::open(const string&, ObjectId obj_id, int flags, mode_t mode, File** file) { CHECK_NOTNULL(file); string local_path = translate_path(obj_id); int fd = ::open(local_path.c_str(), flags, mode); if (fd < 0) { LOG(ERROR) << "Failed to open file: " << local_path; return Status::system_error(errno); } *file = new File(new PosixFileHandler(this, fd)); return Status::OK; }
static int callback_getattr(const char *path, struct stat *st_data) { int res; char * ipath; ipath=translate_path(path); res = lstat(ipath, st_data); free(ipath); if(res == -1) { return -errno; } return 0; }
static int callback_statfs(const char *path, struct statvfs *st_buf) { int res; char *ipath; ipath=translate_path(path); res = statvfs(path, st_buf); free(ipath); if (res == -1) { return -errno; } return 0; }
/* * Get the value of an extended attribute. */ static int callback_getxattr(const char *path, const char *name, char *value, size_t size) { int res; char *ipath; ipath=translate_path(path); res = lgetxattr(ipath, name, value, size); free(ipath); if(res == -1) { return -errno; } return res; }
int rmdir(const char* name) { const vfs_entry_t* vfs = get_vfs_for_path(name); struct _reent* r = __getreent(); if (vfs == NULL) { __errno_r(r) = ENOENT; return -1; } const char* path_within_vfs = translate_path(vfs, name); int ret; CHECK_AND_CALL(ret, r, vfs, rmdir, path_within_vfs); return ret; }
static int mp3fs_getattr(const char *path, struct stat *stbuf) { char* origpath; struct transcoder* trans; mp3fs_debug("getattr %s", path); errno = 0; origpath = translate_path(path); if (!origpath) { goto translate_fail; } /* pass-through for regular files */ if (lstat(origpath, stbuf) == 0) { goto passthrough; } else { /* Not really an error. */ errno = 0; } convert_path(origpath, 1); if (lstat(origpath, stbuf) == -1) { goto stat_fail; } /* * Get size for resulting mp3 from regular file, otherwise it's a * symbolic link. */ if (S_ISREG(stbuf->st_mode)) { trans = transcoder_new(origpath); if (!trans) { goto transcoder_fail; } stbuf->st_size = trans->totalsize; stbuf->st_blocks = (stbuf->st_size + 512 - 1) / 512; transcoder_finish(trans); transcoder_delete(trans); } transcoder_fail: stat_fail: passthrough: free(origpath); translate_fail: return -errno; }
/* * List the supported extended attributes. */ static int callback_listxattr(const char *path, char *list, size_t size) { int res; char *ipath; ipath=translate_path(path); res = llistxattr(ipath, list, size); free(ipath); if(res == -1) { return -errno; } return res; }
static int callback_readlink(const char *path, char *buf, size_t size) { int res; char *ipath; ipath=translate_path(path); res = readlink(ipath, buf, size - 1); free(ipath); if(res == -1) { return -errno; } buf[res] = '\0'; return 0; }
static int process_mkdir_cmd(client_t *client, netiso_mkdir_cmd *cmd) { netiso_mkdir_result result; char *dirpath; uint16_t dp_len; int ret; dp_len = BE16(cmd->dp_len); dirpath = (char *)malloc(dp_len+1); if (!dirpath) { DPRINTF("CRITICAL: memory allocation error\n"); return -1; } dirpath[dp_len] = 0; ret = recv_all(client->s, (void *)dirpath, dp_len); if (ret != dp_len) { DPRINTF("recv failed, getting dirname for mkdir: %d %d\n", ret, get_network_error()); free(dirpath); return -1; } dirpath = translate_path(dirpath, 1, 1, NULL); if (!dirpath) { DPRINTF("Path cannot be translated. Connection with this client will be aborted.\n"); return -1; } DPRINTF("mkdir %s\n", dirpath); #ifdef WIN32 result.mkdir_result = BE32(mkdir(dirpath)); #else result.mkdir_result = BE32(mkdir(dirpath, 0777)); #endif free(dirpath); ret = send(client->s, (char *)&result, sizeof(result), 0); if (ret != sizeof(result)) { DPRINTF("open dir, send result error: %d %d\n", ret, get_network_error()); return -1; } return 0; }