XINU
device
nam
nammap.c
Go to the documentation of this file.
1
/* nammap.c - nammap, namrepl, namcpy */
2
3
#include <
xinu.h
>
4
5
status
namcpy
(
char
*,
char
*,
int32
);
6
did32
namrepl
(
char
*,
char
[]);
7
8
/*------------------------------------------------------------------------
9
* nammap - Using namespace, map name to new name and new device
10
*------------------------------------------------------------------------
11
*/
12
devcall
nammap
(
13
char
*name,
/* The name to map */
14
char
newname[
NM_MAXLEN
],
/* Buffer for mapped name */
15
did32
namdev
/* ID of the namespace device */
16
)
17
{
18
did32
newdev
;
/* Device descriptor to return */
19
char
tmpname[
NM_MAXLEN
];
/* Temporary buffer for name */
20
int32
iter;
/* Number of iterations */
21
22
/* Place original name in temporary buffer and null terminate */
23
24
if
(
namcpy
(tmpname, name, NM_MAXLEN) ==
SYSERR
) {
25
return
SYSERR
;
26
}
27
28
/* Repeatedly substitute the name prefix until a non-namespace */
29
/* device is reached or an iteration limit is exceeded */
30
31
for
(iter=0; iter<
nnames
; iter++) {
32
newdev =
namrepl
(tmpname, newname);
33
if
(newdev != namdev) {
34
return
newdev
;
/* Either valid ID or SYSERR */
35
}
36
namcpy
(tmpname, newname, NM_MAXLEN);
37
}
38
return
SYSERR
;
39
}
40
41
/*------------------------------------------------------------------------
42
* namrepl - Use the name table to perform prefix substitution
43
*------------------------------------------------------------------------
44
*/
45
did32
namrepl
(
46
char
*name,
/* Original name */
47
char
newname[
NM_MAXLEN
]
/* Buffer for mapped name */
48
)
49
{
50
int32
i;
/* Iterate through name table */
51
char
*pptr;
/* Walks through a prefix */
52
char
*rptr;
/* Walks through a replacement */
53
char
*optr;
/* Walks through original name */
54
char
*nptr;
/* Walks through new name */
55
char
olen;
/* Length of original name */
56
/* including the NULL byte */
57
int32
plen;
/* Length of a prefix string */
58
/* *not* including NULL byte */
59
int32
rlen;
/* Length of replacment string */
60
int32
remain;
/* Bytes in name beyond prefix */
61
struct
nmentry
*namptr;
/* Pointer to a table entry */
62
63
/* Search name table for first prefix that matches */
64
65
for
(i=0; i<
nnames
; i++) {
66
namptr = &
nametab
[i];
67
optr = name;
/* Start at beginning of name */
68
pptr = namptr->
nprefix
;
/* Start at beginning of prefix */
69
70
/* Compare prefix to string and count prefix size */
71
72
for
(plen=0; *pptr !=
NULLCH
; plen++) {
73
if
(*pptr != *optr) {
74
break
;
75
}
76
pptr++;
77
optr++;
78
}
79
if
(*pptr !=
NULLCH
) {
/* Prefix does not match */
80
continue
;
81
}
82
83
/* Found a match - check that replacement string plus */
84
/* bytes remaining at the end of the original name will */
85
/* fit into new name buffer. Ignore null on replacement*/
86
/* string, but keep null on remainder of name. */
87
88
olen =
namlen
(name ,NM_MAXLEN);
89
rlen =
namlen
(namptr->
nreplace
,NM_MAXLEN) - 1;
90
remain = olen - plen;
91
if
( (rlen + remain) > NM_MAXLEN) {
92
return
(
did32
)
SYSERR
;
93
}
94
95
/* Place replacement string followed by remainder of */
96
/* original name (and null) into the new name buffer */
97
98
99
nptr = newname;
100
rptr = namptr->
nreplace
;
101
for
(; rlen>0 ; rlen--) {
102
*nptr++ = *rptr++;
103
}
104
for
(; remain>0 ; remain--) {
105
*nptr++ = *optr++;
106
}
107
return
namptr->
ndevice
;
108
}
109
return
(
did32
)
SYSERR
;
110
}
111
112
/*------------------------------------------------------------------------
113
* namcpy - Copy a name from one buffer to another, checking length
114
*------------------------------------------------------------------------
115
*/
116
status
namcpy
(
117
char
*newname,
/* Buffer to hold copy */
118
char
*oldname,
/* Buffer containing name */
119
int32
buflen
/* Size of buffer for copy */
120
)
121
{
122
char
*nptr;
/* Point to new name */
123
char
*optr;
/* Point to old name */
124
int32
cnt;
/* Count of characters copied */
125
126
nptr = newname;
127
optr = oldname;
128
129
for
(cnt=0; cnt<buflen; cnt++) {
130
if
( (*nptr++ = *optr++) ==
NULLCH
) {
131
return
OK
;
132
}
133
}
134
return
SYSERR
;
/* Buffer filled before copy completed */
135
}
nammap
devcall nammap(char *name, char newname[NM_MAXLEN], did32 namdev)
Definition:
nammap.c:12
xinu.h
全てのシステムヘッダファイルをインクルードする。
SYSERR
#define SYSERR
処理が失敗した場合
Definition:
kernel.h:79
OK
#define OK
処理が成功した場合
Definition:
kernel.h:77
nnames
int32 nnames
割り当てられたネームテーブルエントリの数
Definition:
naminit.c:23
status
int32 status
ステータスを意味する返り値の型(OK/SYSERR)
Definition:
kernel.h:57
newdev
void newdev(char *)
Definition:
y.tab.c:2163
NM_MAXLEN
#define NM_MAXLEN
ファイル名の最大サイズ
Definition:
name.h:11
namcpy
status namcpy(char *, char *, int32)
Definition:
nammap.c:116
nametab
struct nmentry nametab[]
名前マッピングのテーブル
Definition:
naminit.c:22
nmentry::ndevice
did32 ndevice
プレフィックス用のデバイスディスクリプタ
Definition:
name.h:26
nmentry
全ての名前マッピングを定義する名前プレフィックステーブルの定義(ネームテーブルエントリ) ...
Definition:
name.h:19
int32
int int32
符号あり32ビット整数(int)
Definition:
kernel.h:11
did32
int32 did32
デバイスID
Definition:
kernel.h:28
nmentry::nprefix
char nprefix[NM_PRELEN]
NULL終端のプレフィックス
Definition:
name.h:22
namrepl
did32 namrepl(char *, char[])
namlen
int32 namlen(char *, int32)
Definition:
mount.c:60
devcall
int32 devcall
デバイスコール関数 返り値の型
Definition:
kernel.h:49
nmentry::nreplace
char nreplace[NM_REPLLEN]
NULL終端置換
Definition:
name.h:24
NULLCH
#define NULLCH
NULL文字(NULL終端)
Definition:
kernel.h:70
Generated by
1.8.13