File: sysfs.c

package info (click to toggle)
ibcs 971113-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,108 kB
  • ctags: 2,061
  • sloc: ansic: 14,910; makefile: 280; sh: 203; asm: 47; perl: 18; pascal: 2
file content (144 lines) | stat: -rw-r--r-- 3,290 bytes parent folder | download | duplicates (2)
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
/*
 *  linux/ibcs/sysfs.c
 *
 *  Copyright (C) 1994  Mike Jagdis (jaggy@purplet.demon.co.uk)
 *
 * $Id: sysfs.c,v 1.12 1997/11/05 09:16:08 jaggy Exp $
 * $Source: /usr/CVS/ibcs/iBCSemul/sysfs.c,v $
 */

#include <linux/config.h>

#include <linux/module.h>
#include <linux/version.h>

#include <asm/segment.h>
#ifndef KERNEL_DS
#include <linux/segment.h>
#endif

#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/ptrace.h>
#include <linux/fcntl.h>

#include <asm/system.h>
#include <linux/fs.h>
#include <linux/sys.h>
#include <linux/string.h>

#include <ibcs/ibcs.h>

/* Kernels prior to 1.1.10 do not have a sysfs() system call and
 * are not supported by iBCS releases after July 1997. Sorry.
 * The kernel sysfs() code is almost all we need but, apparently,
 * the SCO (at least) sysfs() will also accept a "magic number"
 * as an index argument and will return the name of the relevant
 * file system. Since Linux doesn't have any concept of fs magic
 * numbers outside the file system code themselves there is no
 * clean way to do it in the kernel. There isn't a clean way to
 * to it here either but it needs to be done somehow :-(.
 */

#ifdef IBCS_TRACE
#include <ibcs/trace.h>
#endif


#define GETFSIND	1
#define GETFSTYP	2
#define GETNFSTYP	3


int ibcs_sysfs(int cmd, int arg1, int arg2)
{
	if (cmd == GETFSIND)
		return SYS(sysfs)(cmd, (char *)arg1);

	if (cmd == GETNFSTYP)
		return SYS(sysfs)(cmd);

	if (cmd == GETFSTYP) {
		char *buf = (char *)arg2;
		int error;

		if (arg1 & 0x80000000)
			arg1 &= 0x0000ffff;
		if (arg1 >= 0 && arg1 < SYS(sysfs)(GETNFSTYP))
			return SYS(sysfs)(cmd, arg1-1, arg2);

		/* Long enough for the longest fs name. */
		error = verify_area(VERIFY_WRITE, buf, 9);
		if (error)
			return error;

		/* Kludge alert! Hardcoded known magic numbers! */
		switch (arg1) {
			case 0xef53:
			case 0xef51:
				memcpy_tofs(buf, "ext", 5);
				break;
			case 0x137d:
				memcpy_tofs(buf, "ext", 4);
				break;
			case 0x9660:
				memcpy_tofs(buf, "iso9660", 8);
				break;
			case 0x4d44:
				memcpy_tofs(buf, "msdos", 6);
				break;
			case 0x6969:
				memcpy_tofs(buf, "nfs", 4);
				break;
			case 0x9fa0:
				memcpy_tofs(buf, "proc", 5);
				break;
			case 0xe849: /* really 0xf995e849 */
				memcpy_tofs(buf, "hpfs", 5);
				break;
			case 0x137f: /* original */
			case 0x138f: /* original + 30 char names */
			case 0x2468: /* V2 */
			case 0x2478: /* V2 + 30 char names */
				memcpy_tofs(buf, "minix", 6);
				break;
			case 0x564c:
				memcpy_tofs(buf, "ncpfs", 6);
				break;
			case 0x517b:
				memcpy_tofs(buf, "smbfs", 6);
				break;
			case 0x00011954:
				memcpy_tofs(buf, "ufs", 4);
				break;
			case 0x012fd16d:
				memcpy_tofs(buf, "xiafs", 6);
				break;
			case 0x012ff7b3+1:
				memcpy_tofs(buf, "xenix", 6);
				break;
			case 0x012ff7b3+2:
			case 0x012ff7b3+3:
				memcpy_tofs(buf, "sysv", 5);
				break;
			case 0x012ff7b3+4:
				memcpy_tofs(buf, "coherent", 9);
				break;
			default:
				memcpy_tofs(buf, "", 1);
				break;
		}
		return 0;
	}

#ifdef IBCS_TRACE
	if ((ibcs_trace & TRACE_API) || ibcs_func_p->trace) {
		printk(KERN_DEBUG "iBCS2 unsupported sysfs call %d\n", cmd);
	}
#endif
	return -EINVAL;
}