Re: devfs user client
Re: devfs user client
- Subject: Re: devfs user client
- From: Andrew Gallatin <email@hidden>
- Date: Mon, 11 Nov 2002 14:16:16 -0500 (EST)
Matthias Ringwald writes:
>
hi
>
>
I found a discussion on providing /dev/.. devices by a user client on
>
this list from nov 2001.
>
Is it possible to write a pseudo device driver that can be used by
>
other applications over open/read/write/ioctl POSIX calls ?
>
>
I'm trying to port the lirc linux infrared control to mac os x and it
>
uses /dev/.. devices for their communication.
Sure. Using ioctls and devices is much more portable when
you've got code that runs on other UNIXes.
Note that MacOS X uses devfs (the older, uglier one, I think), so you
should make the special files from inside the driver. Also note that
unlike linux & solaris, MacOS & *BSD do not support factory devices.
Drew
PS: Here's working sample code ripped from my (real hardware) driver.
The idea is to make several /dev/sample* devices, with different
permissions based on device number.
static int
sample_macos_special_create ()
{
int i, perms;
char name[16];
sample_macos_major = cdevsw_add (-1, &sample_macos_cdevsw);
if (sample_macos_major == -1)
{
return sample_macos_major;
}
/* got a cdevsw_entry, now create device nodes via devfs */
bzero (sample_macos_specials, SAMPLE_ARCH_MAX_MINOR * sizeof (void *));
for (i = 0; i < SAMPLE_ARCH_MAX_MINOR; i++)
{
if (i < 2 * SAMPLE_ARCH_MAX_INSTANCE)
{
if (i & 1)
{
/* priv. port, so use secure permissions */
sprintf (name, "samplep%d", i / 2);
perms = 0600;
}
else
{
sprintf (name, "sample%d", i / 2);
perms = 0666;
}
}
else
{
sprintf (name, "sample%d", i);
perms = 0666;
}
/* create the special file */
sample_macos_specials[i] = devfs_make_node (makedev (sample_macos_major, i),
DEVFS_CHAR, UID_ROOT, GID_WHEEL,
perms, name, i);
if (sample_macos_specials[i] == NULL)
{
sample_macos_special_destroy ();
return -1;
}
}
return sample_macos_major;
}
/*
* Undo the above. Remove the cdevsw, and free our special devices..
*/
static void
sample_macos_special_destroy ()
{
int i;
cdevsw_remove (sample_macos_major, &sample_macos_cdevsw);
for (i = 0; i < SAMPLE_ARCH_MAX_MINOR; i++)
{
if (sample_macos_specials[i] != NULL)
{
devfs_remove (sample_macos_specials[i]);
sample_macos_specials[i] = 0;
}
}
sample_macos_major = -1;
}
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.