File: misc.c

package info (click to toggle)
oskit 0.97.20000202-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 58,008 kB
  • ctags: 172,612
  • sloc: ansic: 832,827; asm: 7,640; sh: 3,920; yacc: 3,664; perl: 1,457; lex: 427; makefile: 337; csh: 141; awk: 78
file content (162 lines) | stat: -rw-r--r-- 3,202 bytes parent folder | download
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
/*
 * Copyright (c) 1996-1999 The University of Utah and the Flux Group.
 * 
 * This file is part of the OSKit Linux Glue Libraries, which are free
 * software, also known as "open source;" you can redistribute them and/or
 * modify them under the terms of the GNU General Public License (GPL),
 * version 2, as published by the Free Software Foundation (FSF).
 * 
 * The OSKit 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 GPL for more details.  You should have
 * received a copy of the GPL along with the OSKit; see the file COPYING.  If
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
 */
/*
 * Miscellaneous Linux support functions and variables.
 */

#ifndef OSKIT
#define OSKIT
#endif

#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/blk.h>
#include <linux/proc_fs.h>
#include <linux/kernel_stat.h>
#include <linux/time.h>
#include <linux/module.h>

#include "linux_emul.h"
#include "osenv.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_oskit_error(int err)
{
	switch (err) {

	case 0:
		return (0);

	case -EPERM:
		return (OSKIT_E_DEV_BADOP);

	case -EIO:
		return (OSKIT_E_DEV_IOERR);

	case -ENXIO:
		return (OSKIT_E_DEV_NOSUCH_DEV);

	case -EACCES:
		return (OSKIT_E_DEV_BADOP);

	case -EFAULT:
		return (OSKIT_E_DEV_BADPARAM);

	case -EBUSY:
		return (OSKIT_E_DEV_IOERR);	/* XXX */

	case -EINVAL:
		return (OSKIT_E_DEV_BADPARAM);

	case -EROFS:
		return (OSKIT_E_DEV_BADOP);

	case -EWOULDBLOCK:
		return (OSKIT_E_DEV_IOERR);	/* XXX */

	case -ENOMEM:
		return (OSKIT_E_OUTOFMEMORY);

	default:
		osenv_log(OSENV_LOG_NOTICE, "%s:%d: unknown code %d\n", 
			__FILE__, __LINE__, err);
		return (OSKIT_E_DEV_IOERR);
	}
}

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

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)
{
}

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

void
do_gettimeofday(struct timeval *tv)
{
	tv->tv_sec = jiffies;	/* XXX! */
	tv->tv_usec = 0;
}

/*
 * XXX: These *really* need to be fixed
 */

unsigned long
virt_to_phys(volatile void *address)
{
	return ((unsigned long)osenv_mem_get_phys((oskit_addr_t)address));
}

void *
phys_to_virt(unsigned long address)
{
	return ((void *)osenv_mem_get_virt((oskit_addr_t)address));
}

void
iounmap(void *addr)
{
}

#include <linux/string.h>
#include <linux/ctype.h>

#ifndef __HAVE_ARCH_STRNLEN
/*
 * This is used only by the linux DEV code. If its not inlined, define it.
 */
size_t
strnlen(const char * s, size_t count)
{
	const char *sc;

	for (sc = s; count-- && *sc != '\0'; ++sc)
		/* nothing */;
	return sc - s;
}
#endif