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