Lines Matching refs:fuse
23 #include "fuse.h"
32 /* Pseudo-error constant used to indicate that no fuse status is needed
182 static void attr_from_stat(struct fuse* fuse, struct fuse_attr *attr,
198 if (fuse->gid == AID_SDCARD_RW) {
206 attr->gid = multiuser_get_uid(node->userid, fuse->gid);
209 int visible_mode = 0775 & ~fuse->mask;
218 if (fuse->gid == AID_SDCARD_RW) {
244 static void derive_permissions_locked(struct fuse* fuse, struct node *parent,
280 node->graft_path = fuse->global->obb_path;
281 node->graft_pathlen = strlen(fuse->global->obb_path);
290 const auto& iter = fuse->global->package_to_appid->find(node->name);
291 if (iter != fuse->global->package_to_appid->end()) {
299 void derive_permissions_recursive_locked(struct fuse* fuse, struct node *parent) {
302 derive_permissions_locked(fuse, parent, node);
304 derive_permissions_recursive_locked(fuse, node);
312 static bool check_caller_access_to_name(struct fuse* fuse,
334 static bool check_caller_access_to_node(struct fuse* fuse,
336 return check_caller_access_to_name(fuse, hdr, node->parent, node->name, mode);
339 struct node *create_node_locked(struct fuse* fuse,
347 if (fuse->global->inode_ctr == 0) {
373 node->ino = fuse->global->inode_ctr++;
374 node->gen = fuse->global->next_generation++;
378 derive_permissions_locked(fuse, parent, node);
425 static struct node *lookup_node_by_id_locked(struct fuse *fuse, __u64 nid)
428 return &fuse->global->root;
434 static struct node* lookup_node_and_path_by_id_locked(struct fuse* fuse, __u64 nid,
437 struct node* node = lookup_node_by_id_locked(fuse, nid);
459 struct fuse* fuse, struct node* parent,
466 child = create_node_locked(fuse, parent, name, actual_name);
471 static void fuse_status(struct fuse *fuse, __u64 unique, int err)
477 ssize_t ret = TEMP_FAILURE_RETRY(write(fuse->fd, &hdr, sizeof(hdr)));
486 static void fuse_reply(struct fuse *fuse, __u64 unique, void *data, int len)
499 ssize_t ret = TEMP_FAILURE_RETRY(writev(fuse->fd, vec, 2));
508 static int fuse_reply_entry(struct fuse* fuse, __u64 unique,
520 pthread_mutex_lock(&fuse->global->lock);
521 node = acquire_or_create_child_locked(fuse, parent, name, actual_name);
523 pthread_mutex_unlock(&fuse->global->lock);
527 attr_from_stat(fuse, &out.attr, &s, node);
532 pthread_mutex_unlock(&fuse->global->lock);
533 fuse_reply(fuse, unique, &out, sizeof(out));
537 static int fuse_reply_attr(struct fuse* fuse, __u64 unique, const struct node* node,
547 attr_from_stat(fuse, &out.attr, &s, node);
549 fuse_reply(fuse, unique, &out, sizeof(out));
553 static void fuse_notify_delete(struct fuse* fuse, const __u64 parent,
575 ssize_t ret = TEMP_FAILURE_RETRY(writev(fuse->fd, vec, 3));
587 static int handle_lookup(struct fuse* fuse, struct fuse_handler* handler,
595 pthread_mutex_lock(&fuse->global->lock);
596 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
600 pthread_mutex_unlock(&fuse->global->lock);
606 if (!check_caller_access_to_name(fuse, hdr, parent_node, name, R_OK)) {
610 return fuse_reply_entry(fuse, hdr->unique, parent_node, name, actual_name, child_path);
613 static int handle_forget(struct fuse* fuse, struct fuse_handler* handler,
618 pthread_mutex_lock(&fuse->global->lock);
619 node = lookup_node_by_id_locked(fuse, hdr->nodeid);
630 pthread_mutex_unlock(&fuse->global->lock);
634 static int handle_getattr(struct fuse* fuse, struct fuse_handler* handler,
640 pthread_mutex_lock(&fuse->global->lock);
641 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
645 pthread_mutex_unlock(&fuse->global->lock);
650 if (!check_caller_access_to_node(fuse, hdr, node, R_OK)) {
654 return fuse_reply_attr(fuse, hdr->unique, node, path);
657 static int handle_setattr(struct fuse* fuse, struct fuse_handler* handler,
664 pthread_mutex_lock(&fuse->global->lock);
665 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
669 pthread_mutex_unlock(&fuse->global->lock);
676 !check_caller_access_to_node(fuse, hdr, node, W_OK)) {
691 * nanosecond resolution which fuse also has.
718 return fuse_reply_attr(fuse, hdr->unique, node, path);
721 static int handle_mknod(struct fuse* fuse, struct fuse_handler* handler,
729 pthread_mutex_lock(&fuse->global->lock);
730 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
735 pthread_mutex_unlock(&fuse->global->lock);
741 if (!check_caller_access_to_name(fuse, hdr, parent_node, name, W_OK)) {
748 return fuse_reply_entry(fuse, hdr->unique, parent_node, name, actual_name, child_path);
751 static int handle_mkdir(struct fuse* fuse, struct fuse_handler* handler,
759 pthread_mutex_lock(&fuse->global->lock);
760 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
765 pthread_mutex_unlock(&fuse->global->lock);
771 if (!check_caller_access_to_name(fuse, hdr, parent_node, name, W_OK)) {
790 snprintf(nomedia, PATH_MAX, "%s/.nomedia", fuse->global->obb_path);
797 return fuse_reply_entry(fuse, hdr->unique, parent_node, name, actual_name, child_path);
800 static int handle_unlink(struct fuse* fuse, struct fuse_handler* handler,
808 pthread_mutex_lock(&fuse->global->lock);
809 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
813 pthread_mutex_unlock(&fuse->global->lock);
819 if (!check_caller_access_to_name(fuse, hdr, parent_node, name, W_OK)) {
825 pthread_mutex_lock(&fuse->global->lock);
830 pthread_mutex_unlock(&fuse->global->lock);
837 if (fuse != fuse->global->fuse_default) {
838 fuse_notify_delete(fuse->global->fuse_default, parent_node->nid, child_node->nid, name);
840 if (fuse != fuse->global->fuse_read) {
841 fuse_notify_delete(fuse->global->fuse_read, parent_node->nid, child_node->nid, name);
843 if (fuse != fuse->global->fuse_write) {
844 fuse_notify_delete(fuse->global->fuse_write, parent_node->nid, child_node->nid, name);
850 static int handle_rmdir(struct fuse* fuse, struct fuse_handler* handler,
858 pthread_mutex_lock(&fuse->global->lock);
859 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
863 pthread_mutex_unlock(&fuse->global->lock);
869 if (!check_caller_access_to_name(fuse, hdr, parent_node, name, W_OK)) {
875 pthread_mutex_lock(&fuse->global->lock);
880 pthread_mutex_unlock(&fuse->global->lock);
887 if (fuse != fuse->global->fuse_default) {
888 fuse_notify_delete(fuse->global->fuse_default, parent_node->nid, child_node->nid, name);
890 if (fuse != fuse->global->fuse_read) {
891 fuse_notify_delete(fuse->global->fuse_read, parent_node->nid, child_node->nid, name);
893 if (fuse != fuse->global->fuse_write) {
894 fuse_notify_delete(fuse->global->fuse_write, parent_node->nid, child_node->nid, name);
900 static int handle_rename(struct fuse* fuse, struct fuse_handler* handler,
915 pthread_mutex_lock(&fuse->global->lock);
916 old_parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
918 new_parent_node = lookup_node_and_path_by_id_locked(fuse, req->newdir,
929 if (!check_caller_access_to_name(fuse, hdr, old_parent_node, old_name, W_OK)) {
933 if (!check_caller_access_to_name(fuse, hdr, new_parent_node, new_name, W_OK)) {
944 pthread_mutex_unlock(&fuse->global->lock);
965 pthread_mutex_lock(&fuse->global->lock);
969 derive_permissions_locked(fuse, new_parent_node, child_node);
970 derive_permissions_recursive_locked(fuse, child_node);
976 pthread_mutex_lock(&fuse->global->lock);
980 pthread_mutex_unlock(&fuse->global->lock);
995 static int handle_open(struct fuse* fuse, struct fuse_handler* handler,
1003 pthread_mutex_lock(&fuse->global->lock);
1004 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
1008 pthread_mutex_unlock(&fuse->global->lock);
1013 if (!check_caller_access_to_node(fuse, hdr, node,
1029 fuse_reply(fuse, hdr->unique, &out, sizeof(out));
1033 static int handle_read(struct fuse* fuse, struct fuse_handler* handler,
1056 fuse_reply(fuse, unique, read_buffer, res);
1060 static int handle_write(struct fuse* fuse, struct fuse_handler* handler,
1082 fuse_reply(fuse, hdr->unique, &out, sizeof(out));
1086 static int handle_statfs(struct fuse* fuse, struct fuse_handler* handler,
1094 pthread_mutex_lock(&fuse->global->lock);
1096 res = get_node_path_locked(&fuse->global->root, path, sizeof(path));
1097 pthread_mutex_unlock(&fuse->global->lock);
1101 if (TEMP_FAILURE_RETRY(statfs(fuse->global->root.name, &stat)) == -1) {
1113 fuse_reply(fuse, hdr->unique, &out, sizeof(out));
1117 static int handle_release(struct fuse* fuse, struct fuse_handler* handler,
1129 static int handle_fsync(struct fuse* fuse, struct fuse_handler* handler,
1153 static int handle_flush(struct fuse* fuse, struct fuse_handler* handler,
1160 static int handle_opendir(struct fuse* fuse, struct fuse_handler* handler,
1168 pthread_mutex_lock(&fuse->global->lock);
1169 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
1172 pthread_mutex_unlock(&fuse->global->lock);
1177 if (!check_caller_access_to_node(fuse, hdr, node, R_OK)) {
1192 fuse_reply(fuse, hdr->unique, &out, sizeof(out));
1196 static int handle_readdir(struct fuse* fuse, struct fuse_handler* handler,
1220 fuse_reply(fuse, hdr->unique, fde,
1225 static int handle_releasedir(struct fuse* fuse, struct fuse_handler* handler,
1236 static int handle_init(struct fuse* fuse, struct fuse_handler* handler,
1246 * defined (fuse version 7.6). The structure is the same from 7.6 through
1251 LOG(ERROR) << "Fuse kernel version mismatch: Kernel version "
1274 fuse_reply(fuse, hdr->unique, &out, fuse_struct_size);
1278 static int handle_canonical_path(struct fuse* fuse, struct fuse_handler* handler,
1285 pthread_mutex_lock(&fuse->global->lock);
1286 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
1290 pthread_mutex_unlock(&fuse->global->lock);
1295 if (!check_caller_access_to_node(fuse, hdr, node, R_OK)) {
1302 fuse_reply(fuse, hdr->unique, path, len + 1);
1306 static int handle_fuse_request(struct fuse *fuse, struct fuse_handler* handler,
1312 return handle_lookup(fuse, handler, hdr, name);
1317 return handle_forget(fuse, handler, hdr, req);
1322 return handle_getattr(fuse, handler, hdr, req);
1327 return handle_setattr(fuse, handler, hdr, req);
1335 return handle_mknod(fuse, handler, hdr, req, name);
1341 return handle_mkdir(fuse, handler, hdr, req, name);
1346 return handle_unlink(fuse, handler, hdr, name);
1351 return handle_rmdir(fuse, handler, hdr, name);
1358 return handle_rename(fuse, handler, hdr, req, old_name, new_name);
1364 return handle_open(fuse, handler, hdr, req);
1369 return handle_read(fuse, handler, hdr, req);
1375 return handle_write(fuse, handler, hdr, req, buffer);
1379 return handle_statfs(fuse, handler, hdr);
1384 return handle_release(fuse, handler, hdr, req);
1390 return handle_fsync(fuse, handler, hdr, req);
1398 return handle_flush(fuse, handler, hdr);
1403 return handle_opendir(fuse, handler, hdr, req);
1408 return handle_readdir(fuse, handler, hdr, req);
1413 return handle_releasedir(fuse, handler, hdr, req);
1418 return handle_init(fuse, handler, hdr, req);
1422 return handle_canonical_path(fuse, handler, hdr);
1435 struct fuse* fuse = handler->fuse;
1437 ssize_t len = TEMP_FAILURE_RETRY(read(fuse->fd,
1464 int res = handle_fuse_request(fuse, handler, hdr, data, data_len);
1473 fuse_status(fuse, unique, res);