Beispiel #1
0
int _TreeTurnOn(void *dbid, int nid_in)
{
  PINO_DATABASE *dblist = (PINO_DATABASE *)dbid;
  NID *nid = (NID *)&nid_in;
  int       status;
  int       node_num;
  TREE_INFO *info;
  NCI       nci;
  NODE     *node;
  if (!(IS_OPEN(dblist)))
    return TreeNOT_OPEN;
  if (dblist->remote)
    return TreeTurnOnRemote(dbid,nid_in);
  nid_to_tree_nidx(dblist, nid, info, node_num);
  if (!info)
    return TreeNNF;
  status = TreeGetNciLw(info, node_num, &nci);
  if (~status & 1)
    return status;
      
  if (nci.flags & NciM_STATE)
  {
    bitassign(0,nci.flags,NciM_STATE);
    status = TreePutNci(info, node_num, &nci, 0);
    if (~status & 1)
      return status;
    if (!(nci.flags & NciM_PARENT_STATE))
    {
      nid_to_node(dblist, nid, node);
      if (node->INFO.TREE_INFO.child)
	status = SetParentState(dblist, child_of(node), 0);
      if (node->INFO.TREE_INFO.member)
	status = SetParentState(dblist, member_of(node), 0);
    }
    else
      status = TreePARENT_OFF;
  }
  else
  {
    status = TreeUnLockNci(info, 0, node_num);
    if (status & 1)
      status = TreeALREADY_ON;
  }
  return status;
}
Beispiel #2
0
static int SetNodeParentState(PINO_DATABASE *db, NODE *node, NCI *nci, unsigned int state)
{
  TREE_INFO *info;
  int       node_num;
  int status;
  for (info = db->tree_info; 
       info && ((node < info->node) || (node > (info->node + info->header->nodes))); info = info->next_info);
  if (!info)
    return TreeNNF;
  node_num = (int)(node - info->node);
  status = TreeGetNciLw(info, node_num, nci);
  if (status & 1)

  {
    bitassign(state,nci->flags,NciM_PARENT_STATE);
    status = TreePutNci(info, node_num, nci, 0);
  }
  return status;
}
STATIC_ROUTINE int RewriteDatafile(void **dbid, char *tree, int shot, int compress)
{
  int status;
  void *dbid1 = 0, *dbid2 = 0;
  char *from_c = NULL;
  char *to_c = NULL;
  char *from_d = NULL;
  char *to_d = NULL;
  int lstatus;
  status = _TreeOpenEdit(&dbid1, tree, shot);
  if (status & 1)
  {
    int stv;
    PINO_DATABASE *dblist1 = (PINO_DATABASE *)dbid1;
    TREE_INFO *info1 = dblist1->tree_info;
    status = TreeOpenNciW(dblist1->tree_info, 0);
    if (status & 1)
    {
      status = TreeOpenDatafileW(dblist1->tree_info, &stv, 0);
      if (status & 1)
      {
        status = _TreeOpenEdit(&dbid2, tree, shot);
        if (status & 1)
        {
          PINO_DATABASE *dblist2 = (PINO_DATABASE *)dbid2;
          TREE_INFO *info2 = dblist2->tree_info;
          status = TreeOpenNciW(dblist2->tree_info, 1);
          if (status & 1)
          {
            dblist2->tree_info->edit->first_in_mem = dblist1->tree_info->edit->first_in_mem;
            status = TreeOpenDatafileW(dblist2->tree_info, &stv, 1);
            if (status & 1)
            {
              int i;
              for (i=0;i<info1->header->nodes;i++)
              {
                EMPTYXD(xd);
                EMPTYXD(mtxd);
                NCI nci;
                TreeGetNciW(info1, i, &nci);
                TreePutNci(info2, i, &nci, 1);
                lstatus = _TreeGetRecord(dbid1, i, &xd);
                if (lstatus & 1)
                  lstatus = _TreePutRecord(dbid2, i, (struct descriptor *)&xd, compress ? 2 : 1);
                else if (lstatus == TreeBADRECORD || lstatus == TreeINVDFFCLASS)
		{
                  fprintf(stderr,"TreeBADRECORD, Clearing nid %d\n",i);
                  lstatus = _TreePutRecord(dbid2, i, (struct descriptor *)&mtxd, compress ? 2 : 1);
                }
                MdsFree1Dx(&xd,NULL);
                
              }
              from_c = strcpy(malloc(strlen(info1->filespec)+20),info1->filespec);
              strcpy(from_c+strlen(info1->filespec)-4,"characteristics#");
              to_c = strcpy(malloc(strlen(info1->filespec)+20),info1->filespec);
              strcpy(to_c+strlen(info1->filespec)-4,"characteristics");
			  from_d = strcpy(malloc(strlen(info1->filespec)+20),from_c);
              strcpy(from_d+strlen(info1->filespec)-4,"datafile#");
			  to_d = strcpy(malloc(strlen(info1->filespec)+20),to_c);
              strcpy(to_d+strlen(info1->filespec)-4,"datafile");
            }
          }
          _TreeClose(&dbid2, 0, 0);
        }
      }
    }
    _TreeClose(&dbid1, 0, 0);
    if (status & 1)
    {
      status = remove(to_c) == 0 ? TreeNORMAL : TreeFAILURE;
      if (status & 1)
	status = remove(to_d) == 0 ? TreeNORMAL : TreeFAILURE;
      if (status & 1)
      status = ((rename(from_c,to_c) == 0) && (rename(from_d,to_d) == 0)) ? TreeNORMAL : TreeFAILURE;
    }
    if (from_c) free(from_c);
    if (to_c) free(to_c);
    if (from_d) free(from_d);
    if (to_d) free(to_d);
  }
  return status;
}
Beispiel #4
0
extern void       _TreeDeleteNodeExecute(void *dbid)
{
  PINO_DATABASE *dblist = (PINO_DATABASE *)dbid;
  static NID       nid;
  NODE     *node;
  NODE     *prevnode = 0;
  NODE     *parent;
  static NCI empty_nci;
  NODE     *firstempty = (dblist->tree_info->header->free == -1) ? (NODE *) 0 :
	  (NODE *) ((char *) dblist->tree_info->node + dblist->tree_info->header->free);

  TREE_EDIT *edit = dblist->tree_info->edit;
  static int zero = 0;
/*------------------------------------------------------------------------------

 Executable:                                                                  */

  nid.tree = 0;
  nid.node = 0;
  while (_TreeDeleteNodeGetNid(dbid, (int*)&nid) & 1)
  {
    int       found = 0;
    _TreeRemoveNodesTags(dbid, *(int *)&nid);
    _TreeSetNoSubtree(dbid, *(int *)&nid);
    nid_to_node(dblist, (&nid), node);
    parent = parent_of(node);
    if (child_of(parent) == node)
    {
      found = 1;
      if (node->INFO.TREE_INFO.brother)
      {
        link_it(parent->INFO.TREE_INFO.child,brother_of(node),parent);
      }
      else
	parent->INFO.TREE_INFO.child = 0;
    }
    else if (parent->INFO.TREE_INFO.child)
    {
      NODE     *bro;
      for (bro = child_of(parent); bro->INFO.TREE_INFO.brother && (brother_of(bro) != node); bro = brother_of(bro));
      if (brother_of(bro) == node)
      {
	found = 1;
	if (node->INFO.TREE_INFO.brother)
	{
          link_it(bro->INFO.TREE_INFO.brother,brother_of(node),bro);
        }
	else
	  bro->INFO.TREE_INFO.brother = 0;
      }
    }
    if (!found)
    {
      if (member_of(parent) == node)
      {
	if (node->INFO.TREE_INFO.brother)
	{
	  link_it(parent->INFO.TREE_INFO.member,brother_of(node), parent);
        }
	else
	  parent->INFO.TREE_INFO.member = 0;
      }
      else if (parent->INFO.TREE_INFO.member)
      {
	NODE     *bro;
	for (bro = member_of(parent); bro->INFO.TREE_INFO.brother && (brother_of(bro) != node); bro = brother_of(bro));
	if (brother_of(bro) == node)
	{
	  found = 1;
	  if (node->INFO.TREE_INFO.brother)
	  {
	    link_it(bro->INFO.TREE_INFO.brother,brother_of(node), bro);
          }
	  else
	    bro->INFO.TREE_INFO.brother = 0;
	}
      }
    }
    if ((int)nid.node < edit->first_in_mem)
    {
      NCI       old_nci;
      int       nidx = nid.node;
      TreeGetNciLw(dblist->tree_info, nidx, &old_nci);
      TreePutNci(dblist->tree_info, nidx, &empty_nci, 1);
    }
    else
      memcpy(edit->nci + nid.node - edit->first_in_mem, &empty_nci, sizeof(struct nci));
    memcpy(node->name,"deleted node",sizeof(node->name));
    LoadShort(zero,&node->conglomerate_elt);
    node->INFO.TREE_INFO.member = 0;
    node->INFO.TREE_INFO.brother = 0;
    node->usage = 0;
    if (prevnode)
    {
      int tmp;
      link_it(prevnode->parent, node, prevnode);
      tmp = -swapint((char *)&prevnode->parent);
      node->INFO.TREE_INFO.child = swapint((char *)&tmp);
    }
    else
    {
      int tmp;
      link_it(tmp,node, dblist->tree_info->node);
      dblist->tree_info->header->free = swapint((char *)&tmp);
      node->INFO.TREE_INFO.child = 0;
    }
    if (firstempty)
    {
      int tmp;
      link_it(node->parent, firstempty, node);
      tmp = -swapint((char *)&node->parent);
      firstempty->INFO.TREE_INFO.child = swapint((char *)&tmp);
    }
    else
      node->parent = 0;
    prevnode = node;
  }
  dblist->modified = 1;
  _TreeDeleteNodeInitialize(dbid, 0, 0, 1);
}
Beispiel #5
0
int       _TreePutRecord(void *dbid, int nid, struct descriptor *descriptor_ptr, int utility_update)
{
  PINO_DATABASE *dblist = (PINO_DATABASE *)dbid;
  NID       *nid_ptr = (NID *)&nid;
  int       status;
  int       open_status;
  TREE_INFO *info_ptr;
  int       nidx;
  unsigned int old_record_length;
  static int saved_uic = 0;
  int       id = 0;
  int       length = 0;
  int       shot_open;
  compress_utility = utility_update == 2;
#if !defined(HAVE_WINDOWS_H) && !defined(HAVE_VXWORKS_H)
  if (!saved_uic)
    saved_uic = (getgid() << 16) | getuid();
#endif
  if (!(IS_OPEN(dblist)))
    return TreeNOT_OPEN;
  if (dblist->open_readonly)
    return TreeREADONLY;
  if (dblist->remote)
    return PutRecordRemote(dblist,nid,descriptor_ptr,utility_update);
  shot_open = (dblist->shotid != -1);
  nid_to_tree_nidx(dblist, nid_ptr, info_ptr, nidx);
  if (info_ptr)
  {
    int       stv;
    NCI       local_nci;
    status = TreeCallHook(PutData,info_ptr,nid);
    if (status && !(status & 1))
      return status;
    if (info_ptr->reopen)
      TreeCloseFiles(info_ptr);
    if (info_ptr->data_file ? (!info_ptr->data_file->open_for_write) : 1)
      open_status = TreeOpenDatafileW(info_ptr, &stv, 0);
    else
      open_status = 1;
    status = TreeGetNciLw(info_ptr, nidx, &local_nci);
    if (status & 1)
    {
      if (utility_update)
      {
	length = local_nci.length = 0;
	local_nci.DATA_INFO.DATA_LOCATION.record_length = 0;
      }
      else
      {
        unsigned int m1;
        unsigned int m2 = 10000000;
        _int64 addin = LONG_LONG_CONSTANT(0x7c95674beb4000);
        _int64 zero = 0;
        _int64 temp = 0;
        bitassign(dblist->setup_info, local_nci.flags, NciM_SETUP_INFORMATION);
	local_nci.owner_identifier = saved_uic;
	/* VMS time = unixtime * 10,000,000 + 0x7c95674beb4000q */
#ifndef HAVE_VXWORKS_H
        tzset();
#endif

#ifdef USE_TM_GMTOFF      
    /* this is a suggestion to change all code 
       for this as timezone is depricated unix
       annother alternative is to use gettimeofday */
       { struct tm *tm;
         time_t t;
         t = time(NULL);
         tm = localtime(&t);
         m1 = (unsigned int)t + tm->tm_gmtoff;
       }
#else
        m1 = (unsigned int)time(NULL) - timezone + daylight * 3600;
#endif
	LibEmul(&m1,&m2,&zero,&temp);
        local_nci.time_inserted = temp + addin;
      }
      if (!(open_status & 1))
      {
	local_nci.DATA_INFO.ERROR_INFO.stv = stv;
        bitassign_c(1,local_nci.flags2,NciM_ERROR_ON_PUT);
	local_nci.DATA_INFO.ERROR_INFO.error_status = open_status;
	length = local_nci.length = 0;
	TreePutNci(info_ptr, nidx, &local_nci, 1);
	return open_status;
      }
      else
      {
	NCI      *nci = info_ptr->data_file->asy_nci->nci;
	*nci = local_nci;
	if (!utility_update)
	{
	  old_record_length = (nci->flags2 & NciM_DATA_IN_ATT_BLOCK) ? 0 : 
                        nci->DATA_INFO.DATA_LOCATION.record_length;
	  if ((nci->flags & NciM_WRITE_ONCE) && nci->length)
	    status = TreeNOOVERWRITE;
	  if ((status & 1) && (shot_open && (nci->flags & NciM_NO_WRITE_SHOT)))
	    status = TreeNOWRITESHOT;
	  if ((status & 1) && (!shot_open && (nci->flags & NciM_NO_WRITE_MODEL)))
	    status = TreeNOWRITEMODEL;
	}
	if (status & 1)
	{
          unsigned char tree = (unsigned char)nid_ptr->tree;
          int compressible;
          int data_in_altbuf;
          nid_reference = 0;
          path_reference = 0;
	  status = MdsSerializeDscOutZ(descriptor_ptr, info_ptr->data_file->data,FixupNid,&tree,FixupPath,0,
            (compress_utility || (nci->flags & NciM_COMPRESS_ON_PUT)) && !(nci->flags & NciM_DO_NOT_COMPRESS),
            &compressible,&nci->length,&nci->DATA_INFO.DATA_LOCATION.record_length,&nci->dtype,&nci->class,
            sizeof(nci->DATA_INFO.DATA_IN_RECORD.data),nci->DATA_INFO.DATA_IN_RECORD.data,&data_in_altbuf);
          bitassign(path_reference,nci->flags,NciM_PATH_REFERENCE);
          bitassign(nid_reference,nci->flags,NciM_NID_REFERENCE);
          bitassign(compressible,nci->flags,NciM_COMPRESSIBLE);
          bitassign_c(data_in_altbuf,nci->flags2,NciM_DATA_IN_ATT_BLOCK);
        }
	if ((status & 1) && nci->length && (!utility_update))
	  status = CheckUsage(dblist, nid_ptr, nci);
	if (status & 1)
	{
	  if (nci->flags2 & NciM_DATA_IN_ATT_BLOCK)
	  {
	    bitassign_c(0,nci->flags2,NciM_ERROR_ON_PUT);
	    status = TreePutNci(info_ptr, nidx, nci, 1);
	  }
	  else
	  {
	    if ((nci->DATA_INFO.DATA_LOCATION.record_length != old_record_length) ||
		(nci->DATA_INFO.DATA_LOCATION.record_length >= DATAF_C_MAX_RECORD_SIZE) ||
		utility_update ||
		(nci->flags2 & NciM_ERROR_ON_PUT))
	      status = PutDatafile(info_ptr, nidx, nci, info_ptr->data_file->data);
	    else
	      status = UpdateDatafile(info_ptr, nidx, nci, info_ptr->data_file->data);
	  }
	}
      }
    }
  }
Beispiel #6
0
int       _TreeSetNci(void *dbid, int nid_in, NCI_ITM *nci_itm_ptr)
{
  PINO_DATABASE *dblist = (PINO_DATABASE *)dbid;
  NID *nid_ptr = (NID *)&nid_in;
  int       status;
  int       node_number;
  TREE_INFO *tree_info;
  NCI_ITM  *itm_ptr;
  NCI       nci;
/*------------------------------------------------------------------------------

 Executable:
*/
  if (!(IS_OPEN(dblist)))
    return TreeNOTOPEN;
  if (dblist->open_readonly)
      return TreeREADONLY;
  if (dblist->remote)
    return SetNciRemote(dbid,nid_in,nci_itm_ptr);
  nid_to_tree_nidx(dblist, nid_ptr, tree_info, node_number);
  if (!tree_info)
    return TreeNNF;
  status = TreeCallHook(PutNci, tree_info, nid_in);
  if (status && !(status & 1))
    return status;
  status = TreeGetNciLw(tree_info, node_number, &nci);
  if (status & 1)
  {
    for (itm_ptr = nci_itm_ptr; itm_ptr->code != NciEND_OF_LIST && status & 1; itm_ptr++)
    {
      switch (itm_ptr->code)
      {

       case NciSET_FLAGS:
	nci.flags |= *(unsigned int *) itm_ptr->pointer;
	break;
       case NciCLEAR_FLAGS:
	nci.flags &= ~(*(unsigned int *) itm_ptr->pointer);
	break;
       case NciSTATUS:
	nci.status = *(unsigned int *) itm_ptr->pointer;
	break;
      case NciUSAGE:
	{
	  NODE     *node_ptr;

/**************************************************
 First we must check to make sure we are editting
 a valid tree.
**************************************************/

	  if (!(IS_OPEN_FOR_EDIT(dblist)))
	    return TreeNOEDIT;

	  nid_to_node(dblist, nid_ptr, node_ptr);
	  if (node_ptr->usage != *(unsigned char *)itm_ptr->pointer) {
	    node_ptr->usage = *(unsigned char *)itm_ptr->pointer;
	    dblist->modified = 1;
	  }
	  return TreeNORMAL;
	}
       default:
	status = TreeILLEGAL_ITEM;
	break;
      }
    }
    if (status & 1)
      status = TreePutNci(tree_info, node_number, &nci, 1);
  }
  return status;
}