+static bool check_node(const struct exfat_node* node, uint16_t actual_checksum,
+ uint16_t reference_checksum, uint64_t valid_size)
+{
+ char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1];
+
+ /*
+ Validate checksum first. If it's invalid all other fields probably
+ contain just garbage.
+ */
+ if (actual_checksum != reference_checksum)
+ {
+ exfat_get_name(node, buffer, sizeof(buffer) - 1);
+ exfat_error("'%s' has invalid checksum (%#hx != %#hx)", buffer,
+ actual_checksum, reference_checksum);
+ return false;
+ }
+
+ /*
+ exFAT does not support sparse files but allows files with uninitialized
+ clusters. For such files valid_size means initialized data size and
+ cannot be greater than file size. See SetFileValidData() function
+ description in MSDN.
+ */
+ if (valid_size > node->size)
+ {
+ exfat_get_name(node, buffer, sizeof(buffer) - 1);
+ exfat_error("'%s' has valid size (%"PRIu64") greater than size "
+ "(%"PRIu64")", buffer, valid_size, node->size);
+ return false;
+ }
+
+ return true;
+}
+