Pseudofs and pfs_attr_t for non-process based files

Andrew Brampton brampton+freebsd-fs at gmail.com
Sun Jan 18 17:30:45 PST 2009


Hi,
I've recently been coding a pseudofs based file system to export data
from a custom kernel module, and allow users to control the module via
the file system.

Anyway, I quite like how simple it is to use pseudofs, but I found one
annoying "feature". If I call pfs_create_{dir, file, link} with a
pfs_attr_t function pointer, my function will never be called. I
tracked this problem to the function pfs_getattr inside
sys/fs/pseudofs/pseudofs_vnops.c. It has the following lines of code:

if (proc != NULL) {
    ...
    if (pn->pn_attr != NULL)
        error = pn_attr(curthread, proc, pn, vap);
    ...
}

Basically pn_attr calls my pfs_attr_t function pointer, but only if
the proc != null. Now in my case none of my files are created
PFS_PROCDEP flag, which mean proc will always be null. So unless you
are writing a pseudofs which is dependent on the process calling it,
you cannot use a pfs_attr_t function pointer, meaning I can't change
the attributes on my pseudo files.

Now, to fix this problem I made a very simple patch which will call
pn_attr regardless of proc being null or not. By doing this I had to
also make a minor change in procfs.c as it assumes a valid proc is
always passed in.

I'd be grateful if someone look over my patches, and advise me if this
was the correct thing to do. Also I'd be interested to know why this
was original coded like this? Or was it just a oversight? Just for
reference there is also a few more callbacks for various file system
operations, with all of them working if proc is null, with one
exception, the pfs_vis_t callback. Perhaps that should also be updated
also?

Thanks

Andrew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pseudofs_vnops.patch
Type: application/octet-stream
Size: 826 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20090119/799808d4/pseudofs_vnops.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: procfs.patch
Type: application/octet-stream
Size: 1051 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20090119/799808d4/procfs.obj


More information about the freebsd-fs mailing list