Example #1
0
jlong Java_com_zspace_Native_malloc(JNIEnv* env, jobject that, jint bytes) {
    return p2ll(mem_allocz(bytes));
}
Example #2
0
u32t _std dsk_gptinit(u32t disk) {
   hdd_info         *hi = get_by_disk(disk);
   u32t       stype, ii;
   u8t       mbr_buffer[MAX_SECTOR_SIZE];
   disk_geo_data   vgeo;
   struct Disk_MBR *mbr = (struct Disk_MBR *)&mbr_buffer;

   if (!hi) return DPTE_INVDISK;
   dsk_ptrescan(disk,1);
   stype = dsk_sectortype(disk, 0, mbr_buffer);
   if (stype==DSKST_ERROR) return DPTE_ERRREAD;

   log_it(2, "dsk_gptinit(%X)\n", disk);

   if (stype!=DSKST_EMPTY && stype!=DSKST_DATA) {
      if (hi->pt_size>4) return DPTE_EMPTY;
      if (hi->pt_size)
         for (ii=0; ii<4; ii++)
            if (hi->pts[ii].PTE_Type) return DPTE_EMPTY;
   }
   // clear pt entries in case of garbage data
   if (!dsk_newmbr(disk,DSKBR_GPTHEAD|DSKBR_GENDISKID|DSKBR_LVMINFO|DSKBR_GPTCODE))
      return DPTE_ERRWRITE;
   if (hi->ghead)  { free(hi->ghead); hi->ghead=0; }
   if (hi->ghead2) { free(hi->ghead2); hi->ghead2=0; }
   if (hi->ptg)    { free(hi->ptg); hi->ptg=0; }

   hi->non_lvm     = 1;
   hi->gpt_present = 1;
   hi->hybrid      = 0;

   hi->gpthead     = 1;
   hi->gpt_size    = GPT_MINSIZE;
   hi->gpt_sectors = hi->gpt_size * GPT_RECSIZE / hi->info.SectorSize;
   // minimum data to perform dsk_flushgpt()
   hi->ghead  = (struct Disk_GPT *)mem_allocz(memOwner, memPool, MAX_SECTOR_SIZE);
   hi->ptg    = (struct GPT_Record*)mem_allocz(memOwner, memPool,
      sizeof(struct GPT_Record) * hi->gpt_size);
   if (hi->ghead) {
      struct Disk_GPT *pt = hi->ghead;

      pt->GPT_Sign      = GPT_SIGNMAIN;
      pt->GPT_Revision  = 0x10000;
      pt->GPT_HdrSize   = sizeof(struct GPT_Record);
      pt->GPT_Hdr1Pos   = hi->gpthead;
      pt->GPT_Hdr2Pos   = hi->info.TotalSectors - 1;
      pt->GPT_UserFirst = pt->GPT_Hdr1Pos + hi->gpt_sectors + 1;
      pt->GPT_UserLast  = pt->GPT_Hdr2Pos - hi->gpt_sectors - 1;

      pt->GPT_PtInfo    = pt->GPT_Hdr1Pos + 1;
      pt->GPT_PtCout    = hi->gpt_size;
      pt->GPT_PtEntrySize = GPT_RECSIZE;

      dsk_makeguid(pt->GPT_GUID);
   }
   // flush empty GPT data
   ii = dsk_flushgpt(hi);
   if (ii) return ii;
   // rescan to update free space list and actual state
   dsk_ptrescan(hi->disk, 1);

   return 0;
}