Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IOKit /devfs



Hado Hein writes:
 > I want to implement a device interfacing api in /dev that is already
 > done in linux.

Bear in mind that the BSD /dev interface does not provide you with
any easy way to keep track of per-open information.  Eg, there
is no file_ptr->private_data.

The only easy way to do this is to have a whole slew of minors, allow
only one open per minor, and to lookup your per-open information based
on the minor number.

 > So I scanned the docs about i/o kit and kernel for a simple list (or
 > sample code) of how to build a kext that provides a devnode _and_ on
 > where to implement the api.
 > 
 > I looked over the darwin sources of rs232 and saw how to register the
 > devnode but I found nowhere the implementation of
 > open,close,read,write,seek somewhere.
 > 
 > Can one please point me to clear docs where I can see how to implement a
 > (dummy) /devnode. 


Creating /dev nodes and implementing your own open/close/ioctl, etc,
is outside IOKit.  See
/System/Library/Frameworks/Kernel.framework/Headers/sys/conf.h and
/System/Library/Frameworks/Kernel.framework/Headers//miscfs/devfs/devfs.h

For a character device, what you do is to fill in a struct cdevsw (call it
my_cdevsw) with your functions, and call cdevsw_add(-1, &my_cdevsw).
Keep track of the return value, that's your major number.

Then you can call special= devfs_make_node(makedev(major, minor), DEVFS_CHAR,
     uid, gid, permissions, name_format_string, name_args) for each of
your special files.

When unloading, you call devfs_remove() on all the specials you
created, and then call cdevsw_remove() with your major and a pointer
to your cdevsw.
     					
I came from FreeBSD, so I never needed docs on this.  I think this is
the sort of thing where if you don't already know how to use it, they
don't want you to start ;)

Drew

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-drivers mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-drivers/email@hidden

This email sent to email@hidden

References: 
 >IOKit /devfs (From: email@hidden (Hado Hein))



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.