📄 gname.c
字号:
return E_PAR; } } } /* Lock */ Lock(&GNameMgrLock); /* Retrieve an appropriate entry. */ entry = searchEntry(name); if(entry != NULL){ /* When already registered, */ /* Protection specification check */ if ((entry->atr & NA_PROTECT) == NA_PROTECT) { if (pid != entry->pid) { aERR = E_OBJ; goto err_ret; } } DBS(printf("< Global Name Entry Already Exist. >\n")); DBS(prGNameEntry(entry)); switch(atr & (~(TA_DELEXIT | NA_PROTECT))) { case N_MODIFY: case N_FORCE: /* Perform data change. */ if((atr & TA_DELEXIT) == TA_DELEXIT){ pid = getPID(); if(pid <= 0) { aERR = E_SYS; } } if(aERR == E_OK){ setName(entry, name); entry->searchKey = name2Key(entry->gname.name); entry->pid = pid; entry->data = data; DBS(printf("< Global Name Entry Re Enroll: >\n")); DBS(prGNameEntry(entry)); } break; case N_CREATE: aERR = E_OBJ; break; default: aERR = E_PAR; break; } }else { /* When not registered, */ switch(atr & (~(TA_DELEXIT | NA_PROTECT))){ case N_MODIFY: aERR = E_NOEXS; break; case N_CREATE: case N_FORCE: /* Perform data generation. */ if((atr & (TA_DELEXIT | NA_PROTECT)) != TSD_TCN_VAL_0X00000000) { pid = getPID(); if(pid <= 0) { aERR = E_SYS; } } entry = getEntry(&PoolList); if(!entry) { aERR = E_SYSMEM; } if(aERR == E_OK){ initGNameEntry(entry); setName(entry, name); entry->searchKey = name2Key(entry->gname.name); entry->pid = pid; entry->data = data; entry->atr = atr & NA_PROTECT; QueInsert((QUEUE *)entry, (QUEUE *)&(GNameList[entry->searchKey])); DBS(printf("< Global Name Entry Enroll: >\n")); DBS(prGNameEntry(entry)); } break; default: aERR = E_PAR; break; } }err_ret: /* Unlock */ Unlock(&GNameMgrLock); DBS(printf("- cre_nam()\n")); return aERR;}/*--------------------------------------------------------------*//* System Call : del_nam() *//*--------------------------------------------------------------*/LOCAL ER _tkse_del_nam(TC *name){ ER aERR = E_OK; GNameEntry *entry = (GNameEntry *)NULL; W count; TC *nm; ID pid = InvalidPID; DBS(printf("+ del_nam((TC *): %08x)\n", (W)name)); /* Parameter check */ if(!name) { return E_MACV; } for(count = 0, nm = name; count < GlobalNameLengthLimit; count++){ if(CheckSpaceR(nm, sizeof(TC)) < 0) { return E_MACV; } if(*nm == TNULL){ if(count != 0){ break; }else { return E_PAR; } } } /* Lock */ Lock(&GNameMgrLock); /* Retrieve an appropriate entry. */ entry = searchEntry(name); if(entry != NULL){ /* When the entry exists, */ DBS(printf("< Target Entry Exist. >\n")); DBS(prGNameEntry(entry)); /* Protection specification Check */ if ((entry->atr & NA_PROTECT) == NA_PROTECT) { pid = getPID(); if (pid != entry->pid) { aERR = E_OBJ; goto err_ret; } } /* Release the entry. */ QueRemove((QUEUE *)entry); DBS(printf("< Global Name Entry Delete: >\n")); DBS(prGNameEntry(entry)); initGNameEntry(entry); QueInsert((QUEUE *)entry, (QUEUE *)&PoolList); }else { /* When the entry does no exist, */ aERR = E_NOEXS; }err_ret: /* Unlock */ Unlock(&GNameMgrLock); DBS(printf("- del_nam()\n")); return aERR;}/*--------------------------------------------------------------*//* System Call : get_nam() *//*--------------------------------------------------------------*/LOCAL ER _tkse_get_nam(TC *name, W *data){ ER aERR = E_OK; GNameEntry *entry = (GNameEntry *)NULL; W count; TC *nm; DBS(printf("+ get_nam((TC *): %08x, (W *): %08x)\n", (W)name, (W)data)); /* Parameter check */ if(!name || !data) { return E_MACV; } for(count = 0, nm = name; count < GlobalNameLengthLimit; count++){ if(CheckSpaceR(nm, sizeof(TC)) < 0) { return E_MACV; } if(*nm == TNULL){ if(count != 0){ break; }else { return E_PAR; } } } if(CheckSpaceRW(data, sizeof(W)) < 0) { return E_MACV; } /* Lock */ Lock(&GNameMgrLock); /* Retrieve an appropriate entry. */ entry = searchEntry(name); if(entry != NULL){ /* When the entry exists, */ /* Obtain the data, and set data to it. */ *data = entry->data; DBS(printf("Global Name Entry GetValue:\n")); DBS(prGNameEntry(entry)); }else { /* When the entry does not exist, */ aERR = E_NOEXS; } /* Unlock */ Unlock(&GNameMgrLock); DBS(printf("- get_nam()\n")); return aERR;}/*--------------------------------------------------------------*//* SVC Interface *//*--------------------------------------------------------------*/EXPORT WER svc_GNamemgr( VP para, W fn ){ switch ( fn ) { case NM_CRE_NAM_FN: { NM_CRE_NAM_PARA *p = para; return _tkse_cre_nam(p->name, p->data, p->opt); } case NM_DEL_NAM_FN: { NM_DEL_NAM_PARA *p = para; return _tkse_del_nam(p->name); } case NM_GET_NAM_FN: { NM_GET_NAM_PARA *p = para; return _tkse_get_nam(p->name, p->data); } default: { /* nothing to do */ break; } } return E_RSFN;}/*--------------------------------------------------------------*//* cleanup function *//*--------------------------------------------------------------*/EXPORT void cleanupGName(ID resid, ID pid){ DBF(printf("+ vdel_nam(pid:%d)\n", pid)); /* Retrieve the entry that has the same PID, and fetch them after making the list. */ /* Release the entry. */ /* Lock */ Lock(&GNameMgrLock); getListOfPID(&PoolList, pid); /* Unlock */ Unlock(&GNameMgrLock); DBF(printf("- vdel_nam()\n"));}/*--------------------------------------------------------------*//* Dummy GetSysConf *//*--------------------------------------------------------------*/#ifdef DEBUGW GetSysConf(UB *name, W *val){ *val = NumOfPoolEntries; return 1;}#endif/*--------------------------------------------------------------*//* Initialise GrobalNameAdministration (Part Of Process Manager)*//*--------------------------------------------------------------*/LOCAL ER initialize(void){ W v[L_SYSCONF_VAL]; W entries; T_DSSY dssy; ER err; if ( GetSysConf((UB*)MaxNumOfGNameEntries, v) < 1 ) { return E_SYS; } entries = v[0]; GNameEntryPool = (GNameEntry *)Kmalloc(sizeof(GNameEntry) * (UW)entries); if ( GNameEntryPool == NULL ) { return E_SYS; } /* Initialize the entry pool. */ initPoolList(GNameEntryPool, entries); /* Initialize the hash entry. */ initGNameList(); err = CreateLock(&GNameMgrLock, (UB*)"GNam"); if ( err < E_OK ) { return err; } dssy.ssyatr = TA_NULL; dssy.ssypri = NM_PRI; dssy.svchdr = (FP)svc_GNamemgr; dssy.breakfn = NULL; dssy.startupfn = NULL; dssy.cleanupfn = cleanupGName; dssy.eventfn = NULL; dssy.resblksz = 0; err = tk_def_ssy(NM_SVC, &dssy); if ( err < E_OK ) { return err; } return E_OK;}/*--------------------------------------------------------------*//* Shutdown GrobalNameAdministration (Part Of Process Manager) *//*--------------------------------------------------------------*/LOCAL ER shutdown(void){ /* Deregister the manager. */ tk_def_ssy(NM_SVC, NULL); DeleteLock(&GNameMgrLock); Kfree(GNameEntryPool); return E_OK;}/*--------------------------------------------------------------*//* Initialize / Shutdown *//*--------------------------------------------------------------*/EXPORT ER GNameMgr( INT ac, UB *av[] ){ if( ac >= 0 ){ /* initialize */ return initialize(); }else { /* shutdown */ return shutdown(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -