Ejemplo n.º 1
0
//
// Routines
//
char *
get_HFS_name(partition_map *entry, int *kind)
{
    DPME *data;
    struct mdb_record *mdb;
    //struct HFSPlusVolumeHeader *mdb2;
    char *name = NULL;
    int len;

    *kind = kHFS_not;

    mdb = (struct mdb_record *) malloc(PBLOCK_SIZE);
    if (mdb == NULL) {
	error(errno, "can't allocate memory for MDB");
	return NULL;
    }

    data = entry->data;
    if (strcmp(data->dpme_type, kHFSType) == 0) {
	if (read_partition_block(entry, 2, (char *)mdb) == 0) {
	    error(-1, "Can't read block %d from partition %d", 2, entry->disk_address);
	    goto not_hfs;
	}
	if (mdb->drSigWord == HFS_PLUS_SIG) {
	    // pure HFS Plus
	    // printf("%lu HFS Plus\n", entry->disk_address);
	    *kind = kHFS_plus;
	} else if (mdb->drSigWord != HFS_SIG) {
	    // not HFS !!!
	    printf("%lu not HFS\n", entry->disk_address);
	    *kind = kHFS_not;
	} else if (mdb->drEmbedSigWord != HFS_PLUS_SIG) {
	    // HFS
	    // printf("%lu HFS\n", entry->disk_address);
	    *kind = kHFS_std;
	    len = mdb->drVN[0];
	    name = (char *) malloc(len+1);
	    strncpy(name, &mdb->drVN[1], len);
	    name[len] = 0;
	} else {
	    // embedded HFS plus
	    // printf("%lu embedded HFS Plus\n", entry->disk_address);
	    *kind = kHFS_embed;
	    len = mdb->drVN[0];
	    name = (char *) malloc(len+1);
	    strncpy(name, &mdb->drVN[1], len);
	    name[len] = 0;
	}
    }
not_hfs:
    free(mdb);
    return name;
}
Ejemplo n.º 2
0
int parse_ptable_partition(FAR struct partition_state_s *state,
                           partition_handler_t handler,
                           FAR void *arg)
{
  FAR struct ptable_entry_s *entry;
  FAR struct ptable_s *ptable;
  size_t blkpererase;
  size_t block;
  int ret = OK;

  /* Allocate one erase block memory */

  ptable = kmm_malloc(state->erasesize);
  if (ptable == NULL)
    {
      return -ENOMEM;
    }

  /* PTABLE locate in the first or last erase block */

  blkpererase = state->erasesize / state->blocksize;
  for (block = 0;
       block < state->nblocks;
       block += state->nblocks - blkpererase)
    {
      ret = read_partition_block(state, ptable, block, blkpererase);
      if (ret < 0)
        {
          goto out;
        }

      if (strcmp(ptable->magic, PTABLE_MAGIC) == 0)
        {
          break; /* Find the magic number */
        }
    }

  if (block >= state->nblocks)
    {
      ret = -EFTYPE;
      goto out;
    }

  entry = ptable->entries;
  while (!(entry->flags & PTABLE_FLAG_END))
    {
      struct partition_s part;

      /* Convert the entry to partition */

      strncpy(part.name, entry->name, sizeof(part.name));
      part.index      = entry - ptable->entries;
      part.firstblock = entry->offset / state->blocksize;
      part.nblocks    = entry->length / state->blocksize;
      part.blocksize  = state->blocksize;

      /* Notify the caller */

      handler(&part, arg);

      /* Move to the next entry */

      entry++;
      if ((uintptr_t)entry - (uintptr_t)ptable >= state->erasesize)
        {
          break; /* Exit, at the end of erase block */
        }
    }

out:
  kmm_free(ptable);
  return ret;
}