12 #define KMSG_COMPONENT "tape"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15 #include <linux/module.h>
16 #include <linux/types.h>
21 #include <asm/uaccess.h>
23 #define TAPE_DBF_AREA tape_core_dbf
29 #define TAPECHAR_MAJOR 0
34 static ssize_t tapechar_read(
struct file *,
char __user *,
size_t, loff_t *);
35 static ssize_t tapechar_write(
struct file *,
const char __user *,
size_t, loff_t *);
36 static int tapechar_open(
struct inode *,
struct file *);
37 static int tapechar_release(
struct inode *,
struct file *);
38 static long tapechar_ioctl(
struct file *,
unsigned int,
unsigned long);
40 static long tapechar_compat_ioctl(
struct file *,
unsigned int,
unsigned long);
46 .read = tapechar_read,
47 .write = tapechar_write,
48 .unlocked_ioctl = tapechar_ioctl,
50 .compat_ioctl = tapechar_compat_ioctl,
52 .open = tapechar_open,
53 .release = tapechar_release,
102 device->
char_data.idal_buf->size == block_size)
106 DBF_EVENT(3,
"Invalid blocksize (%zd > %d)\n",
112 new = idal_buffer_alloc(block_size, 0);
117 idal_buffer_free(device->
char_data.idal_buf);
128 tapechar_read(
struct file *filp,
char __user *
data,
size_t count, loff_t *ppos)
149 if (count < device->
char_data.block_size) {
150 DBF_EVENT(3,
"TCHAR:read smaller than block "
151 "size was requested\n");
154 block_size = device->
char_data.block_size;
159 rc = tapechar_check_idalbuffer(device, block_size);
163 DBF_EVENT(6,
"TCHAR:nbytes: %lx\n", block_size);
165 request = device->
discipline->read_block(device, block_size);
167 return PTR_ERR(request);
171 rc = block_size - request->
rescnt;
174 if (idal_buffer_to_user(device->
char_data.idal_buf,
186 tapechar_write(
struct file *filp,
const char __user *data,
size_t count, loff_t *ppos)
199 if (count < device->
char_data.block_size) {
200 DBF_EVENT(3,
"TCHAR:write smaller than block "
201 "size was requested\n");
204 block_size = device->
char_data.block_size;
211 rc = tapechar_check_idalbuffer(device, block_size);
215 DBF_EVENT(6,
"TCHAR:nbytes: %lx\n", block_size);
216 DBF_EVENT(6,
"TCHAR:nblocks: %x\n", nblocks);
218 request = device->
discipline->write_block(device, block_size);
220 return PTR_ERR(request);
223 for (i = 0; i < nblocks; i++) {
225 if (idal_buffer_from_user(device->
char_data.idal_buf,
234 block_size - request->
rescnt);
235 written += block_size - request->
rescnt;
263 return rc ? rc : written;
276 imajor(filp->
f_path.dentry->d_inode),
277 iminor(filp->
f_path.dentry->d_inode));
279 if (imajor(filp->
f_path.dentry->d_inode) != tapechar_major)
282 minor = iminor(filp->
f_path.dentry->d_inode);
284 if (IS_ERR(device)) {
285 DBF_EVENT(3,
"TCHAR:open: tape_find_device() failed\n");
286 return PTR_ERR(device);
304 tapechar_release(
struct inode *inode,
struct file *filp)
308 DBF_EVENT(6,
"TCHAR:release: %x\n", iminor(inode));
316 if ((iminor(inode) & 1) != 0) {
328 idal_buffer_free(device->
char_data.idal_buf);
343 unsigned int no,
unsigned long data)
378 if (
op.mt_op ==
MTWEOF && rc == 0) {
402 memset(&
get, 0,
sizeof(
get));
424 if (
copy_to_user((
char __user *) data, &
get,
sizeof(
get)) != 0)
432 return device->
discipline->ioctl_fn(device, no, data);
436 tapechar_ioctl(
struct file *filp,
unsigned int no,
unsigned long data)
445 rc = __tapechar_ioctl(device, no, data);
452 tapechar_compat_ioctl(
struct file *filp,
unsigned int no,
unsigned long data)
462 argp = (
unsigned long) compat_ptr(data);
465 rval = device->
discipline->ioctl_fn(device, no, argp);
486 tapechar_major =
MAJOR(dev);