Logo Search packages:      
Sourcecode: u3-tool version File versions

int u3_partition ( u3_handle_t device,
uint32_t  cd_size 
)

Repartiton device

This repatitions the device into a CD and a data partition. All current data will be lost. Creating a CD partition of size 0 will make this device an ordenary USB stick.

Parameters:
device U3 device handle
cd_size The size of the CD partition in 512 byte sectors.
Returns:
U3_SUCCESS if successful, else U3_FAILURE and an error string can be obtained using u3_error()

Definition at line 149 of file u3_commands.c.

References part_info::cd_size, part_info::data_size, part_info::partition_count, u3_send_cmd(), part_info::unknown1, and part_info::unknown2.

                                                        {
      uint8_t status;
      uint8_t cmd[U3_CMD_LEN] = {
            0xff, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00
      };
      struct part_info data;
      struct property_03 device_properties;
      uint32_t data_size;

      // calculate data partition size
      if (cd_size != 0) {
            if (u3_partition_sector_round(device, round_up, &cd_size) != U3_SUCCESS) {
                  u3_prepend_error(device, "Failed rounding partition sectors");
                  return U3_FAILURE;
            }
      }

      if (u3_read_device_property(device, 3, (uint8_t *) &device_properties,
                  sizeof(device_properties)) != U3_SUCCESS)
      {
            u3_prepend_error(device, "Failed reading device property 0x03");
            return U3_FAILURE;
      }

      if (device_properties.hdr.length != sizeof(device_properties)) {
            u3_set_error(device, "Unexpected device property(0x03) length"
                  ", won't risk breaking device. Aborting! (len=%X)", 
                  device_properties.hdr.length);
            return U3_FAILURE;
      }
      if (cd_size > device_properties.device_size) {
            u3_set_error(device, "Requested CD size is to big for device");
            return U3_FAILURE;
      }

      data_size = device_properties.device_size - cd_size;
      if (u3_partition_sector_round(device, round_down, &data_size) != U3_SUCCESS) {
            u3_prepend_error(device, "Failed rounding partition sectors");
            return U3_FAILURE;
      }
      
      // fill command data
      memset(&data, 0, sizeof(data));
      if (cd_size == 0) {
            data.partition_count = 1;
            data.unknown1 = 0x02;
            data.data_size = data_size;
            data.unknown2 = 0;
            data.cd_size = 0;
      } else {
            data.partition_count = 2;
            data.unknown1 = 0x02;
            data.data_size = data_size;
            data.unknown2 = 0x103;
            data.cd_size = cd_size;
      }

      if (u3_send_cmd(device, cmd, U3_DATA_TO_DEV, sizeof(data),
            (uint8_t *) &data, &status) != U3_SUCCESS)
      {
            return U3_FAILURE;
      }

      if (status != 0) {
            u3_set_error(device, "Device reported command failed: status %d", status);
            return U3_FAILURE;
      }

      return U3_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index