Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:14

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup rtems_bdpart
0007  *
0008  * @brief Prints the Partition Table @a Partitions with @a Count Partitions
0009  */
0010 
0011 /*
0012  * Copyright (C) 2009, 2010 embedded brains GmbH & Co. KG
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #ifdef HAVE_CONFIG_H
0037 #include "config.h"
0038 #endif
0039 
0040 #include <stdio.h>
0041 #include <inttypes.h>
0042 
0043 #include <rtems.h>
0044 #include <rtems/bdpart.h>
0045 
0046 static void rtems_bdpart_type_to_string(
0047   const uuid_t type,
0048   char str [37]
0049 )
0050 {
0051   uuid_unparse_lower( type, str);
0052 }
0053 
0054 void rtems_bdpart_dump( const rtems_bdpart_partition *pt, size_t count)
0055 {
0056   size_t i = 0;
0057 
0058   printf(
0059     "-------------------------------------------------------------------------------\n"
0060     "                                PARTITION TABLE\n"
0061     "------------+------------+-----------------------------------------------------\n"
0062     " BEGIN      | LAST       | TYPE\n"
0063     "------------+------------+-----------------------------------------------------\n"
0064   );
0065 
0066   for (i = 0; i < count; ++i) {
0067     const rtems_bdpart_partition *p = pt + i;
0068     const char *type = NULL;
0069     char type_buffer [52];
0070     uint8_t type_mbr = 0;
0071 
0072     if (rtems_bdpart_to_mbr_partition_type( p->type, &type_mbr)) {
0073       switch (type_mbr) {
0074         case RTEMS_BDPART_MBR_FAT_12:
0075           type = "FAT 12";
0076           break;
0077         case RTEMS_BDPART_MBR_FAT_16:
0078           type = "FAT 16";
0079           break;
0080         case RTEMS_BDPART_MBR_FAT_16_LBA:
0081           type = "FAT 16 LBA";
0082           break;
0083         case RTEMS_BDPART_MBR_FAT_32:
0084           type = "FAT 32";
0085           break;
0086         case RTEMS_BDPART_MBR_FAT_32_LBA:
0087           type = "FAT 32 LBA";
0088           break;
0089         case RTEMS_BDPART_MBR_DATA:
0090           type = "DATA";
0091           break;
0092         default:
0093           snprintf( type_buffer, sizeof( type_buffer), "0x%02" PRIx8, type_mbr);
0094           type = type_buffer;
0095           break;
0096       }
0097     } else {
0098       rtems_bdpart_type_to_string( p->type, type_buffer);
0099       type = type_buffer;
0100     }
0101 
0102     printf(
0103       " %10" PRIu32 " | %10" PRIu32 " |%52s\n",
0104       p->begin,
0105       p->end - 1U,
0106       type
0107     );
0108   }
0109 
0110   puts( "------------+------------+-----------------------------------------------------");
0111 }