efi_disk.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * EFI application disk support
  4. *
  5. * Copyright (c) 2016 Alexander Graf
  6. */
  7. #define LOG_CATEGORY LOGC_EFI
  8. #include <common.h>
  9. #include <blk.h>
  10. #include <dm.h>
  11. #include <efi_loader.h>
  12. #include <fs.h>
  13. #include <log.h>
  14. #include <part.h>
  15. #include <malloc.h>
  16. struct efi_system_partition efi_system_partition;
  17. const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
  18. const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID;
  19. /**
  20. * struct efi_disk_obj - EFI disk object
  21. *
  22. * @header: EFI object header
  23. * @ops: EFI disk I/O protocol interface
  24. * @ifname: interface name for block device
  25. * @dev_index: device index of block device
  26. * @media: block I/O media information
  27. * @dp: device path to the block device
  28. * @part: partition
  29. * @volume: simple file system protocol of the partition
  30. * @offset: offset into disk for simple partition
  31. * @desc: internal block device descriptor
  32. */
  33. struct efi_disk_obj {
  34. struct efi_object header;
  35. struct efi_block_io ops;
  36. const char *ifname;
  37. int dev_index;
  38. struct efi_block_io_media media;
  39. struct efi_device_path *dp;
  40. unsigned int part;
  41. struct efi_simple_file_system_protocol *volume;
  42. lbaint_t offset;
  43. struct blk_desc *desc;
  44. };
  45. /**
  46. * efi_disk_reset() - reset block device
  47. *
  48. * This function implements the Reset service of the EFI_BLOCK_IO_PROTOCOL.
  49. *
  50. * As U-Boot's block devices do not have a reset function simply return
  51. * EFI_SUCCESS.
  52. *
  53. * See the Unified Extensible Firmware Interface (UEFI) specification for
  54. * details.
  55. *
  56. * @this: pointer to the BLOCK_IO_PROTOCOL
  57. * @extended_verification: extended verification
  58. * Return: status code
  59. */
  60. static efi_status_t EFIAPI efi_disk_reset(struct efi_block_io *this,
  61. char extended_verification)
  62. {
  63. EFI_ENTRY("%p, %x", this, extended_verification);
  64. return EFI_EXIT(EFI_SUCCESS);
  65. }
  66. enum efi_disk_direction {
  67. EFI_DISK_READ,
  68. EFI_DISK_WRITE,
  69. };
  70. static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this,
  71. u32 media_id, u64 lba, unsigned long buffer_size,
  72. void *buffer, enum efi_disk_direction direction)
  73. {
  74. struct efi_disk_obj *diskobj;
  75. struct blk_desc *desc;
  76. int blksz;
  77. int blocks;
  78. unsigned long n;
  79. diskobj = container_of(this, struct efi_disk_obj, ops);
  80. desc = (struct blk_desc *) diskobj->desc;
  81. blksz = desc->blksz;
  82. blocks = buffer_size / blksz;
  83. lba += diskobj->offset;
  84. EFI_PRINT("blocks=%x lba=%llx blksz=%x dir=%d\n",
  85. blocks, lba, blksz, direction);
  86. /* We only support full block access */
  87. if (buffer_size & (blksz - 1))
  88. return EFI_BAD_BUFFER_SIZE;
  89. if (direction == EFI_DISK_READ)
  90. n = blk_dread(desc, lba, blocks, buffer);
  91. else
  92. n = blk_dwrite(desc, lba, blocks, buffer);
  93. /* We don't do interrupts, so check for timers cooperatively */
  94. efi_timer_check();
  95. EFI_PRINT("n=%lx blocks=%x\n", n, blocks);
  96. if (n != blocks)
  97. return EFI_DEVICE_ERROR;
  98. return EFI_SUCCESS;
  99. }
  100. /**
  101. * efi_disk_read_blocks() - reads blocks from device
  102. *
  103. * This function implements the ReadBlocks service of the EFI_BLOCK_IO_PROTOCOL.
  104. *
  105. * See the Unified Extensible Firmware Interface (UEFI) specification for
  106. * details.
  107. *
  108. * @this: pointer to the BLOCK_IO_PROTOCOL
  109. * @media_id: id of the medium to be read from
  110. * @lba: starting logical block for reading
  111. * @buffer_size: size of the read buffer
  112. * @buffer: pointer to the destination buffer
  113. * Return: status code
  114. */
  115. static efi_status_t EFIAPI efi_disk_read_blocks(struct efi_block_io *this,
  116. u32 media_id, u64 lba, efi_uintn_t buffer_size,
  117. void *buffer)
  118. {
  119. void *real_buffer = buffer;
  120. efi_status_t r;
  121. if (!this)
  122. return EFI_INVALID_PARAMETER;
  123. /* TODO: check for media changes */
  124. if (media_id != this->media->media_id)
  125. return EFI_MEDIA_CHANGED;
  126. if (!this->media->media_present)
  127. return EFI_NO_MEDIA;
  128. /* media->io_align is a power of 2 or 0 */
  129. if (this->media->io_align &&
  130. (uintptr_t)buffer & (this->media->io_align - 1))
  131. return EFI_INVALID_PARAMETER;
  132. if (lba * this->media->block_size + buffer_size >
  133. (this->media->last_block + 1) * this->media->block_size)
  134. return EFI_INVALID_PARAMETER;
  135. #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
  136. if (buffer_size > EFI_LOADER_BOUNCE_BUFFER_SIZE) {
  137. r = efi_disk_read_blocks(this, media_id, lba,
  138. EFI_LOADER_BOUNCE_BUFFER_SIZE, buffer);
  139. if (r != EFI_SUCCESS)
  140. return r;
  141. return efi_disk_read_blocks(this, media_id, lba +
  142. EFI_LOADER_BOUNCE_BUFFER_SIZE / this->media->block_size,
  143. buffer_size - EFI_LOADER_BOUNCE_BUFFER_SIZE,
  144. buffer + EFI_LOADER_BOUNCE_BUFFER_SIZE);
  145. }
  146. real_buffer = efi_bounce_buffer;
  147. #endif
  148. EFI_ENTRY("%p, %x, %llx, %zx, %p", this, media_id, lba,
  149. buffer_size, buffer);
  150. r = efi_disk_rw_blocks(this, media_id, lba, buffer_size, real_buffer,
  151. EFI_DISK_READ);
  152. /* Copy from bounce buffer to real buffer if necessary */
  153. if ((r == EFI_SUCCESS) && (real_buffer != buffer))
  154. memcpy(buffer, real_buffer, buffer_size);
  155. return EFI_EXIT(r);
  156. }
  157. /**
  158. * efi_disk_write_blocks() - writes blocks to device
  159. *
  160. * This function implements the WriteBlocks service of the
  161. * EFI_BLOCK_IO_PROTOCOL.
  162. *
  163. * See the Unified Extensible Firmware Interface (UEFI) specification for
  164. * details.
  165. *
  166. * @this: pointer to the BLOCK_IO_PROTOCOL
  167. * @media_id: id of the medium to be written to
  168. * @lba: starting logical block for writing
  169. * @buffer_size: size of the write buffer
  170. * @buffer: pointer to the source buffer
  171. * Return: status code
  172. */
  173. static efi_status_t EFIAPI efi_disk_write_blocks(struct efi_block_io *this,
  174. u32 media_id, u64 lba, efi_uintn_t buffer_size,
  175. void *buffer)
  176. {
  177. void *real_buffer = buffer;
  178. efi_status_t r;
  179. if (!this)
  180. return EFI_INVALID_PARAMETER;
  181. if (this->media->read_only)
  182. return EFI_WRITE_PROTECTED;
  183. /* TODO: check for media changes */
  184. if (media_id != this->media->media_id)
  185. return EFI_MEDIA_CHANGED;
  186. if (!this->media->media_present)
  187. return EFI_NO_MEDIA;
  188. /* media->io_align is a power of 2 or 0 */
  189. if (this->media->io_align &&
  190. (uintptr_t)buffer & (this->media->io_align - 1))
  191. return EFI_INVALID_PARAMETER;
  192. if (lba * this->media->block_size + buffer_size >
  193. (this->media->last_block + 1) * this->media->block_size)
  194. return EFI_INVALID_PARAMETER;
  195. #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
  196. if (buffer_size > EFI_LOADER_BOUNCE_BUFFER_SIZE) {
  197. r = efi_disk_write_blocks(this, media_id, lba,
  198. EFI_LOADER_BOUNCE_BUFFER_SIZE, buffer);
  199. if (r != EFI_SUCCESS)
  200. return r;
  201. return efi_disk_write_blocks(this, media_id, lba +
  202. EFI_LOADER_BOUNCE_BUFFER_SIZE / this->media->block_size,
  203. buffer_size - EFI_LOADER_BOUNCE_BUFFER_SIZE,
  204. buffer + EFI_LOADER_BOUNCE_BUFFER_SIZE);
  205. }
  206. real_buffer = efi_bounce_buffer;
  207. #endif
  208. EFI_ENTRY("%p, %x, %llx, %zx, %p", this, media_id, lba,
  209. buffer_size, buffer);
  210. /* Populate bounce buffer if necessary */
  211. if (real_buffer != buffer)
  212. memcpy(real_buffer, buffer, buffer_size);
  213. r = efi_disk_rw_blocks(this, media_id, lba, buffer_size, real_buffer,
  214. EFI_DISK_WRITE);
  215. return EFI_EXIT(r);
  216. }
  217. /**
  218. * efi_disk_flush_blocks() - flushes modified data to the device
  219. *
  220. * This function implements the FlushBlocks service of the
  221. * EFI_BLOCK_IO_PROTOCOL.
  222. *
  223. * As we always write synchronously nothing is done here.
  224. *
  225. * See the Unified Extensible Firmware Interface (UEFI) specification for
  226. * details.
  227. *
  228. * @this: pointer to the BLOCK_IO_PROTOCOL
  229. * Return: status code
  230. */
  231. static efi_status_t EFIAPI efi_disk_flush_blocks(struct efi_block_io *this)
  232. {
  233. EFI_ENTRY("%p", this);
  234. return EFI_EXIT(EFI_SUCCESS);
  235. }
  236. static const struct efi_block_io block_io_disk_template = {
  237. .reset = &efi_disk_reset,
  238. .read_blocks = &efi_disk_read_blocks,
  239. .write_blocks = &efi_disk_write_blocks,
  240. .flush_blocks = &efi_disk_flush_blocks,
  241. };
  242. /**
  243. * efi_fs_from_path() - retrieve simple file system protocol
  244. *
  245. * Gets the simple file system protocol for a file device path.
  246. *
  247. * The full path provided is split into device part and into a file
  248. * part. The device part is used to find the handle on which the
  249. * simple file system protocol is installed.
  250. *
  251. * @full_path: device path including device and file
  252. * Return: simple file system protocol
  253. */
  254. struct efi_simple_file_system_protocol *
  255. efi_fs_from_path(struct efi_device_path *full_path)
  256. {
  257. struct efi_object *efiobj;
  258. struct efi_handler *handler;
  259. struct efi_device_path *device_path;
  260. struct efi_device_path *file_path;
  261. efi_status_t ret;
  262. /* Split the path into a device part and a file part */
  263. ret = efi_dp_split_file_path(full_path, &device_path, &file_path);
  264. if (ret != EFI_SUCCESS)
  265. return NULL;
  266. efi_free_pool(file_path);
  267. /* Get the EFI object for the partition */
  268. efiobj = efi_dp_find_obj(device_path, NULL);
  269. efi_free_pool(device_path);
  270. if (!efiobj)
  271. return NULL;
  272. /* Find the simple file system protocol */
  273. ret = efi_search_protocol(efiobj, &efi_simple_file_system_protocol_guid,
  274. &handler);
  275. if (ret != EFI_SUCCESS)
  276. return NULL;
  277. /* Return the simple file system protocol for the partition */
  278. return handler->protocol_interface;
  279. }
  280. /**
  281. * efi_fs_exists() - check if a partition bears a file system
  282. *
  283. * @desc: block device descriptor
  284. * @part: partition number
  285. * Return: 1 if a file system exists on the partition
  286. * 0 otherwise
  287. */
  288. static int efi_fs_exists(struct blk_desc *desc, int part)
  289. {
  290. if (fs_set_blk_dev_with_part(desc, part))
  291. return 0;
  292. if (fs_get_type() == FS_TYPE_ANY)
  293. return 0;
  294. fs_close();
  295. return 1;
  296. }
  297. /**
  298. * efi_disk_add_dev() - create a handle for a partition or disk
  299. *
  300. * @parent: parent handle
  301. * @dp_parent: parent device path
  302. * @if_typename: interface name for block device
  303. * @desc: internal block device
  304. * @dev_index: device index for block device
  305. * @part_info: partition info
  306. * @part: partition
  307. * @disk: pointer to receive the created handle
  308. * Return: disk object
  309. */
  310. static efi_status_t efi_disk_add_dev(
  311. efi_handle_t parent,
  312. struct efi_device_path *dp_parent,
  313. const char *if_typename,
  314. struct blk_desc *desc,
  315. int dev_index,
  316. struct disk_partition *part_info,
  317. unsigned int part,
  318. struct efi_disk_obj **disk)
  319. {
  320. struct efi_disk_obj *diskobj;
  321. struct efi_object *handle;
  322. const efi_guid_t *guid = NULL;
  323. efi_status_t ret;
  324. /* Don't add empty devices */
  325. if (!desc->lba)
  326. return EFI_NOT_READY;
  327. diskobj = calloc(1, sizeof(*diskobj));
  328. if (!diskobj)
  329. return EFI_OUT_OF_RESOURCES;
  330. /* Hook up to the device list */
  331. efi_add_handle(&diskobj->header);
  332. /* Fill in object data */
  333. if (part_info) {
  334. struct efi_device_path *node = efi_dp_part_node(desc, part);
  335. struct efi_handler *handler;
  336. void *protocol_interface;
  337. /* Parent must expose EFI_BLOCK_IO_PROTOCOL */
  338. ret = efi_search_protocol(parent, &efi_block_io_guid, &handler);
  339. if (ret != EFI_SUCCESS)
  340. goto error;
  341. /*
  342. * Link the partition (child controller) to the block device
  343. * (controller).
  344. */
  345. ret = efi_protocol_open(handler, &protocol_interface, NULL,
  346. &diskobj->header,
  347. EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER);
  348. if (ret != EFI_SUCCESS)
  349. goto error;
  350. diskobj->dp = efi_dp_append_node(dp_parent, node);
  351. efi_free_pool(node);
  352. diskobj->offset = part_info->start;
  353. diskobj->media.last_block = part_info->size - 1;
  354. if (part_info->bootable & PART_EFI_SYSTEM_PARTITION)
  355. guid = &efi_system_partition_guid;
  356. } else {
  357. diskobj->dp = efi_dp_from_part(desc, part);
  358. diskobj->offset = 0;
  359. diskobj->media.last_block = desc->lba - 1;
  360. }
  361. diskobj->part = part;
  362. /*
  363. * Install the device path and the block IO protocol.
  364. *
  365. * InstallMultipleProtocolInterfaces() checks if the device path is
  366. * already installed on an other handle and returns EFI_ALREADY_STARTED
  367. * in this case.
  368. */
  369. handle = &diskobj->header;
  370. ret = EFI_CALL(efi_install_multiple_protocol_interfaces(
  371. &handle, &efi_guid_device_path, diskobj->dp,
  372. &efi_block_io_guid, &diskobj->ops,
  373. guid, NULL, NULL));
  374. if (ret != EFI_SUCCESS)
  375. return ret;
  376. /*
  377. * On partitions or whole disks without partitions install the
  378. * simple file system protocol if a file system is available.
  379. */
  380. if ((part || desc->part_type == PART_TYPE_UNKNOWN) &&
  381. efi_fs_exists(desc, part)) {
  382. diskobj->volume = efi_simple_file_system(desc, part,
  383. diskobj->dp);
  384. ret = efi_add_protocol(&diskobj->header,
  385. &efi_simple_file_system_protocol_guid,
  386. diskobj->volume);
  387. if (ret != EFI_SUCCESS)
  388. return ret;
  389. }
  390. diskobj->ops = block_io_disk_template;
  391. diskobj->ifname = if_typename;
  392. diskobj->dev_index = dev_index;
  393. diskobj->desc = desc;
  394. /* Fill in EFI IO Media info (for read/write callbacks) */
  395. diskobj->media.removable_media = desc->removable;
  396. diskobj->media.media_present = 1;
  397. /*
  398. * MediaID is just an arbitrary counter.
  399. * We have to change it if the medium is removed or changed.
  400. */
  401. diskobj->media.media_id = 1;
  402. diskobj->media.block_size = desc->blksz;
  403. diskobj->media.io_align = desc->blksz;
  404. if (part)
  405. diskobj->media.logical_partition = 1;
  406. diskobj->ops.media = &diskobj->media;
  407. if (disk)
  408. *disk = diskobj;
  409. EFI_PRINT("BlockIO: part %u, present %d, logical %d, removable %d"
  410. ", offset " LBAF ", last_block %llu\n",
  411. diskobj->part,
  412. diskobj->media.media_present,
  413. diskobj->media.logical_partition,
  414. diskobj->media.removable_media,
  415. diskobj->offset,
  416. diskobj->media.last_block);
  417. /* Store first EFI system partition */
  418. if (part && !efi_system_partition.if_type) {
  419. if (part_info->bootable & PART_EFI_SYSTEM_PARTITION) {
  420. efi_system_partition.if_type = desc->if_type;
  421. efi_system_partition.devnum = desc->devnum;
  422. efi_system_partition.part = part;
  423. EFI_PRINT("EFI system partition: %s %x:%x\n",
  424. blk_get_if_type_name(desc->if_type),
  425. desc->devnum, part);
  426. }
  427. }
  428. return EFI_SUCCESS;
  429. error:
  430. efi_delete_handle(&diskobj->header);
  431. return ret;
  432. }
  433. /**
  434. * efi_disk_create_partitions() - create handles and protocols for partitions
  435. *
  436. * Create handles and protocols for the partitions of a block device.
  437. *
  438. * @parent: handle of the parent disk
  439. * @desc: block device
  440. * @if_typename: interface type
  441. * @diskid: device number
  442. * @pdevname: device name
  443. * Return: number of partitions created
  444. */
  445. int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
  446. const char *if_typename, int diskid,
  447. const char *pdevname)
  448. {
  449. int disks = 0;
  450. char devname[32] = { 0 }; /* dp->str is u16[32] long */
  451. int part;
  452. struct efi_device_path *dp = NULL;
  453. efi_status_t ret;
  454. struct efi_handler *handler;
  455. /* Get the device path of the parent */
  456. ret = efi_search_protocol(parent, &efi_guid_device_path, &handler);
  457. if (ret == EFI_SUCCESS)
  458. dp = handler->protocol_interface;
  459. /* Add devices for each partition */
  460. for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
  461. struct disk_partition info;
  462. if (part_get_info(desc, part, &info))
  463. continue;
  464. snprintf(devname, sizeof(devname), "%s:%x", pdevname,
  465. part);
  466. ret = efi_disk_add_dev(parent, dp, if_typename, desc, diskid,
  467. &info, part, NULL);
  468. if (ret != EFI_SUCCESS) {
  469. log_err("Adding partition %s failed\n", pdevname);
  470. continue;
  471. }
  472. disks++;
  473. }
  474. return disks;
  475. }
  476. /**
  477. * efi_disk_register() - register block devices
  478. *
  479. * U-Boot doesn't have a list of all online disk devices. So when running our
  480. * EFI payload, we scan through all of the potentially available ones and
  481. * store them in our object pool.
  482. *
  483. * This function is called in efi_init_obj_list().
  484. *
  485. * TODO(sjg@chromium.org): Actually with CONFIG_BLK, U-Boot does have this.
  486. * Consider converting the code to look up devices as needed. The EFI device
  487. * could be a child of the UCLASS_BLK block device, perhaps.
  488. *
  489. * Return: status code
  490. */
  491. efi_status_t efi_disk_register(void)
  492. {
  493. struct efi_disk_obj *disk;
  494. int disks = 0;
  495. efi_status_t ret;
  496. #ifdef CONFIG_BLK
  497. struct udevice *dev;
  498. for (uclass_first_device_check(UCLASS_BLK, &dev); dev;
  499. uclass_next_device_check(&dev)) {
  500. struct blk_desc *desc = dev_get_uclass_plat(dev);
  501. const char *if_typename = blk_get_if_type_name(desc->if_type);
  502. /* Add block device for the full device */
  503. log_info("Scanning disk %s...\n", dev->name);
  504. ret = efi_disk_add_dev(NULL, NULL, if_typename,
  505. desc, desc->devnum, NULL, 0, &disk);
  506. if (ret == EFI_NOT_READY) {
  507. log_notice("Disk %s not ready\n", dev->name);
  508. continue;
  509. }
  510. if (ret) {
  511. log_err("ERROR: failure to add disk device %s, r = %lu\n",
  512. dev->name, ret & ~EFI_ERROR_MASK);
  513. return ret;
  514. }
  515. disks++;
  516. /* Partitions show up as block devices in EFI */
  517. disks += efi_disk_create_partitions(
  518. &disk->header, desc, if_typename,
  519. desc->devnum, dev->name);
  520. }
  521. #else
  522. int i, if_type;
  523. /* Search for all available disk devices */
  524. for (if_type = 0; if_type < IF_TYPE_COUNT; if_type++) {
  525. const struct blk_driver *cur_drvr;
  526. const char *if_typename;
  527. cur_drvr = blk_driver_lookup_type(if_type);
  528. if (!cur_drvr)
  529. continue;
  530. if_typename = cur_drvr->if_typename;
  531. log_info("Scanning disks on %s...\n", if_typename);
  532. for (i = 0; i < 4; i++) {
  533. struct blk_desc *desc;
  534. char devname[32] = { 0 }; /* dp->str is u16[32] long */
  535. desc = blk_get_devnum_by_type(if_type, i);
  536. if (!desc)
  537. continue;
  538. if (desc->type == DEV_TYPE_UNKNOWN)
  539. continue;
  540. snprintf(devname, sizeof(devname), "%s%d",
  541. if_typename, i);
  542. /* Add block device for the full device */
  543. ret = efi_disk_add_dev(NULL, NULL, if_typename, desc,
  544. i, NULL, 0, &disk);
  545. if (ret == EFI_NOT_READY) {
  546. log_notice("Disk %s not ready\n", devname);
  547. continue;
  548. }
  549. if (ret) {
  550. log_err("ERROR: failure to add disk device %s, r = %lu\n",
  551. devname, ret & ~EFI_ERROR_MASK);
  552. return ret;
  553. }
  554. disks++;
  555. /* Partitions show up as block devices in EFI */
  556. disks += efi_disk_create_partitions
  557. (&disk->header, desc,
  558. if_typename, i, devname);
  559. }
  560. }
  561. #endif
  562. log_info("Found %d disks\n", disks);
  563. return EFI_SUCCESS;
  564. }
  565. /**
  566. * efi_disk_is_system_part() - check if handle refers to an EFI system partition
  567. *
  568. * @handle: handle of partition
  569. *
  570. * Return: true if handle refers to an EFI system partition
  571. */
  572. bool efi_disk_is_system_part(efi_handle_t handle)
  573. {
  574. struct efi_handler *handler;
  575. struct efi_disk_obj *diskobj;
  576. struct disk_partition info;
  577. efi_status_t ret;
  578. int r;
  579. /* check if this is a block device */
  580. ret = efi_search_protocol(handle, &efi_block_io_guid, &handler);
  581. if (ret != EFI_SUCCESS)
  582. return false;
  583. diskobj = container_of(handle, struct efi_disk_obj, header);
  584. r = part_get_info(diskobj->desc, diskobj->part, &info);
  585. if (r)
  586. return false;
  587. return !!(info.bootable & PART_EFI_SYSTEM_PARTITION);
  588. }