blk.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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 BLK_H
  7. #define BLK_H
  8. #include <efi.h>
  9. #ifdef CONFIG_SYS_64BIT_LBA
  10. typedef uint64_t lbaint_t;
  11. #define LBAFlength "ll"
  12. #else
  13. typedef ulong lbaint_t;
  14. #define LBAFlength "l"
  15. #endif
  16. #define LBAF "%" LBAFlength "x"
  17. #define LBAFU "%" LBAFlength "u"
  18. /* Interface types: */
  19. enum if_type {
  20. IF_TYPE_UNKNOWN = 0,
  21. IF_TYPE_IDE,
  22. IF_TYPE_SCSI,
  23. IF_TYPE_ATAPI,
  24. IF_TYPE_USB,
  25. IF_TYPE_DOC,
  26. IF_TYPE_MMC,
  27. IF_TYPE_SD,
  28. IF_TYPE_SATA,
  29. IF_TYPE_HOST,
  30. IF_TYPE_NVME,
  31. IF_TYPE_EFI,
  32. IF_TYPE_COUNT, /* Number of interface types */
  33. };
  34. #define BLK_VEN_SIZE 40
  35. #define BLK_PRD_SIZE 20
  36. #define BLK_REV_SIZE 8
  37. /*
  38. * Identifies the partition table type (ie. MBR vs GPT GUID) signature
  39. */
  40. enum sig_type {
  41. SIG_TYPE_NONE,
  42. SIG_TYPE_MBR,
  43. SIG_TYPE_GUID,
  44. SIG_TYPE_COUNT /* Number of signature types */
  45. };
  46. /*
  47. * With driver model (CONFIG_BLK) this is uclass platform data, accessible
  48. * with dev_get_uclass_platdata(dev)
  49. */
  50. struct blk_desc {
  51. /*
  52. * TODO: With driver model we should be able to use the parent
  53. * device's uclass instead.
  54. */
  55. enum if_type if_type; /* type of the interface */
  56. int devnum; /* device number */
  57. unsigned char part_type; /* partition type */
  58. unsigned char target; /* target SCSI ID */
  59. unsigned char lun; /* target LUN */
  60. unsigned char hwpart; /* HW partition, e.g. for eMMC */
  61. unsigned char type; /* device type */
  62. unsigned char removable; /* removable device */
  63. #ifdef CONFIG_LBA48
  64. /* device can use 48bit addr (ATA/ATAPI v7) */
  65. unsigned char lba48;
  66. #endif
  67. lbaint_t lba; /* number of blocks */
  68. unsigned long blksz; /* block size */
  69. int log2blksz; /* for convenience: log2(blksz) */
  70. char vendor[BLK_VEN_SIZE + 1]; /* device vendor string */
  71. char product[BLK_PRD_SIZE + 1]; /* device product number */
  72. char revision[BLK_REV_SIZE + 1]; /* firmware revision */
  73. enum sig_type sig_type; /* Partition table signature type */
  74. union {
  75. uint32_t mbr_sig; /* MBR integer signature */
  76. efi_guid_t guid_sig; /* GPT GUID Signature */
  77. };
  78. #if CONFIG_IS_ENABLED(BLK)
  79. /*
  80. * For now we have a few functions which take struct blk_desc as a
  81. * parameter. This field allows them to look up the associated
  82. * device. Once these functions are removed we can drop this field.
  83. */
  84. struct udevice *bdev;
  85. #else
  86. unsigned long (*block_read)(struct blk_desc *block_dev,
  87. lbaint_t start,
  88. lbaint_t blkcnt,
  89. void *buffer);
  90. unsigned long (*block_write)(struct blk_desc *block_dev,
  91. lbaint_t start,
  92. lbaint_t blkcnt,
  93. const void *buffer);
  94. unsigned long (*block_erase)(struct blk_desc *block_dev,
  95. lbaint_t start,
  96. lbaint_t blkcnt);
  97. void *priv; /* driver private struct pointer */
  98. #endif
  99. };
  100. #define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz))
  101. #define PAD_TO_BLOCKSIZE(size, blk_desc) \
  102. (PAD_SIZE(size, blk_desc->blksz))
  103. #ifdef CONFIG_BLOCK_CACHE
  104. /**
  105. * blkcache_read() - attempt to read a set of blocks from cache
  106. *
  107. * @param iftype - IF_TYPE_x for type of device
  108. * @param dev - device index of particular type
  109. * @param start - starting block number
  110. * @param blkcnt - number of blocks to read
  111. * @param blksz - size in bytes of each block
  112. * @param buf - buffer to contain cached data
  113. *
  114. * @return - '1' if block returned from cache, '0' otherwise.
  115. */
  116. int blkcache_read(int iftype, int dev,
  117. lbaint_t start, lbaint_t blkcnt,
  118. unsigned long blksz, void *buffer);
  119. /**
  120. * blkcache_fill() - make data read from a block device available
  121. * to the block cache
  122. *
  123. * @param iftype - IF_TYPE_x for type of device
  124. * @param dev - device index of particular type
  125. * @param start - starting block number
  126. * @param blkcnt - number of blocks available
  127. * @param blksz - size in bytes of each block
  128. * @param buf - buffer containing data to cache
  129. *
  130. */
  131. void blkcache_fill(int iftype, int dev,
  132. lbaint_t start, lbaint_t blkcnt,
  133. unsigned long blksz, void const *buffer);
  134. /**
  135. * blkcache_invalidate() - discard the cache for a set of blocks
  136. * because of a write or device (re)initialization.
  137. *
  138. * @param iftype - IF_TYPE_x for type of device
  139. * @param dev - device index of particular type
  140. */
  141. void blkcache_invalidate(int iftype, int dev);
  142. /**
  143. * blkcache_configure() - configure block cache
  144. *
  145. * @param blocks - maximum blocks per entry
  146. * @param entries - maximum entries in cache
  147. */
  148. void blkcache_configure(unsigned blocks, unsigned entries);
  149. /*
  150. * statistics of the block cache
  151. */
  152. struct block_cache_stats {
  153. unsigned hits;
  154. unsigned misses;
  155. unsigned entries; /* current entry count */
  156. unsigned max_blocks_per_entry;
  157. unsigned max_entries;
  158. };
  159. /**
  160. * get_blkcache_stats() - return statistics and reset
  161. *
  162. * @param stats - statistics are copied here
  163. */
  164. void blkcache_stats(struct block_cache_stats *stats);
  165. #else
  166. static inline int blkcache_read(int iftype, int dev,
  167. lbaint_t start, lbaint_t blkcnt,
  168. unsigned long blksz, void *buffer)
  169. {
  170. return 0;
  171. }
  172. static inline void blkcache_fill(int iftype, int dev,
  173. lbaint_t start, lbaint_t blkcnt,
  174. unsigned long blksz, void const *buffer) {}
  175. static inline void blkcache_invalidate(int iftype, int dev) {}
  176. #endif
  177. #if CONFIG_IS_ENABLED(BLK)
  178. struct udevice;
  179. /* Operations on block devices */
  180. struct blk_ops {
  181. /**
  182. * read() - read from a block device
  183. *
  184. * @dev: Device to read from
  185. * @start: Start block number to read (0=first)
  186. * @blkcnt: Number of blocks to read
  187. * @buffer: Destination buffer for data read
  188. * @return number of blocks read, or -ve error number (see the
  189. * IS_ERR_VALUE() macro
  190. */
  191. unsigned long (*read)(struct udevice *dev, lbaint_t start,
  192. lbaint_t blkcnt, void *buffer);
  193. /**
  194. * write() - write to a block device
  195. *
  196. * @dev: Device to write to
  197. * @start: Start block number to write (0=first)
  198. * @blkcnt: Number of blocks to write
  199. * @buffer: Source buffer for data to write
  200. * @return number of blocks written, or -ve error number (see the
  201. * IS_ERR_VALUE() macro
  202. */
  203. unsigned long (*write)(struct udevice *dev, lbaint_t start,
  204. lbaint_t blkcnt, const void *buffer);
  205. /**
  206. * erase() - erase a section of a block device
  207. *
  208. * @dev: Device to (partially) erase
  209. * @start: Start block number to erase (0=first)
  210. * @blkcnt: Number of blocks to erase
  211. * @return number of blocks erased, or -ve error number (see the
  212. * IS_ERR_VALUE() macro
  213. */
  214. unsigned long (*erase)(struct udevice *dev, lbaint_t start,
  215. lbaint_t blkcnt);
  216. /**
  217. * select_hwpart() - select a particular hardware partition
  218. *
  219. * Some devices (e.g. MMC) can support partitioning at the hardware
  220. * level. This is quite separate from the normal idea of
  221. * software-based partitions. MMC hardware partitions must be
  222. * explicitly selected. Once selected only the region of the device
  223. * covered by that partition is accessible.
  224. *
  225. * The MMC standard provides for two boot partitions (numbered 1 and 2),
  226. * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
  227. *
  228. * @desc: Block device to update
  229. * @hwpart: Hardware partition number to select. 0 means the raw
  230. * device, 1 is the first partition, 2 is the second, etc.
  231. * @return 0 if OK, -ve on error
  232. */
  233. int (*select_hwpart)(struct udevice *dev, int hwpart);
  234. };
  235. #define blk_get_ops(dev) ((struct blk_ops *)(dev)->driver->ops)
  236. /*
  237. * These functions should take struct udevice instead of struct blk_desc,
  238. * but this is convenient for migration to driver model. Add a 'd' prefix
  239. * to the function operations, so that blk_read(), etc. can be reserved for
  240. * functions with the correct arguments.
  241. */
  242. unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
  243. lbaint_t blkcnt, void *buffer);
  244. unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
  245. lbaint_t blkcnt, const void *buffer);
  246. unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
  247. lbaint_t blkcnt);
  248. /**
  249. * blk_find_device() - Find a block device
  250. *
  251. * This function does not activate the device. The device will be returned
  252. * whether or not it is activated.
  253. *
  254. * @if_type: Interface type (enum if_type_t)
  255. * @devnum: Device number (specific to each interface type)
  256. * @devp: the device, if found
  257. * @return 0 if found, -ENODEV if no device found, or other -ve error value
  258. */
  259. int blk_find_device(int if_type, int devnum, struct udevice **devp);
  260. /**
  261. * blk_get_device() - Find and probe a block device ready for use
  262. *
  263. * @if_type: Interface type (enum if_type_t)
  264. * @devnum: Device number (specific to each interface type)
  265. * @devp: the device, if found
  266. * @return 0 if found, -ENODEV if no device found, or other -ve error value
  267. */
  268. int blk_get_device(int if_type, int devnum, struct udevice **devp);
  269. /**
  270. * blk_first_device() - Find the first device for a given interface
  271. *
  272. * The device is probed ready for use
  273. *
  274. * @devnum: Device number (specific to each interface type)
  275. * @devp: the device, if found
  276. * @return 0 if found, -ENODEV if no device, or other -ve error value
  277. */
  278. int blk_first_device(int if_type, struct udevice **devp);
  279. /**
  280. * blk_next_device() - Find the next device for a given interface
  281. *
  282. * This can be called repeatedly after blk_first_device() to iterate through
  283. * all devices of the given interface type.
  284. *
  285. * The device is probed ready for use
  286. *
  287. * @devp: On entry, the previous device returned. On exit, the next
  288. * device, if found
  289. * @return 0 if found, -ENODEV if no device, or other -ve error value
  290. */
  291. int blk_next_device(struct udevice **devp);
  292. /**
  293. * blk_create_device() - Create a new block device
  294. *
  295. * @parent: Parent of the new device
  296. * @drv_name: Driver name to use for the block device
  297. * @name: Name for the device
  298. * @if_type: Interface type (enum if_type_t)
  299. * @devnum: Device number, specific to the interface type, or -1 to
  300. * allocate the next available number
  301. * @blksz: Block size of the device in bytes (typically 512)
  302. * @lba: Total number of blocks of the device
  303. * @devp: the new device (which has not been probed)
  304. */
  305. int blk_create_device(struct udevice *parent, const char *drv_name,
  306. const char *name, int if_type, int devnum, int blksz,
  307. lbaint_t lba, struct udevice **devp);
  308. /**
  309. * blk_create_devicef() - Create a new named block device
  310. *
  311. * @parent: Parent of the new device
  312. * @drv_name: Driver name to use for the block device
  313. * @name: Name for the device (parent name is prepended)
  314. * @if_type: Interface type (enum if_type_t)
  315. * @devnum: Device number, specific to the interface type, or -1 to
  316. * allocate the next available number
  317. * @blksz: Block size of the device in bytes (typically 512)
  318. * @lba: Total number of blocks of the device
  319. * @devp: the new device (which has not been probed)
  320. */
  321. int blk_create_devicef(struct udevice *parent, const char *drv_name,
  322. const char *name, int if_type, int devnum, int blksz,
  323. lbaint_t lba, struct udevice **devp);
  324. /**
  325. * blk_prepare_device() - Prepare a block device for use
  326. *
  327. * This reads partition information from the device if supported.
  328. *
  329. * @dev: Device to prepare
  330. * @return 0 if ok, -ve on error
  331. */
  332. int blk_prepare_device(struct udevice *dev);
  333. /**
  334. * blk_unbind_all() - Unbind all device of the given interface type
  335. *
  336. * The devices are removed and then unbound.
  337. *
  338. * @if_type: Interface type to unbind
  339. * @return 0 if OK, -ve on error
  340. */
  341. int blk_unbind_all(int if_type);
  342. /**
  343. * blk_find_max_devnum() - find the maximum device number for an interface type
  344. *
  345. * Finds the last allocated device number for an interface type @if_type. The
  346. * next number is safe to use for a newly allocated device.
  347. *
  348. * @if_type: Interface type to scan
  349. * @return maximum device number found, or -ENODEV if none, or other -ve on
  350. * error
  351. */
  352. int blk_find_max_devnum(enum if_type if_type);
  353. /**
  354. * blk_select_hwpart() - select a hardware partition
  355. *
  356. * Select a hardware partition if the device supports it (typically MMC does)
  357. *
  358. * @dev: Device to update
  359. * @hwpart: Partition number to select
  360. * @return 0 if OK, -ve on error
  361. */
  362. int blk_select_hwpart(struct udevice *dev, int hwpart);
  363. /**
  364. * blk_get_from_parent() - obtain a block device by looking up its parent
  365. *
  366. * All devices with
  367. */
  368. int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
  369. #else
  370. #include <errno.h>
  371. /*
  372. * These functions should take struct udevice instead of struct blk_desc,
  373. * but this is convenient for migration to driver model. Add a 'd' prefix
  374. * to the function operations, so that blk_read(), etc. can be reserved for
  375. * functions with the correct arguments.
  376. */
  377. static inline ulong blk_dread(struct blk_desc *block_dev, lbaint_t start,
  378. lbaint_t blkcnt, void *buffer)
  379. {
  380. ulong blks_read;
  381. if (blkcache_read(block_dev->if_type, block_dev->devnum,
  382. start, blkcnt, block_dev->blksz, buffer))
  383. return blkcnt;
  384. /*
  385. * We could check if block_read is NULL and return -ENOSYS. But this
  386. * bloats the code slightly (cause some board to fail to build), and
  387. * it would be an error to try an operation that does not exist.
  388. */
  389. blks_read = block_dev->block_read(block_dev, start, blkcnt, buffer);
  390. if (blks_read == blkcnt)
  391. blkcache_fill(block_dev->if_type, block_dev->devnum,
  392. start, blkcnt, block_dev->blksz, buffer);
  393. return blks_read;
  394. }
  395. static inline ulong blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
  396. lbaint_t blkcnt, const void *buffer)
  397. {
  398. blkcache_invalidate(block_dev->if_type, block_dev->devnum);
  399. return block_dev->block_write(block_dev, start, blkcnt, buffer);
  400. }
  401. static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start,
  402. lbaint_t blkcnt)
  403. {
  404. blkcache_invalidate(block_dev->if_type, block_dev->devnum);
  405. return block_dev->block_erase(block_dev, start, blkcnt);
  406. }
  407. /**
  408. * struct blk_driver - Driver for block interface types
  409. *
  410. * This provides access to the block devices for each interface type. One
  411. * driver should be provided using U_BOOT_LEGACY_BLK() for each interface
  412. * type that is to be supported.
  413. *
  414. * @if_typename: Interface type name
  415. * @if_type: Interface type
  416. * @max_devs: Maximum number of devices supported
  417. * @desc: Pointer to list of devices for this interface type,
  418. * or NULL to use @get_dev() instead
  419. */
  420. struct blk_driver {
  421. const char *if_typename;
  422. enum if_type if_type;
  423. int max_devs;
  424. struct blk_desc *desc;
  425. /**
  426. * get_dev() - get a pointer to a block device given its number
  427. *
  428. * Each interface allocates its own devices and typically
  429. * struct blk_desc is contained with the interface's data structure.
  430. * There is no global numbering for block devices. This method allows
  431. * the device for an interface type to be obtained when @desc is NULL.
  432. *
  433. * @devnum: Device number (0 for first device on that interface,
  434. * 1 for second, etc.
  435. * @descp: Returns pointer to the block device on success
  436. * @return 0 if OK, -ve on error
  437. */
  438. int (*get_dev)(int devnum, struct blk_desc **descp);
  439. /**
  440. * select_hwpart() - Select a hardware partition
  441. *
  442. * Some devices (e.g. MMC) can support partitioning at the hardware
  443. * level. This is quite separate from the normal idea of
  444. * software-based partitions. MMC hardware partitions must be
  445. * explicitly selected. Once selected only the region of the device
  446. * covered by that partition is accessible.
  447. *
  448. * The MMC standard provides for two boot partitions (numbered 1 and 2),
  449. * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
  450. * Partition 0 is the main user-data partition.
  451. *
  452. * @desc: Block device descriptor
  453. * @hwpart: Hardware partition number to select. 0 means the main
  454. * user-data partition, 1 is the first partition, 2 is
  455. * the second, etc.
  456. * @return 0 if OK, other value for an error
  457. */
  458. int (*select_hwpart)(struct blk_desc *desc, int hwpart);
  459. };
  460. /*
  461. * Declare a new U-Boot legacy block driver. New drivers should use driver
  462. * model (UCLASS_BLK).
  463. */
  464. #define U_BOOT_LEGACY_BLK(__name) \
  465. ll_entry_declare(struct blk_driver, __name, blk_driver)
  466. struct blk_driver *blk_driver_lookup_type(int if_type);
  467. #endif /* !CONFIG_BLK */
  468. /**
  469. * blk_get_devnum_by_typename() - Get a block device by type and number
  470. *
  471. * This looks through the available block devices of the given type, returning
  472. * the one with the given @devnum.
  473. *
  474. * @if_type: Block device type
  475. * @devnum: Device number
  476. * @return point to block device descriptor, or NULL if not found
  477. */
  478. struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum);
  479. /**
  480. * blk_get_devnum_by_type() - Get a block device by type name, and number
  481. *
  482. * This looks up the block device type based on @if_typename, then calls
  483. * blk_get_devnum_by_type().
  484. *
  485. * @if_typename: Block device type name
  486. * @devnum: Device number
  487. * @return point to block device descriptor, or NULL if not found
  488. */
  489. struct blk_desc *blk_get_devnum_by_typename(const char *if_typename,
  490. int devnum);
  491. /**
  492. * blk_dselect_hwpart() - select a hardware partition
  493. *
  494. * This selects a hardware partition (such as is supported by MMC). The block
  495. * device size may change as this effectively points the block device to a
  496. * partition at the hardware level. See the select_hwpart() method above.
  497. *
  498. * @desc: Block device descriptor for the device to select
  499. * @hwpart: Partition number to select
  500. * @return 0 if OK, -ve on error
  501. */
  502. int blk_dselect_hwpart(struct blk_desc *desc, int hwpart);
  503. /**
  504. * blk_list_part() - list the partitions for block devices of a given type
  505. *
  506. * This looks up the partition type for each block device of type @if_type,
  507. * then displays a list of partitions.
  508. *
  509. * @if_type: Block device type
  510. * @return 0 if OK, -ENODEV if there is none of that type
  511. */
  512. int blk_list_part(enum if_type if_type);
  513. /**
  514. * blk_list_devices() - list the block devices of a given type
  515. *
  516. * This lists each block device of the type @if_type, showing the capacity
  517. * as well as type-specific information.
  518. *
  519. * @if_type: Block device type
  520. */
  521. void blk_list_devices(enum if_type if_type);
  522. /**
  523. * blk_show_device() - show information about a given block device
  524. *
  525. * This shows the block device capacity as well as type-specific information.
  526. *
  527. * @if_type: Block device type
  528. * @devnum: Device number
  529. * @return 0 if OK, -ENODEV for invalid device number
  530. */
  531. int blk_show_device(enum if_type if_type, int devnum);
  532. /**
  533. * blk_print_device_num() - show information about a given block device
  534. *
  535. * This is similar to blk_show_device() but returns an error if the block
  536. * device type is unknown.
  537. *
  538. * @if_type: Block device type
  539. * @devnum: Device number
  540. * @return 0 if OK, -ENODEV for invalid device number, -ENOENT if the block
  541. * device is not connected
  542. */
  543. int blk_print_device_num(enum if_type if_type, int devnum);
  544. /**
  545. * blk_print_part_devnum() - print the partition information for a device
  546. *
  547. * @if_type: Block device type
  548. * @devnum: Device number
  549. * @return 0 if OK, -ENOENT if the block device is not connected, -ENOSYS if
  550. * the interface type is not supported, other -ve on other error
  551. */
  552. int blk_print_part_devnum(enum if_type if_type, int devnum);
  553. /**
  554. * blk_read_devnum() - read blocks from a device
  555. *
  556. * @if_type: Block device type
  557. * @devnum: Device number
  558. * @blkcnt: Number of blocks to read
  559. * @buffer: Address to write data to
  560. * @return number of blocks read, or -ve error number on error
  561. */
  562. ulong blk_read_devnum(enum if_type if_type, int devnum, lbaint_t start,
  563. lbaint_t blkcnt, void *buffer);
  564. /**
  565. * blk_write_devnum() - write blocks to a device
  566. *
  567. * @if_type: Block device type
  568. * @devnum: Device number
  569. * @blkcnt: Number of blocks to write
  570. * @buffer: Address to read data from
  571. * @return number of blocks written, or -ve error number on error
  572. */
  573. ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
  574. lbaint_t blkcnt, const void *buffer);
  575. /**
  576. * blk_select_hwpart_devnum() - select a hardware partition
  577. *
  578. * This is similar to blk_dselect_hwpart() but it looks up the interface and
  579. * device number.
  580. *
  581. * @if_type: Block device type
  582. * @devnum: Device number
  583. * @hwpart: Partition number to select
  584. * @return 0 if OK, -ve on error
  585. */
  586. int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart);
  587. /**
  588. * blk_get_if_type_name() - Get the name of an interface type
  589. *
  590. * @if_type: Interface type to check
  591. * @return name of interface, or NULL if none
  592. */
  593. const char *blk_get_if_type_name(enum if_type if_type);
  594. /**
  595. * blk_common_cmd() - handle common commands with block devices
  596. *
  597. * @args: Number of arguments to the command (argv[0] is the command itself)
  598. * @argv: Command arguments
  599. * @if_type: Interface type
  600. * @cur_devnump: Current device number for this interface type
  601. * @return 0 if OK, CMD_RET_ERROR on error
  602. */
  603. int blk_common_cmd(int argc, char * const argv[], enum if_type if_type,
  604. int *cur_devnump);
  605. #endif