XINU
Functions
nammap.c File Reference
#include <xinu.h>
Include dependency graph for nammap.c:

Go to the source code of this file.

Functions

status namcpy (char *, char *, int32)
 
devcall nammap (char *name, char newname[NM_MAXLEN], did32 namdev)
 
did32 namrepl (char *, char[])
 
did32 namrepl (char *name, char newname[NM_MAXLEN])
 

Function Documentation

◆ namcpy()

status namcpy ( char *  newname,
char *  oldname,
int32  buflen 
)

Definition at line 116 of file nammap.c.

References NULLCH, OK, and SYSERR.

Referenced by nammap().

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 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the caller graph for this function:

◆ nammap()

devcall nammap ( char *  name,
char  newname[NM_MAXLEN],
did32  namdev 
)

Definition at line 12 of file nammap.c.

References namcpy(), namrepl(), newdev(), NM_MAXLEN, nnames, and SYSERR.

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 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int32 nnames
割り当てられたネームテーブルエントリの数
Definition: naminit.c:23
void newdev(char *)
Definition: y.tab.c:2163
#define NM_MAXLEN
ファイル名の最大サイズ
Definition: name.h:11
status namcpy(char *, char *, int32)
Definition: nammap.c:116
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 did32
デバイスID
Definition: kernel.h:28
did32 namrepl(char *, char[])
Here is the call graph for this function:

◆ namrepl() [1/2]

did32 namrepl ( char *  ,
char  [] 
)

Referenced by nammap().

Here is the caller graph for this function:

◆ namrepl() [2/2]

did32 namrepl ( char *  name,
char  newname[NM_MAXLEN] 
)

Definition at line 45 of file nammap.c.

References nametab, namlen(), nmentry::ndevice, nnames, nmentry::nprefix, nmentry::nreplace, NULLCH, and SYSERR.

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 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int32 nnames
割り当てられたネームテーブルエントリの数
Definition: naminit.c:23
#define NM_MAXLEN
ファイル名の最大サイズ
Definition: name.h:11
struct nmentry nametab[]
名前マッピングのテーブル
Definition: naminit.c:22
did32 ndevice
プレフィックス用のデバイスディスクリプタ
Definition: name.h:26
全ての名前マッピングを定義する名前プレフィックステーブルの定義(ネームテーブルエントリ) ...
Definition: name.h:19
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 did32
デバイスID
Definition: kernel.h:28
char nprefix[NM_PRELEN]
NULL終端のプレフィックス
Definition: name.h:22
int32 namlen(char *, int32)
Definition: mount.c:60
char nreplace[NM_REPLLEN]
NULL終端置換
Definition: name.h:24
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function: