00001
00002
00003
00004
00005
00006 #ifdef USERLAND
00007 #define __LINUX_VMALLOC_H
00008 #define _LINUX_VMALLOC_H
00009 #define LINUX_VMALLOC_H
00010 inline void panic(char * c) { }
00011 #endif
00012
00013 #ifdef USERLAND
00014 #include<sysgen.h>
00015 #include<lnmsub.h>
00016 #include<system_data_cells.h>
00017 #include<queue.h>
00018 #include<lnmstrdef.h>
00019 #include<ssdef.h>
00020 #else
00021 #include<linux/mm.h>
00022 #include<sysgen.h>
00023 #include<lnmdef.h>
00024 #include<lnmsub.h>
00025 #include<system_data_cells.h>
00026 #include<queue.h>
00027 #include<lnmdef.h>
00028 #include<lnmstrdef.h>
00029 #include<ssdef.h>
00030 #include<descrip.h>
00031 #include<misc.h>
00032 #include <exe_routines.h>
00033 #include <sch_routines.h>
00034 #include <misc_routines.h>
00035 #include <linux/slab.h>
00036 #include <internals.h>
00037 #include <mtxdef.h>
00038 #endif
00039
00040
00041
00042 #define LNM_DEBUG
00043 #undef LNM_DEBUG
00044
00045 #define lnmprintf printk
00046
00047
00048
00049 int lnm_hash(const int length, const unsigned char * log, const unsigned long mask, unsigned long * myhash) {
00050 unsigned char *tmp=log;
00051 unsigned char count=length;
00052 unsigned long hash=count;
00053 #ifdef LNM_DEBUG
00054 lnmprintf("count %x %x %s\n",count,tmp,tmp);
00055 #endif
00056 while (count>3) {
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 hash=hash^(tmp[0]&223)^(tmp[1]&223)^(tmp[2]&223)^(tmp[3]&223);
00068
00069 count-=4;
00070 tmp+=4;
00071 hash=hash<<9;
00072 };
00073
00074 while (count) {
00075
00076 hash=hash^((*tmp)&223);
00077 count--;
00078 tmp++;
00079
00080
00081 };
00082 hash*=0x71279461;
00083 hash/=3;
00084
00085
00086
00087
00088
00089 hash=hash%LNMSHASHTBL;
00090
00091 hash=hash&mask;
00092
00093 *myhash=hash;
00094
00095
00096 return SS__NORMAL;
00097 }
00098
00099 int lnm_searchlog(struct struct_lnm_ret * r,int loglen, char * lognam, int tabnamlen, char * tablename) {
00100 int status;
00101 void * hash;
00102 long ahash;
00103 struct _pcb * pcb = ctl_gl_pcb;
00104 struct struct_rt * rt=lnmmalloc(sizeof(struct struct_rt));
00105 struct struct_nt * nt=lnmmalloc(sizeof(struct struct_nt));
00106 memset(rt,0,sizeof(struct struct_rt));
00107 memset(nt,0,sizeof(struct struct_nt));
00108
00109 #ifdef LNM_DEBUG
00110 lnmprintf("searchlog\n");
00111 #endif
00112
00113 status=lnm_hash(loglen,lognam,0xffff,&ahash);
00114
00115 nt->loglen=loglen;
00116 nt->lognam=lognam;
00117 nt->hash=ahash;
00118
00119 hash=ctl_gl_lnmhash;
00120 status=lnm_presearch(r, hash, nt);
00121
00122 if ((status&1)==0) {
00123 hash=&lnmhshs;
00124 status=lnm_presearch(r, hash, nt);
00125 }
00126
00127 if ((status&1)==0) {
00128 kfree(nt);
00129 kfree(rt);
00130 return status;
00131 }
00132
00133 lnm_setup(r, rt, loglen, lognam,nt);
00134 lnm_table(r, rt, nt);
00135 lnm_contsearch(r, ahash, hash, nt);
00136 #ifdef LNM_DEBUG
00137 lnmprintf("searchlogexit\n");
00138 #endif
00139 kfree(nt);
00140 kfree(rt);
00141 return status;
00142 }
00143
00144 int lnm_search_one(struct struct_lnm_ret * r,int loglen, char * logical, int tabnamlen, char * tablename, char * result) {
00145
00146
00147 #ifdef LNM_DEBUG
00148 lnmprintf("searchoneexit\n");
00149 #endif
00150 #ifdef USERLAND
00151 exit(1);
00152 #endif
00153
00154 }
00155
00156 int lnm_presearch(struct struct_lnm_ret * r,struct lnmhshs * hashtable, struct struct_nt * nt) {
00157 int status;
00158 unsigned long * myhash;
00159
00160 myhash=lnmmalloc(sizeof(unsigned long));
00161 #ifdef LNM_DEBUG
00162 lnmprintf("presearch %x %s\n",nt->loglen,nt->lognam);
00163 #endif
00164 status=lnm_hash(nt->loglen,nt->lognam,0xffff,myhash);
00165 status=lnm_contsearch(r,*myhash,hashtable,nt);
00166
00167 lnmfree(myhash);
00168 return status;
00169 }
00170
00171 int lnm_contsearch(struct struct_lnm_ret * r, int hash, struct lnmhshs * hashtable, struct struct_nt * nt) {
00172 int status;
00173 int lenstatus;
00174 struct _lnmb *head, *tmp, *oldtmp;
00175 head=hashtable->entry[hash*2];
00176 #ifdef LNM_DEBUG
00177 lnmprintf("contsearch %x %x\n",head,hash);
00178 #endif
00179 if (head) {
00180 tmp=nt->lnmb_cur;
00181 if (tmp==0) {
00182 tmp=head;
00183 nt->lnmb_cur=tmp;
00184 }
00185 do {
00186
00187 if (tmp->lnmb_b_count==nt->loglen) {
00188 #if 0
00189 lenstatus=strncmp(nt->lognam,tmp->lnmb_t_name,nt->loglen);
00190 #else
00191
00192 int i;
00193 for(i=0,lenstatus=0;i<nt->loglen && lenstatus==0;i++) {
00194 char c1,c2;
00195 c1=nt->lognam[i];
00196 c2=tmp->lnmb_t_name[i];
00197 if (c1>='A' && c1<='Z') c1|=0x20;
00198 if (c2>='A' && c2<='Z') c2|=0x20;
00199 lenstatus=c1-c2;
00200 }
00201 #endif
00202 if (lenstatus==0) {
00203 if (nt->lnmth && nt->lnmth!=tmp->lnmb_l_table) {
00204 } else {
00205 r->mylnmb=tmp;
00206 #ifdef LNM_DEBUG
00207 lnmprintf("found %x\n",tmp);
00208 #endif
00209 return SS__NORMAL;
00210 }
00211 }
00212 }
00213
00214 nt->lnmb_cur=tmp;
00215 oldtmp=tmp;
00216 tmp=tmp->lnmb_l_flink;
00217 } while (tmp!=head && tmp!=oldtmp) ;
00218 nt->lnmb_cur=0;
00219 }
00220 return SS__NOLOGNAM;
00221 }
00222
00223 int lnm_firsttab(struct struct_lnm_ret * r,int tabnamlen, char * tablename) {
00224 struct struct_rt * MYRT;
00225 struct struct_nt * MYNT;
00226 MYRT=(struct struct_rt *)lnmmalloc(sizeof(struct struct_rt));
00227 memset(MYRT,0,sizeof(struct struct_rt));
00228 MYNT=(struct struct_nt *)lnmmalloc(sizeof(struct struct_nt));
00229 memset(MYNT,0,sizeof(struct struct_nt));
00230 #if 0
00231 MYNT->loglen=tabnamlen;
00232 MYNT->lognam=tablename;
00233 #endif
00234 #ifdef LNM_DEBUG
00235 lnmprintf("firstab %s\n",tablename);
00236 #endif
00237 lnm_setup(r,MYRT,tabnamlen,tablename,MYNT);
00238 lnmfree(MYRT);
00239 lnmfree(MYNT);
00240 }
00241
00242 int lnm_setup(struct struct_lnm_ret * r,struct struct_rt * RT, int tabnamlen, char * tablename, struct struct_nt * nt) {
00243 int status;
00244 RT->depth=0;
00245 RT->tries=255;
00246 #ifdef LNM_DEBUG
00247 lnmprintf("lnm_setup %x %s\n",tablename, tablename);
00248 #endif
00249 status=lnm_lookup(r, RT, tabnamlen, tablename, nt);
00250 if (status==SS__NORMAL) RT->context[RT->depth]=r->mylnmb;
00251 else return status;
00252
00253 status=lnm_table_srch(r, RT, nt);
00254 status=lnm_table(r, RT, nt);
00255 return status;
00256 }
00257
00258 int lnm_table(struct struct_lnm_ret * r,struct struct_rt * rt, struct struct_nt * nt ) {
00259
00260 int status;
00261 status=lnm_table_srch(r,rt,nt);
00262 return status;
00263 }
00264
00265 int lnm_lookup(struct struct_lnm_ret * r,struct struct_rt * rt, int loglen, char * lognam, struct struct_nt * nt) {
00266 int status;
00267 struct _pcb * pcb = ctl_gl_pcb;
00268 void * hash;
00269 nt->loglen=loglen;
00270 nt->lognam=lognam;
00271 #ifdef LNM_DEBUG
00272 lnmprintf("lookup %s %x\n",nt->lognam,nt->loglen);
00273 #endif
00274 nt->lnmb=*lnm_al_dirtbl[1];
00275 hash=ctl_gl_lnmhash;
00276 status=lnm_presearch(r,hash,nt);
00277 if ((status&1)==0) {
00278 nt->lnmb=*lnm_al_dirtbl[0];
00279 hash=&lnmhshs;
00280 status=lnm_presearch(r,hash,nt);
00281 }
00282 if (status!=SS__NOLOGNAM) return status;
00283 return status;
00284 }
00285
00286 int lnm_table_srch(struct struct_lnm_ret * r,struct struct_rt *RT, struct struct_nt * nt) {
00287 struct _lnmx * lnmx = (r->mylnmb)->lnmb_l_lnmx;
00288 int len, status;
00289 do {
00290 RT->tries--;
00291 if (!RT->tries) return SS__TOOMANYLNAM;
00292 if ((lnmx->lnmx_l_flags)&LNMX$M_TERMINAL)
00293 RT->flags|=LNMX_M_TERMINAL;
00294 else
00295 RT->flags&=~LNMX_M_TERMINAL;
00296
00297 if (RT->depth>10) return SS__TOOMANYLNAM;
00298 RT->context[RT->depth]=(r->mylnmb);
00299 if (lnmx->lnmx_l_index==LNMX$C_TABLE) {
00300 return SS__NORMAL;
00301 }
00302 RT->depth++;
00303 len=lnmx->lnmx_l_xlen;
00304 #ifdef LNM_DEBUG
00305 lnmprintf("tsr %x %s \n",lnmx->lnmx_t_xlation,lnmx->lnmx$t_xlation);
00306 #endif
00307 status=lnm_lookup(r,RT,len,lnmx->lnmx$t_xlation,nt);
00308 lnmx=lnmx->lnmx_l_next;
00309 } while (lnmx);
00310 if (lnmx && lnmx->lnmx_l_index==LNMX$C_TABLE) {
00311 RT->depth--;
00312 }
00313 }
00314
00315 int lnm_inslogtab(struct struct_lnm_ret * r, struct _lnmb * mylnmb) {
00316 int status;
00317 unsigned long * myhash;
00318 myhash=lnmmalloc(sizeof(unsigned long));
00319 #ifdef LNM_DEBUG
00320 lnmprintf("inslog\n");
00321 lnmprintf("%x %s\n",mylnmb->lnmb_b_count,&(mylnmb->lnmb$t_name[0]));
00322 #endif
00323 status=lnm_hash(mylnmb->lnmb$b_count,&(mylnmb->lnmb$t_name[0]),0xffff,myhash);
00324
00325
00326
00327 struct lnmhshs * hashtable = &lnmhshs;
00328 if (mylnmb->lnmb_l_table && mylnmb->lnmb$l_table->lnmth$l_hash)
00329 hashtable=mylnmb->lnmb_l_table->lnmth$l_hash;
00330 else
00331 printk("zero hashtable\n");
00332
00333 if (hashtable->entry[2*(*myhash)])
00334 insque(mylnmb,hashtable->entry[2*(*myhash)]);
00335 else {
00336 hashtable->entry[2*(*myhash)]=mylnmb;
00337 hashtable->entry[2*(*myhash)+1]=mylnmb;
00338 mylnmb->lnmb_l_flink=mylnmb;
00339 mylnmb->lnmb_l_blink=mylnmb;
00340 }
00341 }
00342
00343 int lnm_check_prot() { ; }
00344
00345 #ifdef USERLAND
00346
00347 void lnm_lock(void) {
00348 }
00349
00350 void lnm_unlock(void) {
00351 }
00352
00353 void lnm_lockr(void) {
00354 }
00355
00356 void lnm_unlockr(void) {
00357 }
00358
00359 void lnm_lockw(void) {
00360 }
00361
00362 void lnm_unlockw(void) {
00363 }
00364
00365 void getipl(void) {
00366 }
00367
00368 void setipl(void) {
00369 }
00370
00371 void mycli(void) {
00372 }
00373
00374 void mysti(void) {
00375 }
00376
00377 #else
00378
00379 #define lnm_aq_mutex lnm_spin
00380 static struct _mtx lnm_spin = { 65535 };
00381
00382 void lnm_lock(void) {
00383 sch_lockw(&lnm$aq_mutex);
00384 }
00385
00386 void lnm_unlock(void) {
00387 sch_unlockw(&lnm$aq_mutex);
00388 }
00389
00390 void lnm_lockr(void) {
00391 sch_lockw(&lnm$aq_mutex);
00392 }
00393
00394 void lnm_unlockr(void) {
00395 sch_unlockw(&lnm$aq_mutex);
00396 }
00397
00398 void lnm_lockw(void) {
00399 sch_lockw(&lnm$aq_mutex);
00400 }
00401
00402 void lnm_unlockw(void) {
00403 sch_unlockw(&lnm$aq_mutex);
00404 }
00405
00406 #endif
00407
00408 int search_log_prc(char * name, int namelen, char ** retname, int * retsize) {
00409 #if 0
00410 _DESCRIPTOR(prc,"LNM$PROCESS_TABLE");
00411 int sts;
00412 int retlen;
00413 struct item_list_3 itm[2];
00414 struct dsc_descriptor mytabnam, mynam;
00415 char resstring[LNM_C_NAMLENGTH]="";
00416 mynam.dsc_w_length=namelen;
00417 mynam.dsc_a_pointer=name;
00418 itm[0].item_code=LNM__STRING;
00419 itm[0].buflen=LNM_C_NAMLENGTH;
00420 itm[0].bufaddr=resstring;
00421 itm[0].retlenaddr=&retlen;
00422 memset(&itm[1],0,sizeof(struct item_list_3));
00423 sts = exe_trnlnm(0, &prc, &mynam, 0, itm);
00424
00425 if (sts&1) {
00426 char * c = kmalloc(retlen,GFP_KERNEL);
00427 memcpy(c,resstring,retlen);
00428 *retname = c;
00429 *retsize = retlen;
00430 }
00431 return sts;
00432 #else
00433 _DESCRIPTOR(prc,"LNM$PROCESS_TABLE");
00434 int sts;
00435 int retlen;
00436 struct item_list_3 itm[2];
00437 struct dsc_descriptor * mytabnam = &prc;
00438 struct struct_lnm_ret ret={0,0};
00439 sts = lnm_searchlog(&ret,namelen,name,mytabnam->dsc$w_length,mytabnam->dsc$a_pointer);
00440 if (sts&1) {
00441 retlen=(ret.mylnmb)->lnmb_l_lnmx->lnmx$l_xlen;
00442 char * c = kmalloc(retlen,GFP_KERNEL);
00443 memcpy(c,(ret.mylnmb)->lnmb_l_lnmx->lnmx$t_xlation,retlen);
00444 *retname = c;
00445 *retsize = retlen;
00446 }
00447 return sts;
00448 #endif
00449 }
00450
00451 int search_log_sys(char * name, int namelen, char ** retname, int * retsize) {
00452 #if 0
00453 _DESCRIPTOR(sys,"LNM$SYSTEM_TABLE");
00454 int sts;
00455 int retlen;
00456 struct item_list_3 itm[2];
00457 struct dsc_descriptor mytabnam, mynam;
00458 char resstring[LNM_C_NAMLENGTH]="";
00459 mynam.dsc_w_length=namelen;
00460 mynam.dsc_a_pointer=name;
00461 itm[0].item_code=LNM__STRING;
00462 itm[0].buflen=LNM_C_NAMLENGTH;
00463 itm[0].bufaddr=resstring;
00464 itm[0].retlenaddr=&retlen;
00465 memset(&itm[1],0,sizeof(struct item_list_3));
00466 sts = exe_trnlnm(0, &sys, &mynam, 0, itm);
00467
00468 if (sts&1) {
00469 char * c = kmalloc(retlen,GFP_KERNEL);
00470 memcpy(c,resstring,retlen);
00471 *retname = c;
00472 *retsize = retlen;
00473 }
00474 return sts;
00475 #else
00476 _DESCRIPTOR(sys,"LNM$SYSTEM_TABLE");
00477 int sts;
00478 int retlen;
00479 struct item_list_3 itm[2];
00480 struct dsc_descriptor * mytabnam = &sys;
00481 struct struct_lnm_ret ret={0,0};
00482 sts = lnm_searchlog(&ret,namelen,name,mytabnam->dsc$w_length,mytabnam->dsc$a_pointer);
00483 if (sts&1) {
00484 retlen=(ret.mylnmb)->lnmb_l_lnmx->lnmx$l_xlen;
00485 char * c = kmalloc(retlen,GFP_KERNEL);
00486 memcpy(c,(ret.mylnmb)->lnmb_l_lnmx->lnmx$t_xlation,retlen);
00487 *retname = c;
00488 *retsize = retlen;
00489 }
00490 return sts;
00491 #endif
00492 }
00493
00494 #if 0
00495 int search_log_repl(char * name, char ** retname, int * retsize) {
00496 int sts;
00497 int namelen=strlen(name);
00498 #ifndef __i386__
00499 char * myname=kmalloc(namelen,GFP_KERNEL);
00500 #else
00501 char myname[namelen];
00502 #endif
00503 memcpy(myname,name,namelen);
00504 sts=search_log_prc(myname,namelen,retname,retsize);
00505 if (sts&1) goto ret;
00506 sts=search_log_sys(myname,namelen,retname,retsize);
00507 if (sts&1) goto ret;
00508 char * semi = strchr(myname,':');
00509 if (semi==0) goto ret;
00510 * semi = 0;
00511 sts=search_log_prc(myname,semi-myname,retname,retsize);
00512 if (sts&1) goto found;
00513 sts=search_log_sys(myname,semi-myname,retname,retsize);
00514 if ((sts&1)==0) goto ret;
00515
00516 found:
00517 {}
00518
00519 #ifndef __i386__
00520 char * newret = kmalloc((*retsize)+namelen-strlen(myname),GFP_KERNEL);
00521 #else
00522 char * newret;
00523 int alosize;
00524 sts = exe_std_alononpaged((*retsize)+namelen-strlen(myname), &alosize, &newret);
00525 #endif
00526 memcpy(newret,*retname,(*retsize));
00527 newret[*retsize]=0;
00528 if (strchr(newret,':')) {
00529 memcpy(newret+(*retsize),semi+1,namelen-strlen(myname)-1);
00530 (*retsize)--;
00531 } else {
00532 printk("for RMS sys_input, check\n");
00533 newret[*retsize]=':';
00534 memcpy(newret+(*retsize),semi,namelen-strlen(myname));
00535 }
00536 *retname=newret;
00537 *retsize=(*retsize)+namelen-strlen(myname);
00538
00539
00540 ret:
00541 #ifndef __i386__
00542 kfree(myname);
00543 #endif
00544
00545 return sts;
00546 }
00547 #else
00548 int search_log_repl(char * name, char ** retname, int * retsize) {
00549 int sts;
00550 char * semi = 0;
00551 int namelen=strlen(name);
00552 int acmode = 0;
00553 char * newret;
00554 int alosize;
00555 int rms_std_alononpaged (int reqsize, int32 *alosize_p, void **pool_p);
00556 sts = rms_std_alononpaged(128, &alosize, &newret);
00557
00558 struct dsc_descriptor log;
00559 log.dsc_a_pointer = name;
00560 log.dsc_w_length = strlen(name);
00561 _DESCRIPTOR(prc,"LNM$PROCESS_TABLE");
00562 _DESCRIPTOR(sys,"LNM$SYSTEM_TABLE");
00563 struct _iosb iosb;
00564 struct item_list_3 itmlst[2];
00565 int retlen;
00566 int * retlenaddr;
00567 int buflen;
00568 void * bufaddr;
00569 char s[255];
00570 int slen=255;
00571
00572
00573
00574 retlenaddr = retsize;
00575
00576 buflen = 128;
00577 bufaddr = newret;
00578
00579 itmlst[0].item_code=LNM__STRING;
00580 itmlst[0].buflen=buflen;
00581 itmlst[0].retlenaddr=retlenaddr;
00582 itmlst[0].bufaddr=bufaddr;
00583 itmlst[1].item_code=0;
00584
00585 unsigned int sys_trnlnm();
00586 sts=sys_trnlnm(0,&prc,&log,acmode,itmlst);
00587
00588 if (sts&1)
00589 goto found;
00590
00591 sts=sys_trnlnm(0,&sys,&log,acmode,itmlst);
00592
00593 if (sts&1)
00594 goto found;
00595
00596 semi = strchr(name,':');
00597 if (semi == 0)
00598 return sts;
00599
00600 log.dsc_w_length = semi - name;
00601
00602 sts=sys_trnlnm(0,&prc,&log,acmode,itmlst);
00603
00604 if (sts&1)
00605 goto found;
00606
00607 sts=sys_trnlnm(0,&sys,&log,acmode,itmlst);
00608
00609 if ((sts&1)==0)
00610 return sts;
00611
00612 found:
00613
00614 if (semi == 0)
00615 goto ret;
00616
00617 newret[*retsize]=0;
00618 if (strchr(newret,':')) {
00619 memcpy(newret+(*retsize),semi+1,namelen-(semi-name)-1);
00620 (*retsize)--;
00621 } else {
00622 printk("for RMS sys_input, check\n");
00623 newret[*retsize]=':';
00624 memcpy(newret+(*retsize),semi,namelen-(semi-name));
00625 }
00626 *retsize=(*retsize)+namelen-(semi-name);
00627 ret:
00628 *retname=newret;
00629
00630 return sts;
00631 }
00632 #endif
00633