Page MenuHomeFreeBSD

tarfs: 'struct tarfs_fid': Switch 'gen' to 'u_int', avoid packing
ClosedPublic

Authored by olce on Dec 6 2024, 10:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Jan 3, 5:43 AM
Unknown Object (File)
Thu, Dec 19, 12:01 PM
Unknown Object (File)
Fri, Dec 13, 2:07 PM
Unknown Object (File)
Wed, Dec 11, 9:39 AM
Subscribers

Details

Summary

As the 'gen' field in 'struct tarfs_node' (and then 'struct tarfs_fid')
is filled with arc4random() which returns an unsigned int, change its
type in both structures. This allows reordering fields in 'struct
tarfs_fid' to reduce its size, finally avoiding the use of '__packed' to
ensure it fits into 'struct fid'.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

olce requested review of this revision.Dec 6 2024, 10:19 PM
sys/fs/tarfs/tarfs.h
78

arc4random() is listed as returning uint32_t,
so why not change it to that type?
(This makes it crystal clear it is 32bits.)

166

Ditto above.

olce marked 2 inline comments as done.

unsigned int => uint32_t as suggested.

sys/fs/tarfs/tarfs.h
78

I initially wanted to put uint32_t for this exact reason, but then I surveyed tarfs code and saw there were no occurrences of uint32_t (consistency of style). Also, as this is a purely internal structure, I thought that being explicit with its size wasn't that much required here.

Either way is fine with me (just saying in case someone insists in keeping unsigned int).

166

This case is a bit different, as struct tarfs_fid is meant to be an encoding, so the need to change it is more compelling. There's perhaps still the style consistency issue.

markj added a reviewer: des.
This revision is now accepted and ready to land.Mon, Dec 9, 1:51 PM
sys/fs/tarfs/tarfs.h
165

this isn't needed if the struct isn't packed.

This revision was automatically updated to reflect the committed changes.
olce marked an inline comment as done.