1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /** 33 * @defgroup disk Disk 34 * @ingroup filesystem 35 */ 36 37 #ifndef _DISK_H 38 #define _DISK_H 39 40 #include "fs/driver.h" 41 #include "los_base.h" 42 #include "pthread.h" 43 44 #ifdef LOSCFG_FS_FAT_CACHE 45 #include "bcache.h" 46 #endif 47 48 #include "pthread.h" 49 50 #ifdef __cplusplus 51 #if __cplusplus 52 extern "C" { 53 #endif 54 #endif /* __cplusplus */ 55 56 #define SYS_MAX_DISK 5 57 #define MAX_DIVIDE_PART_PER_DISK 16 58 #define MAX_PRIMARY_PART_PER_DISK 4 59 #define SYS_MAX_PART (SYS_MAX_DISK * MAX_DIVIDE_PART_PER_DISK) 60 #define DISK_NAME 255 61 #define DISK_MAX_SECTOR_SIZE 512 62 63 #define PAR_OFFSET 446 /* MBR: Partition table offset (2) */ 64 #define BS_SIG55AA 510 /* Signature word (2) */ 65 #define BS_FILSYSTEMTYPE32 82 /* File system type (1) */ 66 #define BS_JMPBOOT 0 /* x86 jump instruction (3-byte) */ 67 #define BS_FILSYSTYPE 0x36 /* File system type (2) */ 68 #define BS_SIG55AA_VALUE 0xAA55 69 70 #define PAR_TYPE_OFFSET 4 71 #define PAR_START_OFFSET 8 72 #define PAR_COUNT_OFFSET 12 73 #define PAR_TABLE_SIZE 16 74 #define EXTENDED_PAR 0x0F 75 #define EXTENDED_8G 0x05 76 #define EMMC 0xEC 77 #define OTHERS 0x01 /* sdcard or umass */ 78 79 #define BS_FS_TYPE_MASK 0xFFFFFF 80 #define BS_FS_TYPE_VALUE 0x544146 81 #define BS_FS_TYPE_FAT 0x0B 82 #define BS_FS_TYPE_NTFS 0x07 83 84 #define FIRST_BYTE 1 85 #define SECOND_BYTE 2 86 #define THIRD_BYTE 3 87 #define FOURTH_BYTE 4 88 89 #define BIT_FOR_BYTE 8 90 91 #define LD_WORD_DISK(ptr) (UINT16)(((UINT16)*((UINT8 *)(ptr) + FIRST_BYTE) << (BIT_FOR_BYTE * FIRST_BYTE)) | \ 92 (UINT16)*(UINT8 *)(ptr)) 93 #define LD_DWORD_DISK(ptr) (UINT32)(((UINT32)*((UINT8 *)(ptr) + THIRD_BYTE) << (BIT_FOR_BYTE * THIRD_BYTE)) | \ 94 ((UINT32)*((UINT8 *)(ptr) + SECOND_BYTE) << (BIT_FOR_BYTE * SECOND_BYTE)) | \ 95 ((UINT16)*((UINT8 *)(ptr) + FIRST_BYTE) << (BIT_FOR_BYTE * FIRST_BYTE)) | \ 96 (*(UINT8 *)(ptr))) 97 98 #define LD_QWORD_DISK(ptr) ((UINT64)(((UINT64)LD_DWORD_DISK(&(ptr)[FOURTH_BYTE]) << (BIT_FOR_BYTE * FOURTH_BYTE)) | \ 99 LD_DWORD_DISK(ptr))) 100 101 /* Check VBR string, including FAT, NTFS */ 102 #define VERIFY_FS(ptr) (((LD_DWORD_DISK(&(ptr)[BS_FILSYSTEMTYPE32]) & BS_FS_TYPE_MASK) == BS_FS_TYPE_VALUE) || \ 103 !strncmp(&(ptr)[BS_FILSYSTYPE], "FAT", strlen("FAT")) || \ 104 !strncmp(&(ptr)[BS_JMPBOOT], "\xEB\x52\x90" "NTFS ", \ 105 strlen("\xEB\x52\x90" "NTFS "))) 106 107 #define PARTION_MODE_BTYE (PAR_OFFSET + PAR_TYPE_OFFSET) /* 0xEE: GPT(GUID), else: MBR */ 108 #define PARTION_MODE_GPT 0xEE /* 0xEE: GPT(GUID), else: MBR */ 109 #define SIGNATURE_OFFSET 0 /* The offset of GPT partition header signature */ 110 #define SIGNATURE_LEN 8 /* The length of GPT signature */ 111 #define HEADER_SIZE_OFFSET 12 /* The offset of GPT header size */ 112 #define TABLE_SIZE_OFFSET 84 /* The offset of GPT table size */ 113 #define TABLE_NUM_OFFSET 80 /* The number of GPT table */ 114 #define TABLE_START_SECTOR 2 115 #define TABLE_MAX_NUM 128 116 #define TABLE_SIZE 128 117 #define GPT_PAR_START_OFFSET 32 118 #define GPT_PAR_END_OFFSET 40 119 #define PAR_ENTRY_NUM_PER_SECTOR 4 120 #define HEADER_SIZE_MASK 0xFFFFFFFF 121 #define HEADER_SIZE 0x5C 122 #define HARD_DISK_GUID_OFFSET 56 123 #define HARD_DISK_GUID_FOR_ESP 0x0020004900460045 124 #define HARD_DISK_GUID_FOR_MSP 0x007200630069004D 125 #define PAR_VALID_OFFSET0 0 126 #define PAR_VALID_OFFSET1 4 127 #define PAR_VALID_OFFSET2 8 128 #define PAR_VALID_OFFSET3 12 129 130 #define VERIFY_GPT(ptr) ((!strncmp(&(ptr)[SIGNATURE_OFFSET], "EFI PART", SIGNATURE_LEN)) && \ 131 ((LD_DWORD_DISK(&(ptr)[HEADER_SIZE_OFFSET]) & HEADER_SIZE_MASK) == HEADER_SIZE)) 132 133 #define VERITY_PAR_VALID(ptr) ((LD_DWORD_DISK(&(ptr)[PAR_VALID_OFFSET0]) + \ 134 LD_DWORD_DISK(&(ptr)[PAR_VALID_OFFSET1]) + \ 135 LD_DWORD_DISK(&(ptr)[PAR_VALID_OFFSET2]) + \ 136 LD_DWORD_DISK(&(ptr)[PAR_VALID_OFFSET3])) != 0) 137 138 /* ESP MSP */ 139 #define VERITY_AVAILABLE_PAR(ptr) ((LD_QWORD_DISK(&(ptr)[HARD_DISK_GUID_OFFSET]) != HARD_DISK_GUID_FOR_ESP) && \ 140 (LD_QWORD_DISK(&(ptr)[HARD_DISK_GUID_OFFSET]) != HARD_DISK_GUID_FOR_MSP)) 141 142 /* Command code for disk_ioctrl function */ 143 /* Generic command (Used by FatFs) */ 144 #define DISK_CTRL_SYNC 0 /* Complete pending write process */ 145 #define DISK_GET_SECTOR_COUNT 1 /* Get media size */ 146 #define DISK_GET_SECTOR_SIZE 2 /* Get sector size */ 147 #define DISK_GET_BLOCK_SIZE 3 /* Get erase block size */ 148 #define DISK_CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used */ 149 150 /* Generic command (Not used by FatFs) */ 151 #define DISK_CTRL_POWER 5 /* Get/Set power status */ 152 #define DISK_CTRL_LOCK 6 /* Lock/Unlock media removal */ 153 #define DISK_CTRL_EJECT 7 /* Eject media */ 154 #define DISK_CTRL_FORMAT 8 /* Create physical format on the media */ 155 156 /* MMC/SDC specific ioctl command */ 157 #define DISK_MMC_GET_TYPE 10 /* Get card type */ 158 #define DISK_MMC_GET_CSD 11 /* Get CSD */ 159 #define DISK_MMC_GET_CID 12 /* Get CID */ 160 #define DISK_MMC_GET_OCR 13 /* Get OCR */ 161 #define DISK_MMC_GET_SDSTAT 14 /* Get SD status */ 162 163 /* ATA/CF specific ioctl command */ 164 #define DISK_ATA_GET_REV 20 /* Get F/W revision */ 165 #define DISK_ATA_GET_MODEL 21 /* Get model name */ 166 #define DISK_ATA_GET_SN 22 /* Get serial number */ 167 168 #ifdef LOSCFG_FS_FAT_CACHE 169 #define DISK_DIRECT_BUFFER_SIZE 4 /* los_disk direct io buffer when bcache is off */ 170 #endif 171 172 typedef enum _disk_status_ { 173 STAT_UNUSED, 174 STAT_INUSED, 175 STAT_UNREADY 176 } disk_status_e; 177 178 typedef struct _los_disk_ { 179 UINT32 disk_id : 8; /* physics disk number */ 180 UINT32 disk_status : 2; /* status of disk */ 181 UINT32 part_count : 8; /* current partition count */ 182 UINT32 reserved : 14; 183 struct Vnode *dev; /* device */ 184 #ifdef LOSCFG_FS_FAT_CACHE 185 OsBcache *bcache; /* cache of the disk, shared in all partitions */ 186 #endif 187 UINT32 sector_size; /* disk sector size */ 188 UINT64 sector_start; /* disk start sector */ 189 UINT64 sector_count; /* disk sector number */ 190 UINT8 type; 191 CHAR *disk_name; 192 LOS_DL_LIST head; /* link head of all the partitions */ 193 struct pthread_mutex disk_mutex; 194 #ifndef LOSCFG_FS_FAT_CACHE 195 UINT8 *buff; 196 #endif 197 } los_disk; 198 199 typedef struct _los_part_ { 200 UINT32 disk_id : 8; /* physics disk number */ 201 UINT32 part_id : 8; /* partition number in the system */ 202 UINT32 part_no_disk : 8; /* partition number in the disk */ 203 UINT32 part_no_mbr : 5; /* partition number in the mbr */ 204 UINT32 reserved : 3; 205 UINT8 filesystem_type; /* filesystem used in the partition */ 206 UINT8 type; 207 struct Vnode *dev; /* dev devices used in the partition */ 208 CHAR *part_name; 209 UINT64 sector_start; /* 210 * offset of a partition to the primary devices 211 * (multi-mbr partitions are seen as same parition) 212 */ 213 UINT64 sector_count; /* 214 * sector numbers of a partition. If there is no addpartition operation, 215 * then all the mbr devices equal to the primary device count. 216 */ 217 LOS_DL_LIST list; /* linklist of partition */ 218 } los_part; 219 220 struct partition_info { 221 UINT8 type; 222 UINT64 sector_start; 223 UINT64 sector_count; 224 }; 225 226 struct disk_divide_info { 227 UINT64 sector_count; 228 UINT32 sector_size; 229 UINT32 part_count; 230 /* 231 * The primary partition place should be reversed and set to 0 in case all the partitions are 232 * logical partition (maximum 16 currently). So the maximum part number should be 4 + 16. 233 */ 234 struct partition_info part[MAX_DIVIDE_PART_PER_DISK + MAX_PRIMARY_PART_PER_DISK]; 235 }; 236 237 /** 238 * @ingroup disk 239 * @brief Disk driver initialization. 240 * 241 * @par Description: 242 * Initializate a disk dirver, and set the block cache. 243 * 244 * @attention 245 * <ul> 246 * <li>The parameter diskName must point a valid string, which end with the terminating null byte.</li> 247 * <li>The total length of parameter diskName must be less than the value defined by PATH_MAX.</li> 248 * <li>The parameter bops must pointed the right functions, otherwise the system 249 * will crash when the disk is being operated.</li> 250 * <li>The parameter info can be null or point to struct disk_divide_info. when info is null, 251 * the disk will be divided base the information of MBR, otherwise, 252 * the disk will be divided base the information of parameter info.</li> 253 * </ul> 254 * 255 * @param diskName [IN] Type #const CHAR * disk driver name. 256 * @param bops [IN] Type #const struct block_operations * block driver control sturcture. 257 * @param priv [IN] Type #VOID * private data of vnode. 258 * @param diskID [IN] Type #INT32 disk id number, less than SYS_MAX_DISK. 259 * @param info [IN] Type #VOID * disk driver partition information. 260 * 261 * @retval #0 Initialization success. 262 * @retval #-1 Initialization failed. 263 * 264 * @par Dependency: 265 * <ul><li>disk.h</li></ul> 266 * @see los_disk_deinit 267 * 268 */ 269 INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops, 270 VOID *priv, INT32 diskID, VOID *info); 271 272 /** 273 * @ingroup disk 274 * @brief Destroy a disk driver. 275 * 276 * @par Description: 277 * Destroy a disk driver, free the dependent resource. 278 * 279 * @attention 280 * <ul> 281 * None 282 * </ul> 283 * 284 * @param diskID [IN] Type #INT32 disk driver id number, less than the value defined by SYS_MAX_DISK. 285 * 286 * @retval #0 Destroy success. 287 * @retval #-1 Destroy failed. 288 * 289 * @par Dependency: 290 * <ul><li>disk.h</li></ul> 291 * @see los_disk_init 292 * 293 */ 294 INT32 los_disk_deinit(INT32 diskID); 295 296 /** 297 * @ingroup disk 298 * @brief Read data from disk driver. 299 * 300 * @par Description: 301 * Read data from disk driver. 302 * 303 * @attention 304 * <ul> 305 * <li>The sector size of the disk to be read should be acquired by los_part_ioctl before calling this function.</li> 306 * <li>The parameter buf must point to a valid memory and the buf size is count * sector_size.</li> 307 * </ul> 308 * 309 * @param drvID [IN] Type #INT32 disk driver id number, less than the value defined by SYS_MAX_DISK. 310 * @param buf [OUT] Type #VOID * memory which used to store read data. 311 * @param sector [IN] Type #UINT64 expected start sector number to read. 312 * @param count [IN] Type #UINT32 expected sector count to read. 313 * @param useRead [IN] Type #BOOL set FALSE to use the write block for optimization 314 * 315 * @retval #0 Read success. 316 * @retval #-1 Read failed. 317 * 318 * @par Dependency: 319 * <ul><li>disk.h</li></ul> 320 * @see los_disk_write 321 * 322 */ 323 INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL useRead); 324 325 /** 326 * @ingroup disk 327 * @brief Write data to a disk driver. 328 * 329 * @par Description: 330 * Write data to a disk driver. 331 * 332 * @attention 333 * <ul> 334 * <li>The sector size of the disk to be read should be acquired by los_part_ioctl before calling this function.</li> 335 * <li>The parameter buf must point to a valid memory and the buf size is count * sector_size.</li> 336 * </ul> 337 * 338 * @param drvID [IN] Type #INT32 disk driver id number, less than the value defined by SYS_MAX_DISK. 339 * @param buf [IN] Type #const VOID * memory which used to storage write data. 340 * @param sector [IN] Type #UINT64 expected start sector number to read. 341 * @param count [IN] Type #UINT32 experted sector count of write. 342 * 343 * @retval #0 Write success. 344 * @retval #-1 Write failed. 345 * 346 * @par Dependency: 347 * <ul><li>disk.h</li></ul> 348 * @see los_disk_read 349 * 350 */ 351 INT32 los_disk_write(INT32 drvID, const VOID *buf, UINT64 sector, UINT32 count); 352 353 /** 354 * @ingroup disk 355 * @brief Get information of disk driver. 356 * 357 * @par Description: 358 * Get information of disk driver. 359 * 360 * @attention 361 * <ul> 362 * None 363 * </ul> 364 * 365 * @param drvID [IN] Type #INT32 disk driver id number, less than the value defined by SYS_MAX_DISK. 366 * @param cmd [IN] Type #INT32 command to issu, currently support GET_SECTOR_COUNT, GET_SECTOR_SIZE, 367 * GET_BLOCK_SIZE, CTRL_SYNC. 368 * @param buf [OUT] Type #VOID * memory to storage the information, the size must enough for data type(UINT64) 369 * when cmd type is DISK_GET_SECTOR_COUNT, others is size_t. 370 * 371 * @retval #0 Get information success. 372 * @retval #-1 Get information failed. 373 * 374 * @par Dependency: 375 * <ul><li>disk.h</li></ul> 376 * @see None 377 * 378 */ 379 INT32 los_disk_ioctl(INT32 drvID, INT32 cmd, VOID *buf); 380 381 /** 382 * @ingroup disk 383 * @brief Sync blib cache. 384 * 385 * @par Description: 386 * Sync blib cache, write the valid data to disk driver. 387 * 388 * @attention 389 * <ul> 390 * None 391 * </ul> 392 * 393 * @param drvID [IN] Type #INT32 disk driver id number, less than the value defined by SYS_MAX_DISK. 394 * 395 * @retval #0 Sync success. 396 * @retval #INT32 Sync failed. 397 * 398 * @par Dependency: 399 * <ul><li>disk.h</li></ul> 400 * @see None 401 * 402 */ 403 INT32 los_disk_sync(INT32 drvID); 404 405 /** 406 * @ingroup disk 407 * @brief Set blib cache for the disk driver. 408 * 409 * @par Description: 410 * Set blib cache for the disk driver, users can set the number of sectors of per block, 411 * and the number of blocks. 412 * 413 * @attention 414 * <ul> 415 * None 416 * </ul> 417 * 418 * @param drvID [IN] Type #INT32 disk driver id number, less than the value defined by SYS_MAX_DISK. 419 * @param sectorPerBlock [IN] Type #UINT32 sector number of per block, only can be 32 * (1, 2, ..., 8). 420 * @param blockNum [IN] Type #UINT32 block number of cache. 421 * 422 * @retval #0 Set success. 423 * @retval #INT32 Set failed. 424 * 425 * @par Dependency: 426 * <ul><li>disk.h</li></ul> 427 * @see None 428 * 429 */ 430 INT32 los_disk_set_bcache(INT32 drvID, UINT32 sectorPerBlock, UINT32 blockNum); 431 432 /** 433 * @ingroup disk 434 * @brief Read data from chosen partition. 435 * 436 * @par Description: 437 * Read data from chosen partition. 438 * 439 * @attention 440 * <ul> 441 * <li>The sector size of the disk to be read should be acquired by los_part_ioctl before calling this function.</li> 442 * <li>The parameter buf must point to valid memory and the buf size is count * sector_size.</li> 443 * </ul> 444 * 445 * @param pt [IN] Type #INT32 partition number, less than the value defined by SYS_MAX_PART. 446 * @param buf [OUT] Type #VOID * memory which used to store the data to be read. 447 * @param sector [IN] Type #UINT64 start sector number of chosen partition. 448 * @param count [IN] Type #UINT32 the expected sector count for reading. 449 * @param useRead [IN] Type #BOOL FALSE when reading large contiguous data, TRUE for other situations 450 * 451 * @retval #0 Read success. 452 * @retval #-1 Read failed. 453 * 454 * @par Dependency: 455 * <ul><li>disk.h</li></ul> 456 * @see los_part_read 457 * 458 */ 459 INT32 los_part_read(INT32 pt, VOID *buf, UINT64 sector, UINT32 count, BOOL useRead); 460 461 /** 462 * @ingroup disk 463 * @brief Write data to chosen partition. 464 * 465 * @par Description: 466 * Write data to chosen partition. 467 * 468 * @attention 469 * <ul> 470 * <li>The sector size of the disk to be write should be acquired by los_part_ioctl before calling this function.</li> 471 * <li>The parameter buf must point to valid memory and the buf size is count * sector_size.</li> 472 * </ul> 473 * 474 * @param pt [IN] Type #INT32 partition number,less than the value defined by SYS_MAX_PART. 475 * @param buf [IN] Type #VOID * memory which used to storage the written data. 476 * @param sector [IN] Type #UINT64 start sector number of chosen partition. 477 * @param count [IN] Type #UINT32 the expected sector count for write. 478 * 479 * @retval #0 Write success. 480 * @retval #-1 Write failed. 481 * 482 * @par Dependency: 483 * <ul><li>disk.h</li></ul> 484 * @see los_part_read 485 * 486 */ 487 INT32 los_part_write(INT32 pt, const VOID *buf, UINT64 sector, UINT32 count); 488 489 /** 490 * @ingroup disk 491 * @brief Clear the bcache data 492 * 493 * @par Description: 494 * Flush the data and mark the block as unused. 495 * 496 * @attention 497 * <ul> 498 * None 499 * </ul> 500 * 501 * @param drvID [IN] Type #INT32 disk id 502 * 503 * @retval #0 Write success. 504 * @retval #-1 Write failed. 505 * 506 * @par Dependency: 507 * <ul><li>disk.h</li></ul> 508 * @see los_part_read 509 * 510 */ 511 INT32 los_disk_cache_clear(INT32 drvID); 512 513 /** 514 * @ingroup disk 515 * @brief Get information of chosen partition. 516 * 517 * @par Description: 518 * By passed command to get information of chosen partition. 519 * 520 * @attention 521 * <ul> 522 * None 523 * </ul> 524 * 525 * @param pt [IN] Type #INT32 partition number,less than the value defined by SYS_MAX_PART. 526 * @param cmd [IN] Type #INT32 command to issu, currently support GET_SECTOR_COUNT, GET_SECTOR_SIZE, 527 * GET_BLOCK_SIZE, CTRL_SYNC. 528 * @param buf [OUT] Type #VOID * memory to store the information, the size must enough for data type (UINT64) 529 * when cmd type is DISK_GET_SECTOR_COUNT, others is size_t. 530 * 531 * @retval #0 Get information success. 532 * @retval #-1 Get information failed. 533 * 534 * @par Dependency: 535 * <ul><li>disk.h</li></ul> 536 * @see None 537 * 538 */ 539 INT32 los_part_ioctl(INT32 pt, INT32 cmd, VOID *buf); 540 541 /** 542 * @ingroup disk 543 * @brief Decide the chosen partition is exist or not. 544 * 545 * @par Description: 546 * Decide the chosen partition is exist or not. 547 * 548 * @attention 549 * <ul> 550 * <li>The parameter dev is a full path, which begin with '/' and end with '/0'.</li> 551 * </ul> 552 * 553 * @param dev [IN] Type #const CHAR * partition driver name. 554 * @param mode [IN] Type #mode_t access modd. 555 * 556 * @retval #0 The chosen partition is exist. 557 * @retval #-1 The chosen partition is not exist. 558 * 559 * @par Dependency: 560 * <ul><li>disk.h</li></ul> 561 * @see None 562 * 563 */ 564 INT32 los_part_access(const CHAR *dev, mode_t mode); 565 566 /** 567 * @ingroup disk 568 * @brief Find disk partition. 569 * 570 * @par Description: 571 * By driver partition vnode to find disk partition. 572 * 573 * @attention 574 * <ul> 575 * None 576 * </ul> 577 * 578 * @param blkDriver [IN] Type #struct Vnode * partition driver vnode. 579 * 580 * @retval #NULL Can't find chosen disk partition. 581 * @retval #los_part * This is partition structure pointer of chosen disk partition. 582 * 583 * @par Dependency: 584 * <ul><li>disk.h</li></ul> 585 * @see None 586 * 587 */ 588 los_part *los_part_find(struct Vnode *blkDriver); 589 590 /** 591 * @ingroup disk 592 * @brief Find disk driver. 593 * 594 * @par Description: 595 * By disk driver id number to find disk dirver. 596 * 597 * @attention 598 * <ul> 599 * None 600 * </ul> 601 * 602 * @param id [IN] Type #INT32 disk id number,less than the value defined by SYS_MAX_DISK. 603 * 604 * @retval #NULL Can't find chosen disk driver. 605 * @retval #los_disk * This is disk structure pointer of chosen disk driver. 606 * 607 * @par Dependency: 608 * <ul><li>disk.h</li></ul> 609 * @see None 610 * 611 */ 612 los_disk *get_disk(INT32 id); 613 614 /** 615 * @ingroup disk 616 * @brief Find disk partition. 617 * 618 * @par Description: 619 * By driver partition id number to find disk partition. 620 * 621 * @attention 622 * <ul> 623 * None 624 * </ul> 625 * 626 * @param id [IN] Type #INT32 partition id number,less than the value defined by SYS_MAX_PART. 627 * 628 * @retval #NULL Can't find chosen disk partition. 629 * @retval #los_part * This is partition structure pointer of chosen disk partition. 630 * 631 * @par Dependency: 632 * <ul><li>disk.h</li></ul> 633 * @see None 634 * 635 */ 636 los_part *get_part(INT32 id); 637 638 /** 639 * @ingroup disk 640 * @brief Print partition information. 641 * 642 * @par Description: 643 * Print partition information. 644 * 645 * @attention 646 * <ul> 647 * None 648 * </ul> 649 * 650 * @param part [IN] Type #los_part * partition control structure pointer 651 * 652 * @par Dependency: 653 * <ul><li>disk.h</li></ul> 654 * @see None 655 * 656 */ 657 VOID show_part(los_part *part); 658 659 /** 660 * @ingroup disk 661 * @brief Add a new mmc partition. 662 * 663 * @par Description: 664 * Add a new mmc partition, users can set the start sector and size of the new partition. 665 * 666 * @attention 667 * <ul> 668 * None 669 * </ul> 670 * 671 * @param info [IN] Type #struct disk_divide_info * Disk driver information structure pointer. 672 * @param sectorStart [IN] Type #size_t Start sector number of the new partition. 673 * @param sectorCount [IN] Type #size_t Sector count of the new partition. 674 * 675 * @retval #0 Add partition success. 676 * @retval #-1 Add partition failed. 677 * 678 * @par Dependency: 679 * <ul><li>disk.h</li></ul> 680 * @see None 681 * 682 */ 683 INT32 add_mmc_partition(struct disk_divide_info *info, size_t sectorStart, size_t sectorCount); 684 685 /** 686 * @ingroup disk 687 * @brief alloc a new UNUSED disk id. 688 * 689 * @par Description: 690 * Get a free disk id for new device. 691 * 692 * @attention 693 * <ul> 694 * <li>The parameter diskName must point a valid string, which end with the null byte ('\0') </li> 695 * <li>The total length of parameter diskName must be less than the value defined by DISK_NAME </li> 696 * </ul> 697 * 698 * @param diskName [IN] Type #const CHAR * device name. 699 * 700 * @retval #INT32 available disk id 701 * @retval #-1 alloc disk id failed 702 703 * @par Dependency: 704 * <ul><li>disk.h</li></ul> 705 * @see los_get_diskid_byname 706 * 707 */ 708 INT32 los_alloc_diskid_byname(const CHAR *diskName); 709 710 /** 711 * @ingroup disk 712 * @brief get the INUSED disk id. 713 * 714 * @par Description: 715 * Get the correponding INUSED disk id by diskName. 716 * 717 * @attention 718 * <ul> 719 * <li>The parameter diskName must point a valid string, which end with the null byte ('\0') </li> 720 * <li>The total length of parameter diskName must be less than the value defined by DISK_NAME </li> 721 * </ul> 722 * 723 * @param diskName [IN] Type #const CHAR * device name. 724 * 725 * @retval #INT32 available disk id 726 * @retval #-1 get disk id failed 727 728 * @par Dependency: 729 * <ul><li>disk.h</li></ul> 730 * @see los_alloc_diskid_byname 731 * 732 */ 733 INT32 los_get_diskid_byname(const CHAR *diskName); 734 735 736 los_disk *los_get_mmcdisk_bytype(UINT8 type); 737 738 #ifdef __cplusplus 739 #if __cplusplus 740 } 741 #endif 742 #endif /* __cplusplus */ 743 744 #endif 745