int mediafirefs_readdir(const char *path, void *buf, fuse_fill_dir_t filldir, off_t offset, struct fuse_file_info *info) { printf("FUNCTION: readdir. path: %s\n", path); (void)offset; (void)info; struct mediafirefs_context_private *ctx; int retval; ctx = fuse_get_context()->private_data; pthread_mutex_lock(&(ctx->mutex)); retval = folder_tree_readdir(ctx->tree, ctx->conn, path, buf, filldir); pthread_mutex_unlock(&(ctx->mutex)); return retval; }
static int spade_link(const char *from, const char *to) { (*jvm)->AttachCurrentThread(jvm, (void**) &env, NULL); jstring jpathOriginal = (*env)->NewStringUTF(env, from); jstring jpathLink = (*env)->NewStringUTF(env, to); int res; res = link(from, to); if (res == -1) { return -errno; } (*env)->CallVoidMethod(env, reporterInstance, linkMethod, fuse_get_context()->pid, jpathOriginal, jpathLink); return 0; }
int cow_mknod(const char *path, mode_t mode, dev_t rdev) { int i=0; int res = 0; LOG("%s",path); struct cow_config *conf = cow_getConfig(); char *fqpath = NULL; FORDSTDIRS_BEGIN(i, res, path, conf, fqpath); res = mknod(fqpath, mode, rdev); if( res != -1 ){ struct fuse_context *cntx = fuse_get_context(); chown(fqpath, cntx->uid,cntx->gid); } FORDSTDIRS_END(fqpath); return 0; }
static int fuse_chown(const char * path, uid_t uid, gid_t gid) { int ret; struct afp_volume * volume= (struct afp_volume *) ((struct fuse_context *)(fuse_get_context()))->private_data; log_fuse_event(AFPFSD,LOG_DEBUG,"** chown\n"); ret=ml_chown(volume,path,uid,gid); if (ret==-ENOSYS) { log_for_client(NULL,AFPFSD,LOG_WARNING,"chown unsupported\n"); } return ret; }
static void afp_destroy(void * ignore) { struct afp_volume * volume= (struct afp_volume *) ((struct fuse_context *)(fuse_get_context()))->private_data; if (volume->mounted==AFP_VOLUME_UNMOUNTED) { log_for_client(NULL,AFPFSD,LOG_WARNING,"Skipping unmounting of the volume %s\n",volume->volume_name_printable); return; } if ((!volume) || (!volume->server)) return; /* We're just ignoring the results since there's nothing we could do with them anyway. */ afp_unmount_volume(volume); }
int readdir(const char *fusepath, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fi) { const fuse_context *fc = fuse_get_context(); const Config &config = Config::get(fc); const ugid::Set ugid(fc->uid,fc->gid); const rwlock::ReadGuard readlock(&config.srcmountslock); return _readdir(config.srcmounts, fusepath, buf, filler); }
static int ifuse_utimens(const char *path, const struct timespec tv[2]) { afc_client_t afc = fuse_get_context()->private_data; uint64_t mtime = (uint64_t)tv[1].tv_sec * (uint64_t)1000000000 + (uint64_t)tv[1].tv_nsec; afc_error_t err = afc_set_file_time(afc, path, mtime); if (err == AFC_E_UNKNOWN_PACKET_TYPE) { /* ignore error for pre-3.1 devices as they do not support setting file modification times */ return 0; } if (err != AFC_E_SUCCESS) { int res = get_afc_error_as_errno(err); return -res; } return 0; }
static int xmp_readlink(const char *path, char *buf, size_t size) { int res; char *data = malloc(strlen(path)+100); sprintf(data, "readlink:%s:%d:\n", path, (int) size); log_log(data, fuse_get_context()->pid); free(data); //log_log("readlink\n"); res = readlink(path, buf, size - 1); if (res == -1) return -errno; buf[res] = '\0'; return 0; }
static int xmp_open(const char *path, struct fuse_file_info *fi) { int res; char *data = malloc(strlen(path)+100); sprintf(data, "open:%s::\n", path); log_log(data, fuse_get_context()->pid); free(data); res = open(path, fi->flags); if (res == -1) return -errno; close(res); return 0; }
static int f_open(const char *path, struct fuse_file_info *fi) { printf("[Potato_open] calling open\n"); //parse file operation from flags FileOp fileOp; int opflag = fi->flags & 3; if(opflag == O_RDONLY) fileOp = READ; else if(opflag == O_WRONLY) fileOp = WRITE; else if(opflag == O_RDWR) fileOp = READWRITE; else { fprintf(stderr, "Error: no file operation specified in flags!\n"); return -EINVAL; } printf("File operation from flags: %d\n", fileOp); //parse create flag if(fi->flags & O_CREAT) { #ifdef DEBUG printf("O_CREAT flag detected, creating file: %s\n", path); #endif struct fuse_context* fctx = fuse_get_context(); INT succ = Potato_mknod(&fs, path, fctx->uid, fctx->gid); //parse exists flag if((fi->flags & O_EXCL) && (succ == -EEXIST)) { fprintf(stderr, "Error: O_EXCL specified for open but file already exists!\n"); return -EEXIST; } else if(succ < 0) { return succ; } } //parse truncate flag if(fi->flags & (O_TRUNC | O_WRONLY | O_RDWR)) { #ifdef DEBUG printf("O_TRUNC flag detected, truncating file: %s\n", path); #endif //TODO truncate file } return (int)Potato_open(&fs, path, fileOp); }
int dfs_getattr(const char *path, struct stat *st) { TRACE1("getattr", path) // retrieve dfs specific data dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data; // check params and the context var assert(dfs); assert(path); assert(st); // if not connected, try to connect and fail out if we can't. if (NULL == dfs->fs && NULL == (dfs->fs = hdfsConnect(dfs->nn_hostname,dfs->nn_port))) { syslog(LOG_ERR, "ERROR: could not connect to %s:%d %s:%d\n", dfs->nn_hostname, dfs->nn_port,__FILE__, __LINE__); return -EIO; } // call the dfs API to get the actual information hdfsFileInfo *info = hdfsGetPathInfo(dfs->fs,path); if (NULL == info) { return -ENOENT; } fill_stat_structure(&info[0], st); // setup hard link info - for a file it is 1 else num entries in a dir + 2 (for . and ..) if (info[0].mKind == kObjectKindDirectory) { int numEntries = 0; hdfsFileInfo *info = hdfsListDirectory(dfs->fs,path,&numEntries); if (info) { hdfsFreeFileInfo(info,numEntries); } st->st_nlink = numEntries + 2; } else { // not a directory st->st_nlink = 1; } // free the info pointer hdfsFreeFileInfo(info,1); return 0; }
static int spade_unlink(const char *path) { (*jvm)->AttachCurrentThread(jvm, (void**) &env, NULL); jstring jpath = (*env)->NewStringUTF(env, path); int res; res = unlink(path); if (res == -1) { return -errno; } (*env)->CallVoidMethod(env, reporterInstance, unlinkMethod, fuse_get_context()->pid, jpath); return 0; }
static int pgfuse_readdir( const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi ) { PgFuseData *data = (PgFuseData *)fuse_get_context( )->private_data; int id; int res; PgMeta meta; PGconn *conn; if( data->verbose ) { syslog( LOG_INFO, "Readdir '%s' on '%s', thread #%u", path, data->mountpoint, THREAD_ID ); } ACQUIRE( conn ); PSQL_BEGIN( conn ); filler( buf, ".", NULL, 0 ); filler( buf, "..", NULL, 0 ); id = psql_read_meta_from_path( conn, path, &meta ); if( id < 0 ) { PSQL_ROLLBACK( conn ); RELEASE( conn ); return id; } res = psql_readdir( conn, id, buf, filler ); if( res < 0 ) { PSQL_ROLLBACK( conn ); RELEASE( conn ); return res; } if( !data->noatime ) { meta.atime = now( ); res = psql_write_meta( conn, id, path, meta ); if( res < 0 ) { PSQL_ROLLBACK( conn ); RELEASE( conn ); return res; } } PSQL_COMMIT( conn ); RELEASE( conn ); return 0; }
int dfs_mkdir(const char *path, mode_t mode) { TRACE1("mkdir", path) // retrieve dfs specific data dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data; // check params and the context var assert(path); assert(dfs); assert('/' == *path); if (is_protected(path)) { syslog(LOG_ERR,"ERROR: hdfs trying to create the directory: %s", path); return -EACCES; } if (dfs->read_only) { syslog(LOG_ERR,"ERROR: hdfs is configured as read-only, cannot create the directory %s\n",path); return -EACCES; } hdfsFS userFS; // if not connected, try to connect and fail out if we can't. if ((userFS = doConnectAsUser(dfs->nn_hostname,dfs->nn_port))== NULL) { syslog(LOG_ERR, "ERROR: could not connect to dfs %s:%d\n", __FILE__, __LINE__); return -EIO; } // In theory the create and chmod should be atomic. if (hdfsCreateDirectory(userFS, path)) { syslog(LOG_ERR,"ERROR: hdfs trying to create directory %s",path); return -EIO; } #if PERMS if (hdfsChmod(userFS, path, (short)mode)) { syslog(LOG_ERR,"ERROR: hdfs trying to chmod %s to %d",path, (int)mode); return -EIO; } #endif return 0; }
int archivefs_open(const char* path, struct fuse_file_info* info) { char fpath[PATH_MAX]; fullpath(fpath, path); /* Nejprve se pokusím otevřít soubor s cestou path jakoby byl přítomen * fyzicky na disku - použiju systémový open. * Pokud volání této funkce selže, jedná se o soubor uvnitř archivu. */ int fd; if ((fd = open(fpath, info->flags)) != -1) { info->fh = intptr_t(fd); return 0; } FileSystem* fs; FileNode* node; if (!getFile(fpath, &fs, &node)) { print_err("OPEN", path, ENOENT); return -ENOENT; } int ret; struct fuse_context* context = fuse_get_context(); if (info->flags & O_RDWR) { if (fs->access(node, R_OK|W_OK, context->uid, context->gid)) return -EACCES; } else if (info->flags & O_WRONLY) { if (fs->access(node, W_OK, context->uid, context->gid)) return -EACCES; } else { if (fs->access(node, R_OK, context->uid, context->gid)) return -EACCES; } if ((ret = fs->open(node, info->flags)) < 0) { print_err("OPEN", path, ret); return -ret; } info->fh = intptr_t(new FileHandle(fs, node)); return 0; }
int cow_symlink(const char *from, const char *to) { int i=0; int res = 0; LOG("%s -> %s",from, to); struct cow_config *conf = cow_getConfig(); char *fqto = NULL; FORDSTDIRS_BEGIN(i, res, to, conf, fqto); res = symlink(from, fqto); if(res != -1){ struct fuse_context *cntx = fuse_get_context(); chown(fqto, cntx->uid,cntx->gid); } FORDSTDIRS_END(fqto); return 0; }
int mediafirefs_opendir(const char *path, struct fuse_file_info *file_info) { printf("FUNCTION: opendir. path: %s\n", path); (void)path; (void)file_info; struct mediafirefs_context_private *ctx; ctx = fuse_get_context()->private_data; pthread_mutex_lock(&(ctx->mutex)); fprintf(stderr, "opendir is a no-op\n"); pthread_mutex_unlock(&(ctx->mutex)); return 0; }
static sqfs_err sqfs_hl_lookup(sqfs **fs, sqfs_inode *inode, const char *path) { bool found; sqfs_hl *hl = fuse_get_context()->private_data; *fs = &hl->fs; if (inode) *inode = hl->root; /* copy */ if (path) { sqfs_err err = sqfs_lookup_path(*fs, inode, path, &found); if (err) return err; if (!found) return SQFS_ERR; } return SQFS_OK; }
int mknod(const char *fusepath, mode_t mode, dev_t rdev) { const fuse_context *fc = fuse_get_context(); const Config &config = Config::get(fc); const ugid::Set ugid(fc->uid,fc->gid); const rwlock::ReadGuard readlock(&config.srcmountslock); return _mknod(config.getattr, config.mknod, config.srcmounts, config.minfreespace, fusepath, (mode & ~fc->umask), rdev); }
void* thesmurFS_init(struct fuse_conn_info* conn) { //FUSE context available when this is called, return the private data log_msg("Initialising file system..."); //some errnos /*emergency_output_plus_n("EACCES", EACCES); emergency_output_plus_n("EBADF", EBADF); emergency_output_plus_n("EFAULT", EFAULT); emergency_output_plus_n("ELOOP", ELOOP); emergency_output_plus_n("ENAMETOOLONG", ENAMETOOLONG); emergency_output_plus_n("ENOENT", ENOENT); emergency_output_plus_n("ENOMEM", ENOMEM); emergency_output_plus_n("ENOTDIR", ENOTDIR); emergency_output_plus_n("EOVERFLOW", EOVERFLOW); emergency_output_plus_n("ENOTSUP", ENOTSUP);*/ return fuse_get_context()->private_data; }
int mediafirefs_link(const char *target, const char *linkpath) { printf("FUNCTION: link. target: %s, linkpath %s\n", target, linkpath); (void)target; (void)linkpath; struct mediafirefs_context_private *ctx; ctx = fuse_get_context()->private_data; pthread_mutex_lock(&(ctx->mutex)); fprintf(stderr, "link not implemented\n"); pthread_mutex_unlock(&(ctx->mutex)); return -ENOSYS; }
int readdir(const char *fusepath_, void *buf_, fuse_fill_dir_t filler_, off_t offset_, fuse_file_info *ffi_) { DirInfo *di = reinterpret_cast<DirInfo*>(ffi_->fh); const fuse_context *fc = fuse_get_context(); const Config &config = Config::get(fc); const ugid::Set ugid(fc->uid,fc->gid); const rwlock::ReadGuard readlock(&config.branches_lock); return l::readdir(config.branches, di->fusepath.c_str(), buf_, filler_); }
int vfs_fuse_mkdir(const char *path, mode_t mode) { struct vfs_inode *node; struct fuse_context *ctx; int ret; if (store_get_readonly()) return -EPERM; if (!(ctx = fuse_get_context())) return -EFAULT; if ((ret = vfs_node_lookup(path, &node, true)) != 0) return ret; node->data.mode = mode | S_IFDIR; node->data.uid = ctx->uid; node->data.gid = ctx->gid; return vfs_node_commit_and_deref(node); }
static int xmp_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { FILE *f, *memstream; int res; char pathbuf[BUFSIZE]; char *membuf; size_t memsize; (void) fi; xmp_state *state = (xmp_state *)(fuse_get_context()->private_data); f = fopen(_xmp_fullpath(pathbuf, path, BUFSIZE), "r"); memstream = open_memstream(&membuf, &memsize); if (memstream == NULL) return -errno; char attrbuf[8]; ssize_t attr_len = getxattr(pathbuf, ENCRYPTED_ATTR, attrbuf, 8); int encrypted = 0; if(attr_len != -1 && !memcmp(attrbuf, "true", 4)){ encrypted = 1; } if(f != NULL){ do_crypt(f, memstream, (encrypted ? AES_DECRYPT : AES_PASSTHRU), state->key); fclose(f); } fseek(memstream, offset, SEEK_SET); res = fwrite(buf, 1, size, memstream); fflush(memstream); f = fopen(pathbuf, "w"); fseek(memstream, 0, SEEK_SET); do_crypt(memstream, f, (encrypted ? AES_ENCRYPT : AES_PASSTHRU), state->key); fclose(memstream); if (res == -1) res = -errno; fclose(f); return res; }
static int undup_create(const char *path, mode_t mode, struct fuse_file_info *fi) { char b[PATH_MAX+1]; int n, fd; struct undup_hdr hdr; struct stub *stub; struct fuse_context *ctx = fuse_get_context(); int um, e; n = snprintf(b, PATH_MAX, "%s/%s", state->basedir, path); if (n > PATH_MAX) return -ENAMETOOLONG; debug("create path=%s mode=0%o\n", path, mode); um = umask(ctx->umask); fd = creat(b, mode); e = errno; umask(um); if (fd == -1) return -e; hdr.magic = UNDUPFS_MAGIC; hdr.version = 1; hdr.flags = 0; hdr.len = 0; hdr.uid = ctx->uid; hdr.gid = ctx->gid; n = write(fd, &hdr, sizeof(hdr)); if (n == -1) return -errno; if (close(fd) == -1) debug("undup_create: close(%d): %d (%s)\n", fd, errno, strerror(errno)); // XXX whatta hack, do a stub_create() or something stub = stub_open(state, b, O_RDWR); if (!stub) return -errno; fi->fh = (intptr_t)stub; return 0; }
static int pgfuse_readlink( const char *path, char *buf, size_t size ) { PgFuseData *data = (PgFuseData *)fuse_get_context( )->private_data; int64_t id; PgMeta meta; int res; PGconn *conn; if( data->verbose ) { syslog( LOG_INFO, "Dereferencing symlink '%s' on '%s', thread #%u", path, data->mountpoint, THREAD_ID ); } ACQUIRE( conn ); PSQL_BEGIN( conn ); id = psql_read_meta_from_path( conn, path, &meta ); if( id < 0 ) { PSQL_ROLLBACK( conn ); RELEASE( conn ); return id; } if( !S_ISLNK( meta.mode ) ) { PSQL_ROLLBACK( conn ); RELEASE( conn ); return -ENOENT; } if( size < meta.size + 1 ) { PSQL_ROLLBACK( conn ); RELEASE( conn ); return -ENOMEM; } res = psql_read_buf( conn, data->block_size, id, path, buf, 0, meta.size, data->verbose ); if( res < 0 ) { PSQL_ROLLBACK( conn ); RELEASE( conn ); return res; } buf[meta.size] = '\0'; PSQL_COMMIT( conn ); RELEASE( conn ); return 0; }
/* * Writing to this filesystem is only used as a way to signal that the * configuration and should be reparsed. Thus, it does not matter which * writing function is called - they should all act the same. They all call * this. */ int write_attempt(const char* path) { /* * The *only* thing writable is the /reparse_config, and only by root. * When it is written to, it will cause brp to reparse its configuration. */ if (strcmp(path, "/reparse_config") == 0) { struct fuse_context *context = fuse_get_context(); if (context->uid != 0) { /* Non-root users cannot do anything with this file. */ return -EACCES; } else { brp_parse_config(); return 0; } } else { return -EACCES; } }
/* * Check if user has permissions to do something with file. e.g. read or write. */ static int brp_open(const char *in_path, struct fuse_file_info *fi) { SET_CALLER_UID(); struct out_item *out_item; int stratum_id; struct in_item *in_item; char *tail; int ret; struct stat stbuf; /* * /reparse_config is the only file which could possibly be written to. * Get that out of the way here so we can assume everything else later is * only being read. */ if (strcmp(in_path, "/reparse_config") == 0) { struct fuse_context *context = fuse_get_context(); if (context->uid != 0) { /* Non-root users cannot do anything with this file. */ return -EACCES; } else { return 0; } } /* * Everything else in this filesystem is read-only. If the user requested * anything else, return EACCES. * * Note the way permissions are stored in fi->flags do *not* have a single * bit flag for read or write, hence the unusual looking check below. See * `man 2 open`. */ if ((fi->flags & 3) != O_RDONLY ) { return -EACCES; } if ( (ret = corresponding((char*)in_path, NULL, &stbuf, &out_item, &stratum_id, &in_item, &tail)) >= 0) { return 0; } return -ENOENT; }
static int is_user_in_group(backend_store_interface* i, gid_t group) { if (fuse_get_context()->gid == group) { return 1; } int arr_size = 20; gid_t arr[arr_size]; int num_groups = fuse_getgroups(arr_size, arr); int j; for (j = 0; j < num_groups; ++j) { if (arr[j] == group) { return 1; } } return 0; }
int create(const char *fusepath, mode_t mode, fuse_file_info *ffi) { const fuse_context *fc = fuse_get_context(); const Config &config = Config::get(fc); const ugid::Set ugid(fc->uid,fc->gid); const rwlock::ReadGuard readlock(&config.srcmountslock); return _create(config.getattr, config.create, config.srcmounts, config.minfreespace, fusepath, (mode & ~fc->umask), ffi->flags, ffi->fh); }