Regarding freeBSD

Robert Watson rwatson at freebsd.org
Tue Jul 27 07:26:35 PDT 2004


On Tue, 27 Jul 2004, ravi wrote:

> I wanted to know whether there is any structure in FreeBSD that
> corresponds to the file_operations structure of Linux ? 

In FreeBSD, the equivilent of 'struct inode' is 'struct vnode'.  The inode
operation fector on Linux, 'struct file_operations' is equivilent to the
'v_op' vnode operation vector in FreeBSD.  Most file systems use just a
couple of operation vectors -- one for regular files/directories, another
for fifos, and another for special devices.  The file systems will provide
their own vector and then overlay shared vectors from file system
libraries to implement fifos and special devices -- fs/fifofs and
fs/specfs respectively.

In Linux, inode vectors are more frequently substituted for special nodes,
whereas in FreeBSD, file systems that provide for special nodes often
expose an abstraction to the services creating said nodes.  I.e., in
Linux, a broad range of devices override the file operation vector for
device nodes.  In FreeBSD, devfs implements the vnode operation vectors
and forwards specific requests via the device's 'struct devsw' -- open,
close, read, write, ioctl, poll, etc.  As such, it's fairly unusual to
directly override vnode operation vectors; rather, special case nodes
attach to various service APIs to offer method implementations (i.e., fill
out a cdevsw and attach it using make_dev()).

> Is there any way to register read and write functions in a kernel module
> for procfs ? 

I think it might be helpful to know what it is you're currently up to --
are you building a new file system based on pseudofs, extending procfs or
linprocfs to add new entries, or building an entirely new file system? 
Are you adding new per-process procfs entries?  The advice you get will
depend a bit on what it is you want to accomplish...

If you intend to modify the FreeBSD procfs to add new per-process
controls, take a look at fs/procfs/procfs_init(), which registers the
per-process entries with pseudofs, including their procfs_do*() methods.
In particular, I'd probably look at procfs_doprocctl() in proc_ctl.c,
which implements the write functionality for /proc/*/ctl, and
procfs_doprocmap(), which implements the read functionality for
/proc/*/map.

Robert N M Watson             FreeBSD Core Team, TrustedBSD Projects
robert at fledge.watson.org      Principal Research Scientist, McAfee Research



More information about the freebsd-fs mailing list