Example #1
0
void
wb_dbs::checkObject(sOentry *oep)
{
  int nChild = 0;
  pwr_tStatus sts;
  dbs_sQlink *sib_lh;
  dbs_sQlink *sib_ll;
  sOentry *sep;
  dbs_sName n;
  sNentry *nep;    

  // Check object
  if (!oep->flags.b.exist) {
    printf("** Object does not exist!\n");
  }

  m_nTreeObjects++;

  oep->ref = dbs_dMakeRef(dbs_eSect_object, m_sect[dbs_eSect_object].size);
  m_sect[dbs_eSect_object].size += dbs_dAlign(sizeof(dbs_sObject));
  dbs_Qinit(&sts, &oep->o.sib_lh, oep->ref + offsetof(dbs_sObject, sib_lh));
  dbs_Qinit(&sts, &oep->o.sib_ll, oep->ref + offsetof(dbs_sObject, sib_ll));
  dbs_Qinit(&sts, &oep->o.o_ll, oep->ref + offsetof(dbs_sObject, o_ll));

  classInsert(oep);

  switch (oep->o.cid) {
  case pwr_eClass_ClassDef:
    // Version is dependent of attribute objects
    m_v->merep()->classVersion(&sts, cdh_ClassObjidToId(oep->o.oid), &oep->o.time);
    break;
  case pwr_eClass_LibHier:
    if ( !cdh_isClassVolumeClass( m_volume.cid))
      oep->o.flags.b.devOnly = 1;
    break;
  case pwr_eClass_Alias:
    if ( !cdh_isClassVolumeClass( m_volume.cid))
      oep->o.flags.b.isAliasClient = 1;
    break;
  case pwr_eClass_MountVolume:
  case pwr_eClass_CreateVolume:
  case pwr_eClass_MountObject:
    if (m_volume.cid == pwr_eClass_RootVolume || m_volume.cid == pwr_eClass_VolatileVolume) {
      // Root volume or cloned volume
      oep->o.flags.b.isMountClient = 1;
    }
    break;
  default:
    break;    
  }

  oep->o.flags.b.isMountClean = 1;

  // Check all children
  sib_lh = sib_ll = &oep->o.sib_lh;
  for (sep = oep->foep; sep != 0; sep = sep->aoep) {
    if (sep->poep != oep) {
      printf("** Object not linked to right parent!\n");
    }

    checkObject(sep);

    sep->o.pref = oep->ref;
    dbs_Qinsert(&sts, sib_ll, &sep->o.sib_ll, sib_lh);
    sib_ll = &sep->o.sib_ll;
    oep->o.flags.b.isMountClean |= sep->o.flags.b.isMountClean && !sep->o.flags.b.isMountClient;
    nChild++;
  }

  /* Check name table, get reference to first and last child in name order.  */
  memset(&n, 0, sizeof(n));
  n.poix = oep->o.oid.oix;
  nep = (sNentry*)tree_FindSuccessor(&sts, m_name_th, &n);
  if (nep != NULL && nep->n.poix == oep->o.oid.oix) {
    oep->o.name_bt.start = nep->ref;
  }

  n.poix += 1;
  nep = (sNentry*)tree_FindPredecessor(&sts, m_name_th, &n);
  if (nep != NULL && nep->n.poix == oep->o.oid.oix) {
    oep->o.name_bt.end = nep->ref;
  }

  oep->o.name_bt.rsize = dbs_dAlign(sizeof(dbs_sName));
}
Example #2
0
pwr_tStatus
wb_dbs::prepareSectVolref()
{
  char v[dbs_dAlign(sizeof(dbs_sVolRef))];
  dbs_sVolRef *vp = (dbs_sVolRef*)v;
  cdh_uTid    cid;
  sCentry     *cep;
  pwr_tStatus sts;
  pwr_tUInt32 dvVersion;
  
    
  if (fseek(m_fp, m_sect[dbs_eSect_volref].offset, SEEK_SET) != 0)
    return LDH__FILEPOS;

  memset(v, 0, sizeof(v));

  cid.pwr = pwr_cNCid;
  cep = (sCentry*)tree_FindSuccessor(&sts, m_class_th, &cid.pwr);
  while (cep) {
    cdh_uVid vid;

    vid.pwr = pwr_cNVid;
    cid.pwr = cep->c.cid;
    vid.v.vid_0 = cid.c.vid_0;
    vid.v.vid_1 = cid.c.vid_1;
        
    if (vid.pwr != m_volume.vid) {
      wb_mvrep *mvrep = m_v->merep()->volume(&sts, vid.pwr);
      if ( EVEN(sts)) throw wb_error_str("Metavolume not found");

      dvVersion = getDvVersion( mvrep);

      sVentry *vep;

      vep = (sVentry*)tree_Insert(&sts, m_vol_th, &vid.pwr);
      if (sts == TREE__INSERTED) {
        /* was inserted now */
        dbs_Open(&sts, &vep->env, mvrep->fileName());

        strcpy(vep->v.name, mvrep->name());
        vep->v.cid  = mvrep->cid();
	if ( m_volume.cid == pwr_eClass_DetachedClassVolume) {
	  vep->v.time.tv_sec = dvVersion;
	  vep->v.time.tv_nsec = 0;
	}
	else
	  vep->v.time = vep->env.file.time;
        vep->v.size = vep->env.file.size;
        vep->v.offset = 0;

        int i = 0;
        while ((vp = dbs_VolRef(&sts, i, (dbs_sVolRef *)v, &vep->env)) != NULL) {
          sVentry *nvep;
          i++;
          nvep = (sVentry*)tree_Insert(&sts, m_vol_th, &vp->vid);
          if (sts == TREE__INSERTED) {
	    wb_mvrep *nmvrep = m_v->merep()->volume(&sts, vp->vid);
	    if ( EVEN(sts)) {
	      printf( "** Classvolume %s referenced but not loaded\n", vp->name);
	      throw wb_error_str("Metavolume not loaded");
	    }      
      
	    dvVersion = getDvVersion( mvrep);
      
	    dbs_Open(&sts, &nvep->env, nmvrep->fileName());

            strcpy(nvep->v.name, vp->name);
            nvep->v.cid  = vp->cid;
	    if ( m_volume.cid == pwr_eClass_DetachedClassVolume) {
	      nvep->v.time.tv_sec = dvVersion;
	      nvep->v.time.tv_nsec = 0;
	    }
	    else
	      nvep->v.time = vp->time;
	    // nvep->v.dvVersion = vp->dvVersion;
            nvep->v.size = vp->size;
            nvep->v.offset = 0;
          }          
        }
      }
    }
    vid.pwr++;
    cid.pwr = pwr_cNCid;
    cid.c.vid_0 = vid.v.vid_0;
    cid.c.vid_1 = vid.v.vid_1;
    cep = (sCentry*)tree_FindSuccessor(&sts, m_class_th, &cid.pwr);        
  }

  // Search trhough all found volumes and get their volrefs
  int nVolume = 0;
  sVentry *vep;
  vep = (sVentry*)tree_Minimum(&sts, m_vol_th);
  while (vep) {
    if (vep->env.file.cookie == 0) {
      printf("  volume not found: %d\n", vep->v.vid);
    } else {
      nVolume++;
      m_sect[dbs_eSect_volref].size += sizeof(v);
    }
    
    vep = (sVentry*)tree_Successor(&sts, m_vol_th, vep);        
  }

  return LDH__SUCCESS;
}
Example #3
0
main()
{
  tree_sTable* tp;
  sNode* np;
  int key;
  int i;
  char s[256];
  char* cp;
  char c;

  tp = tree_CreateTable(sizeof(int), offsetof(sNode, key), sizeof(sNode), 100,
      tree_eComp_int32, NULL);

  for (i = 0; i < 1000; i += 10) {
    tree_Insert(tp, &i);
  }

  for (;;) {
    printf("Command: ");
    cp = gets(s);
    c = s[0];
    if (cp == NULL || c == '\0') {
      printf("\nGoodbye\n");
      return;
    }
    switch (c) {
    case 'i':
    case 'I':
      printf("Insert, Key: ");
      gets(s);
      key = atoi(s);
      if (tree_Find(tp, &key) == NULL) {
        tree_Insert(tp, &key);
      } else
        printf("\nKey allready exists!\n");
      break;
    case 'd':
    case 'D':
      printf("Delete, Key: ");
      gets(s);
      key = atoi(s);
      if ((np = tree_Find(tp, &key)) != NULL) {
        tree_Remove(tp, &key);
      } else
        printf("\nKey does not exist!\n");
      break;
    case 'f':
    case 'F':
      printf("Find, Key: ");
      gets(s);
      key = atoi(s);
      if ((np = tree_Find(tp, &key)) == NULL) {
        printf("\nKey does not exist!\n");
      } else
        printf("\nKey exists! %d\n", np->key);
      break;
    case 's':
    case 'S':
      printf("Find successor, Key: ");
      gets(s);
      key = atoi(s);
      if ((np = tree_FindSuccessor(tp, &key)) == NULL) {
        printf("\nKey does not exist!\n");
      } else
        printf("\nKey exists! %d\n", np->key);
      break;
    case 'p':
    case 'P':
      printf("Find predecessor, Key: ");
      gets(s);
      key = atoi(s);
      if ((np = tree_FindPredecessor(tp, &key)) == NULL) {
        printf("\nKey does not exist!\n");
      } else
        printf("\nKey exists! %d\n", np->key);
      break;
    case 'q':
    case 'Q':
      printf("\nGoodbye\n");
      return;
      break;
    default:
      printf("Illegal command!\n");

      break;
    }
  }
}