# HG changeset patch # User Paul Boddie # Date 1645033091 -3600 # Node ID 76be2dc3b29451b2a0c99f4b85558b5697883189 # Parent 88d2d7364bea729d62bb0337b6a33a63c2c42c9f Fixed directory link count decrementing, added support for showing link counts. diff -r 88d2d7364bea -r 76be2dc3b294 libe2access/host/test_listing.c --- a/libe2access/host/test_listing.c Wed Feb 16 18:21:01 2022 +0100 +++ b/libe2access/host/test_listing.c Wed Feb 16 18:38:11 2022 +0100 @@ -133,6 +133,7 @@ list_dir_data.fs = fs; list_dir_data.filename = NULL; + list_dir_data.link_count = 0; image_list_dir(fs, "", image_list_dir_proc, &list_dir_data); image_list_dir(fs, "", image_list_dir_proc, &list_dir_data); diff -r 88d2d7364bea -r 76be2dc3b294 libe2access/include/e2access/utils.h --- a/libe2access/include/e2access/utils.h Wed Feb 16 18:21:01 2022 +0100 +++ b/libe2access/include/e2access/utils.h Wed Feb 16 18:38:11 2022 +0100 @@ -32,6 +32,7 @@ { ext2_filsys fs; /* filesystem */ const char *filename; /* single filename to show */ + int link_count; /* flag to show link counts */ }; errcode_t utils_list_dir(ext2_filsys fs, const char *path); diff -r 88d2d7364bea -r 76be2dc3b294 libe2access/lib/src/image.c --- a/libe2access/lib/src/image.c Wed Feb 16 18:21:01 2022 +0100 +++ b/libe2access/lib/src/image.c Wed Feb 16 18:38:11 2022 +0100 @@ -482,8 +482,9 @@ struct ext2_inode_large inode; ext2_ino_t ino_parent = 0; errcode_t retval; + int isdir = _image_isdir(fs, ino); - if (_image_isdir(fs, ino)) + if (isdir) { retval = image_dir_get_parent(fs, ino, &ino_parent); if (retval) @@ -502,10 +503,13 @@ return 0; /* Decrement the reference count. With no more references to the inode, - remove its resources. */ + remove its resources. Directories appear to need a double decrement. */ inode.i_links_count--; + if (isdir && inode.i_links_count) + inode.i_links_count--; + if (!inode.i_links_count) { /* NOTE: Update deletion time. */ diff -r 88d2d7364bea -r 76be2dc3b294 libe2access/lib/src/utils.c --- a/libe2access/lib/src/utils.c Wed Feb 16 18:21:01 2022 +0100 +++ b/libe2access/lib/src/utils.c Wed Feb 16 18:38:11 2022 +0100 @@ -44,6 +44,10 @@ else data.filename = NULL; + /* Do not show link counts by default. */ + + data.link_count = 0; + return image_list_dir(fs, path, utils_list_dir_proc, &data); } @@ -76,6 +80,11 @@ inode.i_gid, EXT2_I_SIZE(&inode)); + /* Show link counts if requested. */ + + if (data->link_count) + printf("%6d ", inode.i_links_count); + /* Output the name which is presumably not necessarily null-terminated. */ fwrite(dirent->name, sizeof(char), ext2fs_dirent_name_len(dirent), stdout);