738 if (zn->zn_key_orig_numints * zn->zn_key_intlen > ZAP_MAXNAMELEN)
739 return (SET_ERROR(ENAMETOOLONG));
740 return (0);
741 }
742
743 static int
744 fzap_checksize(uint64_t integer_size, uint64_t num_integers)
745 {
746 /* Only integer sizes supported by C */
747 switch (integer_size) {
748 case 1:
749 case 2:
750 case 4:
751 case 8:
752 break;
753 default:
754 return (SET_ERROR(EINVAL));
755 }
756
757 if (integer_size * num_integers > ZAP_MAXVALUELEN)
758 return (E2BIG);
759
760 return (0);
761 }
762
763 static int
764 fzap_check(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers)
765 {
766 int err;
767
768 if ((err = fzap_checkname(zn)) != 0)
769 return (err);
770 return (fzap_checksize(integer_size, num_integers));
771 }
772
773 /*
774 * Routines for manipulating attributes.
775 */
776 int
777 fzap_lookup(zap_name_t *zn,
778 uint64_t integer_size, uint64_t num_integers, void *buf,
1018
1019 err = 0;
1020 for (zap_cursor_init(&zc, os, fromobj);
1021 zap_cursor_retrieve(&zc, &za) == 0;
1022 (void) zap_cursor_advance(&zc)) {
1023 if (za.za_integer_length != 8 || za.za_num_integers != 1) {
1024 err = SET_ERROR(EINVAL);
1025 break;
1026 }
1027 err = zap_add(os, intoobj, za.za_name,
1028 8, 1, &za.za_first_integer, tx);
1029 if (err)
1030 break;
1031 }
1032 zap_cursor_fini(&zc);
1033 return (err);
1034 }
1035
1036 int
1037 zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1038 uint64_t value, dmu_tx_t *tx)
1039 {
1040 zap_cursor_t zc;
1041 zap_attribute_t za;
1042 int err;
1043
1044 err = 0;
1045 for (zap_cursor_init(&zc, os, fromobj);
1046 zap_cursor_retrieve(&zc, &za) == 0;
1047 (void) zap_cursor_advance(&zc)) {
1048 if (za.za_integer_length != 8 || za.za_num_integers != 1) {
1049 err = SET_ERROR(EINVAL);
1050 break;
1051 }
1052 err = zap_add(os, intoobj, za.za_name,
1053 8, 1, &value, tx);
1054 if (err)
1055 break;
1056 }
1057 zap_cursor_fini(&zc);
1058 return (err);
1059 }
1060
1061 int
1062 zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1063 dmu_tx_t *tx)
1064 {
1065 zap_cursor_t zc;
1066 zap_attribute_t za;
1067 int err;
1068
1069 err = 0;
1070 for (zap_cursor_init(&zc, os, fromobj);
1071 zap_cursor_retrieve(&zc, &za) == 0;
1072 (void) zap_cursor_advance(&zc)) {
1073 uint64_t delta = 0;
1074
1075 if (za.za_integer_length != 8 || za.za_num_integers != 1) {
1076 err = SET_ERROR(EINVAL);
|
738 if (zn->zn_key_orig_numints * zn->zn_key_intlen > ZAP_MAXNAMELEN)
739 return (SET_ERROR(ENAMETOOLONG));
740 return (0);
741 }
742
743 static int
744 fzap_checksize(uint64_t integer_size, uint64_t num_integers)
745 {
746 /* Only integer sizes supported by C */
747 switch (integer_size) {
748 case 1:
749 case 2:
750 case 4:
751 case 8:
752 break;
753 default:
754 return (SET_ERROR(EINVAL));
755 }
756
757 if (integer_size * num_integers > ZAP_MAXVALUELEN)
758 return (SET_ERROR(E2BIG));
759
760 return (0);
761 }
762
763 static int
764 fzap_check(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers)
765 {
766 int err;
767
768 if ((err = fzap_checkname(zn)) != 0)
769 return (err);
770 return (fzap_checksize(integer_size, num_integers));
771 }
772
773 /*
774 * Routines for manipulating attributes.
775 */
776 int
777 fzap_lookup(zap_name_t *zn,
778 uint64_t integer_size, uint64_t num_integers, void *buf,
1018
1019 err = 0;
1020 for (zap_cursor_init(&zc, os, fromobj);
1021 zap_cursor_retrieve(&zc, &za) == 0;
1022 (void) zap_cursor_advance(&zc)) {
1023 if (za.za_integer_length != 8 || za.za_num_integers != 1) {
1024 err = SET_ERROR(EINVAL);
1025 break;
1026 }
1027 err = zap_add(os, intoobj, za.za_name,
1028 8, 1, &za.za_first_integer, tx);
1029 if (err)
1030 break;
1031 }
1032 zap_cursor_fini(&zc);
1033 return (err);
1034 }
1035
1036 int
1037 zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1038 uint64_t value, dmu_tx_t *tx, boolean_t exists_ok)
1039 {
1040 zap_cursor_t zc;
1041 zap_attribute_t za;
1042 int err;
1043
1044 err = 0;
1045 for (zap_cursor_init(&zc, os, fromobj);
1046 zap_cursor_retrieve(&zc, &za) == 0;
1047 (void) zap_cursor_advance(&zc)) {
1048 if (za.za_integer_length != 8 || za.za_num_integers != 1) {
1049 err = SET_ERROR(EINVAL);
1050 break;
1051 }
1052 err = zap_add(os, intoobj, za.za_name,
1053 8, 1, &value, tx);
1054 if (err != 0) {
1055 if (err == EEXIST && exists_ok)
1056 err = 0;
1057 else
1058 break;
1059 }
1060 }
1061 zap_cursor_fini(&zc);
1062 return (err);
1063 }
1064
1065 int
1066 zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1067 dmu_tx_t *tx)
1068 {
1069 zap_cursor_t zc;
1070 zap_attribute_t za;
1071 int err;
1072
1073 err = 0;
1074 for (zap_cursor_init(&zc, os, fromobj);
1075 zap_cursor_retrieve(&zc, &za) == 0;
1076 (void) zap_cursor_advance(&zc)) {
1077 uint64_t delta = 0;
1078
1079 if (za.za_integer_length != 8 || za.za_num_integers != 1) {
1080 err = SET_ERROR(EINVAL);
|