common: Drop part.h from common header
[platform/kernel/u-boot.git] / disk / part.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2001
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6
7 #include <common.h>
8 #include <blk.h>
9 #include <command.h>
10 #include <env.h>
11 #include <errno.h>
12 #include <ide.h>
13 #include <malloc.h>
14 #include <part.h>
15 #include <ubifs_uboot.h>
16
17 #undef  PART_DEBUG
18
19 #ifdef  PART_DEBUG
20 #define PRINTF(fmt,args...)     printf (fmt ,##args)
21 #else
22 #define PRINTF(fmt,args...)
23 #endif
24
25 /* Check all partition types */
26 #define PART_TYPE_ALL           -1
27
28 static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
29 {
30         struct part_driver *drv =
31                 ll_entry_start(struct part_driver, part_driver);
32         const int n_ents = ll_entry_count(struct part_driver, part_driver);
33         struct part_driver *entry;
34
35         if (dev_desc->part_type == PART_TYPE_UNKNOWN) {
36                 for (entry = drv; entry != drv + n_ents; entry++) {
37                         int ret;
38
39                         ret = entry->test(dev_desc);
40                         if (!ret) {
41                                 dev_desc->part_type = entry->part_type;
42                                 return entry;
43                         }
44                 }
45         } else {
46                 for (entry = drv; entry != drv + n_ents; entry++) {
47                         if (dev_desc->part_type == entry->part_type)
48                                 return entry;
49                 }
50         }
51
52         /* Not found */
53         return NULL;
54 }
55
56 #ifdef CONFIG_HAVE_BLOCK_DEVICE
57 static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
58 {
59         struct blk_desc *dev_desc;
60         int ret;
61
62         dev_desc = blk_get_devnum_by_typename(ifname, dev);
63         if (!dev_desc) {
64                 debug("%s: No device for iface '%s', dev %d\n", __func__,
65                       ifname, dev);
66                 return NULL;
67         }
68         ret = blk_dselect_hwpart(dev_desc, hwpart);
69         if (ret) {
70                 debug("%s: Failed to select h/w partition: err-%d\n", __func__,
71                       ret);
72                 return NULL;
73         }
74
75         return dev_desc;
76 }
77
78 struct blk_desc *blk_get_dev(const char *ifname, int dev)
79 {
80         return get_dev_hwpart(ifname, dev, 0);
81 }
82 #else
83 struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
84 {
85         return NULL;
86 }
87
88 struct blk_desc *blk_get_dev(const char *ifname, int dev)
89 {
90         return NULL;
91 }
92 #endif
93
94 #ifdef CONFIG_HAVE_BLOCK_DEVICE
95
96 /* ------------------------------------------------------------------------- */
97 /*
98  * reports device info to the user
99  */
100
101 #ifdef CONFIG_LBA48
102 typedef uint64_t lba512_t;
103 #else
104 typedef lbaint_t lba512_t;
105 #endif
106
107 /*
108  * Overflowless variant of (block_count * mul_by / 2**right_shift)
109  * when 2**right_shift > mul_by
110  */
111 static lba512_t lba512_muldiv(lba512_t block_count, lba512_t mul_by,
112                               int right_shift)
113 {
114         lba512_t bc_quot, bc_rem;
115
116         /* x * m / d == x / d * m + (x % d) * m / d */
117         bc_quot = block_count >> right_shift;
118         bc_rem  = block_count - (bc_quot << right_shift);
119         return bc_quot * mul_by + ((bc_rem * mul_by) >> right_shift);
120 }
121
122 void dev_print (struct blk_desc *dev_desc)
123 {
124         lba512_t lba512; /* number of blocks if 512bytes block size */
125
126         if (dev_desc->type == DEV_TYPE_UNKNOWN) {
127                 puts ("not available\n");
128                 return;
129         }
130
131         switch (dev_desc->if_type) {
132         case IF_TYPE_SCSI:
133                 printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n",
134                         dev_desc->target,dev_desc->lun,
135                         dev_desc->vendor,
136                         dev_desc->product,
137                         dev_desc->revision);
138                 break;
139         case IF_TYPE_ATAPI:
140         case IF_TYPE_IDE:
141         case IF_TYPE_SATA:
142                 printf ("Model: %s Firm: %s Ser#: %s\n",
143                         dev_desc->vendor,
144                         dev_desc->revision,
145                         dev_desc->product);
146                 break;
147         case IF_TYPE_SD:
148         case IF_TYPE_MMC:
149         case IF_TYPE_USB:
150         case IF_TYPE_NVME:
151                 printf ("Vendor: %s Rev: %s Prod: %s\n",
152                         dev_desc->vendor,
153                         dev_desc->revision,
154                         dev_desc->product);
155                 break;
156         case IF_TYPE_VIRTIO:
157                 printf("%s VirtIO Block Device\n", dev_desc->vendor);
158                 break;
159         case IF_TYPE_DOC:
160                 puts("device type DOC\n");
161                 return;
162         case IF_TYPE_UNKNOWN:
163                 puts("device type unknown\n");
164                 return;
165         default:
166                 printf("Unhandled device type: %i\n", dev_desc->if_type);
167                 return;
168         }
169         puts ("            Type: ");
170         if (dev_desc->removable)
171                 puts ("Removable ");
172         switch (dev_desc->type & 0x1F) {
173         case DEV_TYPE_HARDDISK:
174                 puts ("Hard Disk");
175                 break;
176         case DEV_TYPE_CDROM:
177                 puts ("CD ROM");
178                 break;
179         case DEV_TYPE_OPDISK:
180                 puts ("Optical Device");
181                 break;
182         case DEV_TYPE_TAPE:
183                 puts ("Tape");
184                 break;
185         default:
186                 printf ("# %02X #", dev_desc->type & 0x1F);
187                 break;
188         }
189         puts ("\n");
190         if (dev_desc->lba > 0L && dev_desc->blksz > 0L) {
191                 ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
192                 lbaint_t lba;
193
194                 lba = dev_desc->lba;
195
196                 lba512 = (lba * (dev_desc->blksz/512));
197                 /* round to 1 digit */
198                 /* 2048 = (1024 * 1024) / 512 MB */
199                 mb = lba512_muldiv(lba512, 10, 11);
200
201                 mb_quot = mb / 10;
202                 mb_rem  = mb - (10 * mb_quot);
203
204                 gb = mb / 1024;
205                 gb_quot = gb / 10;
206                 gb_rem  = gb - (10 * gb_quot);
207 #ifdef CONFIG_LBA48
208                 if (dev_desc->lba48)
209                         printf ("            Supports 48-bit addressing\n");
210 #endif
211 #if defined(CONFIG_SYS_64BIT_LBA)
212                 printf ("            Capacity: %lu.%lu MB = %lu.%lu GB (%llu x %lu)\n",
213                         mb_quot, mb_rem,
214                         gb_quot, gb_rem,
215                         lba,
216                         dev_desc->blksz);
217 #else
218                 printf ("            Capacity: %lu.%lu MB = %lu.%lu GB (%lu x %lu)\n",
219                         mb_quot, mb_rem,
220                         gb_quot, gb_rem,
221                         (ulong)lba,
222                         dev_desc->blksz);
223 #endif
224         } else {
225                 puts ("            Capacity: not available\n");
226         }
227 }
228 #endif
229
230 #ifdef CONFIG_HAVE_BLOCK_DEVICE
231
232 void part_init(struct blk_desc *dev_desc)
233 {
234         struct part_driver *drv =
235                 ll_entry_start(struct part_driver, part_driver);
236         const int n_ents = ll_entry_count(struct part_driver, part_driver);
237         struct part_driver *entry;
238
239         blkcache_invalidate(dev_desc->if_type, dev_desc->devnum);
240
241         dev_desc->part_type = PART_TYPE_UNKNOWN;
242         for (entry = drv; entry != drv + n_ents; entry++) {
243                 int ret;
244
245                 ret = entry->test(dev_desc);
246                 debug("%s: try '%s': ret=%d\n", __func__, entry->name, ret);
247                 if (!ret) {
248                         dev_desc->part_type = entry->part_type;
249                         break;
250                 }
251         }
252 }
253
254 static void print_part_header(const char *type, struct blk_desc *dev_desc)
255 {
256 #if CONFIG_IS_ENABLED(MAC_PARTITION) || \
257         CONFIG_IS_ENABLED(DOS_PARTITION) || \
258         CONFIG_IS_ENABLED(ISO_PARTITION) || \
259         CONFIG_IS_ENABLED(AMIGA_PARTITION) || \
260         CONFIG_IS_ENABLED(EFI_PARTITION)
261         puts ("\nPartition Map for ");
262         switch (dev_desc->if_type) {
263         case IF_TYPE_IDE:
264                 puts ("IDE");
265                 break;
266         case IF_TYPE_SATA:
267                 puts ("SATA");
268                 break;
269         case IF_TYPE_SCSI:
270                 puts ("SCSI");
271                 break;
272         case IF_TYPE_ATAPI:
273                 puts ("ATAPI");
274                 break;
275         case IF_TYPE_USB:
276                 puts ("USB");
277                 break;
278         case IF_TYPE_DOC:
279                 puts ("DOC");
280                 break;
281         case IF_TYPE_MMC:
282                 puts ("MMC");
283                 break;
284         case IF_TYPE_HOST:
285                 puts ("HOST");
286                 break;
287         case IF_TYPE_NVME:
288                 puts ("NVMe");
289                 break;
290         case IF_TYPE_VIRTIO:
291                 puts("VirtIO");
292                 break;
293         default:
294                 puts ("UNKNOWN");
295                 break;
296         }
297         printf (" device %d  --   Partition Type: %s\n\n",
298                         dev_desc->devnum, type);
299 #endif /* any CONFIG_..._PARTITION */
300 }
301
302 void part_print(struct blk_desc *dev_desc)
303 {
304         struct part_driver *drv;
305
306         drv = part_driver_lookup_type(dev_desc);
307         if (!drv) {
308                 printf("## Unknown partition table type %x\n",
309                        dev_desc->part_type);
310                 return;
311         }
312
313         PRINTF("## Testing for valid %s partition ##\n", drv->name);
314         print_part_header(drv->name, dev_desc);
315         if (drv->print)
316                 drv->print(dev_desc);
317 }
318
319 #endif /* CONFIG_HAVE_BLOCK_DEVICE */
320
321 int part_get_info(struct blk_desc *dev_desc, int part,
322                        struct disk_partition *info)
323 {
324 #ifdef CONFIG_HAVE_BLOCK_DEVICE
325         struct part_driver *drv;
326
327 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
328         /* The common case is no UUID support */
329         info->uuid[0] = 0;
330 #endif
331 #ifdef CONFIG_PARTITION_TYPE_GUID
332         info->type_guid[0] = 0;
333 #endif
334
335         drv = part_driver_lookup_type(dev_desc);
336         if (!drv) {
337                 debug("## Unknown partition table type %x\n",
338                       dev_desc->part_type);
339                 return -EPROTONOSUPPORT;
340         }
341         if (!drv->get_info) {
342                 PRINTF("## Driver %s does not have the get_info() method\n",
343                        drv->name);
344                 return -ENOSYS;
345         }
346         if (drv->get_info(dev_desc, part, info) == 0) {
347                 PRINTF("## Valid %s partition found ##\n", drv->name);
348                 return 0;
349         }
350 #endif /* CONFIG_HAVE_BLOCK_DEVICE */
351
352         return -1;
353 }
354
355 int part_get_info_whole_disk(struct blk_desc *dev_desc,
356                              struct disk_partition *info)
357 {
358         info->start = 0;
359         info->size = dev_desc->lba;
360         info->blksz = dev_desc->blksz;
361         info->bootable = 0;
362         strcpy((char *)info->type, BOOT_PART_TYPE);
363         strcpy((char *)info->name, "Whole Disk");
364 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
365         info->uuid[0] = 0;
366 #endif
367 #ifdef CONFIG_PARTITION_TYPE_GUID
368         info->type_guid[0] = 0;
369 #endif
370
371         return 0;
372 }
373
374 int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str,
375                           struct blk_desc **dev_desc)
376 {
377         char *ep;
378         char *dup_str = NULL;
379         const char *dev_str, *hwpart_str;
380         int dev, hwpart;
381
382         hwpart_str = strchr(dev_hwpart_str, '.');
383         if (hwpart_str) {
384                 dup_str = strdup(dev_hwpart_str);
385                 dup_str[hwpart_str - dev_hwpart_str] = 0;
386                 dev_str = dup_str;
387                 hwpart_str++;
388         } else {
389                 dev_str = dev_hwpart_str;
390                 hwpart = 0;
391         }
392
393         dev = simple_strtoul(dev_str, &ep, 16);
394         if (*ep) {
395                 printf("** Bad device specification %s %s **\n",
396                        ifname, dev_str);
397                 dev = -EINVAL;
398                 goto cleanup;
399         }
400
401         if (hwpart_str) {
402                 hwpart = simple_strtoul(hwpart_str, &ep, 16);
403                 if (*ep) {
404                         printf("** Bad HW partition specification %s %s **\n",
405                             ifname, hwpart_str);
406                         dev = -EINVAL;
407                         goto cleanup;
408                 }
409         }
410
411         *dev_desc = get_dev_hwpart(ifname, dev, hwpart);
412         if (!(*dev_desc) || ((*dev_desc)->type == DEV_TYPE_UNKNOWN)) {
413                 debug("** Bad device %s %s **\n", ifname, dev_hwpart_str);
414                 dev = -ENOENT;
415                 goto cleanup;
416         }
417
418 #ifdef CONFIG_HAVE_BLOCK_DEVICE
419         /*
420          * Updates the partition table for the specified hw partition.
421          * Always should be done, otherwise hw partition 0 will return stale
422          * data after displaying a non-zero hw partition.
423          */
424         part_init(*dev_desc);
425 #endif
426
427 cleanup:
428         free(dup_str);
429         return dev;
430 }
431
432 #define PART_UNSPECIFIED -2
433 #define PART_AUTO -1
434 int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
435                              struct blk_desc **dev_desc,
436                              struct disk_partition *info, int allow_whole_dev)
437 {
438         int ret = -1;
439         const char *part_str;
440         char *dup_str = NULL;
441         const char *dev_str;
442         int dev;
443         char *ep;
444         int p;
445         int part;
446         struct disk_partition tmpinfo;
447
448 #ifdef CONFIG_SANDBOX
449         /*
450          * Special-case a pseudo block device "hostfs", to allow access to the
451          * host's own filesystem.
452          */
453         if (0 == strcmp(ifname, "hostfs")) {
454                 *dev_desc = NULL;
455                 info->start = 0;
456                 info->size = 0;
457                 info->blksz = 0;
458                 info->bootable = 0;
459                 strcpy((char *)info->type, BOOT_PART_TYPE);
460                 strcpy((char *)info->name, "Sandbox host");
461 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
462                 info->uuid[0] = 0;
463 #endif
464 #ifdef CONFIG_PARTITION_TYPE_GUID
465                 info->type_guid[0] = 0;
466 #endif
467
468                 return 0;
469         }
470 #endif
471
472 #ifdef CONFIG_CMD_UBIFS
473         /*
474          * Special-case ubi, ubi goes through a mtd, rather than through
475          * a regular block device.
476          */
477         if (0 == strcmp(ifname, "ubi")) {
478                 if (!ubifs_is_mounted()) {
479                         printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
480                         return -1;
481                 }
482
483                 *dev_desc = NULL;
484                 memset(info, 0, sizeof(*info));
485                 strcpy((char *)info->type, BOOT_PART_TYPE);
486                 strcpy((char *)info->name, "UBI");
487 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
488                 info->uuid[0] = 0;
489 #endif
490                 return 0;
491         }
492 #endif
493
494         /* If no dev_part_str, use bootdevice environment variable */
495         if (!dev_part_str || !strlen(dev_part_str) ||
496             !strcmp(dev_part_str, "-"))
497                 dev_part_str = env_get("bootdevice");
498
499         /* If still no dev_part_str, it's an error */
500         if (!dev_part_str) {
501                 printf("** No device specified **\n");
502                 goto cleanup;
503         }
504
505         /* Separate device and partition ID specification */
506         part_str = strchr(dev_part_str, ':');
507         if (part_str) {
508                 dup_str = strdup(dev_part_str);
509                 dup_str[part_str - dev_part_str] = 0;
510                 dev_str = dup_str;
511                 part_str++;
512         } else {
513                 dev_str = dev_part_str;
514         }
515
516         /* Look up the device */
517         dev = blk_get_device_by_str(ifname, dev_str, dev_desc);
518         if (dev < 0)
519                 goto cleanup;
520
521         /* Convert partition ID string to number */
522         if (!part_str || !*part_str) {
523                 part = PART_UNSPECIFIED;
524         } else if (!strcmp(part_str, "auto")) {
525                 part = PART_AUTO;
526         } else {
527                 /* Something specified -> use exactly that */
528                 part = (int)simple_strtoul(part_str, &ep, 16);
529                 /*
530                  * Less than whole string converted,
531                  * or request for whole device, but caller requires partition.
532                  */
533                 if (*ep || (part == 0 && !allow_whole_dev)) {
534                         printf("** Bad partition specification %s %s **\n",
535                             ifname, dev_part_str);
536                         goto cleanup;
537                 }
538         }
539
540         /*
541          * No partition table on device,
542          * or user requested partition 0 (entire device).
543          */
544         if (((*dev_desc)->part_type == PART_TYPE_UNKNOWN) ||
545             (part == 0)) {
546                 if (!(*dev_desc)->lba) {
547                         printf("** Bad device size - %s %s **\n", ifname,
548                                dev_str);
549                         goto cleanup;
550                 }
551
552                 /*
553                  * If user specified a partition ID other than 0,
554                  * or the calling command only accepts partitions,
555                  * it's an error.
556                  */
557                 if ((part > 0) || (!allow_whole_dev)) {
558                         printf("** No partition table - %s %s **\n", ifname,
559                                dev_str);
560                         goto cleanup;
561                 }
562
563                 (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz);
564
565                 part_get_info_whole_disk(*dev_desc, info);
566
567                 ret = 0;
568                 goto cleanup;
569         }
570
571         /*
572          * Now there's known to be a partition table,
573          * not specifying a partition means to pick partition 1.
574          */
575         if (part == PART_UNSPECIFIED)
576                 part = 1;
577
578         /*
579          * If user didn't specify a partition number, or did specify something
580          * other than "auto", use that partition number directly.
581          */
582         if (part != PART_AUTO) {
583                 ret = part_get_info(*dev_desc, part, info);
584                 if (ret) {
585                         printf("** Invalid partition %d **\n", part);
586                         goto cleanup;
587                 }
588         } else {
589                 /*
590                  * Find the first bootable partition.
591                  * If none are bootable, fall back to the first valid partition.
592                  */
593                 part = 0;
594                 for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
595                         ret = part_get_info(*dev_desc, p, info);
596                         if (ret)
597                                 continue;
598
599                         /*
600                          * First valid partition, or new better partition?
601                          * If so, save partition ID.
602                          */
603                         if (!part || info->bootable)
604                                 part = p;
605
606                         /* Best possible partition? Stop searching. */
607                         if (info->bootable)
608                                 break;
609
610                         /*
611                          * We now need to search further for best possible.
612                          * If we what we just queried was the best so far,
613                          * save the info since we over-write it next loop.
614                          */
615                         if (part == p)
616                                 tmpinfo = *info;
617                 }
618                 /* If we found any acceptable partition */
619                 if (part) {
620                         /*
621                          * If we searched all possible partition IDs,
622                          * return the first valid partition we found.
623                          */
624                         if (p == MAX_SEARCH_PARTITIONS + 1)
625                                 *info = tmpinfo;
626                 } else {
627                         printf("** No valid partitions found **\n");
628                         ret = -1;
629                         goto cleanup;
630                 }
631         }
632         if (strncmp((char *)info->type, BOOT_PART_TYPE, sizeof(info->type)) != 0) {
633                 printf("** Invalid partition type \"%.32s\""
634                         " (expect \"" BOOT_PART_TYPE "\")\n",
635                         info->type);
636                 ret  = -1;
637                 goto cleanup;
638         }
639
640         (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz);
641
642         ret = part;
643         goto cleanup;
644
645 cleanup:
646         free(dup_str);
647         return ret;
648 }
649
650 int part_get_info_by_name_type(struct blk_desc *dev_desc, const char *name,
651                                struct disk_partition *info, int part_type)
652 {
653         struct part_driver *part_drv;
654         int ret;
655         int i;
656
657         part_drv = part_driver_lookup_type(dev_desc);
658         if (!part_drv)
659                 return -1;
660         for (i = 1; i < part_drv->max_entries; i++) {
661                 ret = part_drv->get_info(dev_desc, i, info);
662                 if (ret != 0) {
663                         /* no more entries in table */
664                         break;
665                 }
666                 if (strcmp(name, (const char *)info->name) == 0) {
667                         /* matched */
668                         return i;
669                 }
670         }
671
672         return -1;
673 }
674
675 int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
676                           struct disk_partition *info)
677 {
678         return part_get_info_by_name_type(dev_desc, name, info, PART_TYPE_ALL);
679 }
680
681 /**
682  * Get partition info from device number and partition name.
683  *
684  * Parse a device number and partition name string in the form of
685  * "device_num#partition_name", for example "0#misc". If the partition
686  * is found, sets dev_desc and part_info accordingly with the information
687  * of the partition with the given partition_name.
688  *
689  * @param[in] dev_iface Device interface
690  * @param[in] dev_part_str Input string argument, like "0#misc"
691  * @param[out] dev_desc Place to store the device description pointer
692  * @param[out] part_info Place to store the partition information
693  * @return 0 on success, or a negative on error
694  */
695 static int part_get_info_by_dev_and_name(const char *dev_iface,
696                                          const char *dev_part_str,
697                                          struct blk_desc **dev_desc,
698                                          struct disk_partition *part_info)
699 {
700         char *ep;
701         const char *part_str;
702         int dev_num;
703
704         part_str = strchr(dev_part_str, '#');
705         if (!part_str || part_str == dev_part_str)
706                 return -EINVAL;
707
708         dev_num = simple_strtoul(dev_part_str, &ep, 16);
709         if (ep != part_str) {
710                 /* Not all the first part before the # was parsed. */
711                 return -EINVAL;
712         }
713         part_str++;
714
715         *dev_desc = blk_get_dev(dev_iface, dev_num);
716         if (!*dev_desc) {
717                 printf("Could not find %s %d\n", dev_iface, dev_num);
718                 return -EINVAL;
719         }
720         if (part_get_info_by_name(*dev_desc, part_str, part_info) < 0) {
721                 printf("Could not find \"%s\" partition\n", part_str);
722                 return -EINVAL;
723         }
724         return 0;
725 }
726
727 int part_get_info_by_dev_and_name_or_num(const char *dev_iface,
728                                          const char *dev_part_str,
729                                          struct blk_desc **dev_desc,
730                                          struct disk_partition *part_info)
731 {
732         /* Split the part_name if passed as "$dev_num#part_name". */
733         if (!part_get_info_by_dev_and_name(dev_iface, dev_part_str,
734                                            dev_desc, part_info))
735                 return 0;
736         /*
737          * Couldn't lookup by name, try looking up the partition description
738          * directly.
739          */
740         if (blk_get_device_part_str(dev_iface, dev_part_str,
741                                     dev_desc, part_info, 1) < 0) {
742                 printf("Couldn't find partition %s %s\n",
743                        dev_iface, dev_part_str);
744                 return -EINVAL;
745         }
746         return 0;
747 }
748
749 void part_set_generic_name(const struct blk_desc *dev_desc,
750         int part_num, char *name)
751 {
752         char *devtype;
753
754         switch (dev_desc->if_type) {
755         case IF_TYPE_IDE:
756         case IF_TYPE_SATA:
757         case IF_TYPE_ATAPI:
758                 devtype = "hd";
759                 break;
760         case IF_TYPE_SCSI:
761                 devtype = "sd";
762                 break;
763         case IF_TYPE_USB:
764                 devtype = "usbd";
765                 break;
766         case IF_TYPE_DOC:
767                 devtype = "docd";
768                 break;
769         case IF_TYPE_MMC:
770         case IF_TYPE_SD:
771                 devtype = "mmcsd";
772                 break;
773         default:
774                 devtype = "xx";
775                 break;
776         }
777
778         sprintf(name, "%s%c%d", devtype, 'a' + dev_desc->devnum, part_num);
779 }