lkml.org 
[lkml]   [2006]   [Jan]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [linux-pm] [RFC/RFT][PATCH -mm 2/5] swsusp: userland interface (rev. 2)
On Wed, Jan 04, 2006 at 11:51:58PM +0100, Rafael J. Wysocki wrote:
> +static struct snapshot_dev interface = {
> + .name = "snapshot",
> +};
> +
> +static ssize_t snapshot_show(struct subsystem * subsys, char *buf)
> +{
> + return sprintf(buf, "%d:%d\n", MAJOR(interface.devno),
> + MINOR(interface.devno));
> +}
> +
> +static struct subsys_attribute snapshot_attr = {
> + .attr = {
> + .name = __stringify(snapshot),
> + .mode = S_IRUGO,
> + },
> + .show = snapshot_show,
> +};
> +
> +static int __init snapshot_dev_init(void)
> +{
> + int error;
> +
> + error = alloc_chrdev_region(&interface.devno, 0, 1, interface.name);
> + if (error)
> + return error;
> + cdev_init(&interface.cdev, &snapshot_fops);
> + interface.cdev.ops = &snapshot_fops;
> + error = cdev_add(&interface.cdev, interface.devno, 1);
> + if (error)
> + goto Unregister;
> + error = sysfs_create_file(&power_subsys.kset.kobj, &snapshot_attr.attr);

Heh, that's a neat hack, register a sysfs file that contains the
major:minor (there is a function that will print that the correct way,
if you really want to do that), in sysfs. It's better to just register
a misc character device with the name "snapshot", and then udev will
create your userspace node with the proper major:minor all automatically
for you.

Unless you want to turn these into syscalls :)

thanks,

greg k-h
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-01-05 00:57    [W:0.090 / U:6.624 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site