Home | History | Annotate | Download | only in sdcard

Lines Matching refs:fuse

36 #include "fuse.h"
42 * sdcard is a program that uses FUSE to emulate FAT-on-sdcard style
88 /* Pseudo-error constant used to indicate that no fuse status is needed
119 /* Global data structure shared by all fuse handlers. */
120 struct fuse {
129 /* Private data used by a single fuse handler. */
131 struct fuse* fuse;
305 struct node *create_node_locked(struct fuse* fuse,
332 node->gen = fuse->next_generation++;
379 static struct node *lookup_node_by_id_locked(struct fuse *fuse, __u64 nid)
382 return &fuse->root;
388 static struct node* lookup_node_and_path_by_id_locked(struct fuse* fuse, __u64 nid,
391 struct node* node = lookup_node_by_id_locked(fuse, nid);
413 struct fuse* fuse, struct node* parent,
420 child = create_node_locked(fuse, parent, name, actual_name);
425 static void fuse_init(struct fuse *fuse, int fd, const char *source_path)
427 pthread_mutex_init(&fuse->lock, NULL);
429 fuse->fd = fd;
430 fuse->next_generation = 0;
432 memset(&fuse->root, 0, sizeof(fuse->root));
433 fuse->root.nid = FUSE_ROOT_ID; /* 1 */
434 fuse->root.refcount = 2;
435 fuse->root.namelen = strlen(source_path);
436 fuse->root.name = strdup(source_path);
439 static void fuse_status(struct fuse *fuse, __u64 unique, int err)
445 write(fuse->fd, &hdr, sizeof(hdr));
448 static void fuse_reply(struct fuse *fuse, __u64 unique, void *data, int len)
463 res = writev(fuse->fd, vec, 2);
469 static int fuse_reply_entry(struct fuse* fuse, __u64 unique,
481 pthread_mutex_lock(&fuse->lock);
482 node = acquire_or_create_child_locked(fuse, parent, name, actual_name);
484 pthread_mutex_unlock(&fuse->lock);
493 pthread_mutex_unlock(&fuse->lock);
494 fuse_reply(fuse, unique, &out, sizeof(out));
498 static int fuse_reply_attr(struct fuse* fuse, __u64 unique, __u64 nid,
510 fuse_reply(fuse, unique, &out, sizeof(out));
514 static int handle_lookup(struct fuse* fuse, struct fuse_handler* handler,
522 pthread_mutex_lock(&fuse->lock);
523 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
527 pthread_mutex_unlock(&fuse->lock);
533 return fuse_reply_entry(fuse, hdr->unique, parent_node, name, actual_name, child_path);
536 static int handle_forget(struct fuse* fuse, struct fuse_handler* handler,
541 pthread_mutex_lock(&fuse->lock);
542 node = lookup_node_by_id_locked(fuse, hdr->nodeid);
551 pthread_mutex_unlock(&fuse->lock);
555 static int handle_getattr(struct fuse* fuse, struct fuse_handler* handler,
561 pthread_mutex_lock(&fuse->lock);
562 fuse, hdr->nodeid, path, sizeof(path));
565 pthread_mutex_unlock(&fuse->lock);
570 return fuse_reply_attr(fuse, hdr->unique, hdr->nodeid, path);
573 static int handle_setattr(struct fuse* fuse, struct fuse_handler* handler,
580 pthread_mutex_lock(&fuse->lock);
581 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
584 pthread_mutex_unlock(&fuse->lock);
601 * nanosecond resolution which fuse also has.
628 return fuse_reply_attr(fuse, hdr->unique, hdr->nodeid, path);
631 static int handle_mknod(struct fuse* fuse, struct fuse_handler* handler,
639 pthread_mutex_lock(&fuse->lock);
640 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
644 pthread_mutex_unlock(&fuse->lock);
654 return fuse_reply_entry(fuse, hdr->unique, parent_node, name, actual_name, child_path);
657 static int handle_mkdir(struct fuse* fuse, struct fuse_handler* handler,
665 pthread_mutex_lock(&fuse->lock);
666 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
670 pthread_mutex_unlock(&fuse->lock);
680 return fuse_reply_entry(fuse, hdr->unique, parent_node, name, actual_name, child_path);
683 static int handle_unlink(struct fuse* fuse, struct fuse_handler* handler,
690 pthread_mutex_lock(&fuse->lock);
691 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
695 pthread_mutex_unlock(&fuse->lock);
707 static int handle_rmdir(struct fuse* fuse, struct fuse_handler* handler,
714 pthread_mutex_lock(&fuse->lock);
715 parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
719 pthread_mutex_unlock(&fuse->lock);
731 static int handle_rename(struct fuse* fuse, struct fuse_handler* handler,
745 pthread_mutex_lock(&fuse->lock);
746 old_parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
748 new_parent_node = lookup_node_and_path_by_id_locked(fuse, req->newdir,
765 pthread_mutex_unlock(&fuse->lock);
786 pthread_mutex_lock(&fuse->lock);
795 pthread_mutex_lock(&fuse->lock);
799 pthread_mutex_unlock(&fuse->lock);
803 static int handle_open(struct fuse* fuse, struct fuse_handler* handler,
811 pthread_mutex_lock(&fuse->lock);
812 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
815 pthread_mutex_unlock(&fuse->lock);
833 fuse_reply(fuse, hdr->unique, &out, sizeof(out));
837 static int handle_read(struct fuse* fuse, struct fuse_handler* handler,
859 fuse_reply(fuse, unique, handler->read_buffer, res);
863 static int handle_write(struct fuse* fuse, struct fuse_handler* handler,
878 fuse_reply(fuse, hdr->unique, &out, sizeof(out));
882 static int handle_statfs(struct fuse* fuse, struct fuse_handler* handler,
890 pthread_mutex_lock(&fuse->lock);
892 res = get_node_path_locked(&fuse->root, path, sizeof(path));
893 pthread_mutex_unlock(&fuse->lock);
897 if (statfs(fuse->root.name, &stat) < 0) {
909 fuse_reply(fuse, hdr->unique, &out, sizeof(out));
913 static int handle_release(struct fuse* fuse, struct fuse_handler* handler,
924 static int handle_fsync(struct fuse* fuse, struct fuse_handler* handler,
940 static int handle_flush(struct fuse* fuse, struct fuse_handler* handler,
947 static int handle_opendir(struct fuse* fuse, struct fuse_handler* handler,
955 pthread_mutex_lock(&fuse->lock);
956 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
959 pthread_mutex_unlock(&fuse->lock);
975 fuse_reply(fuse, hdr->unique, &out, sizeof(out));
979 static int handle_readdir(struct fuse* fuse, struct fuse_handler* handler,
1003 fuse_reply(fuse, hdr->unique, fde,
1008 static int handle_releasedir(struct fuse* fuse, struct fuse_handler* handler,
1019 static int handle_init(struct fuse* fuse, struct fuse_handler* handler,
1033 fuse_reply(fuse, hdr->unique, &out, sizeof(out));
1037 static int handle_fuse_request(struct fuse *fuse, struct fuse_handler* handler,
1043 return handle_lookup(fuse, handler, hdr, name);
1048 return handle_forget(fuse, handler, hdr, req);
1053 return handle_getattr(fuse, handler, hdr, req);
1058 return handle_setattr(fuse, handler, hdr, req);
1066 return handle_mknod(fuse, handler, hdr, req, name);
1072 return handle_mkdir(fuse, handler, hdr, req, name);
1077 return handle_unlink(fuse, handler, hdr, name);
1082 return handle_rmdir(fuse, handler, hdr, name);
1089 return handle_rename(fuse, handler, hdr, req, old_name, new_name);
1095 return handle_open(fuse, handler, hdr, req);
1100 return handle_read(fuse, handler, hdr, req);
1106 return handle_write(fuse, handler, hdr, req, buffer);
1110 return handle_statfs(fuse, handler, hdr);
1115 return handle_release(fuse, handler, hdr, req);
1120 return handle_fsync(fuse, handler, hdr, req);
1128 return handle_flush(fuse, handler, hdr);
1133 return handle_opendir(fuse, handler, hdr, req);
1138 return handle_readdir(fuse, handler, hdr, req);
1143 return handle_releasedir(fuse, handler, hdr, req);
1149 return handle_init(fuse, handler, hdr, req);
1162 struct fuse* fuse = handler->fuse;
1164 ssize_t len = read(fuse->fd,
1188 int res = handle_fuse_request(fuse, handler, hdr, data, data_len);
1197 fuse_status(fuse, unique, res);
1209 static int ignite_fuse(struct fuse* fuse, int num_threads)
1221 handlers[i].fuse = fuse;
1255 struct fuse fuse;
1260 fd = open("/dev/fuse", O_RDWR);
1262 ERROR("cannot open fuse device (error %d)\n", errno);
1270 res = mount("/dev/fuse", dest_path, "fuse", MS_NOSUID | MS_NODEV, opts);
1272 ERROR("cannot mount fuse filesystem (error %d)\n", errno);
1288 fuse_init(&fuse, fd, source_path);
1291 res = ignite_fuse(&fuse, num_threads);