1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3 * (C) Copyright 2000-2004
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 */
6 #ifndef _PART_H
7 #define _PART_H
8
9 #include <blk.h>
10 #include <u-boot/uuid.h>
11 #include <linux/errno.h>
12 #include <linux/list.h>
13
14 struct block_drvr {
15 char *name;
16 int (*select_hwpart)(int dev_num, int hwpart);
17 };
18
19 #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
20 ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
21 ((x & 0xffff0000) ? 16 : 0))
22 #define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
23
24 /* Part types */
25 #define PART_TYPE_UNKNOWN 0x00
26 #define PART_TYPE_MAC 0x01
27 #define PART_TYPE_DOS 0x02
28 #define PART_TYPE_ISO 0x03
29 #define PART_TYPE_AMIGA 0x04
30 #define PART_TYPE_EFI 0x05
31 #define PART_TYPE_MTD 0x06
32 #define PART_TYPE_UBI 0x07
33
34 /* maximum number of partition entries supported by search */
35 #define DOS_ENTRY_NUMBERS 8
36 #define ISO_ENTRY_NUMBERS 64
37 #define MAC_ENTRY_NUMBERS 64
38 #define AMIGA_ENTRY_NUMBERS 8
39 #define MTD_ENTRY_NUMBERS 64
40 #define UBI_ENTRY_NUMBERS UBI_MAX_VOLUMES
41
42 /*
43 * Type string for U-Boot bootable partitions
44 */
45 #define BOOT_PART_TYPE "U-Boot" /* primary boot partition type */
46 #define BOOT_PART_COMP "PPCBoot" /* PPCBoot compatibility type */
47
48 /* device types */
49 #define DEV_TYPE_UNKNOWN 0xff /* not connected */
50 #define DEV_TYPE_HARDDISK 0x00 /* harddisk */
51 #define DEV_TYPE_TAPE 0x01 /* Tape */
52 #define DEV_TYPE_CDROM 0x05 /* CD-ROM */
53 #define DEV_TYPE_OPDISK 0x07 /* optical disk */
54
55 #define PART_NAME_LEN 32
56 #define PART_TYPE_LEN 32
57 #define MAX_SEARCH_PARTITIONS 128
58
59 #define PART_BOOTABLE ((int)BIT(0))
60 #define PART_EFI_SYSTEM_PARTITION ((int)BIT(1))
61
62 struct disk_partition {
63 lbaint_t start; /* # of first block in partition */
64 lbaint_t size; /* number of blocks in partition */
65 ulong blksz; /* block size in bytes */
66 uchar name[PART_NAME_LEN]; /* partition name */
67 uchar type[PART_TYPE_LEN]; /* string type description */
68 /*
69 * The bootable is a bitmask with the following fields:
70 *
71 * PART_BOOTABLE the MBR bootable flag is set
72 * PART_EFI_SYSTEM_PARTITION the partition is an EFI system partition
73 */
74 int bootable;
75 u16 type_flags; /* top 16 bits of GPT partition attributes */
76 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
77 char uuid[UUID_STR_LEN + 1]; /* filesystem UUID as string, if exists */
78 #endif
79 #ifdef CONFIG_PARTITION_TYPE_GUID
80 char type_guid[UUID_STR_LEN + 1]; /* type GUID as string, if exists */
81 #endif
82 #ifdef CONFIG_DOS_PARTITION
83 uchar sys_ind; /* partition type */
84 #endif
85 };
86
87 /* Accessors for struct disk_partition field ->uuid */
88 extern char *__invalid_use_of_disk_partition_uuid;
89
disk_partition_uuid(const struct disk_partition * info)90 static inline const char *disk_partition_uuid(const struct disk_partition *info)
91 {
92 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
93 return info->uuid;
94 #else
95 return __invalid_use_of_disk_partition_uuid;
96 #endif
97 }
98
disk_partition_set_uuid(struct disk_partition * info,const char * val)99 static inline void disk_partition_set_uuid(struct disk_partition *info,
100 const char *val)
101 {
102 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
103 strlcpy(info->uuid, val, UUID_STR_LEN + 1);
104 #endif
105 }
106
disk_partition_clr_uuid(struct disk_partition * info)107 static inline void disk_partition_clr_uuid(struct disk_partition *info)
108 {
109 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
110 *info->uuid = '\0';
111 #endif
112 }
113
114 /* Accessors for struct disk_partition field ->type_guid */
115 extern char *__invalid_use_of_disk_partition_type_guid;
116
117 /**
118 * disk_partition_type_guid() - get partition type GUID
119 *
120 * By using this function to get the partition type GUID we can use
121 * 'if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))' instead of
122 * '#ifdef CONFIG_PARTITION_TYPE_GUID'.
123 *
124 * @info: partition information
125 * Return: partition type GUID
126 */
127 static inline const
disk_partition_type_guid(const struct disk_partition * info)128 char *disk_partition_type_guid(const struct disk_partition *info)
129 {
130 #ifdef CONFIG_PARTITION_TYPE_GUID
131 return info->type_guid;
132 #else
133 return __invalid_use_of_disk_partition_type_guid;
134 #endif
135 }
136
137 /**
138 * disk_partition_set_type_guid() - set partition type GUID
139 *
140 * By using this function to set the partition type GUID we can use
141 * 'if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))' instead of
142 * '#ifdef CONFIG_PARTITION_TYPE_GUID'.
143 *
144 * @info: partition information
145 * @val: partition type GUID as string
146 */
disk_partition_set_type_guid(struct disk_partition * info,const char * val)147 static inline void disk_partition_set_type_guid(struct disk_partition *info,
148 const char *val)
149 {
150 #ifdef CONFIG_PARTITION_TYPE_GUID
151 strlcpy(info->type_guid, val, UUID_STR_LEN + 1);
152 #endif
153 }
154
disk_partition_clr_type_guid(struct disk_partition * info)155 static inline void disk_partition_clr_type_guid(struct disk_partition *info)
156 {
157 #ifdef CONFIG_PARTITION_TYPE_GUID
158 *info->type_guid = '\0';
159 #endif
160 }
161
162 /* Accessors for struct disk_partition field ->sys_ind */
163 extern int __invalid_use_of_disk_partition_sys_ind;
164
disk_partition_sys_ind(const struct disk_partition * info)165 static inline uint disk_partition_sys_ind(const struct disk_partition *info)
166 {
167 #ifdef CONFIG_DOS_PARTITION
168 return info->sys_ind;
169 #else
170 return __invalid_use_of_disk_partition_sys_ind;
171 #endif
172 }
173
174 struct disk_part {
175 int partnum;
176 struct disk_partition gpt_part_info;
177 struct list_head list;
178 };
179
180 /* Misc _get_dev functions */
181 #if CONFIG_IS_ENABLED(PARTITIONS)
182 /**
183 * blk_get_dev() - get a pointer to a block device given its type and number
184 *
185 * Each interface allocates its own devices and typically struct blk_desc is
186 * contained with the interface's data structure. There is no global
187 * numbering for block devices, so the interface name must be provided.
188 *
189 * @ifname: Interface name (e.g. "ide", "scsi")
190 * @dev: Device number (0 for first device on that interface, 1 for
191 * second, etc.
192 * Return:
193 * pointer to the block device, or NULL if not available, or an error occurred.
194 */
195 struct blk_desc *blk_get_dev(const char *ifname, int dev);
196
197 struct blk_desc *mg_disk_get_dev(int dev);
198
199 /**
200 * part_get_info_by_type() - Get partitions from a block device using a specific
201 * partition driver
202 *
203 * Each interface allocates its own devices and typically struct blk_desc is
204 * contained with the interface's data structure. There is no global
205 * numbering for block devices, so the interface name must be provided.
206 *
207 * @desc: Block device descriptor
208 * @part: Partition number to read
209 * @part_type: Partition driver to use, or PART_TYPE_UNKNOWN to automatically
210 * choose a driver
211 * @info: Returned partition information
212 *
213 * Return: 0 on success, negative errno on failure
214 */
215 int part_get_info_by_type(struct blk_desc *desc, int part, int part_type,
216 struct disk_partition *info);
217 int part_get_info(struct blk_desc *desc, int part,
218 struct disk_partition *info);
219 /**
220 * part_get_info_whole_disk() - get partition info for the special case of
221 * a partition occupying the entire disk.
222 *
223 * @desc: block device descriptor
224 * @info: returned partition information
225 * Return: 0 on success
226 */
227 int part_get_info_whole_disk(struct blk_desc *desc,
228 struct disk_partition *info);
229
230 void part_print(struct blk_desc *desc);
231 void part_init(struct blk_desc *desc);
232 void dev_print(struct blk_desc *desc);
233
234 /**
235 * blk_get_device_by_str() - Get a block device given its interface/hw partition
236 *
237 * Each interface allocates its own devices and typically struct blk_desc is
238 * contained with the interface's data structure. There is no global
239 * numbering for block devices, so the interface name must be provided.
240 *
241 * The hardware parition is not related to the normal software partitioning
242 * of a device - each hardware partition is effectively a separately
243 * accessible block device. When a hardware parition is selected on MMC the
244 * other hardware partitions become inaccessible. The same block device is
245 * used to access all hardware partitions, but its capacity may change when a
246 * different hardware partition is selected.
247 *
248 * When a hardware partition number is given, the block device switches to
249 * that hardware partition.
250 *
251 * @ifname: Interface name (e.g. "ide", "scsi")
252 * @dev_str: Device and optional hw partition. This can either be a string
253 * containing the device number (e.g. "2") or the device number
254 * and hardware partition number (e.g. "2.4") for devices that
255 * support it (currently only MMC).
256 * @desc: Returns a pointer to the block device on success
257 * Return: block device number (local to the interface), or -1 on error
258 */
259 int blk_get_device_by_str(const char *ifname, const char *dev_str,
260 struct blk_desc **desc);
261
262 /**
263 * blk_get_device_part_str() - Get a block device and partition
264 *
265 * This calls blk_get_device_by_str() to look up a device. It also looks up
266 * a partition and returns information about it.
267 *
268 * @dev_part_str is in the format <dev>.<hw_part>:<part> where
269 *
270 * * <dev> is the device number,
271 *
272 * * <hw_part> is the optional hardware partition number and
273 *
274 * * <part> is the partition number.
275 *
276 * If @ifname is "hostfs", then this function returns the sandbox host block
277 * device.
278 *
279 * If @ifname is "ubi", then this function returns 0, with @info set to a
280 * special UBI device.
281 *
282 * If @dev_part_str is NULL or empty or "-", then this function looks up
283 * the "bootdevice" environment variable and uses that string instead.
284 *
285 * If the partition string is empty then the first partition is used. If the
286 * partition string is "auto" then the first bootable partition is used.
287 *
288 * @ifname: Interface name (e.g. "ide", "scsi")
289 * @dev_part_str: Device and partition string
290 * @desc: Returns a pointer to the block device on success
291 * @info: Returns partition information
292 * @allow_whole_dev: true to allow the user to select partition 0
293 * (which means the whole device), false to require a valid
294 * partition number >= 1
295 * Return: partition number, or -1 on error
296 *
297 */
298 int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
299 struct blk_desc **desc,
300 struct disk_partition *info, int allow_whole_dev);
301
302 /**
303 * part_get_info_by_name() - Search for a partition by name
304 * among all available registered partitions
305 *
306 * @desc: block device descriptor
307 * @name: the specified table entry name
308 * @info: returns the disk partition info
309 *
310 * Return: the partition number on match (starting on 1), -1 on no match,
311 * otherwise error
312 */
313 int part_get_info_by_name(struct blk_desc *desc, const char *name,
314 struct disk_partition *info);
315
316 /**
317 * part_get_info_by_uuid() - Search for a partition by uuid
318 * among all available registered partitions
319 *
320 * @desc: block device descriptor
321 * @uuid: the specified table entry uuid
322 * @info: the disk partition info
323 *
324 * Return: the partition number on match (starting on 1), -ENOENT on no match,
325 * otherwise error
326 */
327 int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
328 struct disk_partition *info);
329
330 /**
331 * part_get_info_by_dev_and_name_or_num() - Get partition info from dev number
332 * and part name, or dev number and
333 * part number.
334 *
335 * Parse a device number and partition description (either name or number)
336 * in the form of device number plus partition name separated by a "#"
337 * (like "device_num#partition_name") or a device number plus a partition number
338 * separated by a ":". For example both "0#misc" and "0:1" can be valid
339 * partition descriptions for a given interface. If the partition is found, sets
340 * desc and part_info accordingly with the information of the partition.
341 *
342 * @dev_iface: Device interface
343 * @dev_part_str: Input partition description, like "0#misc" or "0:1"
344 * @desc: Place to store the device description pointer
345 * @part_info: Place to store the partition information
346 * @allow_whole_dev: true to allow the user to select partition 0
347 * (which means the whole device), false to require a valid
348 * partition number >= 1
349 * Return: the partition number on success, or negative errno on error
350 */
351 int part_get_info_by_dev_and_name_or_num(const char *dev_iface,
352 const char *dev_part_str,
353 struct blk_desc **desc,
354 struct disk_partition *part_info,
355 int allow_whole_dev);
356
357 /**
358 * part_set_generic_name() - create generic partition like hda1 or sdb2
359 *
360 * Helper function for partition tables, which don't hold partition names
361 * (DOS, ISO). Generates partition name out of the device type and partition
362 * number.
363 *
364 * @desc: pointer to the block device
365 * @part_num: partition number for which the name is generated
366 * @name: buffer where the name is written
367 */
368 void part_set_generic_name(const struct blk_desc *desc, int part_num,
369 char *name);
370
371 extern const struct block_drvr block_drvr[];
372 #else
blk_get_dev(const char * ifname,int dev)373 static inline struct blk_desc *blk_get_dev(const char *ifname, int dev)
374 { return NULL; }
mg_disk_get_dev(int dev)375 static inline struct blk_desc *mg_disk_get_dev(int dev) { return NULL; }
376
part_get_info(struct blk_desc * desc,int part,struct disk_partition * info)377 static inline int part_get_info(struct blk_desc *desc, int part,
378 struct disk_partition *info) { return -1; }
part_get_info_whole_disk(struct blk_desc * desc,struct disk_partition * info)379 static inline int part_get_info_whole_disk(struct blk_desc *desc,
380 struct disk_partition *info)
381 { return -1; }
part_print(struct blk_desc * desc)382 static inline void part_print(struct blk_desc *desc) {}
part_init(struct blk_desc * desc)383 static inline void part_init(struct blk_desc *desc) {}
dev_print(struct blk_desc * desc)384 static inline void dev_print(struct blk_desc *desc) {}
blk_get_device_by_str(const char * ifname,const char * dev_str,struct blk_desc ** desc)385 static inline int blk_get_device_by_str(const char *ifname, const char *dev_str,
386 struct blk_desc **desc)
387 { return -1; }
blk_get_device_part_str(const char * ifname,const char * dev_part_str,struct blk_desc ** desc,struct disk_partition * info,int allow_whole_dev)388 static inline int blk_get_device_part_str(const char *ifname,
389 const char *dev_part_str,
390 struct blk_desc **desc,
391 struct disk_partition *info,
392 int allow_whole_dev)
393 { *desc = NULL; return -1; }
394
part_get_info_by_name(struct blk_desc * desc,const char * name,struct disk_partition * info)395 static inline int part_get_info_by_name(struct blk_desc *desc, const char *name,
396 struct disk_partition *info)
397 {
398 return -ENOENT;
399 }
400
part_get_info_by_uuid(struct blk_desc * desc,const char * uuid,struct disk_partition * info)401 static inline int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
402 struct disk_partition *info)
403 {
404 return -ENOENT;
405 }
406
407 static inline int
part_get_info_by_dev_and_name_or_num(const char * dev_iface,const char * dev_part_str,struct blk_desc ** desc,struct disk_partition * part_info,int allow_whole_dev)408 part_get_info_by_dev_and_name_or_num(const char *dev_iface,
409 const char *dev_part_str,
410 struct blk_desc **desc,
411 struct disk_partition *part_info,
412 int allow_whole_dev)
413 {
414 *desc = NULL;
415 return -ENOSYS;
416 }
417 #endif
418
419 struct udevice;
420 /**
421 * disk_blk_read() - read blocks from a disk partition
422 *
423 * @dev: Device to read from (UCLASS_PARTITION)
424 * @start: Start block number to read in the partition (0=first)
425 * @blkcnt: Number of blocks to read
426 * @buffer: Destination buffer for data read
427 * Return: number of blocks read, or -ve error number (see the
428 * IS_ERR_VALUE() macro
429 */
430 ulong disk_blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
431 void *buffer);
432
433 /**
434 * disk_blk_write() - write to a disk partition
435 *
436 * @dev: Device to write to (UCLASS_PARTITION)
437 * @start: Start block number to write in the partition (0=first)
438 * @blkcnt: Number of blocks to write
439 * @buffer: Source buffer for data to write
440 * Return: number of blocks written, or -ve error number (see the
441 * IS_ERR_VALUE() macro
442 */
443 ulong disk_blk_write(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
444 const void *buffer);
445
446 /**
447 * disk_blk_erase() - erase a section of a disk partition
448 *
449 * @dev: Device to (partially) erase (UCLASS_PARTITION)
450 * @start: Start block number to erase in the partition (0=first)
451 * @blkcnt: Number of blocks to erase
452 * Return: number of blocks erased, or -ve error number (see the
453 * IS_ERR_VALUE() macro
454 */
455 ulong disk_blk_erase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt);
456
457 /*
458 * We don't support printing partition information in SPL and only support
459 * getting partition information in a few cases.
460 */
461 #ifdef CONFIG_XPL_BUILD
462 # define part_print_ptr(x) NULL
463 # if defined(CONFIG_SPL_FS_EXT4) || defined(CONFIG_SPL_FS_FAT) || \
464 defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION)
465 # define part_get_info_ptr(x) x
466 # else
467 # define part_get_info_ptr(x) NULL
468 # endif
469 #else
470 #define part_print_ptr(x) x
471 #define part_get_info_ptr(x) x
472 #endif
473
474 /**
475 * struct part_driver - partition driver
476 */
477 struct part_driver {
478 /** @name: partition name */
479 const char *name;
480 /** @part_type: (MBR) partition type */
481 int part_type;
482 /** @max_entries: maximum number of partition table entries */
483 const int max_entries;
484 /**
485 * @get_info: Get information about a partition
486 *
487 * @get_info.desc: Block device descriptor
488 * @get_info.part: Partition number (1 = first)
489 * @get_info.info: Returns partition information
490 */
491 int (*get_info)(struct blk_desc *desc, int part,
492 struct disk_partition *info);
493
494 /**
495 * @print: Print partition information
496 *
497 * @print.desc: Block device descriptor
498 */
499 void (*print)(struct blk_desc *desc);
500
501 /**
502 * @test: Test if a device contains this partition type
503 *
504 * @test.desc: Block device descriptor
505 * @test.Return:
506 * 0 if the block device appears to contain this partition type,
507 * -ve if not
508 */
509 int (*test)(struct blk_desc *desc);
510 };
511
512 /* Declare a new U-Boot partition 'driver' */
513 #define U_BOOT_PART_TYPE(__name) \
514 ll_entry_declare(struct part_driver, __name, part_driver)
515
516 #include <part_efi.h>
517
518 #if CONFIG_IS_ENABLED(EFI_PARTITION)
519 /* disk/part_efi.c */
520 /**
521 * write_gpt_table() - Write the GUID Partition Table to disk
522 *
523 * @desc: block device descriptor
524 * @gpt_h: pointer to GPT header representation
525 * @gpt_e: pointer to GPT partition table entries
526 *
527 * Return: zero on success, otherwise error
528 */
529 int write_gpt_table(struct blk_desc *desc, gpt_header *gpt_h, gpt_entry *gpt_e);
530
531 /**
532 * gpt_fill_pte() - Fill the GPT partition table entry
533 *
534 * @desc: block device descriptor
535 * @gpt_h: GPT header representation
536 * @gpt_e: GPT partition table entries
537 * @partitions: list of partitions
538 * @parts: number of partitions
539 *
540 * Return: zero on success
541 */
542 int gpt_fill_pte(struct blk_desc *desc, gpt_header *gpt_h, gpt_entry *gpt_e,
543 struct disk_partition *partitions, int parts);
544
545 /**
546 * gpt_fill_header() - Fill the GPT header
547 *
548 * @desc: block device descriptor
549 * @gpt_h: GPT header representation
550 * @str_guid: disk guid string representation
551 * @parts_count: number of partitions
552 *
553 * Return: error on str_guid conversion error
554 */
555 int gpt_fill_header(struct blk_desc *desc, gpt_header *gpt_h, char *str_guid,
556 int parts_count);
557
558 /**
559 * gpt_restore() - Restore GPT partition table
560 *
561 * @desc: block device descriptor
562 * @str_disk_guid: disk GUID
563 * @partitions: list of partitions
564 * @parts_count: number of partitions
565 *
566 * Return: 0 on success
567 */
568 int gpt_restore(struct blk_desc *desc, char *str_disk_guid,
569 struct disk_partition *partitions, const int parts_count);
570
571 /**
572 * is_valid_gpt_buf() - Ensure that the Primary GPT information is valid
573 *
574 * @desc: block device descriptor
575 * @buf: buffer which contains the MBR and Primary GPT info
576 *
577 * Return: 0 on success, otherwise error
578 */
579 int is_valid_gpt_buf(struct blk_desc *desc, void *buf);
580
581 /**
582 * write_mbr_and_gpt_partitions() - write MBR, Primary GPT and Backup GPT
583 *
584 * @desc: block device descriptor
585 * @buf: buffer which contains the MBR and Primary GPT info
586 *
587 * Return: 0 on success, otherwise error
588 */
589 int write_mbr_and_gpt_partitions(struct blk_desc *desc, void *buf);
590
591 /**
592 * gpt_verify_headers() - Read and check CRC32 of the GPT's header
593 * and partition table entries (PTE)
594 *
595 * As a side effect if sets gpt_head and gpt_pte so they point to GPT data.
596 *
597 * @desc: block device descriptor
598 * @gpt_head: pointer to GPT header data read from medium
599 * @gpt_pte: pointer to GPT partition table enties read from medium
600 *
601 * Return: 0 on success, otherwise error
602 */
603 int gpt_verify_headers(struct blk_desc *desc, gpt_header *gpt_head,
604 gpt_entry **gpt_pte);
605
606 /**
607 * gpt_repair_headers() - Function to repair the GPT's header
608 * and partition table entries (PTE)
609 *
610 * @desc: block device descriptor
611 *
612 * Return: 0 on success, otherwise error
613 */
614 int gpt_repair_headers(struct blk_desc *desc);
615
616 /**
617 * gpt_verify_partitions() - Function to check if partitions' name, start and
618 * size correspond to '$partitions' env variable
619 *
620 * This function checks if on medium stored GPT data is in sync with information
621 * provided in '$partitions' environment variable. Specificially, name, start
622 * and size of the partition is checked.
623 *
624 * @desc: block device descriptor
625 * @partitions: partition data read from '$partitions' env variable
626 * @parts: number of partitions read from '$partitions' env variable
627 * @gpt_head: pointer to GPT header data read from medium
628 * @gpt_pte: pointer to GPT partition table enties read from medium
629 *
630 * Return: 0 on success, otherwise error
631 */
632 int gpt_verify_partitions(struct blk_desc *desc,
633 struct disk_partition *partitions, int parts,
634 gpt_header *gpt_head, gpt_entry **gpt_pte);
635
636 /**
637 * get_disk_guid() - Read the GUID string from a device's GPT
638 *
639 * This function reads the GUID string from a block device whose descriptor
640 * is provided.
641 *
642 * @desc: block device descriptor
643 * @guid: pre-allocated string in which to return the GUID
644 *
645 * Return: 0 on success, otherwise error
646 */
647 int get_disk_guid(struct blk_desc *desc, char *guid);
648
649 /**
650 * part_get_gpt_pte() - Get the GPT partition table entry of a partition
651 *
652 * This function reads the GPT partition table entry (PTE) for a given
653 * block device and partition number.
654 *
655 * @desc: block device descriptor
656 * @part: partition number for which to return the PTE
657 * @gpt_e: GPT partition table entry
658 *
659 * Return: 0 on success, otherwise error
660 */
661 int part_get_gpt_pte(struct blk_desc *desc, int part, gpt_entry *gpt_e);
662
663 #endif
664
665 #if CONFIG_IS_ENABLED(DOS_PARTITION)
666 /**
667 * is_valid_dos_buf() - Ensure that a DOS MBR image is valid
668 *
669 * @buf: buffer which contains the MBR
670 *
671 * Return: 0 on success, otherwise error
672 */
673 int is_valid_dos_buf(void *buf);
674
675 /**
676 * write_mbr_sector() - write DOS MBR
677 *
678 * @desc: block device descriptor
679 * @buf: buffer which contains the MBR
680 *
681 * Return: 0 on success, otherwise error
682 */
683 int write_mbr_sector(struct blk_desc *desc, void *buf);
684
685 int write_mbr_partitions(struct blk_desc *dev,
686 struct disk_partition *p, int count, unsigned int disksig);
687 int layout_mbr_partitions(struct disk_partition *p, int count,
688 lbaint_t total_sectors);
689
690 #endif
691
692 #if CONFIG_IS_ENABLED(PARTITIONS)
693 /**
694 * part_driver_get_count() - get partition driver count
695 *
696 * Return: number of partition drivers
697 */
part_driver_get_count(void)698 static inline int part_driver_get_count(void)
699 {
700 return ll_entry_count(struct part_driver, part_driver);
701 }
702
703 /**
704 * part_driver_get_first() - get first partition driver
705 *
706 * Return: pointer to first partition driver on success, otherwise NULL
707 */
part_driver_get_first(void)708 static inline struct part_driver *part_driver_get_first(void)
709 {
710 return ll_entry_start(struct part_driver, part_driver);
711 }
712
713 /**
714 * part_get_type_by_name() - Get partition type by name
715 *
716 * @name: Name of partition type to look up (not case-sensitive)
717 * Return:
718 * Corresponding partition type (PART\_TYPE\_...) or PART\_TYPE\_UNKNOWN
719 */
720 int part_get_type_by_name(const char *name);
721
722 /**
723 * part_get_bootable() - Find the first bootable partition
724 *
725 * @desc: Block-device descriptor
726 * Return: first bootable partition, or 0 if there is none
727 */
728 int part_get_bootable(struct blk_desc *desc);
729
730 #else
part_driver_get_count(void)731 static inline int part_driver_get_count(void)
732 { return 0; }
733
part_driver_get_first(void)734 static inline struct part_driver *part_driver_get_first(void)
735 { return NULL; }
736
part_get_bootable(struct blk_desc * desc)737 static inline bool part_get_bootable(struct blk_desc *desc)
738 { return false; }
739
740 #endif /* CONFIG_PARTITIONS */
741
742 #endif /* _PART_H */
743