39#ifndef LOSCFG_FS_FAT_CACHE
87#define MEM_ADDR_ALIGN_BYTE 64
90#define DISK_LOCK(mux) do { \
91 if (pthread_mutex_lock(mux) != 0) { \
92 PRINT_ERR("%s %d, mutex lock failed\n", __FUNCTION__, __LINE__); \
96#define DISK_UNLOCK(mux) do { \
97 if (pthread_mutex_unlock(mux) != 0) { \
98 PRINT_ERR("%s %d, mutex unlock failed\n", __FUNCTION__, __LINE__); \
102typedef VOID *(*StorageHookFunction)(VOID *);
104#ifdef LOSCFG_FS_FAT_CACHE
127 if (((sectorsPerBlock % UNSIGNED_INTEGER_BITS) == 0) &&
128 ((sectorsPerBlock >> UNINT_LOG2_SHIFT) <= BCACHE_BLOCK_FLAGS)) {
141 if (diskName == NULL) {
142 PRINT_ERR(
"The parameter disk_name is NULL");
146 nameLen = strlen(diskName);
147 if (nameLen > DISK_NAME) {
148 PRINT_ERR(
"diskName is too long!\n");
153 for (diskID = 0; diskID < SYS_MAX_DISK; diskID++) {
163 if ((disk == NULL) || (diskID == SYS_MAX_DISK)) {
164 PRINT_ERR(
"los_alloc_diskid_byname failed %d!\n", diskID);
175 PRINT_ERR(
"los_alloc_diskid_byname alloc disk name failed\n");
179 if (strncpy_s(disk->
disk_name, (nameLen + 1), diskName, nameLen) != EOK) {
180 PRINT_ERR(
"The strncpy_s failed.\n");
197 if (diskName == NULL) {
198 PRINT_ERR(
"The parameter diskName is NULL");
202 diskNameLen = strlen(diskName);
203 if (diskNameLen > DISK_NAME) {
204 PRINT_ERR(
"diskName is too long!\n");
208 for (diskID = 0; diskID < SYS_MAX_DISK; diskID++) {
211 if (strlen(disk->
disk_name) != diskNameLen) {
214 if (strcmp(diskName, disk->
disk_name) == 0) {
219 if ((disk == NULL) || (diskID == SYS_MAX_DISK)) {
220 PRINT_ERR(
"los_get_diskid_byname failed!\n");
228 const CHAR *mmcDevHead =
"/dev/mmcblk";
230 for (
INT32 diskId = 0; diskId < SYS_MAX_DISK; diskId++) {
234 }
else if ((disk->
type == type) && (strncmp(disk->
disk_name, mmcDevHead, strlen(mmcDevHead)) == 0)) {
238 PRINT_ERR(
"Cannot find the mmc disk!\n");
244 if (diskID < SYS_MAX_DISK) {
251 if (diskID < SYS_MAX_DISK) {
252 g_usbMode &= ~((1u << diskID) & UINT_MAX);
256#ifdef LOSCFG_FS_FAT_CACHE
259 return (
g_usbMode & (1u << diskID)) ? TRUE : FALSE;
265 if ((
id >= 0) && (
id < SYS_MAX_DISK)) {
274 if ((
id >= 0) && (
id < SYS_MAX_PART)) {
286 return (firstPart == NULL) ? 0 : firstPart->
sector_start;
312 for (i = 0; i < SYS_MAX_PART; i++) {
313 if (part->
dev == NULL) {
347#define DEV_NAME_BUFF_SIZE (DISK_NAME + 3)
351 CHAR devName[DEV_NAME_BUFF_SIZE];
352 struct Vnode *diskDev = NULL;
353 struct Vnode *partDev = NULL;
358 (disk->
dev == NULL)) {
363 PRINT_ERR(
"DiskAddPart failed: sector start is %llu, sector count is %llu\n", sectorStart, sectorCount);
369 if (IsValidPart == TRUE) {
370 ret = snprintf_s(devName,
sizeof(devName),
sizeof(devName) - 1,
"%s%c%u",
376 if (register_blockdriver(devName, ((
struct drv_data *)diskDev->
data)->ops,
377 RWE_RW_RW, ((
struct drv_data *)diskDev->
data)->priv)) {
378 PRINT_ERR(
"DiskAddPart : register %s fail!\n", devName);
388 (VOID)unregister_blockdriver(devName);
399 if (disk->
type == EMMC) {
416 PRINT_ERR(
"Part[%u] sector_start:%llu, sector_count:%llu, exceed emmc sector_count:%llu.\n", i,
420 PRINT_ERR(
"Part[%u] sector_count change to %llu.\n", i, info->
part[i].
sector_count);
423 if (ret == VFS_ERROR) {
429 if (ret == VFS_ERROR) {
439 const CHAR *buf = parBuf;
440 const CHAR *fsType =
"FAT";
441 const CHAR *str =
"\xEB\x52\x90" "NTFS ";
443 if (((LD_DWORD_DISK(&buf[BS_FILSYSTEMTYPE32]) & BS_FS_TYPE_MASK) == BS_FS_TYPE_VALUE) ||
444 (strncmp(&buf[BS_FILSYSTYPE], fsType, strlen(fsType)) == 0)) {
445 return BS_FS_TYPE_FAT;
446 }
else if (strncmp(&buf[BS_JMPBOOT], str, strlen(str)) == 0) {
447 return BS_FS_TYPE_NTFS;
455 CHAR *buffer1 = NULL;
456 CHAR *buffer2 = NULL;
459 if (buffer1 == NULL) {
460 PRINT_ERR(
"%s buffer1 malloc %lu failed! %d\n", __FUNCTION__, size, __LINE__);
464 if (buffer2 == NULL) {
465 PRINT_ERR(
"%s buffer2 malloc %lu failed! %d\n", __FUNCTION__, size, __LINE__);
469 (VOID)memset_s(buffer1, size, 0, size);
470 (VOID)memset_s(buffer2, size, 0, size);
473 *partitionBuf = buffer2;
482 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)blkDrv->
data)->ops;
484 ret = bops->read(blkDrv, (
UINT8 *)gptBuf, 1, 1);
486 PRINT_ERR(
"%s %d\n", __FUNCTION__, __LINE__);
490 if (!VERIFY_GPT(gptBuf)) {
491 PRINT_ERR(
"%s %d\n", __FUNCTION__, __LINE__);
503 if (VERIFY_FS(partitionBuf)) {
506 if (*partitionCount >= MAX_DIVIDE_PART_PER_DISK) {
509 info->
part[*partitionCount].
type = partitionType;
511 info->
part[*partitionCount].
sector_count = (partitionEnd - partitionStart) + 1;
514 PRINT_ERR(
"The partition type is not allowed to use!\n");
517 PRINT_ERR(
"Do not support the partition type!\n");
526 INT32 ret = VFS_ERROR;
527 UINT64 partitionStart, partitionEnd;
528 struct block_operations *bops = NULL;
530 for (j = 0; j < PAR_ENTRY_NUM_PER_SECTOR; j++) {
531 if (!VERITY_AVAILABLE_PAR(&gptBuf[j * TABLE_SIZE])) {
532 PRINTK(
"The partition type is ESP or MSR!\n");
536 if (!VERITY_PAR_VALID(&gptBuf[j * TABLE_SIZE])) {
540 partitionStart = LD_QWORD_DISK(&gptBuf[(j * TABLE_SIZE) + GPT_PAR_START_OFFSET]);
541 partitionEnd = LD_QWORD_DISK(&gptBuf[(j * TABLE_SIZE) + GPT_PAR_END_OFFSET]);
542 if ((partitionStart >= partitionEnd) || (partitionEnd > info->
sector_count)) {
543 PRINT_ERR(
"GPT partition %u recognition failed : partitionStart = %llu, partitionEnd = %llu\n",
544 j, partitionStart, partitionEnd);
550 bops = (
struct block_operations *)((
struct drv_data *)blkDrv->
data)->ops;
552 ret = bops->read(blkDrv, (
UINT8 *)partitionBuf, partitionStart, 1);
554 PRINT_ERR(
"%s %d\n", __FUNCTION__, __LINE__);
570 CHAR *partitionBuf = NULL;
571 UINT32 tableNum, i, index;
572 UINT32 partitionCount = 0;
585 tableNum = LD_DWORD_DISK(&gptBuf[TABLE_NUM_OFFSET]);
586 if (tableNum > TABLE_MAX_NUM) {
587 tableNum = TABLE_MAX_NUM;
590 index = (tableNum % PAR_ENTRY_NUM_PER_SECTOR) ? ((tableNum / PAR_ENTRY_NUM_PER_SECTOR) + 1) :
591 (tableNum / PAR_ENTRY_NUM_PER_SECTOR);
593 for (i = 0; i < index; i++) {
595 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)blkDrv->
data)->ops;
596 ret = bops->read(blkDrv, (
UINT8 *)gptBuf, TABLE_START_SECTOR + i, 1);
598 PRINT_ERR(
"%s %d\n", __FUNCTION__, __LINE__);
605 if (ret == VFS_ERROR) {
606 ret = (
INT32)partitionCount;
611 ret = (
INT32)partitionCount;
625 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)blkDrv->
data)->ops;
627 ret = bops->read(blkDrv, (
UINT8 *)mbrBuf, 0, 1);
629 PRINT_ERR(
"driver read return error: %d\n", ret);
634 if (LD_WORD_DISK(&mbrBuf[BS_SIG55AA]) != BS_SIG55AA_VALUE) {
646 if (VERIFY_FS(mbrBuf)) {
647 if (info->
sector_count <= LD_DWORD_DISK(&mbrBuf[PAR_OFFSET + PAR_START_OFFSET])) {
651 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)blkDrv->
data)->ops;
652 ret = bops->read(blkDrv, (
UINT8 *)ebrBuf, LD_DWORD_DISK(&mbrBuf[PAR_OFFSET + PAR_START_OFFSET]), 1);
653 if ((ret != 1) || (!VERIFY_FS(ebrBuf))) {
654 PRINT_ERR(
"OsEBRInfoGet, verify_fs error, ret = %d\n", ret);
666 CHAR mbrPartitionType;
667 INT32 extendedFlag = 0;
670 for (i = 0; i < MAX_PRIMARY_PART_PER_DISK; i++) {
671 mbrPartitionType = mbrBuf[PAR_OFFSET + PAR_TYPE_OFFSET + (i * PAR_TABLE_SIZE)];
672 if (mbrPartitionType) {
673 info->
part[i].
type = mbrPartitionType;
674 info->
part[i].
sector_start = LD_DWORD_DISK(&mbrBuf[PAR_OFFSET + PAR_START_OFFSET + (i * PAR_TABLE_SIZE)]);
675 info->
part[i].
sector_count = LD_DWORD_DISK(&mbrBuf[PAR_OFFSET + PAR_COUNT_OFFSET + (i * PAR_TABLE_SIZE)]);
676 if ((mbrPartitionType == EXTENDED_PAR) || (mbrPartitionType == EXTENDED_8G)) {
693 UINT32 extendedOffset = 0;
694 CHAR ebrPartitionType;
700 PRINT_ERR(
"extended partition is out of disk range: extendedAddress = %u, extendedOffset = %u\n",
701 extendedAddress, extendedOffset);
704 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)blkDrv->
data)->ops;
705 ret = bops->read(blkDrv, (
UINT8 *)ebrBuf, extendedAddress + extendedOffset, 1);
707 PRINT_ERR(
"driver read return error: %d, extendedAddress = %u, extendedOffset = %u\n", ret,
708 extendedAddress, extendedOffset);
711 ebrPartitionType = ebrBuf[PAR_OFFSET + PAR_TYPE_OFFSET];
712 if (ebrPartitionType && ((mbrCount + ebrCount) < MAX_DIVIDE_PART_PER_DISK)) {
713 info->
part[MAX_PRIMARY_PART_PER_DISK + ebrCount].
type = ebrPartitionType;
714 info->
part[MAX_PRIMARY_PART_PER_DISK + ebrCount].
sector_start = extendedAddress + extendedOffset +
715 LD_DWORD_DISK(&ebrBuf[PAR_OFFSET +
717 info->
part[MAX_PRIMARY_PART_PER_DISK + ebrCount].
sector_count = LD_DWORD_DISK(&ebrBuf[PAR_OFFSET +
721 extendedOffset = LD_DWORD_DISK(&ebrBuf[PAR_OFFSET + PAR_START_OFFSET + PAR_TABLE_SIZE]);
722 }
while ((ebrBuf[PAR_OFFSET + PAR_TYPE_OFFSET + PAR_TABLE_SIZE] != 0) &&
723 ((mbrCount + ebrCount) < MAX_DIVIDE_PART_PER_DISK));
732 INT32 extendedPos = 0;
738 if (blkDrv == NULL) {
742 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)blkDrv->
data)->ops;
744 if ((bops == NULL) || (bops->read == NULL)) {
759 if (mbrBuf[PARTION_MODE_BTYE] == (
CHAR)PARTION_MODE_GPT) {
772 extendedAddress = LD_DWORD_DISK(&mbrBuf[PAR_OFFSET + PAR_START_OFFSET + (extendedPos * PAR_TABLE_SIZE)]);
794 (VOID)memset_s(parInfo.
part,
sizeof(parInfo.
part), 0,
sizeof(parInfo.
part));
795 partSize =
sizeof(parInfo.
part) /
sizeof(parInfo.
part[0]);
800 if (count == VFS_ERROR) {
805 part->part_no_mbr = 0;
806 PRINTK(
"Disk %s doesn't contain a valid partition table.\n", disk->
disk_name);
808 }
else if (count < 0) {
818 part->part_no_mbr = 0;
820 PRINTK(
"No MBR detected.\n");
824 for (i = 0; i < partSize; i++) {
826 if ((parInfo.
part[i].
type != 0) && (parInfo.
part[i].
type != EXTENDED_PAR) &&
827 (parInfo.
part[i].
type != EXTENDED_8G)) {
832 part->part_no_mbr = i + 1;
839#ifndef LOSCFG_FS_FAT_CACHE
842 INT32 result = VFS_ERROR;
843 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)disk->
dev->
data)->ops;
844 if ((bops == NULL) || (bops->read == NULL)) {
850 for (; count != 0; count -= cnt) {
851 cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
852 result = bops->read(disk->
dev, buffer, sector, cnt);
853 if (result == (
INT32)cnt) {
866 result = bops->read(disk->
dev, buf, sector, count);
867 if (result == count) {
877 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)disk->
dev->
data)->ops;
878 INT32 result = VFS_ERROR;
879 if ((bops == NULL) || (bops->read == NULL)) {
885 for (; count != 0; count -= cnt) {
886 cnt = (count > DISK_DIRECT_BUFFER_SIZE) ? DISK_DIRECT_BUFFER_SIZE : count;
891 result = bops->write(disk->
dev, buffer, sector, cnt);
892 if (result == (
INT32)cnt) {
901 result = bops->write(disk->
dev, buf, sector, count);
902 if (result == count) {
913#ifdef LOSCFG_FS_FAT_CACHE
916 INT32 result = VFS_ERROR;
919 if ((buf == NULL) || (count == 0)) {
937#ifdef LOSCFG_FS_FAT_CACHE
938 if (disk->
bcache != NULL) {
945 if (result != ENOERR) {
946 PRINT_ERR(
"los_disk_read read err = %d, sector = %llu, len = %u\n", result, sector, len);
952 if (disk->
dev == NULL) {
958 if (result != ENOERR) {
972#ifdef LOSCFG_FS_FAT_CACHE
975 INT32 result = VFS_ERROR;
977 if (disk == NULL || disk->
dev == NULL || disk->
dev->
data == NULL) {
981 if ((buf == NULL) || (count == 0)) {
995#ifdef LOSCFG_FS_FAT_CACHE
996 if (disk->
bcache != NULL) {
1002 if (result != ENOERR) {
1003 PRINT_ERR(
"los_disk_write write err = %d, sector = %llu, len = %u\n", result, sector, len);
1009 if (disk->
dev == NULL) {
1015 if (result != ENOERR) {
1029 struct geometry info;
1035 DISK_LOCK(&disk->disk_mutex);
1037 if ((disk->dev == NULL) || (disk->disk_status !=
STAT_INUSED)) {
1041 if (cmd == DISK_CTRL_SYNC) {
1042 DISK_UNLOCK(&disk->disk_mutex);
1050 (VOID)memset_s(&info,
sizeof(info), 0,
sizeof(info));
1052 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)disk->dev->data)->ops;
1053 if ((bops == NULL) || (bops->geometry == NULL) ||
1054 (bops->geometry(disk->dev, &info) != 0)) {
1058 if (cmd == DISK_GET_SECTOR_COUNT) {
1059 *(
UINT64 *)buf = info.geo_nsectors;
1060 if (info.geo_nsectors == 0) {
1063 }
else if (cmd == DISK_GET_SECTOR_SIZE) {
1064 *(
size_t *)buf = info.geo_sectorsize;
1065 }
else if (cmd == DISK_GET_BLOCK_SIZE) {
1067 *(
size_t *)buf = DISK_MAX_SECTOR_SIZE / info.geo_sectorsize;
1072 DISK_UNLOCK(&disk->disk_mutex);
1076 DISK_UNLOCK(&disk->disk_mutex);
1101 PRINT_ERR(
"los_part_read failed, invalid count, count = %u\n", count);
1106 if (part->
type == EMMC) {
1110 PRINT_ERR(
"los_part_read failed, invalid sector, sector = %llu\n", sector);
1117 PRINT_ERR(
"los_part_read error, sector = %llu, count = %u, part->sector_start = %llu, "
1157 PRINT_ERR(
"los_part_write failed, invalid count, count = %u\n", count);
1162 if (part->
type == EMMC) {
1166 PRINT_ERR(
"los_part_write failed, invalid sector, sector = %llu\n", sector);
1173 PRINT_ERR(
"los_part_write, sector = %llu, count = %u, part->sector_start = %llu, "
1191#define GET_ERASE_BLOCK_SIZE 0x2
1195 struct geometry info;
1213 if (cmd == DISK_CTRL_SYNC) {
1222 (VOID)memset_s(&info,
sizeof(info), 0,
sizeof(info));
1224 struct block_operations *bops = (
struct block_operations *)((
struct drv_data *)part->dev->data)->ops;
1225 if ((bops == NULL) || (bops->geometry == NULL) ||
1226 (bops->geometry(part->dev, &info) != 0)) {
1230 if (cmd == DISK_GET_SECTOR_COUNT) {
1231 *(
UINT64 *)buf = part->sector_count;
1235 }
else if (cmd == DISK_GET_SECTOR_SIZE) {
1236 *(
size_t *)buf = info.geo_sectorsize;
1237 }
else if (cmd == DISK_GET_BLOCK_SIZE) {
1238 if ((bops->ioctl == NULL) ||
1239 (bops->ioctl(part->dev, GET_ERASE_BLOCK_SIZE, (
UINTPTR)buf) != 0)) {
1256 INT32 result = ENOERR;
1257#ifdef LOSCFG_FS_FAT_CACHE
1265 if (result != ENOERR) {
1266 PRINTK(
"[ERROR]disk_cache_clear SD sync failed!\n");
1282#ifdef LOSCFG_FS_FAT_CACHE
1292#ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD
1305#define SECTOR_SIZE 512
1308 UINT32 sectorPerBlock = diskInfo->geo_sectorsize / SECTOR_SIZE;
1309 if (sectorPerBlock != 0) {
1311 if (sectorPerBlock != 0) {
1312 bc =
BlockCacheInit(blkDriver, diskInfo->geo_sectorsize, sectorPerBlock,
1318 PRINT_ERR(
"disk_init : disk have not init bcache cache!\n");
1331 PRINT_ERR(
"Blib async preread deinit failed in %s, %d\n", __FUNCTION__, __LINE__);
1333#ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD
1352 disk->
dev = blkDriver;
1357 nameLen = strlen(diskName);
1366 PRINT_ERR(
"DiskStructInit alloc memory failed.\n");
1370 if (strncpy_s(disk->
disk_name, (nameLen + 1), diskName, nameLen) != EOK) {
1371 PRINT_ERR(
"DiskStructInit strncpy_s failed.\n");
1386 if (ret != ENOERR) {
1387 PRINT_ERR(
"DiskDivide failed, ret = %d\n", ret);
1392 if (ret != ENOERR) {
1393 PRINT_ERR(
"DiskPartitionRegister failed, ret = %d\n", ret);
1403 char *diskName = NULL;
1404 CHAR devName[DEV_NAME_BUFF_SIZE];
1409 while (&part->
list != &disk->
head) {
1411 ret = snprintf_s(devName,
sizeof(devName),
sizeof(devName) - 1,
"%s%c%d",
1414 return -ENAMETOOLONG;
1417 (VOID)unregister_blockdriver(devName);
1426#ifdef LOSCFG_FS_FAT_CACHE
1429 if (disk->
buff != NULL) {
1436 (VOID)unregister_blockdriver(disk->
disk_name);
1443 PRINT_ERR(
"%s %d, mutex destroy failed, ret = %d\n", __FUNCTION__, __LINE__, ret);
1453 struct geometry *diskInfo,
struct Vnode *blkDriver)
1455 pthread_mutexattr_t attr;
1456#ifdef LOSCFG_FS_FAT_CACHE
1465 attr.type = PTHREAD_MUTEX_RECURSIVE;
1470#ifndef LOSCFG_FS_FAT_CACHE
1471 disk->
buff =
malloc(diskInfo->geo_sectorsize * DISK_DIRECT_BUFFER_SIZE);
1472 if (disk->
buff == NULL) {
1473 PRINT_ERR(
"OsDiskInitSub: direct buffer of disk init failed\n");
1482 VOID *priv,
INT32 diskID, VOID *info)
1484 struct geometry diskInfo;
1485 struct Vnode *blkDriver = NULL;
1489 if ((diskName == NULL) || (disk == NULL) ||
1494 if (register_blockdriver(diskName, bops, RWE_RW_RW, priv) != 0) {
1495 PRINT_ERR(
"disk_init : register %s fail!\n", diskName);
1504 goto DISK_FIND_ERROR;
1506 struct block_operations *bops2 = (
struct block_operations *)((
struct drv_data *)blkDriver->
data)->ops;
1508 if ((bops2 == NULL) || (bops2->geometry == NULL) || (bops2->geometry(blkDriver, &diskInfo) != 0)) {
1509 goto DISK_BLKDRIVER_ERROR;
1512 if (diskInfo.geo_sectorsize < DISK_MAX_SECTOR_SIZE) {
1513 goto DISK_BLKDRIVER_ERROR;
1516 ret =
OsDiskInitSub(diskName, diskID, disk, &diskInfo, blkDriver);
1517 if (ret != ENOERR) {
1532 disk->
type = OTHERS;
1536DISK_BLKDRIVER_ERROR:
1537 PRINT_ERR(
"disk_init : register %s ok but get disk info fail!\n", diskName);
1540 (VOID)unregister_blockdriver(diskName);
1552 PRINTK(
"warning: %s lost, force umount ret = %d\n", disk->
disk_name, ret);
1581#ifdef LOSCFG_FS_FAT_CACHE
1582 if (disk->
bcache != NULL) {
1593#ifdef LOSCFG_FS_FAT_CACHE
1599 if ((disk == NULL) || (sectorPerBlock == 0)) {
1607 if (((sectorPerBlock % UNSIGNED_INTEGER_BITS) != 0) ||
1608 ((sectorPerBlock >> UNINT_LOG2_SHIFT) > BCACHE_BLOCK_FLAGS)) {
1618 if (disk->
bcache != NULL) {
1620 if (ret != ENOERR) {
1633 if ((bc == NULL) && (blockNum != 0)) {
1665 if (disk->
dev == blkDriver) {
1669 while (&part->
list != &disk->
head) {
1670 if (part->
dev == blkDriver) {
1688 if (blkDriver == NULL) {
1692 for (i = 0; i < SYS_MAX_DISK; i++) {
1709 struct Vnode *node = NULL;
1731 if ((part == NULL) || (src == NULL)) {
1736 if ((len == 0) || (len >= DISK_NAME)) {
1752 PRINT_ERR(
"%s[%d] zalloc failure\n", __FUNCTION__, __LINE__);
1756 if (strcpy_s(part->
part_name, len + 1, src) != EOK) {
1787 if ((info->
part_count >= MAX_DIVIDE_PART_PER_DISK) || (sectorCount == 0)) {
1796 for (i = 0; i < index; i++) {
1812 if ((part == NULL) || (part->
dev == NULL)) {
1813 PRINT_ERR(
"part is NULL\n");
1817 PRINTK(
"\npart info :\n");
1818 PRINTK(
"disk id : %u\n", part->
disk_id);
1819 PRINTK(
"part_id in system: %u\n", part->
part_id);
1821 PRINTK(
"part no in mbr : %u\n", part->
part_no_mbr);
1827#ifdef LOSCFG_DRIVERS_MMC
1833 INT32 ret = VFS_ERROR;
1834#ifdef LOSCFG_DRIVERS_MMC
VOID ResumeAsyncPreread(OsBcache *arg1, const OsBcacheBlock *arg2)
OsBcache * BlockCacheInit(struct Vnode *devNode, UINT32 sectorSize, UINT32 sectorPerBlock, UINT32 blockNum, UINT64 blockCount)
INT32 BlockCacheWrite(OsBcache *bc, const UINT8 *buf, UINT32 *len, UINT64 sector)
写块设备缓存
INT32 BcacheClearCache(OsBcache *bc)
VOID BlockCacheDeinit(OsBcache *bcache)
INT32 BlockCacheSync(OsBcache *bc)
块缓存同步
VOID BcacheSyncThreadInit(OsBcache *bc, INT32 id)
块缓存同步任务初始化,开了个内核任务.
INT32 BlockCacheRead(OsBcache *bc, UINT8 *buf, UINT32 *len, UINT64 sector, BOOL useRead)
读块设备缓存
UINT32 BcacheAsyncPrereadInit(OsBcache *bc)
VOID BcacheSyncThreadDeinit(const OsBcache *bc)
UINT32 BcacheAsyncPrereadDeinit(OsBcache *bc)
los_disk * los_get_mmcdisk_bytype(UINT8 type)
static INT32 DiskPartitionMemZalloc(size_t boundary, size_t size, CHAR **gptBuf, CHAR **partitionBuf)
磁盘分区内存申请
static INT32 DiskAddPart(los_disk *disk, UINT64 sectorStart, UINT64 sectorCount, BOOL IsValidPart)
static UINT32 OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk, struct geometry *diskInfo, struct Vnode *blkDriver)
磁盘初始化
static INT32 OsMBRInfoGet(struct Vnode *blkDrv, CHAR *mbrBuf)
获取MBR信息,即特殊扇区信息,在MBR硬盘中,分区信息直接存储于主引导记录(MBR)中(主引导记录中还存储着系统的引导程序)。
static CHAR GPTPartitionTypeRecognition(const CHAR *parBuf)
GPT分区类型识别
static OsBcache * DiskCacheInit(UINT32 diskID, const struct geometry *diskInfo, struct Vnode *blkDriver)
ssize_t StorageBlockMmcErase(uint32_t blockId, size_t secStart, size_t secNr)
通过磁盘ID 擦除磁盘信息
INT32 EraseDiskByID(UINT32 diskID, size_t startSector, UINT32 sectors)
static INT32 OsPrimaryPartitionRecognition(const CHAR *mbrBuf, struct disk_divide_info *info, INT32 *extendedPos, INT32 *mbrCount)
识别主分区
los_disk g_sysDisk[SYS_MAX_DISK]
支持挂载的磁盘总数量 5个
static UINT32 OsReHookFuncAddDiskRef(StorageHookFunction handler, VOID *param) __attribute__((weakref("osReHookFuncAdd")))
static INT32 DiskPartitionRecognition(struct Vnode *blkDrv, struct disk_divide_info *info)
识别磁盘分区信息 https://blog.csdn.net/Hilavergil/article/details/79270379
static VOID DiskCacheDeinit(los_disk *disk)
static INT32 GPTInfoGet(struct Vnode *blkDrv, CHAR *gptBuf)
获取GPT信息,是GPT还是MBR取决于磁盘上放的内容
static los_part * DiskPartAllocate(struct Vnode *dev, UINT64 start, UINT64 count)
分配一个磁盘分区,必须要有索引节点才给分配.
static BOOL GetDiskUsbStatus(UINT32 diskID)
static VOID DiskCacheThreadInit(UINT32 diskID, OsBcache *bc)
static VOID DiskPartDelFromDisk(los_disk *disk, los_part *part)
从磁盘上删除分区
static INT32 OsGPTPartitionRecognitionSub(struct disk_divide_info *info, const CHAR *partitionBuf, UINT32 *partitionCount, UINT64 partitionStart, UINT64 partitionEnd)
解析GPT分区内容
static INT32 OsEBRInfoGet(struct Vnode *blkDrv, const struct disk_divide_info *info, CHAR *ebrBuf, const CHAR *mbrBuf)
static VOID DiskPartAddToDisk(los_disk *disk, los_part *part)
磁盘增加一个分区
static INT32 DiskGPTPartitionRecognition(struct Vnode *blkDrv, struct disk_divide_info *info)
UINT32 g_uwFatBlockNums
块数量 默认28
static UINT32 OsReHookFuncDelDiskRef(StorageHookFunction handler) __attribute__((weakref("osReHookFuncDel")))
static INT32 disk_write_directly(los_disk *disk, const VOID *buf, UINT64 sector, UINT32 count)
VOID SetFatSectorsPerBlock(UINT32 sectorsPerBlock)
设置FAR每块扇区数
static VOID DiskStructInit(const CHAR *diskName, INT32 diskID, const struct geometry *diskInfo, struct Vnode *blkDriver, los_disk *disk)
磁盘结构体初始化,初始化 los_disk 结构体
UINT32 GetFatBlockNums(VOID)
los_part g_sysPart[SYS_MAX_PART]
支持磁盘的分区总数量 5*16,每个磁盘最大分16个区
spinlock_t g_diskFatBlockSpinlock
磁盘Fat块自旋锁
static VOID DiskPartRelease(los_part *part)
清空分区信息
UINT32 g_uwFatSectorsPerBlock
每块支持扇区数 默认64个扇区
static INT32 DiskDeinit(los_disk *disk)
磁盘反初始化
VOID *(* StorageHookFunction)(VOID *)
INT32 SetDiskPartName(los_part *part, const CHAR *src)
设置分区名称
VOID SetFatBlockNums(UINT32 blockNums)
UINT32 GetFatSectorsPerBlock(VOID)
static INT32 OsLogicalPartitionRecognition(struct Vnode *blkDrv, struct disk_divide_info *info, UINT32 extendedAddress, CHAR *ebrBuf, INT32 mbrCount)
识别扩展分区
static los_part * OsPartFind(los_disk *disk, const struct Vnode *blkDriver)
通过索引节点从磁盘中找分区信息
INT32 DiskPartitionRegister(los_disk *disk)
磁盘分区注册
static INT32 DiskDivide(los_disk *disk, struct disk_divide_info *info)
磁盘分区
static INT32 DiskDivideAndPartitionRegister(struct disk_divide_info *info, los_disk *disk)
磁盘分区和注册分区
static UINT64 GetFirstPartStart(const los_part *part)
static INT32 disk_read_directly(los_disk *disk, VOID *buf, UINT64 sector, UINT32 count)
static INT32 OsGPTPartitionRecognition(struct Vnode *blkDrv, struct disk_divide_info *info, const CHAR *gptBuf, CHAR *partitionBuf, UINT32 *partitionCount)
识别GPT分区内容
spinlock_t g_diskSpinlock
磁盘自锁锁
INT32 add_mmc_partition(struct disk_divide_info *info, size_t sectorStart, size_t sectorCount)
添加 MMC分区 MMC, 是一种闪存卡(Flash Memory Card)标准,它定义了 MMC 的架构以及访问 Flash Memory 的接口和协议。 而eMMC 则是对 MMC 的一个...
INT32 los_disk_write(INT32 drvID, const VOID *buf, UINT64 sector, UINT32 count)
将buf内容写到指定扇区,
INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL useRead)
读磁盘数据
INT32 los_disk_cache_clear(INT32 drvID)
Clear the bcache data
INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops, VOID *priv, INT32 diskID, VOID *info)
磁盘初始化
INT32 los_part_read(INT32 pt, VOID *buf, UINT64 sector, UINT32 count, BOOL useRead)
读分区上扇区内容
los_disk * get_disk(INT32 id)
Find disk driver.
INT32 los_disk_set_bcache(INT32 drvID, UINT32 sectorPerBlock, UINT32 blockNum)
设置磁盘块缓存
INT32 los_get_diskid_byname(const CHAR *diskName)
通过名称查询使用中(STAT_INUSED)磁盘ID
VOID OsSetUsbStatus(UINT32 diskID)
Set usb mode.
INT32 los_disk_deinit(INT32 diskID)
磁盘反初始化
VOID show_part(los_part *part)
OHOS #partinfo /dev/mmcblk0p0 命令输出信息
los_part * get_part(INT32 id)
获取某个分区的描述符
los_part * los_part_find(struct Vnode *blkDriver)
通过索引节点找到分区信息
INT32 los_part_access(const CHAR *dev, mode_t mode)
访问分区
INT32 los_disk_ioctl(INT32 drvID, INT32 cmd, VOID *buf)
Get information of disk driver.
INT32 los_alloc_diskid_byname(const CHAR *diskName)
通过名称分配磁盘ID
INT32 los_part_write(INT32 pt, const VOID *buf, UINT64 sector, UINT32 count)
将数据写入指定分区的指定扇区
VOID OsClearUsbStatus(UINT32 diskID)
Set usb mode.
INT32 los_part_ioctl(INT32 pt, INT32 cmd, VOID *buf)
Get information of chosen partition.
INT32 los_disk_sync(INT32 drvID)
磁盘同步,同步指的是缓存同步
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the tail of a doubly linked list.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
Identify whether a specified doubly linked list is empty. | 判断链表是否为空
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS)))
STATIC INLINE BOOL LOS_IsUserAddressRange(VADDR_T vaddr, size_t len)
虚拟地址[vaddr,vaddr + len]是否在用户空间
void * zalloc(size_t size)
void * memalign(size_t boundary, size_t size)
void * malloc(size_t size)
动态分配内存块大小
void free(void *ptr)
释放ptr所指向的内存空间
int ForceUmountDev(struct Vnode *dev)
int pthread_mutex_destroy(pthread_mutex_t *mutex)
销毁互斥锁
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexAttr)
初始化互斥锁。 如果 mutexAttr 为 NULL,则使用默认属性。
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
初始化互斥锁属性
struct pthread_mutex disk_mutex
struct LOS_DL_LIST * pstNext
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
struct partition_info part[MAX_DIVIDE_PART_PER_DISK+MAX_PRIMARY_PART_PER_DISK]
BcachePrereadFun prereadFun
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
INT32 LOS_CopyToKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count)
将用户空间的数据拷贝到内核空间
INT32 LOS_CopyFromKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count)
将内核数据拷贝到用户空间
int VnodeHold(void)
拿锁,封装互斥量
int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags)
通过路径查询vnode节点