Import 2.3.30
[davej-history.git] / drivers / block / loop.c
blob3459ec1fd01e4bedcca6115058bcfe66fc8a3439
1 /*
2 * linux/drivers/block/loop.c
4 * Written by Theodore Ts'o, 3/29/93
5 *
6 * Copyright 1993 by Theodore Ts'o. Redistribution of this file is
7 * permitted under the GNU Public License.
9 * DES encryption plus some minor changes by Werner Almesberger, 30-MAY-1993
10 * more DES encryption plus IDEA encryption by Nicholas J. Leon, June 20, 1996
12 * Modularized and updated for 1.1.16 kernel - Mitch Dsouza 28th May 1994
13 * Adapted for 1.3.59 kernel - Andries Brouwer, 1 Feb 1996
15 * Fixed do_loop_request() re-entrancy - Vincent.Renardias@waw.com Mar 20, 1997
17 * Handle sparse backing files correctly - Kenn Humborg, Jun 28, 1998
19 * Loadable modules and other fixes by AK, 1998
21 * Make real block number available to downstream transfer functions, enables
22 * CBC (and relatives) mode encryption requiring unique IVs per data block.
23 * Reed H. Petty, rhp@draper.net
25 * Maximum number of loop devices now dynamic via max_loop module parameter.
26 * Russell Kroll <rkroll@exploits.org> 19990701
28 * Maximum number of loop devices when compiled-in now selectable by passing
29 * max_loop=<1-255> to the kernel on boot.
30 * Erik I. Bolsø, <eriki@himolde.no>, Oct 31, 1999
32 * Still To Fix:
33 * - Advisory locking is ignored here.
34 * - Should use an own CAP_* category instead of CAP_SYS_ADMIN
35 * - Should use the underlying filesystems/devices read function if possible
36 * to support read ahead (and for write)
38 * WARNING/FIXME:
39 * - The block number as IV passing to low level transfer functions is broken:
40 * it passes the underlying device's block number instead of the
41 * offset. This makes it change for a given block when the file is
42 * moved/restored/copied and also doesn't work over NFS.
43 */
45 #include <linux/module.h>
47 #include <linux/sched.h>
48 #include <linux/fs.h>
49 #include <linux/file.h>
50 #include <linux/stat.h>
51 #include <linux/errno.h>
52 #include <linux/major.h>
54 #include <linux/init.h>
56 #include <asm/uaccess.h>
58 #include <linux/loop.h>
60 #define MAJOR_NR LOOP_MAJOR
62 #define DEVICE_NAME "loop"
63 #define DEVICE_REQUEST do_lo_request
64 #define DEVICE_NR(device) (MINOR(device))
65 #define DEVICE_ON(device)
66 #define DEVICE_OFF(device)
67 #define DEVICE_NO_RANDOM
68 #define TIMEOUT_VALUE (6 * HZ)
69 #include <linux/blk.h>
71 #include <linux/malloc.h>
72 static int max_loop = 8;
73 static struct loop_device *loop_dev;
74 static int *loop_sizes;
75 static int *loop_blksizes;
77 #define FALSE 0
78 #define TRUE (!FALSE)
80 /* Forward declaration of function to create missing blocks in the
81 backing file (can happen if the backing file is sparse) */
82 static int create_missing_block(struct loop_device *lo, int block, int blksize);
85 * Transfer functions
87 static int transfer_none(struct loop_device *lo, int cmd, char *raw_buf,
88 char *loop_buf, int size, int real_block)
90 if (cmd == READ)
91 memcpy(loop_buf, raw_buf, size);
92 else
93 memcpy(raw_buf, loop_buf, size);
94 return 0;
97 static int transfer_xor(struct loop_device *lo, int cmd, char *raw_buf,
98 char *loop_buf, int size, int real_block)
100 char *in, *out, *key;
101 int i, keysize;
103 if (cmd == READ) {
104 in = raw_buf;
105 out = loop_buf;
106 } else {
107 in = loop_buf;
108 out = raw_buf;
110 key = lo->lo_encrypt_key;
111 keysize = lo->lo_encrypt_key_size;
112 for (i=0; i < size; i++)
113 *out++ = *in++ ^ key[(i & 511) % keysize];
114 return 0;
117 static int none_status(struct loop_device *lo, struct loop_info *info)
119 return 0;
122 static int xor_status(struct loop_device *lo, struct loop_info *info)
124 if (info->lo_encrypt_key_size <= 0)
125 return -EINVAL;
126 return 0;
129 struct loop_func_table none_funcs = {
130 number: LO_CRYPT_NONE,
131 transfer: transfer_none,
132 init: none_status
135 struct loop_func_table xor_funcs = {
136 number: LO_CRYPT_XOR,
137 transfer: transfer_xor,
138 init: xor_status
141 /* xfer_funcs[0] is special - its release function is never called */
142 struct loop_func_table *xfer_funcs[MAX_LO_CRYPT] = {
143 &none_funcs,
144 &xor_funcs
147 #define MAX_DISK_SIZE 1024*1024*1024
149 static void figure_loop_size(struct loop_device *lo)
151 int size;
153 if (S_ISREG(lo->lo_dentry->d_inode->i_mode))
154 size = (lo->lo_dentry->d_inode->i_size - lo->lo_offset) >> BLOCK_SIZE_BITS;
155 else {
156 kdev_t lodev = lo->lo_device;
157 if (blk_size[MAJOR(lodev)])
158 size = blk_size[MAJOR(lodev)][MINOR(lodev)] -
159 (lo->lo_offset >> BLOCK_SIZE_BITS);
160 else
161 size = MAX_DISK_SIZE;
164 loop_sizes[lo->lo_number] = size;
167 static void do_lo_request(void)
169 int real_block, block, offset, len, blksize, size;
170 char *dest_addr;
171 struct loop_device *lo;
172 struct buffer_head *bh;
173 struct request *current_request;
174 int block_present;
176 repeat:
177 INIT_REQUEST;
178 current_request=CURRENT;
179 CURRENT=current_request->next;
180 if (MINOR(current_request->rq_dev) >= max_loop)
181 goto error_out;
182 lo = &loop_dev[MINOR(current_request->rq_dev)];
183 if (!lo->lo_dentry || !lo->transfer)
184 goto error_out;
186 blksize = BLOCK_SIZE;
187 if (blksize_size[MAJOR(lo->lo_device)]) {
188 blksize = blksize_size[MAJOR(lo->lo_device)][MINOR(lo->lo_device)];
189 if (!blksize)
190 blksize = BLOCK_SIZE;
193 dest_addr = current_request->buffer;
195 if (blksize < 512) {
196 block = current_request->sector * (512/blksize);
197 offset = 0;
198 } else {
199 block = current_request->sector / (blksize >> 9);
200 offset = (current_request->sector % (blksize >> 9)) << 9;
202 block += lo->lo_offset / blksize;
203 offset += lo->lo_offset % blksize;
204 if (offset > blksize) {
205 block++;
206 offset -= blksize;
208 len = current_request->current_nr_sectors << 9;
210 if (current_request->cmd == WRITE) {
211 if (lo->lo_flags & LO_FLAGS_READ_ONLY)
212 goto error_out;
213 } else if (current_request->cmd != READ) {
214 printk(KERN_ERR "unknown loop device command (%d)?!?", current_request->cmd);
215 goto error_out;
217 spin_unlock_irq(&io_request_lock);
218 while (len > 0) {
220 size = blksize - offset;
221 if (size > len)
222 size = len;
224 real_block = block;
225 block_present = TRUE;
227 if (lo->lo_flags & LO_FLAGS_DO_BMAP) {
228 real_block = bmap(lo->lo_dentry->d_inode, block);
229 if (!real_block) {
231 /* The backing file is a sparse file and this block
232 doesn't exist. If reading, return zeros. If
233 writing, force the underlying FS to create
234 the block */
235 if (current_request->cmd == READ) {
236 memset(dest_addr, 0, size);
237 block_present = FALSE;
238 } else {
239 if (!create_missing_block(lo, block, blksize)) {
240 goto error_out_lock;
242 real_block = bmap(lo->lo_dentry->d_inode, block);
248 if (block_present) {
249 bh = getblk(lo->lo_device, real_block, blksize);
250 if (!bh) {
251 printk(KERN_ERR "loop: device %s: getblk(-, %d, %d) returned NULL",
252 kdevname(lo->lo_device),
253 block, blksize);
254 goto error_out_lock;
256 if (!buffer_uptodate(bh) && ((current_request->cmd == READ) ||
257 (offset || (len < blksize)))) {
258 ll_rw_block(READ, 1, &bh);
259 wait_on_buffer(bh);
260 if (!buffer_uptodate(bh)) {
261 brelse(bh);
262 goto error_out_lock;
266 if ((lo->transfer)(lo, current_request->cmd, bh->b_data + offset,
267 dest_addr, size, real_block)) {
268 printk(KERN_ERR "loop: transfer error block %d\n", block);
269 brelse(bh);
270 goto error_out_lock;
273 if (current_request->cmd == WRITE) {
274 mark_buffer_uptodate(bh, 1);
275 mark_buffer_dirty(bh, 1);
277 brelse(bh);
279 dest_addr += size;
280 len -= size;
281 offset = 0;
282 block++;
284 spin_lock_irq(&io_request_lock);
285 current_request->next=CURRENT;
286 CURRENT=current_request;
287 end_request(1);
288 goto repeat;
289 error_out_lock:
290 spin_lock_irq(&io_request_lock);
291 error_out:
292 current_request->next=CURRENT;
293 CURRENT=current_request;
294 end_request(0);
295 goto repeat;
298 static int create_missing_block(struct loop_device *lo, int block, int blksize)
300 struct file *file;
301 loff_t new_offset;
302 char zero_buf[1] = { 0 };
303 ssize_t retval;
304 mm_segment_t old_fs;
305 struct inode *inode;
307 file = lo->lo_backing_file;
308 if (file == NULL) {
309 printk(KERN_WARNING "loop: cannot create block - no backing file\n");
310 return FALSE;
313 if (file->f_op == NULL) {
314 printk(KERN_WARNING "loop: cannot create block - no file ops\n");
315 return FALSE;
318 new_offset = block * blksize;
320 if (file->f_op->llseek != NULL) {
321 file->f_op->llseek(file, new_offset, 0);
322 } else {
323 /* Do what the default llseek() code would have done */
324 file->f_pos = new_offset;
325 file->f_reada = 0;
326 file->f_version = ++event;
329 if (file->f_op->write == NULL) {
330 printk(KERN_WARNING "loop: cannot create block - file not writeable\n");
331 return FALSE;
334 old_fs = get_fs();
335 set_fs(get_ds());
337 inode = file->f_dentry->d_inode;
338 down(&inode->i_sem);
339 retval = file->f_op->write(file, zero_buf, 1, &file->f_pos);
340 up(&inode->i_sem);
342 set_fs(old_fs);
344 if (retval < 0) {
345 printk(KERN_WARNING "loop: cannot create block - FS write failed: code %d\n",
346 retval);
347 return FALSE;
348 } else {
349 return TRUE;
353 static int loop_set_fd(struct loop_device *lo, kdev_t dev, unsigned int arg)
355 struct file *file;
356 struct inode *inode;
357 int error;
359 MOD_INC_USE_COUNT;
361 error = -EBUSY;
362 if (lo->lo_dentry)
363 goto out;
365 error = -EBADF;
366 file = fget(arg);
367 if (!file)
368 goto out;
370 error = -EINVAL;
371 inode = file->f_dentry->d_inode;
372 if (!inode) {
373 printk(KERN_ERR "loop_set_fd: NULL inode?!?\n");
374 goto out_putf;
377 if (S_ISBLK(inode->i_mode)) {
378 error = blkdev_open(inode, file);
379 lo->lo_device = inode->i_rdev;
380 lo->lo_flags = 0;
382 /* Backed by a block device - don't need to hold onto
383 a file structure */
384 lo->lo_backing_file = NULL;
385 } else if (S_ISREG(inode->i_mode)) {
386 if (!inode->i_op->get_block) {
387 printk(KERN_ERR "loop: device has no block access/not implemented\n");
388 goto out_putf;
391 /* Backed by a regular file - we need to hold onto
392 a file structure for this file. We'll use it to
393 write to blocks that are not already present in
394 a sparse file. We create a new file structure
395 based on the one passed to us via 'arg'. This is
396 to avoid changing the file structure that the
397 caller is using */
399 lo->lo_device = inode->i_dev;
400 lo->lo_flags = LO_FLAGS_DO_BMAP;
402 error = -ENFILE;
403 lo->lo_backing_file = get_empty_filp();
404 if (lo->lo_backing_file) {
405 lo->lo_backing_file->f_mode = file->f_mode;
406 lo->lo_backing_file->f_pos = file->f_pos;
407 lo->lo_backing_file->f_flags = file->f_flags;
408 lo->lo_backing_file->f_owner = file->f_owner;
409 lo->lo_backing_file->f_dentry = file->f_dentry;
410 lo->lo_backing_file->f_op = file->f_op;
411 lo->lo_backing_file->private_data = file->private_data;
412 file_moveto(lo->lo_backing_file, file);
414 error = get_write_access(inode);
415 if (error) {
416 put_filp(lo->lo_backing_file);
417 lo->lo_backing_file = NULL;
421 if (error)
422 goto out_putf;
424 if (IS_RDONLY (inode) || is_read_only(lo->lo_device)) {
425 lo->lo_flags |= LO_FLAGS_READ_ONLY;
426 set_device_ro(dev, 1);
427 } else {
428 vmtruncate (inode, 0);
429 set_device_ro(dev, 0);
432 lo->lo_dentry = dget(file->f_dentry);
433 lo->transfer = NULL;
434 lo->ioctl = NULL;
435 figure_loop_size(lo);
437 out_putf:
438 fput(file);
439 out:
440 if (error)
441 MOD_DEC_USE_COUNT;
442 return error;
445 static int loop_release_xfer(struct loop_device *lo)
447 int err = 0;
448 if (lo->lo_encrypt_type) {
449 struct loop_func_table *xfer= xfer_funcs[lo->lo_encrypt_type];
450 if (xfer && xfer->release)
451 err = xfer->release(lo);
452 if (xfer && xfer->unlock)
453 xfer->unlock(lo);
454 lo->lo_encrypt_type = 0;
456 return err;
459 static int loop_init_xfer(struct loop_device *lo, int type,struct loop_info *i)
461 int err = 0;
462 if (type) {
463 struct loop_func_table *xfer = xfer_funcs[type];
464 if (xfer->init)
465 err = xfer->init(lo, i);
466 if (!err) {
467 lo->lo_encrypt_type = type;
468 if (xfer->lock)
469 xfer->lock(lo);
472 return err;
475 static int loop_clr_fd(struct loop_device *lo, kdev_t dev)
477 struct dentry *dentry = lo->lo_dentry;
479 if (!dentry)
480 return -ENXIO;
481 if (lo->lo_refcnt > 1) /* we needed one fd for the ioctl */
482 return -EBUSY;
484 if (S_ISBLK(dentry->d_inode->i_mode))
485 blkdev_release (dentry->d_inode);
486 lo->lo_dentry = NULL;
488 if (lo->lo_backing_file != NULL) {
489 fput(lo->lo_backing_file);
490 lo->lo_backing_file = NULL;
491 } else {
492 dput(dentry);
495 loop_release_xfer(lo);
496 lo->transfer = NULL;
497 lo->ioctl = NULL;
498 lo->lo_device = 0;
499 lo->lo_encrypt_type = 0;
500 lo->lo_offset = 0;
501 lo->lo_encrypt_key_size = 0;
502 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
503 memset(lo->lo_name, 0, LO_NAME_SIZE);
504 loop_sizes[lo->lo_number] = 0;
505 invalidate_buffers(dev);
506 MOD_DEC_USE_COUNT;
507 return 0;
510 static int loop_set_status(struct loop_device *lo, struct loop_info *arg)
512 struct loop_info info;
513 int err;
514 unsigned int type;
516 if (lo->lo_encrypt_key_size && lo->lo_key_owner != current->uid &&
517 !capable(CAP_SYS_ADMIN))
518 return -EPERM;
519 if (!lo->lo_dentry)
520 return -ENXIO;
521 if (copy_from_user(&info, arg, sizeof (struct loop_info)))
522 return -EFAULT;
523 if ((unsigned int) info.lo_encrypt_key_size > LO_KEY_SIZE)
524 return -EINVAL;
525 type = info.lo_encrypt_type;
526 if (type >= MAX_LO_CRYPT || xfer_funcs[type] == NULL)
527 return -EINVAL;
528 err = loop_release_xfer(lo);
529 if (!err)
530 err = loop_init_xfer(lo, type, &info);
531 if (err)
532 return err;
534 lo->lo_offset = info.lo_offset;
535 strncpy(lo->lo_name, info.lo_name, LO_NAME_SIZE);
537 lo->transfer = xfer_funcs[type]->transfer;
538 lo->ioctl = xfer_funcs[type]->ioctl;
539 lo->lo_encrypt_key_size = info.lo_encrypt_key_size;
540 lo->lo_init[0] = info.lo_init[0];
541 lo->lo_init[1] = info.lo_init[1];
542 if (info.lo_encrypt_key_size) {
543 memcpy(lo->lo_encrypt_key, info.lo_encrypt_key,
544 info.lo_encrypt_key_size);
545 lo->lo_key_owner = current->uid;
547 figure_loop_size(lo);
548 return 0;
551 static int loop_get_status(struct loop_device *lo, struct loop_info *arg)
553 struct loop_info info;
555 if (!lo->lo_dentry)
556 return -ENXIO;
557 if (!arg)
558 return -EINVAL;
559 memset(&info, 0, sizeof(info));
560 info.lo_number = lo->lo_number;
561 info.lo_device = kdev_t_to_nr(lo->lo_dentry->d_inode->i_dev);
562 info.lo_inode = lo->lo_dentry->d_inode->i_ino;
563 info.lo_rdevice = kdev_t_to_nr(lo->lo_device);
564 info.lo_offset = lo->lo_offset;
565 info.lo_flags = lo->lo_flags;
566 strncpy(info.lo_name, lo->lo_name, LO_NAME_SIZE);
567 info.lo_encrypt_type = lo->lo_encrypt_type;
568 if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
569 info.lo_encrypt_key_size = lo->lo_encrypt_key_size;
570 memcpy(info.lo_encrypt_key, lo->lo_encrypt_key,
571 lo->lo_encrypt_key_size);
573 return copy_to_user(arg, &info, sizeof(info)) ? -EFAULT : 0;
576 static int lo_ioctl(struct inode * inode, struct file * file,
577 unsigned int cmd, unsigned long arg)
579 struct loop_device *lo;
580 int dev;
582 if (!inode)
583 return -EINVAL;
584 if (MAJOR(inode->i_rdev) != MAJOR_NR) {
585 printk(KERN_WARNING "lo_ioctl: pseudo-major != %d\n", MAJOR_NR);
586 return -ENODEV;
588 dev = MINOR(inode->i_rdev);
589 if (dev >= max_loop)
590 return -ENODEV;
591 lo = &loop_dev[dev];
592 switch (cmd) {
593 case LOOP_SET_FD:
594 return loop_set_fd(lo, inode->i_rdev, arg);
595 case LOOP_CLR_FD:
596 return loop_clr_fd(lo, inode->i_rdev);
597 case LOOP_SET_STATUS:
598 return loop_set_status(lo, (struct loop_info *) arg);
599 case LOOP_GET_STATUS:
600 return loop_get_status(lo, (struct loop_info *) arg);
601 case BLKGETSIZE: /* Return device size */
602 if (!lo->lo_dentry)
603 return -ENXIO;
604 if (!arg)
605 return -EINVAL;
606 return put_user(loop_sizes[lo->lo_number] << 1, (long *) arg);
607 default:
608 return lo->ioctl ? lo->ioctl(lo, cmd, arg) : -EINVAL;
610 return 0;
613 static int lo_open(struct inode *inode, struct file *file)
615 struct loop_device *lo;
616 int dev, type;
619 if (!inode)
620 return -EINVAL;
621 if (MAJOR(inode->i_rdev) != MAJOR_NR) {
622 printk(KERN_WARNING "lo_open: pseudo-major != %d\n", MAJOR_NR);
623 return -ENODEV;
625 dev = MINOR(inode->i_rdev);
626 if (dev >= max_loop) {
627 return -ENODEV;
629 lo = &loop_dev[dev];
631 type = lo->lo_encrypt_type;
632 if (type && xfer_funcs[type] && xfer_funcs[type]->lock)
633 xfer_funcs[type]->lock(lo);
634 lo->lo_refcnt++;
635 MOD_INC_USE_COUNT;
636 return 0;
639 static int lo_release(struct inode *inode, struct file *file)
641 struct loop_device *lo;
642 int dev, err;
644 if (!inode)
645 return 0;
646 if (MAJOR(inode->i_rdev) != MAJOR_NR) {
647 printk(KERN_WARNING "lo_release: pseudo-major != %d\n", MAJOR_NR);
648 return 0;
650 dev = MINOR(inode->i_rdev);
651 if (dev >= max_loop)
652 return 0;
653 err = fsync_dev(inode->i_rdev);
654 lo = &loop_dev[dev];
655 if (lo->lo_refcnt <= 0)
656 printk(KERN_ERR "lo_release: refcount(%d) <= 0\n", lo->lo_refcnt);
657 else {
658 int type = lo->lo_encrypt_type;
659 --lo->lo_refcnt;
660 if (xfer_funcs[type] && xfer_funcs[type]->unlock)
661 xfer_funcs[type]->unlock(lo);
662 MOD_DEC_USE_COUNT;
664 return err;
667 static struct file_operations lo_fops = {
668 NULL, /* lseek - default */
669 block_read, /* read - general block-dev read */
670 block_write, /* write - general block-dev write */
671 NULL, /* readdir - bad */
672 NULL, /* poll */
673 lo_ioctl, /* ioctl */
674 NULL, /* mmap */
675 lo_open, /* open */
676 NULL, /* flush */
677 lo_release /* release */
681 * And now the modules code and kernel interface.
683 #ifdef MODULE
684 #define loop_init init_module
685 MODULE_PARM(max_loop, "i");
686 MODULE_PARM_DESC(max_loop, "Maximum number of loop devices (1-255)");
687 #endif
689 int loop_register_transfer(struct loop_func_table *funcs)
691 if ((unsigned)funcs->number > MAX_LO_CRYPT || xfer_funcs[funcs->number])
692 return -EINVAL;
693 xfer_funcs[funcs->number] = funcs;
694 return 0;
697 int loop_unregister_transfer(int number)
699 struct loop_device *lo;
701 if ((unsigned)number >= MAX_LO_CRYPT)
702 return -EINVAL;
703 for (lo = &loop_dev[0]; lo < &loop_dev[max_loop]; lo++) {
704 int type = lo->lo_encrypt_type;
705 if (type == number) {
706 xfer_funcs[type]->release(lo);
707 lo->transfer = NULL;
708 lo->lo_encrypt_type = 0;
711 xfer_funcs[number] = NULL;
712 return 0;
715 EXPORT_SYMBOL(loop_register_transfer);
716 EXPORT_SYMBOL(loop_unregister_transfer);
718 int __init loop_init(void)
720 int i;
722 if (register_blkdev(MAJOR_NR, "loop", &lo_fops)) {
723 printk(KERN_WARNING "Unable to get major number %d for loop device\n",
724 MAJOR_NR);
725 return -EIO;
728 if ((max_loop < 1) || (max_loop > 255)) {
729 printk (KERN_WARNING "loop: invalid max_loop (must be between 1 and 255), using default (8)\n");
730 max_loop = 8;
733 printk(KERN_INFO "loop: registered device at major %d\n", MAJOR_NR);
734 printk(KERN_INFO "loop: enabling %d loop devices\n", max_loop);
736 loop_dev = kmalloc (max_loop * sizeof(struct loop_device), GFP_KERNEL);
737 if (!loop_dev) {
738 printk (KERN_ERR "loop: Unable to create loop_dev\n");
739 return -ENOMEM;
742 loop_sizes = kmalloc(max_loop * sizeof(int), GFP_KERNEL);
743 if (!loop_sizes) {
744 printk (KERN_ERR "loop: Unable to create loop_sizes\n");
745 kfree (loop_dev);
746 return -ENOMEM;
749 loop_blksizes = kmalloc (max_loop * sizeof(int), GFP_KERNEL);
750 if (!loop_blksizes) {
751 printk (KERN_ERR "loop: Unable to create loop_blksizes\n");
752 kfree (loop_dev);
753 kfree (loop_sizes);
754 return -ENOMEM;
757 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
758 for (i=0; i < max_loop; i++) {
759 memset(&loop_dev[i], 0, sizeof(struct loop_device));
760 loop_dev[i].lo_number = i;
762 memset(loop_sizes, 0, max_loop * sizeof(int));
763 memset(loop_blksizes, 0, max_loop * sizeof(int));
764 blk_size[MAJOR_NR] = loop_sizes;
765 blksize_size[MAJOR_NR] = loop_blksizes;
767 return 0;
770 #ifdef MODULE
771 void cleanup_module(void)
773 if (unregister_blkdev(MAJOR_NR, "loop") != 0)
774 printk(KERN_WARNING "loop: cannot unregister blkdev\n");
776 kfree (loop_dev);
777 kfree (loop_sizes);
778 kfree (loop_blksizes);
780 #endif
782 #ifndef MODULE
783 static int __init max_loop_setup(char *str)
785 max_loop = simple_strtol(str,NULL,0);
786 return 1;
789 __setup("max_loop=", max_loop_setup);
790 #endif