fs: Add static asserts for the size of fid structures

File system specific *fid structures are copied into the generic
struct fid defined in sys/mount.h.
As such, they cannot be larger than struct fid.

This patch adds _Static_assert()s to check for this.

ZFS and fuse already have _Static_assert()s.

Reviewed by:	imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D47936
This commit is contained in:
Rick Macklem 2024-12-05 17:56:23 -08:00
parent 53484f516a
commit 91b5592a1e
4 changed files with 8 additions and 0 deletions

View file

@ -1962,6 +1962,8 @@ msdosfs_vptofh(struct vop_vptofh_args *ap)
{
struct denode *dep;
struct defid *defhp;
_Static_assert(sizeof(struct defid) <= sizeof(struct fid),
"struct defid cannot be larger than struct fid");
dep = VTODE(ap->a_vp);
defhp = (struct defid *)ap->a_fhp;

View file

@ -1709,6 +1709,8 @@ vop_vptofh {
struct tmpfs_fid_data tfd;
struct tmpfs_node *node;
struct fid *fhp;
_Static_assert(sizeof(struct tmpfs_fid_data) <= sizeof(struct fid),
"struct tmpfs_fid_data cannot be larger than struct fid");
node = VP_TO_TMPFS_NODE(ap->a_vp);
fhp = ap->a_fhp;

View file

@ -1274,6 +1274,8 @@ udf_vptofh(struct vop_vptofh_args *a)
{
struct udf_node *node;
struct ifid *ifhp;
_Static_assert(sizeof(struct ifid) <= sizeof(struct fid),
"struct ifid cannot be larger than struct fid");
node = VTON(a->a_vp);
ifhp = (struct ifid *)a->a_fhp;

View file

@ -1919,6 +1919,8 @@ ffs_vptofh(
{
struct inode *ip;
struct ufid *ufhp;
_Static_assert(sizeof(struct ufid) <= sizeof(struct fid),
"struct ufid cannot be larger than struct fid");
ip = VTOI(ap->a_vp);
ufhp = (struct ufid *)ap->a_fhp;