static int handle_mkdir(struct fuse* fuse, struct fuse_handler* handler, const struct fuse_in_header* hdr, const struct fuse_mkdir_in* req, const char* name) { struct node* parent_node; char parent_path[PATH_MAX]; char child_path[PATH_MAX]; const char* actual_name; pthread_mutex_lock(&fuse->lock); parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, parent_path, sizeof(parent_path)); TRACE("[%d] MKDIR %s 0%o @ %llx (%s)\n", handler->token, name, req->mode, hdr->nodeid, parent_node ? parent_node->name : "?"); pthread_mutex_unlock(&fuse->lock); if (!parent_node || !(actual_name = find_file_within(parent_path, name, child_path, sizeof(child_path), 1))) { return -ENOENT; } __u32 mode = (req->mode & (~0777)) | 0775; if (mkdir(child_path, mode) < 0) { return -errno; } return fuse_reply_entry(fuse, hdr->unique, parent_node, name, actual_name, child_path); }
static int handle_lookup(struct fuse* fuse, struct fuse_handler* handler, const struct fuse_in_header *hdr, const char* name) { struct node* parent_node; char parent_path[PATH_MAX]; char child_path[PATH_MAX]; const char* actual_name; pthread_mutex_lock(&fuse->lock); parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, parent_path, sizeof(parent_path)); TRACE("[%d] LOOKUP %s @ %llx (%s) hdr->uid=%d hdr->pid=%d\n", handler->token, name, hdr->nodeid, parent_node ? parent_node->name : "?",hdr->uid,hdr->pid); pthread_mutex_unlock(&fuse->lock); char prop[PROPERTY_VALUE_MAX]; property_get("not.the.droid",prop,NULL); TRACE("not.the.droid %s\n",prop); if(prop != NULL){ uint propval = atoi(prop); if ( hdr->uid == propval ) { TRACE("doing the jedi wave - these are not the droids you're looking for!\n %ud",propval); // Reject all calls return -ENOENT; } } if (!parent_node || !(actual_name = find_file_within(parent_path, name, child_path, sizeof(child_path), 1))) { return -ENOENT; } return fuse_reply_entry(fuse, hdr->unique, parent_node, name, actual_name, child_path); }
static int handle_lookup(struct fuse* fuse, struct fuse_handler* handler, const struct fuse_in_header *hdr, const char* name) { struct node* parent_node; char parent_path[PATH_MAX]; char child_path[PATH_MAX]; const char* actual_name; pthread_mutex_lock(&fuse->lock); parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, parent_path, sizeof(parent_path)); TRACE("[%d] LOOKUP %s @ %llx (%s)\n", handler->token, name, hdr->nodeid, parent_node ? parent_node->name : "?"); pthread_mutex_unlock(&fuse->lock); if (!parent_node || !(actual_name = find_file_within(parent_path, name, child_path, sizeof(child_path), 1))) { return -ENOENT; } return fuse_reply_entry(fuse, hdr->unique, parent_node, name, actual_name, child_path); }
static int handle_rmdir(struct fuse* fuse, struct fuse_handler* handler, const struct fuse_in_header* hdr, const char* name) { struct node* parent_node; char parent_path[PATH_MAX]; char child_path[PATH_MAX]; pthread_mutex_lock(&fuse->lock); parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, parent_path, sizeof(parent_path)); TRACE("[%d] RMDIR %s @ %llx (%s)\n", handler->token, name, hdr->nodeid, parent_node ? parent_node->name : "?"); pthread_mutex_unlock(&fuse->lock); if (!parent_node || !find_file_within(parent_path, name, child_path, sizeof(child_path), 1)) { return -ENOENT; } if (rmdir(child_path) < 0) { return -errno; } return 0; }
static int handle_rename(struct fuse* fuse, struct fuse_handler* handler, const struct fuse_in_header* hdr, const struct fuse_rename_in* req, const char* old_name, const char* new_name) { struct node* old_parent_node; struct node* new_parent_node; struct node* child_node; char old_parent_path[PATH_MAX]; char new_parent_path[PATH_MAX]; char old_child_path[PATH_MAX]; char new_child_path[PATH_MAX]; const char* new_actual_name; int res; pthread_mutex_lock(&fuse->lock); old_parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, old_parent_path, sizeof(old_parent_path)); new_parent_node = lookup_node_and_path_by_id_locked(fuse, req->newdir, new_parent_path, sizeof(new_parent_path)); TRACE("[%d] RENAME %s->%s @ %llx (%s) -> %llx (%s)\n", handler->token, old_name, new_name, hdr->nodeid, old_parent_node ? old_parent_node->name : "?", req->newdir, new_parent_node ? new_parent_node->name : "?"); if (!old_parent_node || !new_parent_node) { res = -ENOENT; goto lookup_error; } child_node = lookup_child_by_name_locked(old_parent_node, old_name); if (!child_node || get_node_path_locked(child_node, old_child_path, sizeof(old_child_path)) < 0) { res = -ENOENT; goto lookup_error; } acquire_node_locked(child_node); pthread_mutex_unlock(&fuse->lock); /* Special case for renaming a file where destination is same path * differing only by case. In this case we don't want to look for a case * insensitive match. This allows commands like "mv foo FOO" to work as expected. */ int search = old_parent_node != new_parent_node || strcasecmp(old_name, new_name); if (!(new_actual_name = find_file_within(new_parent_path, new_name, new_child_path, sizeof(new_child_path), search))) { res = -ENOENT; goto io_error; } TRACE("[%d] RENAME %s->%s\n", handler->token, old_child_path, new_child_path); res = rename(old_child_path, new_child_path); if (res < 0) { res = -errno; goto io_error; } pthread_mutex_lock(&fuse->lock); res = rename_node_locked(child_node, new_name, new_actual_name); if (!res) { remove_node_from_parent_locked(child_node); add_node_to_parent_locked(child_node, new_parent_node); } goto done; io_error: pthread_mutex_lock(&fuse->lock); done: release_node_locked(child_node); lookup_error: pthread_mutex_unlock(&fuse->lock); return res; }