XINU
mount.c
Go to the documentation of this file.
1 /* mount.c - mount, namlen */
2 
3 #include <xinu.h>
4 
5 /*------------------------------------------------------------------------
6  * mount - Add a prefix mapping to the name space
7  *------------------------------------------------------------------------
8  */
10  char *prefix, /* Prefix to add */
11  char *replace, /* Replacement string */
12  did32 device /* Device ID to use */
13 )
14 {
15  intmask mask; /* Saved interrupt mask */
16  struct nmentry *namptr; /* Pointer to unused table entry*/
17  int32 psiz, rsiz; /* Sizes of prefix & replacement*/
18  int32 i; /* Counter for copy loop */
19 
20  mask = disable();
21 
22  psiz = namlen(prefix, NM_PRELEN);
23  rsiz = namlen(replace, NM_REPLLEN);
24 
25  /* If arguments are invalid or table is full, return error */
26 
27  if ( (psiz == SYSERR) || (rsiz == SYSERR) ||
28  (isbaddev(device)) || (nnames >= NNAMES) ) {
29  restore(mask);
30  return SYSERR;
31  }
32 
33  /* Allocate a slot in the table */
34 
35  namptr = &nametab[nnames]; /* Next unused entry in table */
36 
37  /* copy prefix and replacement strings and record device ID */
38 
39  for (i=0; i<psiz; i++) { /* Copy prefix into table entry */
40  namptr->nprefix[i] = *prefix++;
41  }
42 
43  for (i=0; i<rsiz; i++) { /* Copy replacement into entry */
44  namptr->nreplace[i] = *replace++;
45  }
46 
47  namptr->ndevice = device; /* Record the device ID */
48 
49  nnames++; /* Increment number of names */
50 
51  restore(mask);
52  return OK;
53 }
54 
55 
56 /*------------------------------------------------------------------------
57  * namlen - Compute the length of a string stopping at maxlen
58  *------------------------------------------------------------------------
59  */
61  char *name, /* Name to use */
62  int32 maxlen /* Maximum length (including a */
63  /* NULLCH) */
64 )
65 {
66  int32 i; /* Count of characters found */
67 
68  /* Search until a null terminator or length reaches max */
69 
70  for (i=0; i < maxlen; i++) {
71  if (*name++ == NULLCH) {
72  return i+1; /* Include NULLCH in length */
73  }
74  }
75  return SYSERR;
76 }
int32 namlen(char *name, int32 maxlen)
Definition: mount.c:60
void restore(intmask)
全てのシステムヘッダファイルをインクルードする。
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define NNAMES
プレフィックス定義の数
Definition: name.h:13
syscall mount(char *prefix, char *replace, did32 device)
Definition: mount.c:9
#define OK
処理が成功した場合
Definition: kernel.h:77
#define NM_REPLLEN
置換(1個)の最大サイズ
Definition: name.h:9
int32 nnames
割り当てられたネームテーブルエントリの数
Definition: naminit.c:23
struct nmentry nametab[]
名前マッピングのテーブル
Definition: naminit.c:22
did32 ndevice
プレフィックス用のデバイスディスクリプタ
Definition: name.h:26
全ての名前マッピングを定義する名前プレフィックステーブルの定義(ネームテーブルエントリ) ...
Definition: name.h:19
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
#define NM_PRELEN
プレフィックス文字列の最大サイズ
Definition: name.h:7
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
int32 did32
デバイスID
Definition: kernel.h:28
char nprefix[NM_PRELEN]
NULL終端のプレフィックス
Definition: name.h:22
int32 syscall
システムコール関数 返り値の型
Definition: kernel.h:47
char nreplace[NM_REPLLEN]
NULL終端置換
Definition: name.h:24
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
intmask disable(void)
割り込み禁止(intr.Sに定義がある)