|
|
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>
56: #include <vm/vm_map.h>
57: #include <vm/vm_page.h>
58: #include <device/device_types.h>
59:
60: #define MACH_INCLUDE
61: #include <linux/types.h>
62: #include <linux/config.h>
63: #include <linux/errno.h>
64: #include <linux/mm.h>
65: #include <linux/fs.h>
66: #include <linux/blk.h>
67: #include <linux/proc_fs.h>
68: #include <linux/kernel_stat.h>
69:
70: extern boolean_t vm_map_lookup_entry (register vm_map_t, register vm_offset_t,
71: vm_map_entry_t *);
72: extern int printf (const char *, ...);
73:
74: int (*dispatch_scsi_info_ptr) (int ino, char *buffer, char **start,
75: off_t offset, int length, int inout) = 0;
76:
77: struct kernel_stat kstat;
78:
79: int
80: linux_to_mach_error (int err)
81: {
82: switch (err)
83: {
84: case 0:
85: return D_SUCCESS;
86:
87: case -LINUX_EPERM:
88: return D_INVALID_OPERATION;
89:
90: case -LINUX_EIO:
91: return D_IO_ERROR;
92:
93: case -LINUX_ENXIO:
94: return D_NO_SUCH_DEVICE;
95:
96: case -LINUX_EACCES:
97: return D_INVALID_OPERATION;
98:
99: case -LINUX_EFAULT:
100: return D_INVALID_SIZE;
101:
102: case -LINUX_EBUSY:
103: return D_ALREADY_OPEN;
104:
105: case -LINUX_EINVAL:
106: return D_INVALID_SIZE;
107:
108: case -LINUX_EROFS:
109: return D_READ_ONLY;
110:
111: case -LINUX_EWOULDBLOCK:
112: return D_WOULD_BLOCK;
113:
114: case -LINUX_ENOMEM:
115: return D_NO_MEMORY;
116:
117: default:
118: printf ("linux_to_mach_error: unknown code %d\n", err);
119: return D_IO_ERROR;
120: }
121: }
122:
123: int
124: issig ()
125: {
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 ());
151: return -LINUX_EFAULT;
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: {
232: host_get_time (1, tv);
233: }
234:
235: int
236: dev_get_info (char *buffer, char **start, off_t offset, int length, int dummy)
237: {
238: return 0;
239: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.