Lines Matching defs:mtree

206 				 * directory files, like mtree(8) -d option. */
209 * global values. When generating mtree
358 * Indent a line as the mtree utility does so it is readable for people.
361 mtree_indent(struct mtree_writer *mtree)
366 if (mtree->classic) {
367 if (mtree->indent) {
369 pd = mtree->depth * 4;
371 nd = mtree->depth?4:0;
377 s = r = mtree->ebuf.s;
385 archive_strappend_char(&mtree->buf, ' ');
386 archive_strncat(&mtree->buf, s, r - s);
388 archive_strncat(&mtree->buf, " \\\n", 3);
390 archive_strappend_char(&mtree->buf, ' ');
394 archive_strappend_char(&mtree->buf, ' ');
405 archive_strncat(&mtree->buf, s, x - s);
406 archive_strncat(&mtree->buf, " \\\n", 3);
408 archive_strappend_char(&mtree->buf, ' ');
415 archive_strappend_char(&mtree->buf, ' ');
416 archive_strcat(&mtree->buf, s);
421 archive_strncat(&mtree->buf, s, x - s);
422 archive_strncat(&mtree->buf, " \\\n", 3);
424 archive_strappend_char(&mtree->buf, ' ');
427 archive_strcat(&mtree->buf, s);
428 archive_string_empty(&mtree->ebuf);
437 write_global(struct mtree_writer *mtree)
446 keys = mtree->keys & SET_KEYS;
447 oldkeys = mtree->set.keys;
449 acs = &mtree->acs;
450 if (mtree->set.processing) {
459 mtree->set.uid == acs->uid_list->m_entry->uid)
466 mtree->set.gid == acs->gid_list->m_entry->gid)
473 mtree->set.mode == acs->mode_list->m_entry->mode)
481 mtree->set.fflags_set &&
483 mtree->set.fflags_clear))
497 if (mtree->dironly) {
499 mtree->set.type = AE_IFDIR;
502 mtree->set.type = AE_IFREG;
516 mtree->set.uid = acs->uid_list->m_entry->uid;
518 (intmax_t)mtree->set.uid);
531 mtree->set.gid = acs->gid_list->m_entry->gid;
533 (intmax_t)mtree->set.gid);
536 mtree->set.mode = acs->mode_list->m_entry->mode;
538 (unsigned int)mtree->set.mode);
546 mtree->set.fflags_set =
548 mtree->set.fflags_clear =
557 archive_string_sprintf(&mtree->buf, "/unset%s\n", unsetstr.s);
560 archive_string_sprintf(&mtree->buf, "/set%s\n", setstr.s);
562 mtree->set.keys = keys;
563 mtree->set.processing = 1;
639 attr_counter_set_collect(struct mtree_writer *mtree, struct mtree_entry *me)
642 struct att_counter_set *acs = &mtree->acs;
643 int keys = mtree->keys;
716 attr_counter_set_free(struct mtree_writer *mtree)
718 struct att_counter_set *acs = &mtree->acs;
727 get_global_set_keys(struct mtree_writer *mtree, struct mtree_entry *me)
731 keys = mtree->keys;
737 if (mtree->set.keys == 0)
740 if ((mtree->set.keys & (F_GNAME | F_GID)) != 0 &&
741 mtree->set.gid == me->gid)
743 if ((mtree->set.keys & (F_UNAME | F_UID)) != 0 &&
744 mtree->set.uid == me->uid)
746 if (mtree->set.keys & F_FLAGS) {
747 if (mtree->set.fflags_set == me->fflags_set &&
748 mtree->set.fflags_clear == me->fflags_clear)
751 if ((mtree->set.keys & F_MODE) != 0 && mtree->set.mode == me->mode)
759 if ((mtree->set.keys & F_TYPE) != 0 &&
760 mtree->set.type == AE_IFDIR)
765 if ((mtree->set.keys & F_TYPE) != 0 &&
766 mtree->set.type == AE_IFREG)
788 "Can't allocate memory for a mtree entry");
827 "Can't allocate memory for a mtree entry");
840 "Can't allocate memory for a mtree entry");
870 struct mtree_writer *mtree= a->format_data;
874 if (mtree->first) {
875 mtree->first = 0;
876 archive_strcat(&mtree->buf, "#mtree\n");
877 if ((mtree->keys & SET_KEYS) == 0)
878 mtree->output_global_set = 0;/* Disabled. */
881 mtree->entry_bytes_remaining = archive_entry_size(entry);
884 if (mtree->dironly && archive_entry_filetype(entry) != AE_IFDIR)
895 mtree->mtree_entry = mtree_entry;
901 sum_init(mtree);
909 struct mtree_writer *mtree = a->format_data;
914 if (mtree->classic) {
917 * pathname of the entry as mtree utility does
920 if (!mtree->dironly)
921 archive_strappend_char(&mtree->buf, '\n');
923 archive_string_sprintf(&mtree->buf,
927 archive_string_sprintf(&mtree->buf,
931 if (mtree->output_global_set)
932 write_global(mtree);
934 archive_string_empty(&mtree->ebuf);
935 str = (mtree->indent || mtree->classic)? &mtree->ebuf : &mtree->buf;
937 if (!mtree->classic && me->parentdir.s) {
947 keys = get_global_set_keys(mtree, me);
964 } else if (mtree->set.processing &&
965 (mtree->set.keys & F_FLAGS) != 0)
1044 if (mtree->indent || mtree->classic)
1045 mtree_indent(mtree);
1047 if (mtree->buf.length > 32768) {
1049 a, mtree->buf.s, mtree->buf.length);
1050 archive_string_empty(&mtree->buf);
1059 struct mtree_writer *mtree = a->format_data;
1063 if (mtree->indent) {
1064 int i, pd = mtree->depth * 4;
1066 archive_strappend_char(&mtree->buf, ' ');
1068 archive_string_sprintf(&mtree->buf, "# %s/%s\n",
1072 if (mtree->indent) {
1073 archive_string_empty(&mtree->ebuf);
1074 archive_strncat(&mtree->ebuf, "..\n\n", (mtree->dironly)?3:4);
1075 mtree_indent(mtree);
1077 archive_strncat(&mtree->buf, "..\n\n", (mtree->dironly)?3:4);
1079 if (mtree->buf.length > 32768) {
1081 a, mtree->buf.s, mtree->buf.length);
1082 archive_string_empty(&mtree->buf);
1089 * Write mtree entries saved at attr_counter_set_collect() function.
1094 struct mtree_writer *mtree = a->format_data;
1095 struct mtree_entry *np = mtree->root;
1100 if (mtree->output_global_set) {
1105 attr_counter_set_reset(mtree);
1108 if (attr_counter_set_collect(mtree, e) < 0) {
1115 if (!np->dir_info->virtual || mtree->classic) {
1125 if (mtree->output_global_set)
1126 write_global(mtree);
1131 mtree->depth++;
1143 mtree->depth--;
1150 if (mtree->indent)
1151 mtree->depth++;
1153 } else if (mtree->classic) {
1155 * While printing mtree classic, if there are not
1170 if (mtree->indent)
1171 mtree->depth--;
1172 if (mtree->classic) {
1181 * Switch to next mtree entry in the directory.
1195 struct mtree_writer *mtree = a->format_data;
1198 if ((me = mtree->mtree_entry) == NULL)
1200 mtree->mtree_entry = NULL;
1203 sum_final(mtree, me->reg_info);
1211 struct mtree_writer *mtree= a->format_data;
1214 if (mtree->root != NULL) {
1222 return __archive_write_output(a, mtree->buf.s, mtree->buf.length);
1228 struct mtree_writer *mtree= a->format_data;
1230 if (n > mtree->entry_bytes_remaining)
1231 n = (size_t)mtree->entry_bytes_remaining;
1232 mtree->entry_bytes_remaining -= n;
1235 if (mtree->mtree_entry == NULL)
1238 if (mtree->mtree_entry->filetype == AE_IFREG)
1239 sum_update(mtree, buff, n);
1247 struct mtree_writer *mtree= a->format_data;
1249 if (mtree == NULL)
1253 mtree_entry_register_free(mtree);
1254 archive_string_free(&mtree->cur_dirstr);
1255 archive_string_free(&mtree->ebuf);
1256 archive_string_free(&mtree->buf);
1257 attr_counter_set_free(mtree);
1258 free(mtree);
1267 struct mtree_writer *mtree= a->format_data;
1283 mtree->dironly = (value != NULL)? 1: 0;
1299 mtree->indent = (value != NULL)? 1: 0;
1356 mtree->output_global_set = (value != NULL)? 1: 0;
1363 mtree->keys |= keybit;
1365 mtree->keys &= ~keybit;
1379 struct mtree_writer *mtree;
1386 if ((mtree = calloc(1, sizeof(*mtree))) == NULL) {
1388 "Can't allocate mtree data");
1392 mtree->mtree_entry = NULL;
1393 mtree->first = 1;
1394 memset(&(mtree->set), 0, sizeof(mtree->set));
1395 mtree->keys = DEFAULT_KEYS;
1396 mtree->dironly = 0;
1397 mtree->indent = 0;
1398 archive_string_init(&mtree->ebuf);
1399 archive_string_init(&mtree->buf);
1400 mtree_entry_register_init(mtree);
1401 a->format_data = mtree;
1403 a->format_name = "mtree";
1410 a->archive.archive_format_name = "mtree";
1431 struct mtree_writer *mtree;
1433 mtree = (struct mtree_writer *)a->format_data;
1435 /* Set to output a mtree archive in classic format. */
1436 mtree->classic = 1;
1437 /* Basically, mtree classic format uses '/set' global
1439 mtree->output_global_set = 1;
1445 sum_init(struct mtree_writer *mtree)
1448 mtree->compute_sum = 0;
1450 if (mtree->keys & F_CKSUM) {
1451 mtree->compute_sum |= F_CKSUM;
1452 mtree->crc = 0;
1453 mtree->crc_len = 0;
1456 if (mtree->keys & F_MD5) {
1457 if (archive_md5_init(&mtree->md5ctx) == ARCHIVE_OK)
1458 mtree->compute_sum |= F_MD5;
1460 mtree->keys &= ~F_MD5;/* Not supported. */
1464 if (mtree->keys & F_RMD160) {
1465 if (archive_rmd160_init(&mtree->rmd160ctx) == ARCHIVE_OK)
1466 mtree->compute_sum |= F_RMD160;
1468 mtree->keys &= ~F_RMD160;/* Not supported. */
1472 if (mtree->keys & F_SHA1) {
1473 if (archive_sha1_init(&mtree->sha1ctx) == ARCHIVE_OK)
1474 mtree->compute_sum |= F_SHA1;
1476 mtree->keys &= ~F_SHA1;/* Not supported. */
1480 if (mtree->keys & F_SHA256) {
1481 if (archive_sha256_init(&mtree->sha256ctx) == ARCHIVE_OK)
1482 mtree->compute_sum |= F_SHA256;
1484 mtree->keys &= ~F_SHA256;/* Not supported. */
1488 if (mtree->keys & F_SHA384) {
1489 if (archive_sha384_init(&mtree->sha384ctx) == ARCHIVE_OK)
1490 mtree->compute_sum |= F_SHA384;
1492 mtree->keys &= ~F_SHA384;/* Not supported. */
1496 if (mtree->keys & F_SHA512) {
1497 if (archive_sha512_init(&mtree->sha512ctx) == ARCHIVE_OK)
1498 mtree->compute_sum |= F_SHA512;
1500 mtree->keys &= ~F_SHA512;/* Not supported. */
1506 sum_update(struct mtree_writer *mtree, const void *buff, size_t n)
1508 if (mtree->compute_sum & F_CKSUM) {
1516 COMPUTE_CRC(mtree->crc, *p);
1517 mtree->crc_len += n;
1520 if (mtree->compute_sum & F_MD5)
1521 archive_md5_update(&mtree->md5ctx, buff, n);
1524 if (mtree->compute_sum & F_RMD160)
1525 archive_rmd160_update(&mtree->rmd160ctx, buff, n);
1528 if (mtree->compute_sum & F_SHA1)
1529 archive_sha1_update(&mtree->sha1ctx, buff, n);
1532 if (mtree->compute_sum & F_SHA256)
1533 archive_sha256_update(&mtree->sha256ctx, buff, n);
1536 if (mtree->compute_sum & F_SHA384)
1537 archive_sha384_update(&mtree->sha384ctx, buff, n);
1540 if (mtree->compute_sum & F_SHA512)
1541 archive_sha512_update(&mtree->sha512ctx, buff, n);
1546 sum_final(struct mtree_writer *mtree, struct reg_info *reg)
1549 if (mtree->compute_sum & F_CKSUM) {
1552 for (len = mtree->crc_len; len != 0; len >>= 8)
1553 COMPUTE_CRC(mtree->crc, len & 0xff);
1554 reg->crc = ~mtree->crc;
1557 if (mtree->compute_sum & F_MD5)
1558 archive_md5_final(&mtree->md5ctx, reg->digest.md5);
1561 if (mtree->compute_sum & F_RMD160)
1562 archive_rmd160_final(&mtree->rmd160ctx, reg->digest.rmd160);
1565 if (mtree->compute_sum & F_SHA1)
1566 archive_sha1_final(&mtree->sha1ctx, reg->digest.sha1);
1569 if (mtree->compute_sum & F_SHA256)
1570 archive_sha256_final(&mtree->sha256ctx, reg->digest.sha256);
1573 if (mtree->compute_sum & F_SHA384)
1574 archive_sha384_final(&mtree->sha384ctx, reg->digest.sha384);
1577 if (mtree->compute_sum & F_SHA512)
1578 archive_sha512_final(&mtree->sha512ctx, reg->digest.sha512);
1581 reg->compute_sum = mtree->compute_sum;
1834 * to add "./" to the head of the pathname because mtree reader
1835 * will suppose that it is v1(a.k.a classic) mtree format and
1911 mtree_entry_register_add(struct mtree_writer *mtree, struct mtree_entry *file)
1914 *mtree->file_list.last = file;
1915 mtree->file_list.last = &(file->next);
1919 mtree_entry_register_init(struct mtree_writer *mtree)
1921 mtree->file_list.first = NULL;
1922 mtree->file_list.last = &(mtree->file_list.first);
1926 mtree_entry_register_free(struct mtree_writer *mtree)
1930 file = mtree->file_list.first;
1996 struct mtree_writer *mtree = (struct mtree_writer *)a->format_data;
2005 if (mtree->root != NULL) {
2006 np = mtree->root;
2009 mtree->root = file;
2010 mtree_entry_register_add(mtree, file);
2029 if (archive_strlen(&(mtree->cur_dirstr))
2031 strcmp(mtree->cur_dirstr.s, fn) == 0) {
2033 &(mtree->cur_dirent->dir_info->rbtree),
2037 &(mtree->cur_dirent->dir_info->rbtree),
2041 file->parent = mtree->cur_dirent;
2042 mtree_entry_register_add(mtree, file);
2046 dent = mtree->root;
2060 dent == mtree->root) {
2106 mtree->root = vp;
2113 mtree_entry_register_add(mtree, vp);
2132 mtree->cur_dirent = dent;
2133 archive_string_empty(&(mtree->cur_dirstr));
2134 archive_string_ensure(&(mtree->cur_dirstr),
2139 mtree->cur_dirstr.s[0] = 0;
2142 archive_string_copy(&(mtree->cur_dirstr),
2145 &(mtree->cur_dirstr), '/');
2147 archive_string_concat(&(mtree->cur_dirstr),
2159 mtree_entry_register_add(mtree, file);
2191 /* Update the existent mtree entry's attributes by the new one's. */