コード例 #1
0
ファイル: linux.c プロジェクト: ebichu/dd-wrt
void detect_linux_lvm(SECTION *section, int level)
{
  unsigned char *buf;
  char s[256];
  int minor_version, pv_number;
  u8 pe_size, pe_count, pe_start;

  if (get_buffer(section, 0, 1024, (void **)&buf) < 1024)
    return;

  /* signature */
  if (buf[0] != 'H' || buf[1] != 'M')
    return;
  /* helpful sanity check... */
  if (get_le_long(buf + 36) == 0 || get_le_long(buf + 40) == 0)
    return;

  minor_version = get_le_short(buf + 2);
  print_line(level, "Linux LVM1 volume, version %d%s",
             minor_version,
             (minor_version < 1 || minor_version > 2) ? " (unknown)" : "");

  /* volume group name */
  get_string(buf + 172, 128, s);
  print_line(level + 1, "Volume group name \"%s\"", s);

  /* "UUID" of this physical volume */
  format_uuid_lvm(buf + 0x2c, s);
  print_line(level + 1, "PV UUID %s", s);

  /* number of this physical volume */
  pv_number = get_le_long(buf + 432);
  print_line(level + 1, "PV number %d", pv_number);

  /* volume size */
  pe_size = get_le_long(buf + 452);
  pe_count = get_le_long(buf + 456);
  format_blocky_size(s, pe_count, pe_size * 512, "PEs", NULL);
  print_line(level + 1, "Useable size %s", s);

  /* get start of first PE */
  if (minor_version == 1) {
    /* minor format 1: first PE starts after the declared length of the PE tables */
    pe_start = get_le_long(buf + 36) + get_le_long(buf + 40);
  } else if (minor_version == 2) {
    /* minor format 2: a field in the header indicates this */
    pe_start = get_le_long(buf + 464) << 9;
  } else {
    /* unknown minor format */
    pe_start = 0;
  }

  /* try to detect from first PE */
  if (pe_start > 0) {
    analyze_recursive(section, level + 1,
                      pe_start, 0, 0);
    /* TODO: elaborate on this by reading the PE allocation map */
  }
}
コード例 #2
0
ファイル: apple.c プロジェクト: hnl/android_external_disktype
void detect_apple_partmap(SECTION *section, int level)
{
    int i, sectorsize, magic, count;
    char s[256], append[64];
    unsigned char *buf;
    u8 start, size;

    /* partition maps only occur at the start of a device */
    /*  disabled to allow for APM maps in El Torito entries
    if (section->pos != 0)
      return;
    */

    /*
      if (buf[off] == 0x45 && buf[off+1] == 0x52) {
        print_line(level, "HFS driver description map at sector %d", i);
      }
    */

    for (sectorsize = 512; sectorsize <= 4096; sectorsize <<= 1) {
        if (get_buffer(section, sectorsize, sectorsize, (void **)&buf) < sectorsize)
            return;

        magic = get_be_short(buf);
        if (magic == 0x5453) {
            print_line(level, "Old-style Apple partition map");
            return;
        }
        if (magic != 0x504D)
            continue;

        /* get partition count and print info */
        count = get_be_long(buf + 4);
        print_line(level, "Apple partition map, %d entries, %d byte sectors",
                   count, sectorsize);

        for (i = 1; i <= count; i++) {
            /* read the right sector */
            /* NOTE: the previous run through the loop might have called
             *  get_buffer indirectly, invalidating our old pointer */
            if (i > 1 && get_buffer(section, i * sectorsize, sectorsize,
                                    (void **)&buf) < sectorsize)
                return;

            /* check signature */
            if (get_be_short(buf) != 0x504D) {
                print_line(level, "Partition %d: invalid signature, skipping", i);
                continue;
            }

            /* get position and size */
            start = get_be_long(buf + 8);
            size = get_be_long(buf + 12);
            sprintf(append, " from %llu", start);
            format_blocky_size(s, size, sectorsize, "sectors", append);
            print_line(level, "Partition %d: %s",
                       i, s);

            /* get type */
            get_string(buf + 48, 32, s);
            print_line(level+1, "Type \"%s\"", s);

            /* recurse for content detection */
            if (start > count && size > 0) {  /* avoid recursion on self */
                analyze_recursive(section, level + 1,
                                  start * sectorsize, size * sectorsize, 0);
            }
        }
        return;  /* don't try bigger sector sizes */
    }
}
コード例 #3
0
ファイル: apple.c プロジェクト: hnl/android_external_disktype
void detect_apple_volume(SECTION *section, int level)
{
    char s[256], t[514];
    unsigned char *buf;
    u2 magic, version, volnamelen;
    u4 blocksize, blockstart;
    u8 blockcount, offset;
    u8 catalogstart, cataloglength;
    u4 firstleafnode, nodesize;

    if (get_buffer(section, 1024, 512, (void **)&buf) < 512)
        return;

    magic = get_be_short(buf);
    version = get_be_short(buf + 2);

    if (magic == 0xD2D7) {
        print_line(level, "MFS file system");

    } else if (magic == 0x4244) {
        print_line(level, "HFS file system");
        blockcount = get_be_short(buf + 18);
        blocksize = get_be_long(buf + 20);
        blockstart = get_be_short(buf + 28);

        get_pstring(buf + 36, s);
        format_ascii(s, t);
        print_line(level + 1, "Volume name \"%s\"", t);

        format_blocky_size(s, blockcount, blocksize, "blocks", NULL);
        print_line(level + 1, "Volume size %s", s);

        if (get_be_short(buf + 0x7c) == 0x482B) {
            print_line(level, "HFS wrapper for HFS Plus");

            offset = (u8)get_be_short(buf + 0x7e) * blocksize +
                     (u8)blockstart * 512;
            /* TODO: size */

            analyze_recursive(section, level + 1,
                              offset, 0, 0);
        }

    } else if (magic == 0x482B) {
        print_line(level, "HFS Plus file system");

        blocksize = get_be_long(buf + 40);
        blockcount = get_be_long(buf + 44);

        format_blocky_size(s, blockcount, blocksize, "blocks", NULL);
        print_line(level + 1, "Volume size %s", s);

        /* To read the volume name, we have to parse some structures...
           This code makes many assumptions which are usually true,
           but don't have to be. */

        /* get catalog file location on disk */
        /* ASSUMPTION: This reads the location of the first extent
           of the catalog file. If the catalog file is fragmented, we'll
           be working with only the first fragment, which may not include
           the node we're looking for. */
        catalogstart = get_be_long(buf + 288) * blocksize;
        cataloglength = get_be_long(buf + 292) * blocksize;
        /* limit to actual length (byte count instead of block count) */
        if (cataloglength > get_be_quad(buf + 272))
            cataloglength = get_be_quad(buf + 272);

        /* read header node of B-tree (4096 is the minimum node size) */
        if (get_buffer(section, catalogstart, 4096, (void **)&buf) < 4096)
            return;
        firstleafnode = get_be_long(buf + 24);
        nodesize = get_be_short(buf + 32);
        if (nodesize < 4096)
            return;  /* illegal value */

        /* read first lead node */
        if ((firstleafnode + 1) * nodesize > cataloglength)
            return;  /* the location is beyond the end of the catalog */
        if (get_buffer(section, catalogstart + firstleafnode * nodesize,
                       nodesize, (void **)&buf) < nodesize)
            return;

        /* the first record in this leaf node should be for parent id 1 */
        if (buf[8] != 0xff)
            return;  /* not a leaf node */
        if (get_be_short(buf + 14) <= 6)
            return;  /* key of first record is too short to contain a name */
        if (get_be_long(buf + 16) != 1)
            return;  /* parent folder id is not "root parent" */
        volnamelen = get_be_short(buf + 20);
        format_utf16_be(buf + 22, volnamelen * 2, t);
        print_line(level + 1, "Volume name \"%s\"", t);
    }
}