Checking local filesystem fsid from osx kernel extension (kext)

I have a WA to check the local fsid from the kext context by simply reading the predefined local file status.

static inline uint64_t get_fsid(const vfs_context_t ctx, const vnode_t vp) {
    struct vnode_attr vap;
    VATTR_INIT(&vap);
    VATTR_WANTED(&vap, va_fsid);
    vnode_getattr(vp, &vap, ctx);
    return (uint64_t)vap.va_fsid;
}

      

another option is to calculate the fsid from user space and pass that information to the driver (using getmntinfo

)

However, I prefer to get this data directly from kernel space rather than relying on any files that currently exist. is there a KPI to support this request?

+3


source to share


1 answer


You can iterate over all mount points on the system using the function

int vfs_iterate(int, int (*)(struct mount *, void *), void *);

      

For each object, mount

you can check its fsid with



struct vfsstatfs *  vfs_statfs(mount_t);

      

vfsstatfs

has a field f_fsid

.

Both functions and structure are declared and documented in <sys/mount.h>

. Functions are exported to BSD KPIs.

+1


source







All Articles