2 * Copyright (C) 1996, 1997 Claus-Justus Heine.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 * This file contains the code that registers the zftape frontend
20 * to the ftape floppy tape driver for Linux
23 #include <linux/config.h>
24 #include <linux/module.h>
25 #include <linux/errno.h>
26 #include <linux/version.h>
28 #include <linux/kernel.h>
29 #include <linux/signal.h>
30 #include <linux/major.h>
31 #include <linux/slab.h>
33 #include <linux/kmod.h>
35 #include <linux/fcntl.h>
36 #include <linux/smp_lock.h>
37 #include <linux/devfs_fs_kernel.h>
39 #include <linux/zftape.h>
40 #include <linux/init.h>
41 #include <linux/device.h>
43 #include "../zftape/zftape-init.h"
44 #include "../zftape/zftape-read.h"
45 #include "../zftape/zftape-write.h"
46 #include "../zftape/zftape-ctl.h"
47 #include "../zftape/zftape-buffers.h"
49 char zft_src
[] __initdata
= "$Source: /homes/cvs/ftape-stacked/ftape/zftape/zftape-init.c,v $";
50 char zft_rev
[] __initdata
= "$Revision: 1.8 $";
51 char zft_dat
[] __initdata
= "$Date: 1997/11/06 00:48:56 $";
53 MODULE_AUTHOR("(c) 1996, 1997 Claus-Justus Heine "
54 "(claus@momo.math.rwth-aachen.de)");
55 MODULE_DESCRIPTION(ZFTAPE_VERSION
" - "
56 "VFS interface for the Linux floppy tape driver. "
57 "Support for QIC-113 compatible volume table "
58 "and builtin compression (lzrw3 algorithm)");
59 MODULE_SUPPORTED_DEVICE("char-major-27");
60 MODULE_LICENSE("GPL");
64 struct zft_cmpr_ops
*zft_cmpr_ops
= NULL
;
65 const ftape_info
*zft_status
;
69 static unsigned long busy_flag
;
71 static sigset_t orig_sigmask
;
73 /* the interface to the kernel vfs layer
76 /* Note about llseek():
78 * st.c and tpqic.c update fp->f_pos but don't implment llseek() and
79 * initialize the llseek component of the file_ops struct with NULL.
80 * This means that the user will get the default seek, but the tape
81 * device will not respect the new position, but happily read from the
82 * old position. Think a zftape specific llseek() function would be
83 * better, returning -ESPIPE. TODO.
86 static int zft_open (struct inode
*ino
, struct file
*filep
);
87 static int zft_close(struct inode
*ino
, struct file
*filep
);
88 static int zft_ioctl(struct inode
*ino
, struct file
*filep
,
89 unsigned int command
, unsigned long arg
);
90 static int zft_mmap(struct file
*filep
, struct vm_area_struct
*vma
);
91 static ssize_t
zft_read (struct file
*fp
, char __user
*buff
,
92 size_t req_len
, loff_t
*ppos
);
93 static ssize_t
zft_write(struct file
*fp
, const char __user
*buff
,
94 size_t req_len
, loff_t
*ppos
);
96 static struct file_operations zft_cdev
=
104 .release
= zft_close
,
107 static struct class_simple
*zft_class
;
109 /* Open floppy tape device
111 static int zft_open(struct inode
*ino
, struct file
*filep
)
114 TRACE_FUN(ft_t_flow
);
116 nonseekable_open(ino
, filep
);
117 TRACE(ft_t_flow
, "called for minor %d", iminor(ino
));
118 if ( test_and_set_bit(0,&busy_flag
) ) {
119 TRACE_ABORT(-EBUSY
, ft_t_warn
, "failed: already busy");
121 if ((iminor(ino
) & ~(ZFT_MINOR_OP_MASK
| FTAPE_NO_REWIND
))
124 clear_bit(0,&busy_flag
);
125 TRACE_ABORT(-ENXIO
, ft_t_err
, "failed: invalid unit nr");
127 orig_sigmask
= current
->blocked
;
128 sigfillset(¤t
->blocked
);
129 result
= _zft_open(iminor(ino
), filep
->f_flags
& O_ACCMODE
);
131 current
->blocked
= orig_sigmask
; /* restore mask */
132 clear_bit(0,&busy_flag
);
133 TRACE_ABORT(result
, ft_t_err
, "_ftape_open failed");
135 /* Mask signals that will disturb proper operation of the
136 * program that is calling.
138 current
->blocked
= orig_sigmask
;
139 sigaddsetmask (¤t
->blocked
, _DO_BLOCK
);
144 /* Close floppy tape device
146 static int zft_close(struct inode
*ino
, struct file
*filep
)
149 TRACE_FUN(ft_t_flow
);
151 if ( !test_bit(0,&busy_flag
) || iminor(ino
) != zft_unit
) {
152 TRACE(ft_t_err
, "failed: not busy or wrong unit");
155 sigfillset(¤t
->blocked
);
156 result
= _zft_close();
158 TRACE(ft_t_err
, "_zft_close failed");
160 current
->blocked
= orig_sigmask
; /* restore before open state */
161 clear_bit(0,&busy_flag
);
165 /* Ioctl for floppy tape device
167 static int zft_ioctl(struct inode
*ino
, struct file
*filep
,
168 unsigned int command
, unsigned long arg
)
171 sigset_t old_sigmask
;
172 TRACE_FUN(ft_t_flow
);
174 if ( !test_bit(0,&busy_flag
) || iminor(ino
) != zft_unit
|| ft_failure
) {
175 TRACE_ABORT(-EIO
, ft_t_err
,
176 "failed: not busy, failure or wrong unit");
178 old_sigmask
= current
->blocked
; /* save mask */
179 sigfillset(¤t
->blocked
);
180 /* This will work as long as sizeof(void *) == sizeof(long) */
181 result
= _zft_ioctl(command
, (void __user
*) arg
);
182 current
->blocked
= old_sigmask
; /* restore mask */
186 /* Ioctl for floppy tape device
188 static int zft_mmap(struct file
*filep
, struct vm_area_struct
*vma
)
191 sigset_t old_sigmask
;
192 TRACE_FUN(ft_t_flow
);
194 if ( !test_bit(0,&busy_flag
) ||
195 iminor(filep
->f_dentry
->d_inode
) != zft_unit
||
198 TRACE_ABORT(-EIO
, ft_t_err
,
199 "failed: not busy, failure or wrong unit");
201 old_sigmask
= current
->blocked
; /* save mask */
202 sigfillset(¤t
->blocked
);
203 if ((result
= ftape_mmap(vma
)) >= 0) {
204 #ifndef MSYNC_BUG_WAS_FIXED
205 static struct vm_operations_struct dummy
= { NULL
, };
206 vma
->vm_ops
= &dummy
;
209 current
->blocked
= old_sigmask
; /* restore mask */
213 /* Read from floppy tape device
215 static ssize_t
zft_read(struct file
*fp
, char __user
*buff
,
216 size_t req_len
, loff_t
*ppos
)
219 sigset_t old_sigmask
;
220 struct inode
*ino
= fp
->f_dentry
->d_inode
;
221 TRACE_FUN(ft_t_flow
);
223 TRACE(ft_t_data_flow
, "called with count: %ld", (unsigned long)req_len
);
224 if (!test_bit(0,&busy_flag
) || iminor(ino
) != zft_unit
|| ft_failure
) {
225 TRACE_ABORT(-EIO
, ft_t_err
,
226 "failed: not busy, failure or wrong unit");
228 old_sigmask
= current
->blocked
; /* save mask */
229 sigfillset(¤t
->blocked
);
230 result
= _zft_read(buff
, req_len
);
231 current
->blocked
= old_sigmask
; /* restore mask */
232 TRACE(ft_t_data_flow
, "return with count: %d", result
);
236 /* Write to tape device
238 static ssize_t
zft_write(struct file
*fp
, const char __user
*buff
,
239 size_t req_len
, loff_t
*ppos
)
242 sigset_t old_sigmask
;
243 struct inode
*ino
= fp
->f_dentry
->d_inode
;
244 TRACE_FUN(ft_t_flow
);
246 TRACE(ft_t_flow
, "called with count: %ld", (unsigned long)req_len
);
247 if (!test_bit(0,&busy_flag
) || iminor(ino
) != zft_unit
|| ft_failure
) {
248 TRACE_ABORT(-EIO
, ft_t_err
,
249 "failed: not busy, failure or wrong unit");
251 old_sigmask
= current
->blocked
; /* save mask */
252 sigfillset(¤t
->blocked
);
253 result
= _zft_write(buff
, req_len
);
254 current
->blocked
= old_sigmask
; /* restore mask */
255 TRACE(ft_t_data_flow
, "return with count: %d", result
);
259 /* END OF VFS INTERFACE
261 *****************************************************************************/
263 /* driver/module initialization
266 /* the compression module has to call this function to hook into the zftape
269 int zft_cmpr_register(struct zft_cmpr_ops
*new_ops
)
271 TRACE_FUN(ft_t_flow
);
273 if (zft_cmpr_ops
!= NULL
) {
276 zft_cmpr_ops
= new_ops
;
281 struct zft_cmpr_ops
*zft_cmpr_unregister(void)
283 struct zft_cmpr_ops
*old_ops
= zft_cmpr_ops
;
284 TRACE_FUN(ft_t_flow
);
290 /* lock the zft-compressor() module.
292 int zft_cmpr_lock(int try_to_load
)
294 if (zft_cmpr_ops
== NULL
) {
297 request_module("zft-compressor");
298 if (zft_cmpr_ops
== NULL
) {
308 (*zft_cmpr_ops
->lock
)();
312 #ifdef CONFIG_ZFT_COMPRESSOR
313 extern int zft_compressor_init(void);
316 /* Called by modules package when installing the driver or by kernel
317 * during the initialization phase
319 int __init
zft_init(void)
322 TRACE_FUN(ft_t_flow
);
325 printk(KERN_INFO ZFTAPE_VERSION
"\n");
326 if (TRACE_LEVEL
>= ft_t_info
) {
329 "(c) 1996, 1997 Claus-Justus Heine (claus@momo.math.rwth-aachen.de)\n"
331 "vfs interface for ftape floppy tape driver.\n"
333 "Support for QIC-113 compatible volume table, dynamic memory allocation\n"
335 "and builtin compression (lzrw3 algorithm).\n"
337 "Compiled for Linux version %s\n", UTS_RELEASE
);
340 /* print a short no-nonsense boot message */
341 printk(KERN_INFO ZFTAPE_VERSION
" for Linux " UTS_RELEASE
"\n");
343 TRACE(ft_t_info
, "zft_init @ 0x%p", zft_init
);
345 "installing zftape VFS interface for ftape driver ...");
346 TRACE_CATCH(register_chrdev(QIC117_TAPE_MAJOR
, "zft", &zft_cdev
),);
348 zft_class
= class_simple_create(THIS_MODULE
, "zft");
349 for (i
= 0; i
< 4; i
++) {
350 class_simple_device_add(zft_class
, MKDEV(QIC117_TAPE_MAJOR
, i
), NULL
, "qft%i", i
);
351 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR
, i
),
352 S_IFCHR
| S_IRUSR
| S_IWUSR
,
354 class_simple_device_add(zft_class
, MKDEV(QIC117_TAPE_MAJOR
, i
+ 4), NULL
, "nqft%i", i
);
355 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR
, i
+ 4),
356 S_IFCHR
| S_IRUSR
| S_IWUSR
,
358 class_simple_device_add(zft_class
, MKDEV(QIC117_TAPE_MAJOR
, i
+ 16), NULL
, "zqft%i", i
);
359 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR
, i
+ 16),
360 S_IFCHR
| S_IRUSR
| S_IWUSR
,
362 class_simple_device_add(zft_class
, MKDEV(QIC117_TAPE_MAJOR
, i
+ 20), NULL
, "nzqft%i", i
);
363 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR
, i
+ 20),
364 S_IFCHR
| S_IRUSR
| S_IWUSR
,
366 class_simple_device_add(zft_class
, MKDEV(QIC117_TAPE_MAJOR
, i
+ 32), NULL
, "rawqft%i", i
);
367 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR
, i
+ 32),
368 S_IFCHR
| S_IRUSR
| S_IWUSR
,
370 class_simple_device_add(zft_class
, MKDEV(QIC117_TAPE_MAJOR
, i
+ 36), NULL
, "nrawrawqft%i", i
);
371 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR
, i
+ 36),
372 S_IFCHR
| S_IRUSR
| S_IWUSR
,
376 #ifdef CONFIG_ZFT_COMPRESSOR
377 (void)zft_compressor_init();
379 zft_status
= ftape_get_status(); /* fetch global data of ftape
386 /* Called by modules package when removing the driver
388 static void zft_exit(void)
391 TRACE_FUN(ft_t_flow
);
393 if (unregister_chrdev(QIC117_TAPE_MAJOR
, "zft") != 0) {
394 TRACE(ft_t_warn
, "failed");
396 TRACE(ft_t_info
, "successful");
398 for (i
= 0; i
< 4; i
++) {
399 devfs_remove("qft%i", i
);
400 class_simple_device_remove(MKDEV(QIC117_TAPE_MAJOR
, i
));
401 devfs_remove("nqft%i", i
);
402 class_simple_device_remove(MKDEV(QIC117_TAPE_MAJOR
, i
+ 4));
403 devfs_remove("zqft%i", i
);
404 class_simple_device_remove(MKDEV(QIC117_TAPE_MAJOR
, i
+ 16));
405 devfs_remove("nzqft%i", i
);
406 class_simple_device_remove(MKDEV(QIC117_TAPE_MAJOR
, i
+ 20));
407 devfs_remove("rawqft%i", i
);
408 class_simple_device_remove(MKDEV(QIC117_TAPE_MAJOR
, i
+ 32));
409 devfs_remove("nrawqft%i", i
);
410 class_simple_device_remove(MKDEV(QIC117_TAPE_MAJOR
, i
+ 36));
412 class_simple_destroy(zft_class
);
413 zft_uninit_mem(); /* release remaining memory, if any */
414 printk(KERN_INFO
"zftape successfully unloaded.\n");
418 module_init(zft_init
);
419 module_exit(zft_exit
);