]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - disk/part_dos.c
disk: Fixed capacity message
[people/ms/u-boot.git] / disk / part_dos.c
index 5f8d949b84c7a680c33ce29e296ea0174cf87727..ed78334a9dd85059c81dc744692fa6dd34308853 100644 (file)
@@ -87,11 +87,11 @@ static int test_block_type(unsigned char *buffer)
 }
 
 
-static int test_part_dos(struct blk_desc *dev_desc)
+static int part_test_dos(struct blk_desc *dev_desc)
 {
        ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
 
-       if (dev_desc->block_read(dev_desc, 0, 1, (ulong *)buffer) != 1)
+       if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1)
                return -1;
 
        if (test_block_type(buffer) != DOS_MBR)
@@ -111,8 +111,7 @@ static void print_partition_extended(struct blk_desc *dev_desc,
        dos_partition_t *pt;
        int i;
 
-       if (dev_desc->block_read(dev_desc, ext_part_sector, 1,
-                                (ulong *)buffer) != 1) {
+       if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
                printf ("** Can't read partition table on %d:" LBAFU " **\n",
                        dev_desc->devnum, ext_part_sector);
                return;
@@ -177,8 +176,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
        int i;
        int dos_type;
 
-       if (dev_desc->block_read(dev_desc, ext_part_sector, 1,
-                                (ulong *)buffer) != 1) {
+       if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
                printf ("** Can't read partition table on %d:" LBAFU " **\n",
                        dev_desc->devnum, ext_part_sector);
                return -1;
@@ -211,35 +209,8 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
                        info->start = (lbaint_t)(ext_part_sector +
                                        le32_to_int(pt->start4));
                        info->size  = (lbaint_t)le32_to_int(pt->size4);
-                       switch(dev_desc->if_type) {
-                               case IF_TYPE_IDE:
-                               case IF_TYPE_SATA:
-                               case IF_TYPE_ATAPI:
-                                       sprintf((char *)info->name, "hd%c%d",
-                                               'a' + dev_desc->devnum,
-                                               part_num);
-                                       break;
-                               case IF_TYPE_SCSI:
-                                       sprintf((char *)info->name, "sd%c%d",
-                                               'a' + dev_desc->devnum,
-                                               part_num);
-                                       break;
-                               case IF_TYPE_USB:
-                                       sprintf((char *)info->name, "usbd%c%d",
-                                               'a' + dev_desc->devnum,
-                                               part_num);
-                                       break;
-                               case IF_TYPE_DOC:
-                                       sprintf((char *)info->name, "docd%c%d",
-                                               'a' + dev_desc->devnum,
-                                               part_num);
-                                       break;
-                               default:
-                                       sprintf((char *)info->name, "xx%c%d",
-                                               'a' + dev_desc->devnum,
-                                               part_num);
-                                       break;
-                       }
+                       part_set_generic_name(dev_desc, part_num,
+                                             (char *)info->name);
                        /* sprintf(info->type, "%d, pt->sys_ind); */
                        strcpy((char *)info->type, "U-Boot");
                        info->bootable = is_bootable(pt);
@@ -287,7 +258,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
        return -1;
 }
 
-void print_part_dos(struct blk_desc *dev_desc)
+void part_print_dos(struct blk_desc *dev_desc)
 {
        printf("Part\tStart Sector\tNum Sectors\tUUID\t\tType\n");
        print_partition_extended(dev_desc, 0, 0, 1, 0);
@@ -299,12 +270,33 @@ int part_get_info_dos(struct blk_desc *dev_desc, int part,
        return part_get_info_extended(dev_desc, 0, 0, 1, part, info, 0);
 }
 
+int is_valid_dos_buf(void *buf)
+{
+       return test_block_type(buf) == DOS_MBR ? 0 : -1;
+}
+
+int write_mbr_partition(struct blk_desc *dev_desc, void *buf)
+{
+       if (is_valid_dos_buf(buf))
+               return -1;
+
+       /* write MBR */
+       if (blk_dwrite(dev_desc, 0, 1, buf) != 1) {
+               printf("%s: failed writing '%s' (1 blks at 0x0)\n",
+                      __func__, "MBR");
+               return 1;
+       }
+
+       return 0;
+}
+
 U_BOOT_PART_TYPE(dos) = {
        .name           = "DOS",
        .part_type      = PART_TYPE_DOS,
+       .max_entries    = DOS_ENTRY_NUMBERS,
        .get_info       = part_get_info_ptr(part_get_info_dos),
-       .print          = part_print_ptr(print_part_dos),
-       .test           = test_part_dos,
+       .print          = part_print_ptr(part_print_dos),
+       .test           = part_test_dos,
 };
 
 #endif