apfsck: ignore orphans in the volume file counts

It seems that orphans aren't counted in the file totals reported by the
volume superblock. Fix this.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
This commit is contained in:
Ernesto A. Fernández
2022-08-11 23:44:06 -03:00
parent 68b424f5a3
commit 8b1575bdae
2 changed files with 28 additions and 2 deletions
+27
View File
@@ -206,6 +206,33 @@ void parse_dentry_record(void *key, struct apfs_drec_val *val, int len)
inode->i_mode |= dtype << 12;
}
/*
* Orphans aren't counted for the file totals, but I can't tell them
* apart inside parse_inode_record(), so do it here instead.
*/
if (parent_ino == APFS_PRIV_DIR_INO_NUM) {
switch (dtype << 12) {
case S_IFREG:
vsb->v_file_count--;
break;
case S_IFDIR:
if (inode->i_ino >= APFS_MIN_USER_INO_NUM)
vsb->v_dir_count--;
break;
case S_IFLNK:
vsb->v_symlink_count--;
break;
case S_IFSOCK:
case S_IFBLK:
case S_IFCHR:
case S_IFIFO:
vsb->v_special_count--;
break;
default:
report("Dentry record", "invalid file mode.");
}
}
parse_dentry_xfields((struct apfs_xf_blob *)val->xfields,
len - sizeof(*val), &sibling_id);
+1 -2
View File
@@ -860,8 +860,7 @@ void check_volume_super(void)
report("Catalog", "the private directory is missing.");
if (le64_to_cpu(vsb_raw->apfs_num_files) != vsb->v_file_count)
/* Sometimes this is off by one. TODO: why? */
report_weird("File count in volume superblock");
report("Volume superblock", "bad regular file count.");
if (le64_to_cpu(vsb_raw->apfs_num_directories) != vsb->v_dir_count)
report("Volume superblock", "bad directory count.");
if (le64_to_cpu(vsb_raw->apfs_num_symlinks) != vsb->v_symlink_count)