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