|
|
1.1 root 1: /*
2: * Miscellaneous routines and data for Linux emulation.
3: *
4: * Copyright (C) 1996 The University of Utah and the Computer Systems
5: * Laboratory at the University of Utah (CSL)
6: *
7: * This program is free software; you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as published by
9: * the Free Software Foundation; either version 2, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20: *
21: * Author: Shantanu Goel, University of Utah CSL
22: */
23:
24: /*
25: * linux/fs/proc/scsi.c
26: * (c) 1995 Michael Neuffer [email protected]
27: *
28: * The original version was derived from linux/fs/proc/net.c,
29: * which is Copyright (C) 1991, 1992 Linus Torvalds.
30: * Much has been rewritten, but some of the code still remains.
31: *
32: * /proc/scsi directory handling functions
33: *
34: * last change: 95/07/04
35: *
36: * Initial version: March '95
37: * 95/05/15 Added subdirectories for each driver and show every
38: * registered HBA as a single file.
39: * 95/05/30 Added rudimentary write support for parameter passing
40: * 95/07/04 Fixed bugs in directory handling
41: * 95/09/13 Update to support the new proc-dir tree
42: *
43: * TODO: Improve support to write to the driver files
44: * Add some more comments
45: */
46:
47: /*
48: * linux/fs/buffer.c
49: *
50: * Copyright (C) 1991, 1992 Linus Torvalds
51: */
52:
53: #include <sys/types.h>
54: #include <mach/vm_param.h>
55: #include <kern/thread.h>
1.1.1.3 ! root 56: #include <kern/printf.h>
1.1 root 57: #include <vm/vm_map.h>
58: #include <vm/vm_page.h>
59: #include <device/device_types.h>
60:
61: #define MACH_INCLUDE
62: #include <linux/types.h>
63: #include <linux/config.h>
64: #include <linux/errno.h>
65: #include <linux/mm.h>
66: #include <linux/fs.h>
67: #include <linux/blk.h>
68: #include <linux/proc_fs.h>
69: #include <linux/kernel_stat.h>
1.1.1.3 ! root 70: #include <linux/dev/glue/glue.h>
1.1 root 71:
72: int (*dispatch_scsi_info_ptr) (int ino, char *buffer, char **start,
73: off_t offset, int length, int inout) = 0;
74:
75: struct kernel_stat kstat;
76:
77: int
78: linux_to_mach_error (int err)
79: {
80: switch (err)
81: {
82: case 0:
83: return D_SUCCESS;
84:
1.1.1.3 ! root 85: case -EPERM:
1.1 root 86: return D_INVALID_OPERATION;
87:
1.1.1.3 ! root 88: case -EIO:
1.1 root 89: return D_IO_ERROR;
90:
1.1.1.3 ! root 91: case -ENXIO:
1.1 root 92: return D_NO_SUCH_DEVICE;
93:
1.1.1.3 ! root 94: case -EACCES:
1.1 root 95: return D_INVALID_OPERATION;
96:
1.1.1.3 ! root 97: case -EFAULT:
1.1 root 98: return D_INVALID_SIZE;
99:
1.1.1.3 ! root 100: case -EBUSY:
1.1 root 101: return D_ALREADY_OPEN;
102:
1.1.1.3 ! root 103: case -EINVAL:
1.1 root 104: return D_INVALID_SIZE;
105:
1.1.1.3 ! root 106: case -EROFS:
1.1 root 107: return D_READ_ONLY;
108:
1.1.1.3 ! root 109: case -EWOULDBLOCK:
1.1 root 110: return D_WOULD_BLOCK;
111:
1.1.1.3 ! root 112: case -ENOMEM:
1.1 root 113: return D_NO_MEMORY;
114:
115: default:
116: printf ("linux_to_mach_error: unknown code %d\n", err);
117: return D_IO_ERROR;
118: }
119: }
120:
121: int
122: issig ()
123: {
1.1.1.3 ! root 124: if (!current_thread())
! 125: return 0;
1.1 root 126: return current_thread ()->wait_result != THREAD_AWAKENED;
127: }
128:
129: int
130: block_fsync (struct inode *inode, struct file *filp)
131: {
132: return 0;
133: }
134:
135: int
136: verify_area (int rw, const void *p, unsigned long size)
137: {
138: vm_prot_t prot = (rw == VERIFY_WRITE) ? VM_PROT_WRITE : VM_PROT_READ;
139: vm_offset_t addr = trunc_page ((vm_offset_t) p);
140: vm_size_t len = round_page ((vm_size_t) size);
141: vm_map_entry_t entry;
142:
143: vm_map_lock_read (current_map ());
144:
145: while (1)
146: {
147: if (!vm_map_lookup_entry (current_map (), addr, &entry)
148: || (entry->protection & prot) != prot)
149: {
150: vm_map_unlock_read (current_map ());
1.1.1.3 ! root 151: return -EFAULT;
1.1 root 152: }
153: if (entry->vme_end - entry->vme_start >= len)
154: break;
155: len -= entry->vme_end - entry->vme_start;
156: addr += entry->vme_end - entry->vme_start;
157: }
158:
159: vm_map_unlock_read (current_map ());
160: return 0;
161: }
162:
163: /*
164: * Print device name (in decimal, hexadecimal or symbolic) -
165: * at present hexadecimal only.
166: * Note: returns pointer to static data!
167: */
168: char *
169: kdevname (kdev_t dev)
170: {
171: static char buffer[32];
172: linux_sprintf (buffer, "%02x:%02x", MAJOR (dev), MINOR (dev));
173: return buffer;
174: }
175:
176: /* RO fail safe mechanism */
177:
178: static long ro_bits[MAX_BLKDEV][8];
179:
180: int
181: is_read_only (kdev_t dev)
182: {
183: int minor, major;
184:
185: major = MAJOR (dev);
186: minor = MINOR (dev);
187: if (major < 0 || major >= MAX_BLKDEV)
188: return 0;
189: return ro_bits[major][minor >> 5] & (1 << (minor & 31));
190: }
191:
192: void
193: set_device_ro (kdev_t dev, int flag)
194: {
195: int minor, major;
196:
197: major = MAJOR (dev);
198: minor = MINOR (dev);
199: if (major < 0 || major >= MAX_BLKDEV)
200: return;
201: if (flag)
202: ro_bits[major][minor >> 5] |= 1 << (minor & 31);
203: else
204: ro_bits[major][minor >> 5] &= ~(1 << (minor & 31));
205: }
206:
207: struct proc_dir_entry proc_scsi;
208: struct inode_operations proc_scsi_inode_operations;
209: struct proc_dir_entry proc_net;
210: struct inode_operations proc_net_inode_operations;
211:
212: int
213: proc_register (struct proc_dir_entry *xxx1, struct proc_dir_entry *xxx2)
214: {
215: return 0;
216: }
217:
218: int
219: proc_unregister (struct proc_dir_entry *xxx1, int xxx2)
220: {
221: return 0;
222: }
223:
224: void
225: add_blkdev_randomness (int major)
226: {
227: }
228:
229: void
230: do_gettimeofday (struct timeval *tv)
231: {
1.1.1.3 ! root 232: /*
! 233: * XXX: The first argument should be mach_host_self (), but that's too
! 234: * expensive, and the host argument is not used by host_get_time (),
! 235: * only checked not to be HOST_NULL.
! 236: */
! 237: host_get_time ((host_t) 1, (time_value_t *) tv);
1.1 root 238: }
239:
240: int
241: dev_get_info (char *buffer, char **start, off_t offset, int length, int dummy)
242: {
243: return 0;
244: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.