Lines Matching +full:next +full:- +full:mode

4  * SPDX-License-Identifier: BSD-4-Clause
68 assert(strcmp((*a)->name, (*b)->name) != 0); in cmp()
69 if (strcmp((*a)->name, ".") == 0) in cmp()
70 return (-1); in cmp()
71 if (strcmp((*b)->name, ".") == 0) in cmp()
73 return (strcoll((*a)->name, (*b)->name)); in cmp()
88 for (cur = list; cur != NULL; cur = cur->next) in sort_dir()
95 for (i = 0, cur = list; cur != NULL; i++, cur = cur->next) in sort_dir()
99 array[i]->first = array[0]; in sort_dir()
100 array[i]->next = i == nitems - 1 ? NULL : array[i + 1]; in sort_dir()
108 * walk_dir --
140 while (cur->next != NULL) in walk_dir()
141 cur = cur->next; in walk_dir()
145 name = dent->d_name; in walk_dir()
163 if ((size_t)snprintf(path + len, sizeof(path) - len, "/%s", in walk_dir()
164 name) >= sizeof(path) - len) in walk_dir()
166 if (lstat(path, &stbuf) == -1) in walk_dir()
177 cur = join->next; in walk_dir()
179 if (cur == NULL || strcmp(cur->name, name) == 0) in walk_dir()
181 cur = cur->next; in walk_dir()
184 if (S_ISDIR(cur->type) && in walk_dir()
188 path, cur->child); in walk_dir()
189 cur->child = walk_dir(root, rp, cur, in walk_dir()
190 cur->child); in walk_dir()
195 inode_type(cur->type)); in walk_dir()
200 cur->parent = parent; in walk_dir()
201 cur->next = first; in walk_dir()
203 if (!dot && S_ISDIR(cur->type)) { in walk_dir()
204 cur->child = walk_dir(root, rp, cur, NULL); in walk_dir()
210 curino = link_check(cur->inode); in walk_dir()
212 free(cur->inode); in walk_dir()
213 cur->inode = curino; in walk_dir()
214 cur->inode->nlink++; in walk_dir()
217 (unsigned long long)curino->st.st_dev, in walk_dir()
218 (unsigned long long)curino->st.st_ino); in walk_dir()
221 if (S_ISLNK(cur->type)) { in walk_dir()
225 llen = readlink(path, slink, sizeof(slink) - 1); in walk_dir()
226 if (llen == -1) in walk_dir()
229 cur->symlink = estrdup(slink); in walk_dir()
232 if (closedir(dirp) == -1) in walk_dir()
244 cur->path = estrdup(path); in create_fsnode()
245 cur->name = estrdup(name); in create_fsnode()
246 cur->inode = ecalloc(1, sizeof(*cur->inode)); in create_fsnode()
247 cur->root = root; in create_fsnode()
248 cur->type = stbuf->st_mode & S_IFMT; in create_fsnode()
249 cur->inode->nlink = 1; in create_fsnode()
250 cur->inode->st = *stbuf; in create_fsnode()
257 * free_fsnodes --
264 fsnode *cur, *next; in free_fsnodes() local
269 if (node->first == node) { in free_fsnodes()
270 assert(node->name[0] == '.' && node->name[1] == '\0'); in free_fsnodes()
271 if (node->parent) { in free_fsnodes()
272 assert(node->parent->child == node); in free_fsnodes()
273 node = node->parent; in free_fsnodes()
278 if (node->first != node) { in free_fsnodes()
279 for (cur = node->first; cur->next; cur = cur->next) { in free_fsnodes()
280 if (cur->next == node) { in free_fsnodes()
281 cur->next = node->next; in free_fsnodes()
282 node->next = NULL; in free_fsnodes()
288 for (cur = node; cur != NULL; cur = next) { in free_fsnodes()
289 next = cur->next; in free_fsnodes()
290 if (cur->child) { in free_fsnodes()
291 cur->child->parent = NULL; in free_fsnodes()
292 free_fsnodes(cur->child); in free_fsnodes()
294 if (cur->inode->nlink-- == 1) in free_fsnodes()
295 free(cur->inode); in free_fsnodes()
296 if (cur->symlink) in free_fsnodes()
297 free(cur->symlink); in free_fsnodes()
298 free(cur->path); in free_fsnodes()
299 free(cur->name); in free_fsnodes()
305 * apply_specfile --
336 assert(strcmp(root->name, ".") == 0); in apply_specfile()
337 assert(root->type == F_DIR); in apply_specfile()
358 if (specnode->type != F_DIR) in apply_specdir()
360 dir, specnode->name); in apply_specdir()
361 if (dirnode->type != S_IFDIR) in apply_specdir()
363 dir, dirnode->name); in apply_specdir()
373 fsnode *next; in apply_specdir() local
374 assert(dirnode->name[0] == '.' && dirnode->name[1] == '\0'); in apply_specdir()
375 for (curfsnode = dirnode->next; curfsnode != NULL; curfsnode = next) { in apply_specdir()
376 next = curfsnode->next; in apply_specdir()
377 for (curnode = specnode->child; curnode != NULL; in apply_specdir()
378 curnode = curnode->next) { in apply_specdir()
379 if (strcmp(curnode->name, curfsnode->name) == 0) in apply_specdir()
384 printf("apply_specdir: trimming %s/%s %p\n", dir, curfsnode->name, curfsnode); in apply_specdir()
391 /* now walk specnode->child matching up with dirnode */ in apply_specdir()
392 for (curnode = specnode->child; curnode != NULL; in apply_specdir()
393 curnode = curnode->next) { in apply_specdir()
396 curnode->name); in apply_specdir()
397 for (curfsnode = dirnode->next; curfsnode != NULL; in apply_specdir()
398 curfsnode = curfsnode->next) { in apply_specdir()
402 curfsnode->name); in apply_specdir()
404 if (strcmp(curnode->name, curfsnode->name) == 0) in apply_specdir()
408 curnode->name) >= sizeof(path)) in apply_specdir()
417 if ((curnode->flags & F_OPT) && in apply_specdir()
418 lstat(path, &stbuf) == -1) in apply_specdir()
425 NODETEST(curnode->flags & F_TYPE, "type"); in apply_specdir()
426 NODETEST(curnode->flags & F_MODE, "mode"); in apply_specdir()
428 NODETEST(curnode->flags & F_GID || in apply_specdir()
429 curnode->flags & F_GNAME, "group"); in apply_specdir()
430 NODETEST(curnode->flags & F_UID || in apply_specdir()
431 curnode->flags & F_UNAME, "user"); in apply_specdir()
432 /* if (curnode->type == F_BLOCK || curnode->type == F_CHAR) in apply_specdir()
433 NODETEST(curnode->flags & F_DEV, in apply_specdir()
439 curnode->name); in apply_specdir()
442 stbuf.st_mode = nodetoino(curnode->type); in apply_specdir()
450 curfsnode = create_fsnode(".", ".", curnode->name, in apply_specdir()
452 curfsnode->parent = dirnode->parent; in apply_specdir()
453 curfsnode->first = dirnode; in apply_specdir()
454 curfsnode->next = dirnode->next; in apply_specdir()
455 dirnode->next = curfsnode; in apply_specdir()
456 if (curfsnode->type == S_IFDIR) { in apply_specdir()
458 curfsnode->child = create_fsnode(".", ".", ".", in apply_specdir()
460 curfsnode->child->parent = curfsnode; in apply_specdir()
461 curfsnode->child->first = curfsnode->child; in apply_specdir()
463 if (curfsnode->type == S_IFLNK) { in apply_specdir()
464 assert(curnode->slink != NULL); in apply_specdir()
466 curfsnode->symlink = estrdup(curnode->slink); in apply_specdir()
470 if (curnode->type == F_DIR) { in apply_specdir()
471 if (curfsnode->type != S_IFDIR) in apply_specdir()
473 assert (curfsnode->child != NULL); in apply_specdir()
474 apply_specdir(path, curnode, curfsnode->child, speconly); in apply_specdir()
486 if (nodetoino(specnode->type) != dirnode->type) in apply_specentry()
488 dir, specnode->name, inode_type(nodetoino(specnode->type)), in apply_specentry()
489 inode_type(dirnode->type)); in apply_specentry()
492 printf("apply_specentry: %s/%s\n", dir, dirnode->name); in apply_specentry()
499 if (specnode->flags & (F_GID | F_GNAME)) { in apply_specentry()
501 dirnode->inode->st.st_gid, specnode->st_gid); in apply_specentry()
502 dirnode->inode->st.st_gid = specnode->st_gid; in apply_specentry()
504 if (specnode->flags & F_MODE) { in apply_specentry()
505 ASEPRINT("mode", "%#o", in apply_specentry()
506 dirnode->inode->st.st_mode & ALLPERMS, specnode->st_mode); in apply_specentry()
507 dirnode->inode->st.st_mode &= ~ALLPERMS; in apply_specentry()
508 dirnode->inode->st.st_mode |= (specnode->st_mode & ALLPERMS); in apply_specentry()
511 if (specnode->flags & F_SIZE) { in apply_specentry()
513 (long long)dirnode->inode->st.st_size, in apply_specentry()
514 (long long)specnode->st_size); in apply_specentry()
515 dirnode->inode->st.st_size = specnode->st_size; in apply_specentry()
517 if (specnode->flags & F_SLINK) { in apply_specentry()
518 assert(dirnode->symlink != NULL); in apply_specentry()
519 assert(specnode->slink != NULL); in apply_specentry()
520 ASEPRINT("symlink", "%s", dirnode->symlink, specnode->slink); in apply_specentry()
521 free(dirnode->symlink); in apply_specentry()
522 dirnode->symlink = estrdup(specnode->slink); in apply_specentry()
524 if (specnode->flags & F_TIME) { in apply_specentry()
526 (long)dirnode->inode->st.st_mtime, in apply_specentry()
527 (long)specnode->st_mtimespec.tv_sec); in apply_specentry()
528 dirnode->inode->st.st_mtime = specnode->st_mtimespec.tv_sec; in apply_specentry()
529 dirnode->inode->st.st_atime = specnode->st_mtimespec.tv_sec; in apply_specentry()
530 dirnode->inode->st.st_ctime = start_time.tv_sec; in apply_specentry()
532 dirnode->inode->st.st_mtimensec = specnode->st_mtimespec.tv_nsec; in apply_specentry()
533 dirnode->inode->st.st_atimensec = specnode->st_mtimespec.tv_nsec; in apply_specentry()
534 dirnode->inode->st.st_ctimensec = start_time.tv_nsec; in apply_specentry()
537 if (specnode->flags & (F_UID | F_UNAME)) { in apply_specentry()
539 dirnode->inode->st.st_uid, specnode->st_uid); in apply_specentry()
540 dirnode->inode->st.st_uid = specnode->st_uid; in apply_specentry()
542 if (specnode->flags & F_FLAGS) { in apply_specentry()
544 (unsigned long)FSINODE_ST_FLAGS(*dirnode->inode), in apply_specentry()
545 (unsigned long)specnode->st_flags); in apply_specentry()
546 FSINODE_ST_FLAGS(*dirnode->inode) = specnode->st_flags; in apply_specentry()
548 /* if (specnode->flags & F_DEV) { in apply_specentry()
550 (unsigned long long)dirnode->inode->st.st_rdev, in apply_specentry()
551 (unsigned long long)specnode->st_rdev); in apply_specentry()
552 dirnode->inode->st.st_rdev = specnode->st_rdev; in apply_specentry()
556 dirnode->flags |= FSNODE_F_HASSPEC; in apply_specentry()
561 * dump_fsnodes --
570 printf("dump_fsnodes: %s %p\n", root->path, root); in dump_fsnodes()
571 for (cur = root; cur != NULL; cur = cur->next) { in dump_fsnodes()
572 if (snprintf(path, sizeof(path), "%s/%s", cur->path, in dump_fsnodes()
573 cur->name) >= (int)sizeof(path)) in dump_fsnodes()
578 cur, cur->parent, cur->first); in dump_fsnodes()
579 printf("%7s: %s", inode_type(cur->type), path); in dump_fsnodes()
580 if (S_ISLNK(cur->type)) { in dump_fsnodes()
581 assert(cur->symlink != NULL); in dump_fsnodes()
582 printf(" -> %s", cur->symlink); in dump_fsnodes()
584 assert (cur->symlink == NULL); in dump_fsnodes()
586 if (cur->inode->nlink > 1) in dump_fsnodes()
587 printf(", nlinks=%d", cur->inode->nlink); in dump_fsnodes()
590 if (cur->child) { in dump_fsnodes()
591 assert (cur->type == S_IFDIR); in dump_fsnodes()
592 dump_fsnodes(cur->child); in dump_fsnodes()
595 printf("dump_fsnodes: finished %s/%s\n", root->path, root->name); in dump_fsnodes()
600 * inode_type --
601 * for a given inode type `mode', return a descriptive string.
605 inode_type(mode_t mode) in inode_type() argument
607 if (S_ISREG(mode)) in inode_type()
609 if (S_ISLNK(mode)) in inode_type()
611 if (S_ISDIR(mode)) in inode_type()
613 if (S_ISFIFO(mode)) in inode_type()
615 if (S_ISSOCK(mode)) in inode_type()
618 if (S_ISCHR(mode)) in inode_type()
620 if (S_ISBLK(mode)) in inode_type()
627 * link_check --
632 * pointer instead. -- dbj@netbsd.org
641 static int htmask; /* allocated size - 1 */ in link_check()
663 htmask = (1 << htshift) - 1; in link_check()
679 tmp = entry->st.st_dev; in link_check()
681 tmp |= entry->st.st_ino; in link_check()
683 h = tmp >> (HTBITS - htshift); in link_check()
684 h2 = 1 | ( tmp >> (HTBITS - (htshift<<1) - 1)); /* must be odd */ in link_check()
688 if ((htable[h].data->st.st_ino == entry->st.st_ino) && in link_check()
689 (htable[h].data->st.st_dev == entry->st.st_dev)) { in link_check()