blob: 91b0fd021a95d08eef106b3e0b86a41e3a135055 [file] [log] [blame]
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -08001/*
2 * linux/kernel/power/user.c
3 *
4 * This file provides the user space interface for software suspend/resume.
5 *
6 * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
7 *
8 * This file is released under the GPLv2.
9 *
10 */
11
12#include <linux/suspend.h>
13#include <linux/syscalls.h>
Stefan Seyfried35926952006-12-06 20:34:06 -080014#include <linux/reboot.h>
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080015#include <linux/string.h>
16#include <linux/device.h>
17#include <linux/miscdevice.h>
18#include <linux/mm.h>
19#include <linux/swap.h>
20#include <linux/swapops.h>
21#include <linux/pm.h>
22#include <linux/fs.h>
Ben Hutchingsc3360782011-12-27 22:54:52 +010023#include <linux/compat.h>
Rafael J. Wysocki97c78012006-10-11 01:20:45 -070024#include <linux/console.h>
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -070025#include <linux/cpu.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080026#include <linux/freezer.h>
Rafael J. Wysockic7510852009-04-12 20:06:56 +020027#include <scsi/scsi_scan.h>
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080028
29#include <asm/uaccess.h>
30
31#include "power.h"
32
Rafael J. Wysockieb57c1c2007-10-26 01:01:10 +020033
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080034#define SNAPSHOT_MINOR 231
35
36static struct snapshot_data {
37 struct snapshot_handle handle;
38 int swap;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080039 int mode;
40 char frozen;
41 char ready;
Rafael J. Wysockieb57c1c2007-10-26 01:01:10 +020042 char platform_support;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080043} snapshot_state;
44
Rafael J. Wysocki0709db62007-05-06 14:50:45 -070045atomic_t snapshot_device_available = ATOMIC_INIT(1);
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080046
47static int snapshot_open(struct inode *inode, struct file *filp)
48{
49 struct snapshot_data *data;
Alan Sternc3e94d82007-11-19 23:38:25 +010050 int error;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080051
Srivatsa S. Bhatbcda53f2011-12-07 22:29:54 +010052 lock_system_sleep();
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +020053
54 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
55 error = -EBUSY;
56 goto Unlock;
57 }
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080058
Rafael J. Wysocki1525a2a2007-05-06 14:50:44 -070059 if ((filp->f_flags & O_ACCMODE) == O_RDWR) {
Rafael J. Wysocki0709db62007-05-06 14:50:45 -070060 atomic_inc(&snapshot_device_available);
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +020061 error = -ENOSYS;
62 goto Unlock;
Rafael J. Wysocki1525a2a2007-05-06 14:50:44 -070063 }
64 if(create_basic_memory_bitmaps()) {
Rafael J. Wysocki0709db62007-05-06 14:50:45 -070065 atomic_inc(&snapshot_device_available);
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +020066 error = -ENOMEM;
67 goto Unlock;
Rafael J. Wysocki1525a2a2007-05-06 14:50:44 -070068 }
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080069 nonseekable_open(inode, filp);
70 data = &snapshot_state;
71 filp->private_data = data;
72 memset(&data->handle, 0, sizeof(struct snapshot_handle));
73 if ((filp->f_flags & O_ACCMODE) == O_RDONLY) {
Rafael J. Wysockic7510852009-04-12 20:06:56 +020074 /* Hibernating. The image device should be accessible. */
Rafael J. Wysocki915bae92006-12-06 20:34:07 -080075 data->swap = swsusp_resume_device ?
Rafael J. Wysocki7bf23682007-01-05 16:36:28 -080076 swap_type_of(swsusp_resume_device, 0, NULL) : -1;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080077 data->mode = O_RDONLY;
Alan Sternc3e94d82007-11-19 23:38:25 +010078 error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
79 if (error)
80 pm_notifier_call_chain(PM_POST_HIBERNATION);
Andrey Borzenkovebae2602009-02-14 02:05:14 +010081 } else {
Rafael J. Wysockic7510852009-04-12 20:06:56 +020082 /*
83 * Resuming. We may need to wait for the image device to
84 * appear.
85 */
86 wait_for_device_probe();
87 scsi_complete_async_scans();
88
Andrey Borzenkovebae2602009-02-14 02:05:14 +010089 data->swap = -1;
90 data->mode = O_WRONLY;
91 error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
92 if (error)
93 pm_notifier_call_chain(PM_POST_RESTORE);
Alan Sternc3e94d82007-11-19 23:38:25 +010094 }
Michal Kubecek8440f4b2011-06-18 20:34:01 +020095 if (error) {
96 free_basic_memory_bitmaps();
Alan Sternc3e94d82007-11-19 23:38:25 +010097 atomic_inc(&snapshot_device_available);
Michal Kubecek8440f4b2011-06-18 20:34:01 +020098 }
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -080099 data->frozen = 0;
100 data->ready = 0;
Rafael J. Wysockieb57c1c2007-10-26 01:01:10 +0200101 data->platform_support = 0;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800102
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200103 Unlock:
Srivatsa S. Bhatbcda53f2011-12-07 22:29:54 +0100104 unlock_system_sleep();
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200105
106 return error;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800107}
108
109static int snapshot_release(struct inode *inode, struct file *filp)
110{
111 struct snapshot_data *data;
112
Srivatsa S. Bhatbcda53f2011-12-07 22:29:54 +0100113 lock_system_sleep();
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200114
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800115 swsusp_free();
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700116 free_basic_memory_bitmaps();
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800117 data = filp->private_data;
Rafael J. Wysockid1d241c2007-05-06 14:50:47 -0700118 free_all_swap_pages(data->swap);
Rafael J. Wysocki97449972011-05-10 21:10:01 +0200119 if (data->frozen) {
120 pm_restore_gfp_mask();
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800121 thaw_processes();
Rafael J. Wysocki97449972011-05-10 21:10:01 +0200122 }
Takashi Iwai1497dd12010-12-10 00:16:39 +0100123 pm_notifier_call_chain(data->mode == O_RDONLY ?
Alan Sternc3e94d82007-11-19 23:38:25 +0100124 PM_POST_HIBERNATION : PM_POST_RESTORE);
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700125 atomic_inc(&snapshot_device_available);
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200126
Srivatsa S. Bhatbcda53f2011-12-07 22:29:54 +0100127 unlock_system_sleep();
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200128
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800129 return 0;
130}
131
132static ssize_t snapshot_read(struct file *filp, char __user *buf,
133 size_t count, loff_t *offp)
134{
135 struct snapshot_data *data;
136 ssize_t res;
Jiri Slabyd3c1b242010-05-01 23:52:02 +0200137 loff_t pg_offp = *offp & ~PAGE_MASK;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800138
Srivatsa S. Bhatbcda53f2011-12-07 22:29:54 +0100139 lock_system_sleep();
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200140
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800141 data = filp->private_data;
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200142 if (!data->ready) {
143 res = -ENODATA;
144 goto Unlock;
145 }
Jiri Slabyd3c1b242010-05-01 23:52:02 +0200146 if (!pg_offp) { /* on page boundary? */
147 res = snapshot_read_next(&data->handle);
148 if (res <= 0)
149 goto Unlock;
150 } else {
151 res = PAGE_SIZE - pg_offp;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800152 }
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200153
Jiri Slabyd3c1b242010-05-01 23:52:02 +0200154 res = simple_read_from_buffer(buf, count, &pg_offp,
155 data_of(data->handle), res);
156 if (res > 0)
157 *offp += res;
158
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200159 Unlock:
Srivatsa S. Bhatbcda53f2011-12-07 22:29:54 +0100160 unlock_system_sleep();
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200161
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800162 return res;
163}
164
165static ssize_t snapshot_write(struct file *filp, const char __user *buf,
166 size_t count, loff_t *offp)
167{
168 struct snapshot_data *data;
169 ssize_t res;
Jiri Slabyd3c1b242010-05-01 23:52:02 +0200170 loff_t pg_offp = *offp & ~PAGE_MASK;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800171
Srivatsa S. Bhatbcda53f2011-12-07 22:29:54 +0100172 lock_system_sleep();
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200173
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800174 data = filp->private_data;
Jiri Slabyd3c1b242010-05-01 23:52:02 +0200175
176 if (!pg_offp) {
177 res = snapshot_write_next(&data->handle);
178 if (res <= 0)
179 goto unlock;
180 } else {
181 res = PAGE_SIZE - pg_offp;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800182 }
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200183
Jiri Slabyd3c1b242010-05-01 23:52:02 +0200184 res = simple_write_to_buffer(data_of(data->handle), res, &pg_offp,
185 buf, count);
186 if (res > 0)
187 *offp += res;
188unlock:
Srivatsa S. Bhatbcda53f2011-12-07 22:29:54 +0100189 unlock_system_sleep();
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200190
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800191 return res;
192}
193
Alan Cox52d11022008-06-11 22:07:52 +0200194static long snapshot_ioctl(struct file *filp, unsigned int cmd,
195 unsigned long arg)
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800196{
197 int error = 0;
198 struct snapshot_data *data;
Rafael J. Wysockiaf508b32007-10-26 00:59:31 +0200199 loff_t size;
Rafael J. Wysocki3aef83e2006-12-06 20:34:10 -0800200 sector_t offset;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800201
202 if (_IOC_TYPE(cmd) != SNAPSHOT_IOC_MAGIC)
203 return -ENOTTY;
204 if (_IOC_NR(cmd) > SNAPSHOT_IOC_MAXNR)
205 return -ENOTTY;
206 if (!capable(CAP_SYS_ADMIN))
207 return -EPERM;
208
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200209 if (!mutex_trylock(&pm_mutex))
210 return -EBUSY;
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800211
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200212 data = filp->private_data;
Alan Cox52d11022008-06-11 22:07:52 +0200213
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800214 switch (cmd) {
215
216 case SNAPSHOT_FREEZE:
217 if (data->frozen)
218 break;
Rafael J. Wysocki1bfcf132008-10-15 22:01:21 -0700219
Alan Sternc3e94d82007-11-19 23:38:25 +0100220 printk("Syncing filesystems ... ");
221 sys_sync();
222 printk("done.\n");
Rafael J. Wysocki232b1432007-10-18 03:04:44 -0700223
Rafael J. Wysocki1bfcf132008-10-15 22:01:21 -0700224 error = freeze_processes();
Rafael J. Wysocki1e732032012-03-28 23:30:21 +0200225 if (!error)
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800226 data->frozen = 1;
227 break;
228
229 case SNAPSHOT_UNFREEZE:
Rafael J. Wysocki2f41ddd2007-06-16 10:16:03 -0700230 if (!data->frozen || data->ready)
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800231 break;
Rafael J. Wysockic9e664f2010-12-03 22:57:45 +0100232 pm_restore_gfp_mask();
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800233 thaw_processes();
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800234 data->frozen = 0;
235 break;
236
Jiri Slabyb694e522010-01-27 23:47:50 +0100237 case SNAPSHOT_CREATE_IMAGE:
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800238 if (data->mode != O_RDONLY || !data->frozen || data->ready) {
239 error = -EPERM;
240 break;
241 }
Rafael J. Wysockic9e664f2010-12-03 22:57:45 +0100242 pm_restore_gfp_mask();
Rafael J. Wysockieb57c1c2007-10-26 01:01:10 +0200243 error = hibernation_snapshot(data->platform_support);
Srivatsa S. Bhat51d6ff72012-02-04 22:26:38 +0100244 if (!error) {
Rafael J. Wysockicc5d2072007-10-26 01:03:33 +0200245 error = put_user(in_suspend, (int __user *)arg);
Srivatsa S. Bhata556d5b52012-02-04 23:39:56 +0100246 data->ready = !freezer_test_done && !error;
247 freezer_test_done = false;
Srivatsa S. Bhat97819a22011-12-01 22:33:10 +0100248 }
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800249 break;
250
251 case SNAPSHOT_ATOMIC_RESTORE:
Rafael J. Wysocki83573762006-12-06 20:34:18 -0800252 snapshot_write_finalize(&data->handle);
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800253 if (data->mode != O_WRONLY || !data->frozen ||
254 !snapshot_image_loaded(&data->handle)) {
255 error = -EPERM;
256 break;
257 }
Rafael J. Wysockieb57c1c2007-10-26 01:01:10 +0200258 error = hibernation_restore(data->platform_support);
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800259 break;
260
261 case SNAPSHOT_FREE:
262 swsusp_free();
263 memset(&data->handle, 0, sizeof(struct snapshot_handle));
264 data->ready = 0;
Rafael J. Wysocki181e9bd2012-01-29 20:35:52 +0100265 /*
266 * It is necessary to thaw kernel threads here, because
267 * SNAPSHOT_CREATE_IMAGE may be invoked directly after
268 * SNAPSHOT_FREE. In that case, if kernel threads were not
269 * thawed, the preallocation of memory carried out by
270 * hibernation_snapshot() might run into problems (i.e. it
271 * might fail or even deadlock).
272 */
273 thaw_kernel_threads();
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800274 break;
275
Jiri Slabyb694e522010-01-27 23:47:50 +0100276 case SNAPSHOT_PREF_IMAGE_SIZE:
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800277 image_size = arg;
278 break;
279
Rafael J. Wysockiaf508b32007-10-26 00:59:31 +0200280 case SNAPSHOT_GET_IMAGE_SIZE:
281 if (!data->ready) {
282 error = -ENODATA;
283 break;
284 }
285 size = snapshot_get_image_size();
286 size <<= PAGE_SHIFT;
287 error = put_user(size, (loff_t __user *)arg);
288 break;
289
Jiri Slabyb694e522010-01-27 23:47:50 +0100290 case SNAPSHOT_AVAIL_SWAP_SIZE:
Rafael J. Wysockiaf508b32007-10-26 00:59:31 +0200291 size = count_swap_pages(data->swap, 1);
292 size <<= PAGE_SHIFT;
293 error = put_user(size, (loff_t __user *)arg);
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800294 break;
295
Jiri Slabyb694e522010-01-27 23:47:50 +0100296 case SNAPSHOT_ALLOC_SWAP_PAGE:
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800297 if (data->swap < 0 || data->swap >= MAX_SWAPFILES) {
298 error = -ENODEV;
299 break;
300 }
Rafael J. Wysockid1d241c2007-05-06 14:50:47 -0700301 offset = alloc_swapdev_block(data->swap);
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800302 if (offset) {
303 offset <<= PAGE_SHIFT;
Rafael J. Wysockicc5d2072007-10-26 01:03:33 +0200304 error = put_user(offset, (loff_t __user *)arg);
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800305 } else {
306 error = -ENOSPC;
307 }
308 break;
309
310 case SNAPSHOT_FREE_SWAP_PAGES:
311 if (data->swap < 0 || data->swap >= MAX_SWAPFILES) {
312 error = -ENODEV;
313 break;
314 }
Rafael J. Wysockid1d241c2007-05-06 14:50:47 -0700315 free_all_swap_pages(data->swap);
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800316 break;
317
Luca Tettamanti9b238202006-03-23 03:00:09 -0800318 case SNAPSHOT_S2RAM:
319 if (!data->frozen) {
320 error = -EPERM;
321 break;
322 }
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700323 /*
324 * Tasks are frozen and the notifiers have been called with
325 * PM_HIBERNATION_PREPARE
326 */
327 error = suspend_devices_and_enter(PM_SUSPEND_MEM);
Rafael J. Wysocki36cb7032011-05-10 21:10:13 +0200328 data->ready = 0;
Luca Tettamanti9b238202006-03-23 03:00:09 -0800329 break;
330
Rafael J. Wysockieb57c1c2007-10-26 01:01:10 +0200331 case SNAPSHOT_PLATFORM_SUPPORT:
332 data->platform_support = !!arg;
333 break;
334
335 case SNAPSHOT_POWER_OFF:
336 if (data->platform_support)
337 error = hibernation_platform_enter();
338 break;
339
Rafael J. Wysocki37b2ba12006-12-06 20:34:15 -0800340 case SNAPSHOT_SET_SWAP_AREA:
Rafael J. Wysockid1d241c2007-05-06 14:50:47 -0700341 if (swsusp_swap_in_use()) {
Rafael J. Wysocki37b2ba12006-12-06 20:34:15 -0800342 error = -EPERM;
343 } else {
344 struct resume_swap_area swap_area;
345 dev_t swdev;
346
347 error = copy_from_user(&swap_area, (void __user *)arg,
348 sizeof(struct resume_swap_area));
349 if (error) {
350 error = -EFAULT;
351 break;
352 }
353
354 /*
355 * User space encodes device types as two-byte values,
356 * so we need to recode them
357 */
Jiri Slabyd88d4052010-04-10 22:28:56 +0200358 swdev = new_decode_dev(swap_area.dev);
Rafael J. Wysocki37b2ba12006-12-06 20:34:15 -0800359 if (swdev) {
360 offset = swap_area.offset;
Rafael J. Wysocki7bf23682007-01-05 16:36:28 -0800361 data->swap = swap_type_of(swdev, offset, NULL);
Rafael J. Wysocki37b2ba12006-12-06 20:34:15 -0800362 if (data->swap < 0)
363 error = -ENODEV;
364 } else {
365 data->swap = -1;
366 error = -EINVAL;
367 }
368 }
369 break;
370
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800371 default:
372 error = -ENOTTY;
373
374 }
Rafael J. Wysocki25f2f3d2008-06-11 22:09:45 +0200375
376 mutex_unlock(&pm_mutex);
377
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800378 return error;
379}
380
Ben Hutchingsc3360782011-12-27 22:54:52 +0100381#ifdef CONFIG_COMPAT
382
383struct compat_resume_swap_area {
384 compat_loff_t offset;
385 u32 dev;
386} __packed;
387
388static long
389snapshot_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
390{
391 BUILD_BUG_ON(sizeof(loff_t) != sizeof(compat_loff_t));
392
393 switch (cmd) {
394 case SNAPSHOT_GET_IMAGE_SIZE:
395 case SNAPSHOT_AVAIL_SWAP_SIZE:
396 case SNAPSHOT_ALLOC_SWAP_PAGE: {
397 compat_loff_t __user *uoffset = compat_ptr(arg);
398 loff_t offset;
399 mm_segment_t old_fs;
400 int err;
401
402 old_fs = get_fs();
403 set_fs(KERNEL_DS);
404 err = snapshot_ioctl(file, cmd, (unsigned long) &offset);
405 set_fs(old_fs);
406 if (!err && put_user(offset, uoffset))
407 err = -EFAULT;
408 return err;
409 }
410
411 case SNAPSHOT_CREATE_IMAGE:
412 return snapshot_ioctl(file, cmd,
413 (unsigned long) compat_ptr(arg));
414
415 case SNAPSHOT_SET_SWAP_AREA: {
416 struct compat_resume_swap_area __user *u_swap_area =
417 compat_ptr(arg);
418 struct resume_swap_area swap_area;
419 mm_segment_t old_fs;
420 int err;
421
422 err = get_user(swap_area.offset, &u_swap_area->offset);
423 err |= get_user(swap_area.dev, &u_swap_area->dev);
424 if (err)
425 return -EFAULT;
426 old_fs = get_fs();
427 set_fs(KERNEL_DS);
428 err = snapshot_ioctl(file, SNAPSHOT_SET_SWAP_AREA,
429 (unsigned long) &swap_area);
430 set_fs(old_fs);
431 return err;
432 }
433
434 default:
435 return snapshot_ioctl(file, cmd, arg);
436 }
437}
438
439#endif /* CONFIG_COMPAT */
440
Helge Deller15ad7cd2006-12-06 20:40:36 -0800441static const struct file_operations snapshot_fops = {
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800442 .open = snapshot_open,
443 .release = snapshot_release,
444 .read = snapshot_read,
445 .write = snapshot_write,
446 .llseek = no_llseek,
Alan Cox52d11022008-06-11 22:07:52 +0200447 .unlocked_ioctl = snapshot_ioctl,
Ben Hutchingsc3360782011-12-27 22:54:52 +0100448#ifdef CONFIG_COMPAT
449 .compat_ioctl = snapshot_compat_ioctl,
450#endif
Rafael J. Wysocki6e1819d2006-03-23 03:00:03 -0800451};
452
453static struct miscdevice snapshot_device = {
454 .minor = SNAPSHOT_MINOR,
455 .name = "snapshot",
456 .fops = &snapshot_fops,
457};
458
459static int __init snapshot_device_init(void)
460{
461 return misc_register(&snapshot_device);
462};
463
464device_initcall(snapshot_device_init);