Пример #1
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;
}
Пример #2
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);
	  }
	}
      }
    }
  }
Пример #3
0
/*------------------------------------------------------------------------------

		Name: TreeOpenNciW

		Type:   C function

		Author:	Josh Stillerman
			MIT Plasma Fusion Center

		Date:   22-MAR-1988

		Purpose: Open a tree characteristics file for write access.

------------------------------------------------------------------------------

	Call sequence:
		       status = TreeOpenNciW(info_ptr)

------------------------------------------------------------------------------
   Copyright (c) 1988
   Property of Massachusetts Institute of Technology, Cambridge MA 02139.
   This program cannot be copied or distributed in any form for non-MIT
   use without specific written approval of MIT Plasma Fusion Center
   Management.
---------------------------------------------------------------------------

	Description:


+-----------------------------------------------------------------------------*/
int TreeOpenNciW(TREE_INFO *info, int tmpfile)
{
  int       status;

/****************************************************
  If there is no characterisitics file block allocated then
    Allocate one
*****************************************************/

  if (info->nci_file == 0)
  {
    status = ((info->nci_file = (struct nci_file *)malloc(sizeof(NCI_FILE))) != NULL) ? TreeNORMAL : TreeFAILURE;
    if (status & 1)
    {
      size_t len = strlen(info->filespec)-4;
      char *filename = strncpy(malloc(len+20),info->filespec,len);
      filename[len]='\0';
      strcat(filename,tmpfile ? "characteristics#" : "characteristics");
      memset(info->nci_file,0, sizeof(NCI_FILE));
      info->nci_file->get = MDS_IO_OPEN(filename,tmpfile ? O_RDWR | O_CREAT | O_TRUNC  : O_RDONLY,0664);
      status = (info->nci_file->get == -1) ? TreeFAILURE : TreeNORMAL;
      if (info->nci_file->get == -1)
        info->nci_file->get = 0;
      if (status & 1)
      {
        info->nci_file->put = MDS_IO_OPEN(filename,O_RDWR, 0);
        status = (info->nci_file->put == -1) ? TreeFAILURE : TreeNORMAL;
        if (info->nci_file->put == -1)
          info->nci_file->put = 0;
      }
      free(filename);
    }
  }
  else
  {
  /*******************************************
    Else the file was open for read access so
    close it and re-open it for write access.
  *******************************************/
    size_t len = strlen(info->filespec)-4;
    char *filename = strncpy(malloc(len+20),info->filespec,len);
    filename[len]='\0';
    strcat(filename,tmpfile ? "characteristics#" : "characteristics");
    if (info->nci_file->put)
      MDS_IO_CLOSE(info->nci_file->put);
    info->nci_file->put = MDS_IO_OPEN(filename,(tmpfile ? O_RDWR | O_CREAT | O_TRUNC : O_RDWR), 0664);
    status = (info->nci_file->put == -1) ? TreeFAILURE : TreeNORMAL;
    if (info->nci_file->put == -1)
      info->nci_file->put = 0;
    free(filename);
  }
  if (status & 1)
  {
    if (info->edit)
    {
    info->edit->first_in_mem = (int)MDS_IO_LSEEK(info->nci_file->put,0,SEEK_END)/42;
    }
  /**********************************************
   Set up the RABs for buffered reads and writes
   and CONNECT it.
   If there is a problem then close it, free the
   memory and return.
  **********************************************/
  }
  else
    {
      free(info->nci_file);
      info->nci_file = NULL;
    }
  if (status & 1)
    TreeCallHook(OpenNCIFileWrite, info,0);
  return status;
}