summaryrefslogtreecommitdiff
path: root/linux/dev/glue/misc.c
blob: 98c8248f23ef6b8a74ab77aa6795ea20298523dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
 * Miscellaneous routines and data for Linux emulation.
 *
 * Copyright (C) 1996 The University of Utah and the Computer Systems
 * Laboratory at the University of Utah (CSL)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *      Author: Shantanu Goel, University of Utah CSL
 */

/*
 *  linux/fs/proc/scsi.c  
 *  (c) 1995 Michael Neuffer neuffer@goofy.zdv.uni-mainz.de
 *
 *  The original version was derived from linux/fs/proc/net.c,
 *  which is Copyright (C) 1991, 1992 Linus Torvalds. 
 *  Much has been rewritten, but some of the code still remains.
 *
 *  /proc/scsi directory handling functions
 *
 *  last change: 95/07/04    
 *
 *  Initial version: March '95
 *  95/05/15 Added subdirectories for each driver and show every
 *           registered HBA as a single file. 
 *  95/05/30 Added rudimentary write support for parameter passing
 *  95/07/04 Fixed bugs in directory handling
 *  95/09/13 Update to support the new proc-dir tree
 *
 *  TODO: Improve support to write to the driver files
 *        Add some more comments
 */

/*
 *  linux/fs/buffer.c
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 */

#include <sys/types.h>
#include <mach/vm_param.h>
#include <kern/thread.h>
#include <kern/printf.h>
#include <vm/vm_map.h>
#include <vm/vm_page.h>
#include <device/device_types.h>

#define MACH_INCLUDE
#include <linux/types.h>
#include <linux/config.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/blk.h>
#include <linux/proc_fs.h>
#include <linux/kernel_stat.h>
#include <linux/dev/glue/glue.h>

int (*dispatch_scsi_info_ptr) (int ino, char *buffer, char **start,
			       off_t offset, int length, int inout) = 0;

struct kernel_stat kstat;

int
linux_to_mach_error (int err)
{
  switch (err)
    {
    case 0:
      return D_SUCCESS;

    case -LINUX_EPERM:
      return D_INVALID_OPERATION;

    case -LINUX_EIO:
      return D_IO_ERROR;

    case -LINUX_ENXIO:
      return D_NO_SUCH_DEVICE;

    case -LINUX_EACCES:
      return D_INVALID_OPERATION;

    case -LINUX_EFAULT:
      return D_INVALID_SIZE;

    case -LINUX_EBUSY:
      return D_ALREADY_OPEN;

    case -LINUX_EINVAL:
      return D_INVALID_SIZE;

    case -LINUX_EROFS:
      return D_READ_ONLY;

    case -LINUX_EWOULDBLOCK:
      return D_WOULD_BLOCK;

    case -LINUX_ENOMEM:
      return D_NO_MEMORY;

    default:
      printf ("linux_to_mach_error: unknown code %d\n", err);
      return D_IO_ERROR;
    }
}

int
issig ()
{
  return current_thread ()->wait_result != THREAD_AWAKENED;
}

int
block_fsync (struct inode *inode, struct file *filp)
{
  return 0;
}

int
verify_area (int rw, const void *p, unsigned long size)
{
  vm_prot_t prot = (rw == VERIFY_WRITE) ? VM_PROT_WRITE : VM_PROT_READ;
  vm_offset_t addr = trunc_page ((vm_offset_t) p);
  vm_size_t len = round_page ((vm_size_t) size);
  vm_map_entry_t entry;

  vm_map_lock_read (current_map ());

  while (1)
    {
      if (!vm_map_lookup_entry (current_map (), addr, &entry)
	  || (entry->protection & prot) != prot)
	{
	  vm_map_unlock_read (current_map ());
	  return -LINUX_EFAULT;
	}
      if (entry->vme_end - entry->vme_start >= len)
	break;
      len -= entry->vme_end - entry->vme_start;
      addr += entry->vme_end - entry->vme_start;
    }

  vm_map_unlock_read (current_map ());
  return 0;
}

/*
 * Print device name (in decimal, hexadecimal or symbolic) -
 * at present hexadecimal only.
 * Note: returns pointer to static data!
 */
char *
kdevname (kdev_t dev)
{
  static char buffer[32];
  linux_sprintf (buffer, "%02x:%02x", MAJOR (dev), MINOR (dev));
  return buffer;
}

/* RO fail safe mechanism */

static long ro_bits[MAX_BLKDEV][8];

int
is_read_only (kdev_t dev)
{
  int minor, major;

  major = MAJOR (dev);
  minor = MINOR (dev);
  if (major < 0 || major >= MAX_BLKDEV)
    return 0;
  return ro_bits[major][minor >> 5] & (1 << (minor & 31));
}

void
set_device_ro (kdev_t dev, int flag)
{
  int minor, major;

  major = MAJOR (dev);
  minor = MINOR (dev);
  if (major < 0 || major >= MAX_BLKDEV)
    return;
  if (flag)
    ro_bits[major][minor >> 5] |= 1 << (minor & 31);
  else
    ro_bits[major][minor >> 5] &= ~(1 << (minor & 31));
}

struct proc_dir_entry proc_scsi;
struct inode_operations proc_scsi_inode_operations;
struct proc_dir_entry proc_net;
struct inode_operations proc_net_inode_operations;

int
proc_register (struct proc_dir_entry *xxx1, struct proc_dir_entry *xxx2)
{
  return 0;
}

int
proc_unregister (struct proc_dir_entry *xxx1, int xxx2)
{
  return 0;
}

void
add_blkdev_randomness (int major)
{
}

void
do_gettimeofday (struct timeval *tv)
{
  /*
   * XXX: The first argument should be mach_host_self (), but that's too
   * expensive, and the host argument is not used by host_get_time (),
   * only checked not to be HOST_NULL.
   */
  host_get_time ((host_t) 1, (time_value_t *) tv);
}

int
dev_get_info (char *buffer, char **start, off_t offset, int length, int dummy)
{
  return 0;
}