ia64/xen-unstable

view xenolinux-2.4.21-sparse/arch/xeno/drivers/block/xl_physdisk_proc.c @ 542:eacf3abcd1da

bitkeeper revision 1.301 (3f0ac784kapr1mR68k4rqPH-g7cZCQ)

Get rid of some GNU extensions.
author sos22@labyrinth.cl.cam.ac.uk
date Tue Jul 08 13:30:44 2003 +0000 (2003-07-08)
parents 85abfe09ce32
children fdb4cc73ddc7
line source
1 /* We stuff the domain number into the proc_dir_entry data pointer. */
2 #include <linux/kernel.h>
3 #include <linux/module.h>
4 #include <linux/fs.h>
5 #include <asm/errno.h>
6 #include <linux/slab.h>
7 #include <asm/hypervisor-ifs/block.h>
8 #include <asm/uaccess.h>
9 #include <linux/proc_fs.h>
11 #include "xl_block.h"
13 extern int xenolinux_control_msg(int operration, char *buffer, int size);
14 extern unsigned short xldev_to_physdev(kdev_t xldev);
16 static dev_t physdev_to_xldev(unsigned short physdev)
17 {
18 switch (physdev & XENDEV_TYPE_MASK) {
19 case XENDEV_IDE:
20 if ( (physdev & XENDEV_IDX_MASK) < XLIDE_DEVS_PER_MAJOR) {
21 return MKDEV(XLIDE_MAJOR_0,
22 (physdev & XENDEV_IDX_MASK) << XLIDE_PARTN_SHIFT);
23 } else if ( (physdev & XENDEV_IDX_MASK) < (XLIDE_DEVS_PER_MAJOR * 2)) {
24 return MKDEV(XLIDE_MAJOR_1,
25 (physdev & XENDEV_IDX_MASK) << XLIDE_PARTN_SHIFT);
26 }
27 break;
28 case XENDEV_SCSI:
29 return MKDEV(XLSCSI_MAJOR,
30 (physdev & XENDEV_IDX_MASK) << XLSCSI_PARTN_SHIFT);
31 case XENDEV_VIRTUAL:
32 return MKDEV(XLVIRT_MAJOR,
33 (physdev & XENDEV_IDX_MASK) << XLVIRT_PARTN_SHIFT);
34 }
35 printk(KERN_ALERT "Unrecognised xl device: %x\n", physdev);
36 BUG();
37 return -1;
38 }
40 static ssize_t proc_read_phd(struct file *file, char *buff, size_t size,
41 loff_t * off)
42 {
43 physdisk_probebuf_t *buf;
44 int res;
45 struct proc_dir_entry *pde;
46 int x;
48 if (size != sizeof(physdisk_probebuf_t))
49 return -EINVAL;
51 buf = kmalloc(sizeof(physdisk_probebuf_t), GFP_KERNEL);
52 if (!buf)
53 return -ENOMEM;
55 pde = file->f_dentry->d_inode->u.generic_ip;
56 buf->domain = (int) pde->data;
58 /* The offset reported by lseek and friends doesn't have to be in
59 bytes, and it's marginally easier to say that it's in records, so
60 that's what we do. */
61 buf->start_ind = *off;
62 res = xenolinux_control_msg(XEN_BLOCK_PHYSDEV_PROBE, (void *) buf,
63 sizeof(physdisk_probebuf_t));
64 *off += buf->n_aces;
66 if (res)
67 res = -EINVAL;
68 else {
69 for (x = 0; x < buf->n_aces; x++)
70 buf->entries[x].device =
71 physdev_to_xldev(buf->entries[x].device);
72 res = sizeof(physdisk_probebuf_t);
73 if (copy_to_user(buff, buf, sizeof(physdisk_probebuf_t))) {
74 res = -EFAULT;
75 }
76 }
77 kfree(buf);
78 return res;
79 }
81 static int proc_write_phd(struct file *file, const char *buffer,
82 size_t count, loff_t * ignore)
83 {
84 char *local;
85 int res;
86 xp_disk_t *xpd;
87 struct proc_dir_entry *pde;
89 if (count != sizeof(xp_disk_t))
90 return -EINVAL;
92 local = kmalloc(count + 1, GFP_KERNEL);
93 if (!local)
94 return -ENOMEM;
95 if (copy_from_user(local, buffer, count)) {
96 res = -EFAULT;
97 goto out;
98 }
100 xpd = (xp_disk_t *) local;
102 pde = file->f_dentry->d_inode->u.generic_ip;
103 xpd->domain = (int) pde->data;
104 xpd->device = xldev_to_physdev(xpd->device);
106 res = xenolinux_control_msg(XEN_BLOCK_PHYSDEV_GRANT, local, count);
107 if (res == 0)
108 res = count;
109 else
110 res = -EINVAL;
111 out:
112 kfree(local);
113 return res;
114 }
116 struct file_operations dom0_phd_fops = {
117 read:proc_read_phd,
118 write:proc_write_phd
119 };