Lines Matching defs:node

46 static void acquire_node_locked(struct node* node)
48 node->refcount++;
49 DLOG(INFO) << "ACQUIRE " << std::hex << node << std::dec
50 << " (" << node->name << ") rc=" << node->refcount;
53 static void remove_node_from_parent_locked(struct node* node);
55 static void release_node_locked(struct node* node)
57 DLOG(INFO) << "RELEASE " << std::hex << node << std::dec
58 << " (" << node->name << ") rc=" << node->refcount;
59 if (node->refcount > 0) {
60 node->refcount--;
61 if (!node->refcount) {
62 DLOG(INFO) << "DESTROY " << std::hex << node << std::dec << " (" << node->name << ")";
63 remove_node_from_parent_locked(node);
66 memset(node->name, 0xef, node->namelen);
67 free(node->name);
68 free(node->actual_name);
69 memset(node, 0xfc, sizeof(*node));
70 free(node);
73 LOG(ERROR) << std::hex << node << std::dec << " refcount=0";
77 static void add_node_to_parent_locked(struct node *node, struct node *parent) {
78 node->parent = parent;
79 node->next = parent->child;
80 parent->child = node;
84 static void remove_node_from_parent_locked(struct node* node)
86 if (node->parent) {
87 if (node->parent->child == node) {
88 node->parent->child = node->parent->child->next;
90 struct node *node2;
91 node2 = node->parent->child;
92 while (node2->next != node)
94 node2->next = node->next;
96 release_node_locked(node->parent);
97 node->parent = NULL;
98 node->next = NULL;
102 /* Gets the absolute path to a node into the provided buffer.
107 static ssize_t get_node_path_locked(struct node* node, char* buf, size_t bufsize) {
110 if (node->graft_path) {
111 name = node->graft_path;
112 namelen = node->graft_pathlen;
113 } else if (node->actual_name) {
114 name = node->actual_name;
115 namelen = node->namelen;
117 name = node->name;
118 namelen = node->namelen;
126 if (node->parent && node->graft_path == NULL) {
127 pathlen = get_node_path_locked(node->parent, buf, bufsize - namelen - 1);
183 const struct stat *s, const struct node* node) {
184 attr->ino = node->ino;
196 attr->uid = node->uid;
206 attr->gid = multiuser_get_uid(node->userid, fuse->gid);
210 if (node->perm == PERM_PRE_ROOT) {
214 } else if (node->under_android) {
244 static void derive_permissions_locked(struct fuse* fuse, struct node *parent,
245 struct node *node) {
248 /* By default, each node inherits from its parent */
249 node->perm = PERM_INHERIT;
250 node->userid = parent->userid;
251 node->uid = parent->uid;
252 node->under_android = parent->under_android;
254 /* Derive custom permissions based on parent and current node */
261 node->perm = PERM_ROOT;
262 node->userid = strtoul(node->name, NULL, 10);
266 if (!strcasecmp(node->name, "Android")) {
268 node->perm = PERM_ANDROID;
269 node->under_android = true;
273 if (!strcasecmp(node->name, "data")) {
275 node->perm = PERM_ANDROID_DATA;
276 } else if (!strcasecmp(node->name, "obb")) {
278 node->perm = PERM_ANDROID_OBB;
280 node->graft_path = fuse->global->obb_path;
281 node->graft_pathlen = strlen(fuse->global->obb_path);
282 } else if (!strcasecmp(node->name, "media")) {
284 node->perm = PERM_ANDROID_MEDIA;
290 const auto& iter = fuse->global->package_to_appid->find(node->name);
293 node->uid = multiuser_get_uid(parent->userid, appid);
299 void derive_permissions_recursive_locked(struct fuse* fuse, struct node *parent) {
300 struct node *node;
301 for (node = parent->child; node; node = node->next) {
302 derive_permissions_locked(fuse, parent, node);
303 if (node->child) {
304 derive_permissions_recursive_locked(fuse, node);
313 const struct fuse_in_header *hdr, const struct node* parent_node,
335 const struct fuse_in_header *hdr, const struct node* node, int mode) {
336 return check_caller_access_to_name(fuse, hdr, node->parent, node->name, mode);
339 struct node *create_node_locked(struct fuse* fuse,
340 struct node *parent, const char *name, const char* actual_name)
342 struct node *node;
352 node = static_cast<struct node*>(calloc(1, sizeof(struct node)));
353 if (!node) {
356 node->name = static_cast<char*>(malloc(namelen + 1));
357 if (!node->name) {
358 free(node);
361 memcpy(node->name, name, namelen + 1);
363 node->actual_name = static_cast<char*>(malloc(namelen + 1));
364 if (!node->actual_name) {
365 free(node->name);
366 free(node);
369 memcpy(node->actual_name, actual_name, namelen + 1);
371 node->namelen = namelen;
372 node->nid = ptr_to_id(node);
373 node->ino = fuse->global->inode_ctr++;
374 node->gen = fuse->global->next_generation++;
376 node->deleted = false;
378 derive_permissions_locked(fuse, parent, node);
379 acquire_node_locked(node);
380 add_node_to_parent_locked(node, parent);
381 return node;
384 static int rename_node_locked(struct node *node, const char *name,
392 if (namelen > node->namelen) {
393 char* new_name = static_cast<char*>(realloc(node->name, namelen + 1));
397 node->name = new_name;
398 if (need_actual_name && node->actual_name) {
399 char* new_actual_name = static_cast<char*>(realloc(node->actual_name, namelen + 1));
403 node->actual_name = new_actual_name;
409 if (!node->actual_name) {
410 node->actual_name = static_cast<char*>(malloc(namelen + 1));
411 if (!node->actual_name) {
415 memcpy(node->actual_name, actual_name, namelen + 1);
417 free(node->actual_name);
418 node->actual_name = NULL;
420 memcpy(node->name, name, namelen + 1);
421 node->namelen = namelen;
425 static struct node *lookup_node_by_id_locked(struct fuse *fuse, __u64 nid)
430 return static_cast<struct node*>(id_to_ptr(nid));
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);
438 if (node && get_node_path_locked(node, buf, bufsize) < 0) {
439 node = NULL;
441 return node;
444 static struct node *lookup_child_by_name_locked(struct node *node, const char *name)
446 for (node = node->child; node; node = node->next) {
451 if (!strcmp(name, node->name) && !node->deleted) {
452 return node;
458 static struct node* acquire_or_create_child_locked(
459 struct fuse* fuse, struct node* parent,
462 struct node* child = lookup_child_by_name_locked(parent, name);
509 struct node* parent, const char* name, const char* actual_name,
512 struct node* node;
521 node = acquire_or_create_child_locked(fuse, parent, name, actual_name);
522 if (!node) {
527 attr_from_stat(fuse, &out.attr, &s, node);
530 out.nodeid = node->nid;
531 out.generation = node->gen;
537 static int fuse_reply_attr(struct fuse* fuse, __u64 unique, const struct node* node,
547 attr_from_stat(fuse, &out.attr, &s, node);
590 struct node* parent_node;
616 struct node* node;
619 node = lookup_node_by_id_locked(fuse, hdr->nodeid);
622 << " (" << (node ? node->name : "?") << ")";
623 if (node) {
627 release_node_locked(node);
637 struct node* node;
641 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
644 << " (" << (node ? node->name : "?") << ")";
647 if (!node) {
650 if (!check_caller_access_to_node(fuse, hdr, node, R_OK)) {
654 return fuse_reply_attr(fuse, hdr->unique, node, path);
660 struct node* node;
665 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
668 << " (" << (node ? node->name : "?") << ")";
671 if (!node) {
676 !check_caller_access_to_node(fuse, hdr, node, W_OK)) {
718 return fuse_reply_attr(fuse, hdr->unique, node, path);
724 struct node* parent_node;
754 struct node* parent_node;
803 struct node* parent_node;
804 struct node* child_node;
832 /* Tell all other views that node is gone */
853 struct node* child_node;
854 struct node* parent_node;
882 /* Tell all other views that node is gone */
904 struct node* old_parent_node;
905 struct node* new_parent_node;
906 struct node* child_node;
998 struct node* node;
1004 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
1007 << " (" << (node ? node->name : "?") << ")";
1010 if (!node) {
1013 if (!check_caller_access_to_node(fuse, hdr, node,
1163 struct node* node;
1169 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
1171 << " (" << (node ? node->name : "?") << ")";
1174 if (!node) {
1177 if (!check_caller_access_to_node(fuse, hdr, node, R_OK)) {
1281 struct node* node;
1286 node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
1289 << std::dec << " (" << (node ? node->name : "?") << ")";
1292 if (!node) {
1295 if (!check_caller_access_to_node(fuse, hdr, node, R_OK)) {