Lines Matching +full:os +full:- +full:manifest +full:- +full:offset

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
53 zfs_objset_t *os; member
55 /* Offset table for system attributes, indexed by a zpl_attr_t. */
62 * The order of the attributes doesn't matter, this is simply the one hard-coded
123 * layout and just hard-codes attribute offsets.
177 return (strcmp(cur->name, ".") == 0); in fsnode_isroot()
181 * Visit each node in a directory hierarchy, in pre-order depth-first order.
186 assert(root->type == S_IFDIR); in fsnode_foreach()
188 for (fsnode *cur = root; cur != NULL; cur = cur->next) { in fsnode_foreach()
189 assert(cur->type == S_IFREG || cur->type == S_IFDIR || in fsnode_foreach()
190 cur->type == S_IFLNK); in fsnode_foreach()
194 if (cur->type == S_IFDIR && cur->child != NULL) in fsnode_foreach()
195 fsnode_foreach(cur->child, cb, arg); in fsnode_foreach()
205 switch (cur->type) { in fs_populate_dirent()
219 dir = SLIST_FIRST(&arg->dirs); in fs_populate_dirent()
220 zap_add_uint64(dir->zap, cur->name, ZFS_DIRENT_MAKE(type, dnid)); in fs_populate_dirent()
227 assert(ind < fs->sacnt); in fs_populate_attr()
228 assert(fs->saoffs[ind] != 0xffff); in fs_populate_attr()
230 memcpy(attrbuf + fs->saoffs[ind], val, fs->satab[ind].size); in fs_populate_attr()
231 *szp += fs->satab[ind].size; in fs_populate_attr()
238 assert(ind < fs->sacnt); in fs_populate_varszattr()
239 assert(fs->saoffs[ind] != 0xffff); in fs_populate_varszattr()
240 assert(fs->satab[ind].size == 0); in fs_populate_varszattr()
242 memcpy(attrbuf + fs->saoffs[ind] + varoff, val, valsz); in fs_populate_varszattr()
252 * dealing with an mtree manifest, so both mechanisms are implemented.
258 if (cur->contents != NULL) { in fs_populate_path()
262 n = strlcpy(path, cur->contents, sz); in fs_populate_path()
264 } else if (cur->root == NULL) { in fs_populate_path()
267 *dirfdp = SLIST_FIRST(&arg->dirs)->dirfd; in fs_populate_path()
268 n = strlcpy(path, cur->name, sz); in fs_populate_path()
275 cur->root, cur->path, cur->name); in fs_populate_path()
313 if (cur->symlink != NULL) { in fs_readlink()
316 n = strlcpy(buf, cur->symlink, bufsz); in fs_readlink()
323 n = readlinkat(fd, path, buf, bufsz - 1); in fs_readlink()
324 if (n == -1) in fs_readlink()
325 err(1, "readlinkat(%s)", cur->name); in fs_readlink()
336 assert(ind < fs->sacnt); in fs_populate_time()
337 assert(fs->saoffs[ind] != 0xffff); in fs_populate_time()
338 assert(fs->satab[ind].size == sizeof(timebuf)); in fs_populate_time()
340 timebuf[0] = ts->tv_sec; in fs_populate_time()
341 timebuf[1] = ts->tv_nsec; in fs_populate_time()
359 assert(dnode->dn_bonustype == DMU_OT_SA); in fs_populate_sattrs()
360 assert(dnode->dn_nblkptr == 1); in fs_populate_sattrs()
362 fs = arg->fs; in fs_populate_sattrs()
363 sb = &cur->inode->st; in fs_populate_sattrs()
365 switch (cur->type) { in fs_populate_sattrs()
368 links = cur->inode->nlink; in fs_populate_sattrs()
369 objsize = sb->st_size; in fs_populate_sattrs()
370 parent = SLIST_FIRST(&arg->dirs)->objid; in fs_populate_sattrs()
382 for (fsnode *c = fsnode_isroot(cur) ? cur->next : cur->child; in fs_populate_sattrs()
383 c != NULL; c = c->next) { in fs_populate_sattrs()
384 if (c->type == S_IFDIR) in fs_populate_sattrs()
390 parent = SLIST_EMPTY(&arg->dirs) ? in fs_populate_sattrs()
391 arg->rootdirid : SLIST_FIRST(&arg->dirs)->objid; in fs_populate_sattrs()
399 parent = SLIST_FIRST(&arg->dirs)->objid; in fs_populate_sattrs()
409 gid = sb->st_gid; in fs_populate_sattrs()
410 mode = sb->st_mode; in fs_populate_sattrs()
411 uid = sb->st_uid; in fs_populate_sattrs()
450 /* At most one variable-length attribute. */ in fs_populate_sattrs()
454 /* At most five variable-length attributes. */ in fs_populate_sattrs()
462 sahdr->sa_magic = SA_MAGIC; in fs_populate_sattrs()
463 SA_HDR_LAYOUT_INFO_ENCODE(sahdr->sa_layout_info, layout, hdrsz); in fs_populate_sattrs()
482 fs_populate_time(fs, attrbuf, &sb->st_mtim, ZPL_ATIME, &bonussz); in fs_populate_sattrs()
483 fs_populate_time(fs, attrbuf, &sb->st_ctim, ZPL_CTIME, &bonussz); in fs_populate_sattrs()
484 fs_populate_time(fs, attrbuf, &sb->st_mtim, ZPL_MTIME, &bonussz); in fs_populate_sattrs()
487 fs_populate_time(fs, attrbuf, &sb->st_ctim, ZPL_CRTIME, &bonussz); in fs_populate_sattrs()
489 fs_populate_time(fs, attrbuf, &sb->st_birthtim, ZPL_CRTIME, &bonussz); in fs_populate_sattrs()
494 sahdr->sa_lengths[0] = sizeof(aces); in fs_populate_sattrs()
496 if (cur->type == S_IFLNK) { in fs_populate_sattrs()
501 sahdr->sa_lengths[0], ZPL_SYMLINK, &bonussz); in fs_populate_sattrs()
502 sahdr->sa_lengths[1] = (uint16_t)objsize; in fs_populate_sattrs()
505 dnode->dn_bonuslen = bonussz; in fs_populate_sattrs()
521 assert(cur->type == S_IFREG); in fs_populate_file()
522 assert((cur->inode->flags & FI_ROOT) == 0); in fs_populate_file()
524 zfs = arg->zfs; in fs_populate_file()
526 assert(cur->inode->ino != 0); in fs_populate_file()
527 if ((cur->inode->flags & FI_ALLOCATED) != 0) { in fs_populate_file()
531 * XXX-MJ need to check whether it crosses datasets, add a test in fs_populate_file()
534 fs_populate_dirent(arg, cur, cur->inode->ino); in fs_populate_file()
538 dnode = objset_dnode_bonus_alloc(arg->fs->os, in fs_populate_file()
540 cur->inode->ino = dnid; in fs_populate_file()
541 cur->inode->flags |= FI_ALLOCATED; in fs_populate_file()
545 buf = zfs->filebuf; in fs_populate_file()
546 bufsz = sizeof(zfs->filebuf); in fs_populate_file()
547 size = cur->inode->st.st_size; in fs_populate_file()
548 c = dnode_cursor_init(zfs, arg->fs->os, dnode, size, 0); in fs_populate_file()
556 nbytes = MIN(size - foff, (off_t)bufsz); in fs_populate_file()
560 err(1, "reading from '%s'", cur->name); in fs_populate_file()
563 cur->name); in fs_populate_file()
568 memset(buf + nbytes, 0, bufsz - nbytes); in fs_populate_file()
571 loc = objset_space_alloc(zfs, arg->fs->os, &reqbytes); in fs_populate_file()
586 zfs_objset_t *os; in fs_populate_dir() local
590 assert(cur->type == S_IFDIR); in fs_populate_dir()
591 assert((cur->inode->flags & FI_ALLOCATED) == 0); in fs_populate_dir()
593 os = arg->fs->os; in fs_populate_dir()
595 dnode = objset_dnode_bonus_alloc(os, DMU_OT_DIRECTORY_CONTENTS, in fs_populate_dir()
601 if (!SLIST_EMPTY(&arg->dirs)) { in fs_populate_dir()
610 arg->rootdirid = dnid; in fs_populate_dir()
611 dirfd = arg->rootdirfd; in fs_populate_dir()
612 arg->rootdirfd = -1; in fs_populate_dir()
624 if ((cur->inode->flags & FI_ROOT) == 0) { in fs_populate_dir()
628 dir->dirfd = dirfd; in fs_populate_dir()
629 dir->objid = dnid; in fs_populate_dir()
630 dir->zap = zap_alloc(os, dnode); in fs_populate_dir()
631 SLIST_INSERT_HEAD(&arg->dirs, dir, next); in fs_populate_dir()
633 zap_write(arg->zfs, zap_alloc(os, dnode)); in fs_populate_dir()
634 fs_build_one(arg->zfs, cur->inode->param, cur->child, dirfd); in fs_populate_dir()
644 assert(cur->type == S_IFLNK); in fs_populate_symlink()
645 assert((cur->inode->flags & (FI_ALLOCATED | FI_ROOT)) == 0); in fs_populate_symlink()
647 dnode = objset_dnode_bonus_alloc(arg->fs->os, in fs_populate_symlink()
663 switch (cur->type) { in fs_foreach_populate()
679 ret = (cur->inode->flags & FI_ROOT) != 0 ? 0 : 1; in fs_foreach_populate()
681 if (cur->next == NULL && in fs_foreach_populate()
682 (cur->child == NULL || (cur->inode->flags & FI_ROOT) != 0)) { in fs_foreach_populate()
690 dir = SLIST_FIRST(&arg->dirs); in fs_foreach_populate()
691 SLIST_REMOVE_HEAD(&arg->dirs, next); in fs_foreach_populate()
692 zap_write(arg->zfs, dir->zap); in fs_foreach_populate()
693 if (dir->dirfd != -1) in fs_foreach_populate()
694 eclose(dir->dirfd); in fs_foreach_populate()
696 cur = cur->parent; in fs_foreach_populate()
697 } while (cur != NULL && cur->next == NULL && in fs_foreach_populate()
698 (cur->inode->flags & FI_ROOT) == 0); in fs_foreach_populate()
728 zfs_objset_t *os; in fs_set_zpl_attrs() local
731 uint16_t offset; in fs_set_zpl_attrs() local
733 os = fs->os; in fs_set_zpl_attrs()
736 * The on-disk tables are stored in two ZAP objects, the registry object in fs_set_zpl_attrs()
744 saobj = objset_dnode_alloc(os, DMU_OT_SA_MASTER_NODE, &saobjid); in fs_set_zpl_attrs()
745 salobj = objset_dnode_alloc(os, DMU_OT_SA_ATTR_LAYOUTS, &salobjid); in fs_set_zpl_attrs()
746 sarobj = objset_dnode_alloc(os, DMU_OT_SA_ATTR_REGISTRATION, &sarobjid); in fs_set_zpl_attrs()
748 sarzap = zap_alloc(os, sarobj); in fs_set_zpl_attrs()
755 SA_ATTR_ENCODE(attr, (uint64_t)i, sa->size, sa->bs); in fs_set_zpl_attrs()
756 zap_add_uint64(sarzap, sa->name, attr); in fs_set_zpl_attrs()
762 * layouts for use by the ZPL, one for non-symlinks and one for in fs_set_zpl_attrs()
766 salzap = zap_alloc(os, salobj); in fs_set_zpl_attrs()
767 assert(zpl_attr_layout[nitems(zpl_attr_layout) - 1] == ZPL_SYMLINK); in fs_set_zpl_attrs()
769 zpl_attr_layout, nitems(zpl_attr_layout) - 1); in fs_set_zpl_attrs()
774 sazap = zap_alloc(os, saobj); in fs_set_zpl_attrs()
784 * Build the offset table used when setting file attributes. File in fs_set_zpl_attrs()
786 * provides the buffer offset of attributes referenced by the layout in fs_set_zpl_attrs()
789 fs->sacnt = nitems(zpl_attrs); in fs_set_zpl_attrs()
790 fs->saoffs = ecalloc(fs->sacnt, sizeof(*fs->saoffs)); in fs_set_zpl_attrs()
791 for (size_t i = 0; i < fs->sacnt; i++) in fs_set_zpl_attrs()
792 fs->saoffs[i] = 0xffff; in fs_set_zpl_attrs()
793 offset = 0; in fs_set_zpl_attrs()
797 assert(zpl_attr_layout[i] < fs->sacnt); in fs_set_zpl_attrs()
799 fs->saoffs[zpl_attr_layout[i]] = offset; in fs_set_zpl_attrs()
801 offset += size; in fs_set_zpl_attrs()
803 fs->satab = zpl_attrs; in fs_set_zpl_attrs()
827 if (zfs->bootfs != NULL && strcmp(zfs->bootfs, in fs_layout_one()
829 zap_add_uint64(zfs->poolprops, "bootfs", in fs_layout_one()
840 if (strcmp(mountpoint, zfs->rootpath) != 0) { in fs_layout_one()
841 mountpoint += strlen(zfs->rootpath); in fs_layout_one()
856 for (; cur != NULL && strcmp(cur->name, name) != 0; in fs_layout_one()
857 cur = cur->next) in fs_layout_one()
865 if (cur->type != S_IFDIR) { in fs_layout_one()
871 cur = cur->child; in fs_layout_one()
876 assert(cur->type == S_IFDIR); in fs_layout_one()
883 assert((cur->inode->flags & FI_ROOT) == 0); in fs_layout_one()
885 cur->inode->flags |= FI_ROOT; in fs_layout_one()
886 assert(cur->inode->param == NULL); in fs_layout_one()
887 cur->inode->param = dsldir; in fs_layout_one()
899 if (cur->type == S_IFDIR && fsnode_isroot(cur)) in fs_foreach_mark()
902 if (cur->inode->ino == 0) { in fs_foreach_mark()
903 cur->inode->ino = ++(*countp); in fs_foreach_mark()
904 cur->inode->nlink = 1; in fs_foreach_mark()
906 cur->inode->nlink++; in fs_foreach_mark()
909 return ((cur->inode->flags & FI_ROOT) != 0 ? 0 : 1); in fs_foreach_mark()
914 * - create an object set for the dataset,
915 * - add required metadata (SA tables, property definitions, etc.) to that
917 * - optionally populate the object set with file objects, using "root" as the
929 zfs_objset_t *os; in fs_build_one() local
943 assert(dirfd == -1); in fs_build_one()
946 root->inode = ecalloc(1, sizeof(*root->inode)); in fs_build_one()
947 root->name = estrdup("."); in fs_build_one()
948 root->type = S_IFDIR; in fs_build_one()
950 stp = &root->inode->st; in fs_build_one()
951 stp->st_uid = 0; in fs_build_one()
952 stp->st_gid = 0; in fs_build_one()
953 stp->st_mode = S_IFDIR | 0755; in fs_build_one()
955 assert(root->type == S_IFDIR); in fs_build_one()
961 os = objset_alloc(zfs, DMU_OST_ZFS); in fs_build_one()
962 masterobj = objset_dnode_alloc(os, DMU_OT_MASTER_NODE, &moid); in fs_build_one()
966 fs.os = os; in fs_build_one()
999 deleteq = objset_dnode_alloc(os, DMU_OT_UNLINKED_SET, &deleteqid); in fs_build_one()
1000 zap_write(zfs, zap_alloc(os, deleteq)); in fs_build_one()
1007 masterzap = zap_alloc(os, masterobj); in fs_build_one()
1023 dsl_dir_dataset_write(zfs, os, dsldir); in fs_build_one()
1026 free(root->inode); in fs_build_one()
1027 free(root->name); in fs_build_one()
1041 fs_build_one(zfs, dsldir, NULL, -1); in fs_build_unmounted()
1055 dsl_dir_foreach(zfs, zfs->rootdsldir, fs_layout_one, root); in fs_build()
1060 if (zfs->bootfs != NULL && !zap_entry_exists(zfs->poolprops, "bootfs")) in fs_build()
1062 zfs->bootfs); in fs_build()
1074 fs_build_one(zfs, root->inode->param, root, dirfd); in fs_build()
1081 dsl_dir_foreach(zfs, zfs->rootdsldir, fs_build_unmounted, NULL); in fs_build()