]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commit
xfs: correct nlink printf specifier from hd to PRIu32
authorhexiaole <hexiaole@kylinos.cn>
Thu, 14 Jul 2022 01:58:24 +0000 (20:58 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 14 Jul 2022 01:58:24 +0000 (20:58 -0500)
commit03bc653907cc4e89cbb45524063439800a722d9b
tree162f7ccf170bbed33b8b07b80ebbdc2b13af2dbd
parentdaebb4ce880209dd28c5cf409ce40cca72836736
xfs: correct nlink printf specifier from hd to PRIu32

1. Description
libxfs/xfs_log_format.h declare 'di_nlink' as unsigned 32-bit integer:

typedef struct xfs_icdinode {
        ...
        __uint32_t      di_nlink;       /* number of links to file */
        ...
} xfs_icdinode_t;

But logprint/log_misc.c use '%hd' to print 'di_nlink':

void
xlog_print_trans_inode_core(xfs_icdinode_t *ip)
{
    ...
    printf(_("nlink %hd uid %d gid %d\n"),
           ip->di_nlink, ip->di_uid, ip->di_gid);
    ...
}

'%hd' can be 16-bit on many architectures, on these architectures, the 'printf' only print the low 16-bit of 'di_nlink'.

2. Reproducer
2.1. Commands
[root@localhost ~]# cd
[root@localhost ~]# xfs_mkfile 128m 128m.xfs
[root@localhost ~]# mkfs.xfs 128m.xfs
[root@localhost ~]# mount 128m.xfs /mnt/
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# seq 1 65534|xargs mkdir -p
[root@localhost mnt]# cd
[root@localhost ~]# umount /mnt/
[root@localhost ~]# xfs_logprint 128m.xfs|grep nlink|tail -1

2.2. Expect result
nlink 65536

2.3. Actual result
nlink 0

Signed-off-by: hexiaole <hexiaole@kylinos.cn>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
logprint/log_misc.c