void lke_setgdr(void) { gd_region *r_top; mval reset; bool def; short len; char buf[256]; int4 rundown_status = EXIT_NRM; /* if gds_rundown went smoothly */ static readonly char init_gdr[] = "gtmgbldir"; gvcmy_rundown(); gv_cur_region = gd_header->regions; r_top = gv_cur_region + gd_header->n_regions; for (gv_cur_region = gd_header->regions, r_top = gv_cur_region + gd_header->n_regions; gv_cur_region < r_top; gv_cur_region++) { tp_change_reg(); UNIX_ONLY(rundown_status |=) gds_rundown(); } if (EXIT_NRM != rundown_status) rts_error(VARLSTCNT(1) ERR_NOTALLDBRNDWN); if (cli_present("gld")) { cli_get_value("gld", buf) ; def = FALSE; reset.mvtype = MV_STR; reset.str.len = STRLEN(buf); reset.str.addr = buf; } else { reset.mvtype = MV_STR; reset.str.len = SIZEOF(init_gdr) - 1; reset.str.addr = init_gdr; } zgbldir(&reset); cs_addrs = 0; cs_data = 0; region_init(FALSE) ; #ifndef MUTEX_MSEM_WAKE mutex_sock_cleanup(); #endif gtmsecshr_sock_cleanup(CLIENT); }
void gvinit(void) { mval v; int4 keysize; gv_key *tmp_currkey, *tmp_altkey; if (!gd_header) { v.mvtype = MV_STR; v.str.len = 0; gd_header = zgbldir(&v); gd_map = gd_header->maps; gd_map_top = gd_map + gd_header->n_maps; gd_targ_addr = gd_header; } /* May get in here after an extended ref call, so you don't want to lose any preexisting keys */ keysize = (gd_header->regions->max_key_size + MAX_NUM_SUBSC_LEN + 4) & (-4); assert(keysize); if (keysize > gv_keysize) { tmp_currkey = gv_currkey; tmp_altkey = gv_altkey; gv_altkey = (gv_key*)malloc(sizeof(gv_key) - 1 + keysize); gv_currkey = (gv_key*)malloc(sizeof(gv_key) - 1 + keysize); gv_keysize = keysize; gv_currkey->top = gv_altkey->top = gv_keysize; if (tmp_currkey) { assert(tmp_altkey); free(tmp_currkey); free(tmp_altkey); } } else assert(gv_currkey && gv_altkey); gv_currkey->end = gv_currkey->prev = gv_altkey->end = gv_altkey->prev = 0; gv_altkey->base[0] = gv_currkey->base[0] = '\0'; }
void op_svput(int varnum, mval *v) { int i, ok, state; char *vptr; DCL_THREADGBL_ACCESS; SETUP_THREADGBL_ACCESS; switch (varnum) { case SV_X: MV_FORCE_NUM(v); io_curr_device.out->dollar.x = (short)MV_FORCE_INT(v); if ((short)(io_curr_device.out->dollar.x) < 0) io_curr_device.out->dollar.x = 0; break; case SV_Y: MV_FORCE_NUM(v); io_curr_device.out->dollar.y = (short)MV_FORCE_INT(v); if ((short)(io_curr_device.out->dollar.y) < 0) io_curr_device.out->dollar.y = 0; break; case SV_ZCOMPILE: MV_FORCE_STR(v); if ((TREF(dollar_zcompile)).addr) free ((TREF(dollar_zcompile)).addr); (TREF(dollar_zcompile)).addr = (char *)malloc(v->str.len); memcpy((TREF(dollar_zcompile)).addr, v->str.addr, v->str.len); (TREF(dollar_zcompile)).len = v->str.len; break; case SV_ZSTEP: MV_FORCE_STR(v); op_commarg(v,indir_linetail); op_unwind(); dollar_zstep = *v; break; case SV_ZGBLDIR: MV_FORCE_STR(v); if ((dollar_zgbldir.str.len != v->str.len) || memcmp(dollar_zgbldir.str.addr, v->str.addr, dollar_zgbldir.str.len)) { if (0 == v->str.len) { /* set $zgbldir="" */ dpzgbini(); gd_header = NULL; } else { gd_header = zgbldir(v); /* update the gd_map */ SET_GD_MAP; dollar_zgbldir.str.len = v->str.len; dollar_zgbldir.str.addr = v->str.addr; s2pool(&dollar_zgbldir.str); } if (NULL != gv_currkey) { gv_currkey->base[0] = '\0'; gv_currkey->prev = gv_currkey->end = 0; } else if (NULL != gd_header) gvinit(); if (NULL != gv_target) gv_target->clue.end = 0; } break; case SV_ZMAXTPTIME: dollar_zmaxtptime = mval2i(v); break; case SV_ZROUTINES: MV_FORCE_STR(v); /* The string(v) should be parsed and loaded before setting $zroutines * to retain the old value in case errors occur while loading */ zro_load(&v->str); if ((TREF(dollar_zroutines)).addr) free ((TREF(dollar_zroutines)).addr); (TREF(dollar_zroutines)).addr = (char *)malloc(v->str.len); memcpy((TREF(dollar_zroutines)).addr, v->str.addr, v->str.len); (TREF(dollar_zroutines)).len = v->str.len; break; case SV_ZSOURCE: MV_FORCE_STR(v); dollar_zsource.mvtype = MV_STR; dollar_zsource.str = v->str; break; case SV_ZTRAP: # ifdef GTM_TRIGGER if (0 < gtm_trigger_depth) rts_error(VARLSTCNT(1) ERR_NOZTRAPINTRIG); # endif MV_FORCE_STR(v); if (ztrap_new) op_newintrinsic(SV_ZTRAP); dollar_ztrap.mvtype = MV_STR; dollar_ztrap.str = v->str; /* Setting either $ZTRAP or $ETRAP to empty causes any current error trapping to be canceled */ if (!v->str.len) { dollar_etrap.mvtype = MV_STR; dollar_etrap.str = v->str; ztrap_explicit_null = TRUE; } else /* Ensure that $ETRAP and $ZTRAP are not both active at the same time */ { ztrap_explicit_null = FALSE; if (dollar_etrap.str.len > 0) gtm_newintrinsic(&dollar_etrap); } if (ztrap_form & ZTRAP_POP) ztrap_save_ctxt(); if (tp_timeout_deferred && !dollar_zininterrupt) /* A tp timeout was deferred. Now that $ETRAP is no longer in effect and no job interrupt is in * effect, the timeout need no longer be deferred and can be recognized. */ tptimeout_set(0); break; case SV_ZSTATUS: MV_FORCE_STR(v); dollar_zstatus.mvtype = MV_STR; dollar_zstatus.str = v->str; break; case SV_PROMPT: MV_FORCE_STR(v); MV_FORCE_LEN_STRICT(v); /* Ensure that direct mode prompt will not have BADCHARs, * otherwise the BADCHAR error may fill up the filesystem */ if (v->str.len <= SIZEOF_prombuf) (TREF(gtmprompt)).len = v->str.len; else if (!gtm_utf8_mode) (TREF(gtmprompt)).len = SIZEOF_prombuf; # ifdef UNICODE_SUPPORTED else { UTF8_LEADING_BYTE(v->str.addr + SIZEOF_prombuf, v->str.addr, vptr); (TREF(gtmprompt)).len = INTCAST(vptr - v->str.addr); } # endif memcpy((TREF(gtmprompt)).addr, v->str.addr, (TREF(gtmprompt)).len); break; case SV_ECODE: MV_FORCE_STR(v); if (v->str.len) { /* Format must be like ,Mnnn,Mnnn,Zxxx,Uxxx, * Mnnn are ANSI standard error codes * Zxxx are implementation-specific codes * Uxxx are end-user defined codes * Note that there must be commas at the start and at the end */ for (state = 2, i = 0; (i < v->str.len) && (state <= 2); i++) { switch(state) { case 2: state = (v->str.addr[i] == ',') ? 1 : 101; break; case 1: state = ((v->str.addr[i] == 'M') || (v->str.addr[i] == 'U') || (v->str.addr[i] == 'Z')) ? 0 : 101; break; case 0: state = (v->str.addr[i] == ',') ? 1 : 0; break; } } /* The above check would pass strings like "," * so double-check that there are at least three characters * (starting comma, ending comma, and something in between) */ if ((state != 1) || (v->str.len < 3)) { /* error, ecode = M101 */ rts_error(VARLSTCNT(4) ERR_INVECODEVAL, 2, v->str.len, v->str.addr); } } if (v->str.len > 0) { ecode_add(&v->str); rts_error(VARLSTCNT(2) ERR_SETECODE, 0); } else { NULLIFY_DOLLAR_ECODE; /* reset $ECODE related variables to correspond to $ECODE = NULL state */ NULLIFY_ERROR_FRAME; /* we are no more in error-handling mode */ if (tp_timeout_deferred && !dollar_zininterrupt) /* A tp timeout was deferred. Now that we are clear of error handling and no job interrupt * is in process, allow the timeout to be recognized. */ tptimeout_set(0); } break; case SV_ETRAP: MV_FORCE_STR(v); dollar_etrap.mvtype = MV_STR; dollar_etrap.str = v->str; /* Setting either $ZTRAP or $ETRAP to empty causes any current error trapping to be canceled */ if (!v->str.len) { dollar_ztrap.mvtype = MV_STR; dollar_ztrap.str = v->str; } else if (dollar_ztrap.str.len > 0) { /* Ensure that $ETRAP and $ZTRAP are not both active at the same time */ assert(FALSE == ztrap_explicit_null); gtm_newintrinsic(&dollar_ztrap); } ztrap_explicit_null = FALSE; break; case SV_ZERROR: MV_FORCE_STR(v); dollar_zerror.mvtype = MV_STR; dollar_zerror.str = v->str; break; case SV_ZYERROR: MV_FORCE_STR(v); dollar_zyerror.mvtype = MV_STR; dollar_zyerror.str = v->str; break; case SV_SYSTEM: assert(FALSE); rts_error(VARLSTCNT(4) ERR_SYSTEMVALUE, 2, v->str.len, v->str.addr); break; case SV_ZDIR: setzdir(v, NULL); /* change directory to v */ getzdir(); /* update dollar_zdir with current working directory */ break; case SV_ZINTERRUPT: MV_FORCE_STR(v); dollar_zinterrupt.mvtype = MV_STR; dollar_zinterrupt.str = v->str; break; case SV_ZDATE_FORM: MV_FORCE_NUM(v); TREF(zdate_form) = (short)MV_FORCE_INT(v); break; case SV_ZTEXIT: MV_FORCE_STR(v); dollar_ztexit.mvtype = MV_STR; dollar_ztexit.str = v->str; /* Coercing $ZTEXIT to boolean at SET command is more efficient than coercing before each * rethrow at TR/TRO. Since we want to maintain dollar_ztexit as a string, coercion should * not be performed on dollar_ztext, but on a temporary (i.e. parameter v) */ dollar_ztexit_bool = MV_FORCE_BOOL(v); break; case SV_ZQUIT: dollar_zquit_anyway = MV_FORCE_BOOL(v); break; case SV_ZTVALUE: # ifdef GTM_TRIGGER assert(!dollar_tlevel || (tstart_trigger_depth <= gtm_trigger_depth)); if (!dollar_tlevel || (tstart_trigger_depth == gtm_trigger_depth)) rts_error(VARLSTCNT(4) ERR_SETINTRIGONLY, 2, RTS_ERROR_TEXT("$ZTVALUE")); if (dollar_ztriggerop != &gvtr_cmd_mval[GVTR_CMDTYPE_SET]) rts_error(VARLSTCNT(4) ERR_SETINSETTRIGONLY, 2, RTS_ERROR_TEXT("$ZTVALUE")); assert(0 < gtm_trigger_depth); memcpy(dollar_ztvalue, v, SIZEOF(mval)); dollar_ztvalue->mvtype &= ~MV_ALIASCONT; /* Make sure to shut off alias container flag on copy */ assert(NULL != ztvalue_changed_ptr); *ztvalue_changed_ptr = TRUE; break; # else rts_error(VARLSTCNT(1) ERR_UNIMPLOP); # endif case SV_ZTWORMHOLE: # ifdef GTM_TRIGGER MV_FORCE_STR(v); /* See jnl.h for why MAX_ZTWORMHOLE_SIZE should be less than minimum alignsize */ assert(MAX_ZTWORMHOLE_SIZE < (JNL_MIN_ALIGNSIZE * DISK_BLOCK_SIZE)); if (MAX_ZTWORMHOLE_SIZE < v->str.len) rts_error(VARLSTCNT(4) ERR_ZTWORMHOLE2BIG, 2, v->str.len, MAX_ZTWORMHOLE_SIZE); dollar_ztwormhole.mvtype = MV_STR; dollar_ztwormhole.str = v->str; break; # else rts_error(VARLSTCNT(1) ERR_UNIMPLOP); # endif case SV_ZTSLATE: # ifdef GTM_TRIGGER assert(!dollar_tlevel || (tstart_trigger_depth <= gtm_trigger_depth)); if (!dollar_tlevel || (tstart_trigger_depth == gtm_trigger_depth)) rts_error(VARLSTCNT(4) ERR_SETINTRIGONLY, 2, RTS_ERROR_TEXT("$ZTSLATE")); assert(0 < gtm_trigger_depth); MV_FORCE_DEFINED(v); memcpy((char *)&dollar_ztslate, v, SIZEOF(mval)); dollar_ztslate.mvtype &= ~MV_ALIASCONT; /* Make sure to shut off alias container flag on copy */ break; # else rts_error(VARLSTCNT(1) ERR_UNIMPLOP); # endif default: GTMASSERT; } return; }
void op_svput(int varnum, mval *v) { int i, ok, state; error_def(ERR_UNIMPLOP); error_def(ERR_TEXT); error_def(ERR_INVECODEVAL); error_def(ERR_SETECODE); error_def(ERR_SYSTEMVALUE); switch (varnum) { case SV_X: MV_FORCE_NUM(v); io_curr_device.out->dollar.x = (short)MV_FORCE_INT(v); if ((short)(io_curr_device.out->dollar.x) < 0) io_curr_device.out->dollar.x = 0; break; case SV_Y: MV_FORCE_NUM(v); io_curr_device.out->dollar.y = (short)MV_FORCE_INT(v); if ((short)(io_curr_device.out->dollar.y) < 0) io_curr_device.out->dollar.y = 0; break; case SV_ZCOMPILE: MV_FORCE_STR(v); if (dollar_zcompile.addr) free (dollar_zcompile.addr); dollar_zcompile.addr = (char *)malloc(v->str.len); memcpy (dollar_zcompile.addr, v->str.addr, v->str.len); dollar_zcompile.len = v->str.len; break; case SV_ZSTEP: MV_FORCE_STR(v); op_commarg(v,indir_linetail); op_unwind(); dollar_zstep = *v; break; case SV_ZGBLDIR: MV_FORCE_STR(v); if (!(dollar_zgbldir.str.len == v->str.len && !memcmp(dollar_zgbldir.str.addr, v->str.addr, dollar_zgbldir.str.len))) { if(v->str.len == 0) { /* set $zgbldir="" */ dpzgbini(); gd_header = NULL; } else { gd_header = zgbldir(v); dollar_zgbldir.str.len = v->str.len; dollar_zgbldir.str.addr = v->str.addr; s2pool(&dollar_zgbldir.str); } if (gv_currkey) gv_currkey->base[0] = 0; if (gv_target) gv_target->clue.end = 0; } break; case SV_ZMAXTPTIME: dollar_zmaxtptime = mval2i(v); break; case SV_ZROUTINES: MV_FORCE_STR(v); /* The string(v) should be parsed and loaded before setting $zroutines * to retain the old value in case errors occur while loading */ zro_load(&v->str); if (dollar_zroutines.addr) free (dollar_zroutines.addr); dollar_zroutines.addr = (char *)malloc(v->str.len); memcpy (dollar_zroutines.addr, v->str.addr, v->str.len); dollar_zroutines.len = v->str.len; break; case SV_ZSOURCE: MV_FORCE_STR(v); dollar_zsource = v->str; break; case SV_ZTRAP: MV_FORCE_STR(v); if (ztrap_new) op_newintrinsic(SV_ZTRAP); dollar_ztrap.mvtype = MV_STR; dollar_ztrap.str = v->str; /* Setting either $ZTRAP or $ETRAP to empty causes any current error trapping to be canceled */ if (!v->str.len) { dollar_etrap.mvtype = MV_STR; dollar_etrap.str = v->str; ztrap_explicit_null = TRUE; } else /* Ensure that $ETRAP and $ZTRAP are not both active at the same time */ { ztrap_explicit_null = FALSE; if (dollar_etrap.str.len > 0) gtm_newintrinsic(&dollar_etrap); } if (ztrap_form & ZTRAP_POP) ztrap_save_ctxt(); break; case SV_ZSTATUS: MV_FORCE_STR(v); dollar_zstatus.mvtype = MV_STR; dollar_zstatus.str = v->str; break; case SV_PROMPT: MV_FORCE_STR(v); gtmprompt.len = v->str.len < sizeof(prombuf) ? v->str.len : sizeof(prombuf); memcpy(gtmprompt.addr,v->str.addr,gtmprompt.len); break; case SV_ECODE: MV_FORCE_STR(v); if (v->str.len) { /* Format must be like ,Mnnn,Mnnn,Zxxx,Uxxx, * Mnnn are ANSI standard error codes * Zxxx are implementation-specific codes * Uxxx are end-user defined codes * Note that there must be commas at the start and at the end */ for (state = 2, i = 0; (i < v->str.len) && (state <= 2); i++) { switch(state) { case 2: state = (v->str.addr[i] == ',') ? 1 : 101; break; case 1: state = ((v->str.addr[i] == 'M') || (v->str.addr[i] == 'U') || (v->str.addr[i] == 'Z')) ? 0 : 101; break; case 0: state = (v->str.addr[i] == ',') ? 1 : 0; break; } } /* The above check would pass strings like "," * so double-check that there are at least three characters * (starting comma, ending comma, and something in between) */ if ((state != 1) || (v->str.len < 3)) { /* error, ecode = M101 */ rts_error(VARLSTCNT(4) ERR_INVECODEVAL, 2, v->str.len, v->str.addr); } } if (v->str.len > 0) { ecode_add(&v->str); rts_error(VARLSTCNT(2) ERR_SETECODE, 0); } else { NULLIFY_DOLLAR_ECODE; /* reset $ECODE related variables to correspond to $ECODE = NULL state */ NULLIFY_ERROR_FRAME; /* we are no more in error-handling mode */ } break; case SV_ETRAP: MV_FORCE_STR(v); dollar_etrap.mvtype = MV_STR; dollar_etrap.str = v->str; /* Setting either $ZTRAP or $ETRAP to empty causes any current error trapping to be canceled */ if (!v->str.len) { dollar_ztrap.mvtype = MV_STR; dollar_ztrap.str = v->str; } else if (dollar_ztrap.str.len > 0) { /* Ensure that $ETRAP and $ZTRAP are not both active at the same time */ assert(FALSE == ztrap_explicit_null); gtm_newintrinsic(&dollar_ztrap); } ztrap_explicit_null = FALSE; break; case SV_ZERROR: MV_FORCE_STR(v); dollar_zerror.mvtype = MV_STR; dollar_zerror.str = v->str; break; case SV_ZYERROR: MV_FORCE_STR(v); dollar_zyerror.mvtype = MV_STR; dollar_zyerror.str = v->str; break; case SV_SYSTEM: ok = 1; if (!(v->mvtype & MV_STR)) ok = 0; if (ok && v->str.addr[0] != '4') ok = 0; if (ok && v->str.addr[1] != '7') ok = 0; if ((' ' != v->str.addr[2]) && !ispunct(v->str.addr[2])) ok = 0; if (ok) dollar_system.str = v->str; else rts_error(VARLSTCNT(4) ERR_SYSTEMVALUE, 2, v->str.len, v->str.addr); break; case SV_ZDIR: setzdir(v, NULL); /* change directory to v */ getzdir(); /* update dollar_zdir with current working directory */ break; case SV_ZINTERRUPT: MV_FORCE_STR(v); dollar_zinterrupt.mvtype = MV_STR; dollar_zinterrupt.str = v->str; break; case SV_ZDATE_FORM: MV_FORCE_NUM(v); zdate_form = (short)MV_FORCE_INT(v); break; case SV_ZTEXIT: MV_FORCE_STR(v); dollar_ztexit.mvtype = MV_STR; dollar_ztexit.str = v->str; /* Coercing $ZTEXIT to boolean at SET command is more efficient than coercing before each * rethrow at TR/TRO. Since we want to maintain dollar_ztexit as a string, coercion should * not be performed on dollar_ztext, but on a temporary (i.e. parameter v) */ dollar_ztexit_bool = MV_FORCE_BOOL(v); break; default: GTMASSERT; } return; }
int omi_lkextnam( omi_conn *cptr, uns_short len, char *ref, char *data) { mlk_pvtblk *r; sgmnt_addrs *sa; gd_region *reg; mval ext, lck; char *ptr, *end; int subcnt, elen; omi_li li; omi_si si; bool rv; /* Pointers into the global reference */ ptr = ref; end = ref + len; /* Initialize part of the mval */ ext.mvtype = MV_STR; /* Refine the gd_addr given this environment */ OMI_LI_READ(&li, ptr); if (ptr + li.value > end) return -OMI_ER_PR_INVGLOBREF; ext.str.len = li.value; ext.str.addr = ptr; cptr->ga = zgbldir(&ext); ptr += li.value; elen = end - ptr; /* Refine the gd_addr given this name */ OMI_SI_READ(&si, ptr); if (!si.value || ptr + si.value > end) return -OMI_ER_PR_INVGLOBREF; lck.str.len = si.value; lck.str.addr = ptr; ptr += si.value; subcnt = 1; /* Refine the gd_addr given these subscripts */ while (ptr < end) { OMI_SI_READ(&si, ptr); if (!si.value || ptr + si.value > end) return -OMI_ER_PR_INVGLOBREF; ptr += si.value; subcnt++; } lck.mvtype = ext.mvtype = MV_STR; reg = mlk_region_lookup(&lck, cptr->ga); OMI_SI_READ(&si, data); r = (mlk_pvtblk *)malloc(sizeof(mlk_pvtblk) + elen + si.value); memset(r, 0, sizeof(mlk_pvtblk) - 1); r->translev = 1; r->subscript_cnt = subcnt; r->total_length = elen; memcpy(&r->value[0], lck.str.addr - 1, elen); r->value[elen++] = si.value; memcpy(&r->value[elen], data, si.value); r->region = reg; sa = &FILE_INFO(r->region)->s_addrs; r->ctlptr = (mlk_ctldata *)sa->lock_addrs[0]; if (!mlk_pvtblk_insert(r)) { if (r->value[r->total_length] == mlk_pvt_root->value[mlk_pvt_root->total_length] && !memcmp(&r->value[elen],&mlk_pvt_root->value[elen],r->value[r->total_length])) { free(r); return TRUE; } else return FALSE; } else if (r != mlk_pvt_root) return -OMI_ER_DB_UNRECOVER; return TRUE; }
main() { struct FAB fab; header_struct *header; gd_addr *addr, *addr1, *addr2, *addr3; gd_region *region; gd_segment *segment; int4 *long_ptr, ret_addr; short iosb[4]; mval v; char file_name1[] = "dtgbld01.gld", file_name2[] = "dtgbld02.gld", file_name3[] = "dtgbld03.gld"; char label[] = GDE_LABEL_LITERAL; char file_name4[]="dtlog1"; uint4 status, size; $DESCRIPTOR(proc_tab, "LNM$PROCESS"); $DESCRIPTOR(gbldir, "GTM$GBLDIR"); $DESCRIPTOR(dtlog, "DTLOG1"); typedef struct { short buf_len; short item; int4 buf_addr; int4 ret_addr; int4 term; } item_list; item_list ilist; char acmo=PSL$C_USER; /************************* Create logical names for tests **********************************************************/ ilist.item = LNM$_STRING; ilist.buf_len = SIZEOF(file_name1) - 1; ilist.buf_addr = file_name1; ilist.term = 0; ilist.ret_addr = &ret_addr; status = sys$crelnm(0, &proc_tab, &gbldir, &acmo, &ilist); if (!(status & 1)) rts_error(VARLSTCNT(1) status); ilist.buf_len = SIZEOF(file_name2) - 1; ilist.buf_addr = file_name2; status = sys$crelnm(0, &proc_tab, &dtlog, &acmo, &ilist); if (!(status & 1)) rts_error(VARLSTCNT(1) status); /************************* Create global directory files for tests *************************************************/ fab = cc$rms_fab; fab.fab$l_alq = 5; fab.fab$l_fna = file_name1; fab.fab$b_fns = SIZEOF(file_name1) - 1; fab.fab$l_fop = (FAB$M_UFO | FAB$M_CBT); fab.fab$b_fac = (FAB$M_PUT | FAB$M_GET | FAB$M_BIO); fab.fab$b_shr = (FAB$M_SHRPUT | FAB$M_SHRGET | FAB$M_UPI); status = sys$create(&fab); if (status != RMS$_CREATED && status != RMS$_FILEPURGED && status != RMS$_NORMAL) sys$exit(status); size = SIZEOF(header_struct) + SIZEOF(gd_addr) + 3 * SIZEOF(gd_binding) + SIZEOF(gd_region) + SIZEOF(gd_segment); header = malloc(((size + 511) / 512) * 512); header->filesize = size; size = ((size + 511) / 512) * 512; memcpy(header->label, label, SIZEOF(label)-1); addr = (char*)header + SIZEOF(header_struct); addr->maps = SIZEOF(gd_addr); addr->n_maps = 3; addr->regions = (int4)(addr->maps) + 3 * SIZEOF(gd_binding); addr->n_regions = 1; addr->segments = (int4)(addr->regions) + SIZEOF(gd_region); addr->n_segments = 1; addr->link = addr->tab_ptr = addr->id = addr->local_locks = 0; addr->max_rec_size = 100; addr->end = addr->segments + SIZEOF(gd_segment); long_ptr = (char*)addr + (int4)(addr->maps); *long_ptr++ = 0xFFFF2F23; *long_ptr++ = 0xFFFFFFFF; *long_ptr++ = addr->regions; *long_ptr++ = 0xFFFFFF24; *long_ptr++ = 0xFFFFFFFF; *long_ptr++ = addr->regions; *long_ptr++ = 0xFFFFFFFF; *long_ptr++ = 0xFFFFFFFF; *long_ptr++ = addr->regions; region = (char*)addr + (int4)(addr->regions); segment = (char*)addr + (int4)(addr->segments); memset(region, 0, SIZEOF(gd_region)); region->rname_len = 5; memcpy(region->rname,"TEMP1",5); region->dyn.offset = addr->segments; region->max_rec_size = 100; region->max_key_size = 64; segment->sname_len = 5; memcpy(segment->sname, "TEMP1", 5); memcpy(segment->fname, "MUMPS1.DAT", 10); segment->fname_len = 10; segment->blk_size = 2 * DISK_BLOCK_SIZE; segment->allocation = 100; segment->ext_blk_count = 100; segment->cm_blk = 0; segment->lock_space = 20; memcpy(segment->defext, ".DAT", 4); segment->global_buffers = 64; segment->buckets = 0; segment->windows = 0; segment->acc_meth = dba_bg; segment->defer_time = 0; segment->file_cntl = 0; status = sys$qiow(EFN$C_ENF, fab.fab$l_stv, IO$_WRITEVBLK, &iosb[0], 0, 0, header, size, 1, 0, 0, 0); if (!(status & 1)) rts_error(VARLSTCNT(1) status); if (!(iosb[0] & 1)) rts_error(VARLSTCNT(1) status); sys$dassgn(fab.fab$l_stv); region->rname_len = 5; memcpy(region->rname,"TEMP2",5); segment->sname_len = 5; memcpy(segment->sname,"TEMP2",5); memcpy(segment->fname,"MUMPS2.DAT",10); segment->fname_len = 10; fab.fab$l_fna = file_name2; fab.fab$b_fns = SIZEOF(file_name3) - 1; status = sys$create(&fab); if (status != RMS$_CREATED && status != RMS$_FILEPURGED && status != RMS$_NORMAL) sys$exit(status); status = sys$qiow(EFN$C_ENF, fab.fab$l_stv, IO$_WRITEVBLK, &iosb[0], 0, 0, header, size, 1, 0, 0, 0); if (!(status & 1)) rts_error(VARLSTCNT(1) status); if (!(iosb[0] & 1)) rts_error(VARLSTCNT(1) status); sys$dassgn(fab.fab$l_stv); region->rname_len = 5; memcpy(region->rname, "TEMP3", 5); segment->sname_len = 5; memcpy(segment->sname, "TEMP3", 5); memcpy(segment->fname, "MUMPS3.DAT", 10); segment->fname_len = 10; fab.fab$l_fna = file_name3; fab.fab$b_fns = SIZEOF(file_name3) - 1; status = sys$create(&fab); if (status != RMS$_CREATED && status != RMS$_FILEPURGED && status != RMS$_NORMAL) sys$exit(status); status = sys$qiow(EFN$C_ENF, fab.fab$l_stv, IO$_WRITEVBLK, &iosb[0], 0, 0, header, size, 1, 0, 0, 0); if (!(status & 1)) rts_error(VARLSTCNT(1) status); if (!(iosb[0] & 1)) rts_error(VARLSTCNT(1) status); sys$dassgn(fab.fab$l_stv); /*************************** Run tests********************************************/ v.str.len = SIZEOF(file_name1) - 1; v.str.addr = file_name1; PRINTF("Open first global directory: dtgbld01.gld\n"); addr1 = zgbldir(&v); PRINTF("Region name is %s, expected TEMP1\n", addr1->regions->rname); PRINTF("Segment name is %s, expected TEMP1\n", addr1->regions->dyn.addr->sname); PRINTF("File name is %s, expected MUMPS1.DAT\n", addr1->regions->dyn.addr->fname); v.str.len = SIZEOF(file_name2) - 1; v.str.addr = file_name2; PRINTF("Open second global directory: dtgbld02.gld\n"); addr2 = zgbldir(&v); PRINTF("Region name is %s, expected TEMP2\n", addr2->regions->rname); PRINTF("Segment name is %s, expected TEMP2\n", addr2->regions->dyn.addr->sname); PRINTF("File name is %s, expected MUMPS2.DAT\n", addr2->regions->dyn.addr->fname); v.str.len = SIZEOF(file_name3) - 1; v.str.addr = file_name3; PRINTF("Open third global directory: dtgbld03.gld\n"); addr3 = zgbldir(&v); PRINTF("Region name is %s, expected TEMP3\n", addr3->regions->rname); PRINTF("Segment name is %s, expected TEMP3\n", addr3->regions->dyn.addr->sname); PRINTF("File name is %s, expected MUMPS3.DAT\n", addr3->regions->dyn.addr->fname); PRINTF("Open null string global directory: dtgbld01.gld\n"); v.str.len = 0; addr = zgbldir(&v); if (addr != addr1) PRINTF("Expected pointer to previous struct, got new structure\n"); else PRINTF("Got same pointer as expected.\n"); PRINTF("Open dtlog1 global directory: dtgbld02.gld\n"); v.str.len = SIZEOF(file_name4) - 1; v.str.addr = file_name4; addr = zgbldir(&v); if (addr != addr2) PRINTF("Expected pointer to previous struct, got new structure\n"); else PRINTF("Got same pointer as expected.\n"); v.str.len = SIZEOF(file_name3) - 1; v.str.addr = file_name3; PRINTF("Reopen third global directory: dtgbld03.gld\n"); addr = zgbldir(&v); if (addr != addr3) PRINTF("Expected pointer to previous struct, got new structure\n"); else PRINTF("Got same pointer as expected.\n"); return; }
int omi_gvextnam (omi_conn *cptr, uns_short len, char *ref) { bool was_null, is_null; mval v; char *ptr, *end, c[MAX_FBUFF + 1]; omi_li li; omi_si si; parse_blk pblk; int4 status; gd_segment *cur_seg, *last_seg; DCL_THREADGBL_ACCESS; SETUP_THREADGBL_ACCESS; /* Pointers into the global reference */ ptr = ref; end = ref + len; /* Initialize part of the mval */ v.mvtype = MV_STR; /* Refine the gd_addr given this environment */ OMI_LI_READ(&li, ptr); if (ptr + li.value > end) return -OMI_ER_PR_INVGLOBREF; v.str.len = li.value; v.str.addr = ptr; cptr->ga = zgbldir(&v); memset(&pblk, 0, SIZEOF(pblk)); pblk.buffer = c; pblk.buff_size = MAX_FBUFF; pblk.def1_buf = DEF_GDR_EXT; pblk.def1_size = SIZEOF(DEF_GDR_EXT) - 1; status = parse_file(&v.str, &pblk); /* for all segments insert the full path in the segment fname */ cur_seg = cptr->ga->segments; last_seg = cur_seg + cptr->ga->n_segments; for( ; cur_seg < last_seg ; cur_seg++) { if ('/' != cur_seg->fname[0]) { /* doesn't contains full path ; specify full path */ memmove(&cur_seg->fname[0] + pblk.b_dir, cur_seg->fname, cur_seg->fname_len); memcpy(cur_seg->fname, pblk.l_dir, pblk.b_dir); cur_seg->fname_len += pblk.b_dir; } } ptr += li.value; /* Refine the gd_addr given this name */ OMI_SI_READ(&si, ptr); if (si.value <= 1 || *ptr != '^') return -OMI_ER_PR_INVGLOBREF; ptr++; si.value--; if (ptr + si.value > end) return -OMI_ER_PR_INVGLOBREF; v.str.len = si.value; v.str.addr = ptr; gd_header = cptr->ga; GV_BIND_NAME_AND_ROOT_SEARCH(cptr->ga, &v.str); ptr += si.value; /* Refine the gd_addr given these subscripts */ was_null = is_null = FALSE; while (ptr < end) { was_null |= is_null; OMI_SI_READ(&si, ptr); if (ptr + si.value > end) return -OMI_ER_PR_INVGLOBREF; v.mvtype = MV_STR; v.str.len = si.value; v.str.addr = ptr; is_null = (si.value == 0); mval2subsc(&v, gv_currkey); ptr += si.value; } TREF(gv_some_subsc_null) = was_null; /* if true, it indicates there is a null subscript (except the last subscript) in current key */ TREF(gv_last_subsc_null) = is_null; /* if true, it indicates that last subscript in current key is null */ if (was_null && NEVER == gv_cur_region->null_subs) return -OMI_ER_DB_INVGLOBREF; return 0; }