Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
5bed688c
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
464
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5bed688c
编写于
12月 13, 2021
作者:
O
openharmony_ci
提交者:
Gitee
12月 13, 2021
浏览文件
操作
浏览文件
下载
差异文件
!731 【请求检视】fix: 修复LOSCFG_FS_FAT_CACHE宏关闭后编译失败的BUG
Merge pull request !731 from Far/master
上级
9b397173
63e71fec
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
169 addition
and
68 deletion
+169
-68
drivers/block/disk/include/disk.h
drivers/block/disk/include/disk.h
+7
-0
drivers/block/disk/src/disk.c
drivers/block/disk/src/disk.c
+115
-29
fs/fat/os_adapt/fatfs.c
fs/fat/os_adapt/fatfs.c
+47
-39
未找到文件。
drivers/block/disk/include/disk.h
浏览文件 @
5bed688c
...
...
@@ -165,6 +165,10 @@ extern "C" {
#define DISK_ATA_GET_MODEL 21
/* Get model name */
#define DISK_ATA_GET_SN 22
/* Get serial number */
#ifdef LOSCFG_FS_FAT_CACHE
#define DISK_DIRECT_BUFFER_SIZE 4
/* los_disk direct io buffer when bcache is off */
#endif
typedef
enum
_disk_status_
{
STAT_UNUSED
,
STAT_INUSED
,
...
...
@@ -187,6 +191,9 @@ typedef struct _los_disk_ {
CHAR
*
disk_name
;
LOS_DL_LIST
head
;
/* link head of all the partitions */
struct
pthread_mutex
disk_mutex
;
#ifndef LOSCFG_FS_FAT_CACHE
UINT8
*
buff
;
#endif
}
los_disk
;
typedef
struct
_los_part_
{
...
...
drivers/block/disk/src/disk.c
浏览文件 @
5bed688c
...
...
@@ -36,6 +36,10 @@
#include "sys/mount.h"
#include "linux/spinlock.h"
#include "path_cache.h"
#ifndef LOSCFG_FS_FAT_CACHE
#include "los_vm_common.h"
#include "user_copy.h"
#endif
los_disk
g_sysDisk
[
SYS_MAX_DISK
];
los_part
g_sysPart
[
SYS_MAX_PART
];
...
...
@@ -799,6 +803,78 @@ INT32 DiskPartitionRegister(los_disk *disk)
return
ENOERR
;
}
#ifndef LOSCFG_FS_FAT_CACHE
static
INT32
disk_read_directly
(
los_disk
*
disk
,
VOID
*
buf
,
UINT64
sector
,
UINT32
count
)
{
INT32
result
=
VFS_ERROR
;
struct
block_operations
*
bops
=
(
struct
block_operations
*
)((
struct
drv_data
*
)
disk
->
dev
->
data
)
->
ops
;
if
((
bops
==
NULL
)
||
(
bops
->
read
==
NULL
))
{
return
VFS_ERROR
;
}
if
(
LOS_IsUserAddressRange
((
VADDR_T
)
buf
,
count
*
disk
->
sector_size
))
{
UINT32
cnt
=
0
;
UINT8
*
buffer
=
disk
->
buff
;
for
(;
count
!=
0
;
count
-=
cnt
)
{
cnt
=
(
count
>
DISK_DIRECT_BUFFER_SIZE
)
?
DISK_DIRECT_BUFFER_SIZE
:
count
;
result
=
bops
->
read
(
disk
->
dev
,
buffer
,
sector
,
cnt
);
if
(
result
==
(
INT32
)
cnt
)
{
result
=
ENOERR
;
}
else
{
break
;
}
if
(
LOS_CopyFromKernel
(
buf
,
disk
->
sector_size
*
cnt
,
buffer
,
disk
->
sector_size
*
cnt
))
{
result
=
VFS_ERROR
;
break
;
}
buf
=
(
UINT8
*
)
buf
+
disk
->
sector_size
*
cnt
;
sector
+=
cnt
;
}
}
else
{
result
=
bops
->
read
(
disk
->
dev
,
buf
,
sector
,
count
);
if
(
result
==
count
)
{
result
=
ENOERR
;
}
}
return
result
;
}
static
INT32
disk_write_directly
(
los_disk
*
disk
,
const
VOID
*
buf
,
UINT64
sector
,
UINT32
count
)
{
struct
block_operations
*
bops
=
(
struct
block_operations
*
)((
struct
drv_data
*
)
disk
->
dev
->
data
)
->
ops
;
INT32
result
=
VFS_ERROR
;
if
((
bops
==
NULL
)
||
(
bops
->
read
==
NULL
))
{
return
VFS_ERROR
;
}
if
(
LOS_IsUserAddressRange
((
VADDR_T
)
buf
,
count
*
disk
->
sector_size
))
{
UINT32
cnt
=
0
;
UINT8
*
buffer
=
disk
->
buff
;
for
(;
count
!=
0
;
count
-=
cnt
)
{
cnt
=
(
count
>
DISK_DIRECT_BUFFER_SIZE
)
?
DISK_DIRECT_BUFFER_SIZE
:
count
;
if
(
LOS_CopyToKernel
(
buffer
,
disk
->
sector_size
*
cnt
,
buf
,
disk
->
sector_size
*
cnt
))
{
result
=
VFS_ERROR
;
break
;
}
result
=
bops
->
write
(
disk
->
dev
,
buffer
,
sector
,
cnt
);
if
(
result
==
(
INT32
)
cnt
)
{
result
=
ENOERR
;
}
else
{
break
;
}
buf
=
(
UINT8
*
)
buf
+
disk
->
sector_size
*
cnt
;
sector
+=
cnt
;
}
}
else
{
result
=
bops
->
write
(
disk
->
dev
,
buf
,
sector
,
count
);
if
(
result
==
count
)
{
result
=
ENOERR
;
}
}
return
result
;
}
#endif
INT32
los_disk_read
(
INT32
drvID
,
VOID
*
buf
,
UINT64
sector
,
UINT32
count
,
BOOL
useRead
)
{
#ifdef LOSCFG_FS_FAT_CACHE
...
...
@@ -837,21 +913,14 @@ INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL us
PRINT_ERR
(
"los_disk_read read err = %d, sector = %llu, len = %u
\n
"
,
result
,
sector
,
len
);
}
}
else
{
#endif
result
=
VFS_ERROR
;
}
#else
if
(
disk
->
dev
==
NULL
)
{
goto
ERROR_HANDLE
;
}
struct
block_operations
*
bops
=
(
struct
block_operations
*
)((
struct
drv_data
*
)
disk
->
dev
->
data
)
->
ops
;
if
((
bops
!=
NULL
)
&&
(
bops
->
read
!=
NULL
))
{
result
=
bops
->
read
(
disk
->
dev
,
(
UINT8
*
)
buf
,
sector
,
count
);
if
(
result
==
(
INT32
)
count
)
{
result
=
ENOERR
;
}
}
#ifdef LOSCFG_FS_FAT_CACHE
}
result
=
disk_read_directly
(
disk
,
buf
,
sector
,
count
);
#endif
if
(
result
!=
ENOERR
)
{
goto
ERROR_HANDLE
;
}
...
...
@@ -900,18 +969,14 @@ INT32 los_disk_write(INT32 drvID, const VOID *buf, UINT64 sector, UINT32 count)
PRINT_ERR
(
"los_disk_write write err = %d, sector = %llu, len = %u
\n
"
,
result
,
sector
,
len
);
}
}
else
{
#endif
struct
block_operations
*
bops
=
(
struct
block_operations
*
)((
struct
drv_data
*
)
disk
->
dev
->
data
)
->
ops
;
if
((
bops
!=
NULL
)
&&
(
bops
->
write
!=
NULL
))
{
result
=
bops
->
write
(
disk
->
dev
,
(
UINT8
*
)
buf
,
sector
,
count
);
if
(
result
==
(
INT32
)
count
)
{
result
=
ENOERR
;
}
result
=
VFS_ERROR
;
}
#ifdef LOSCFG_FS_FAT_CACHE
#else
if
(
disk
->
dev
==
NULL
)
{
goto
ERROR_HANDLE
;
}
result
=
disk_write_directly
(
disk
,
buf
,
sector
,
count
);
#endif
if
(
result
!=
ENOERR
)
{
goto
ERROR_HANDLE
;
}
...
...
@@ -1153,7 +1218,8 @@ ERROR_HANDLE:
INT32
los_disk_cache_clear
(
INT32
drvID
)
{
INT32
result
;
INT32
result
=
ENOERR
;
#ifdef LOSCFG_FS_FAT_CACHE
los_part
*
part
=
get_part
(
drvID
);
los_disk
*
disk
=
NULL
;
...
...
@@ -1161,7 +1227,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
return
VFS_ERROR
;
}
result
=
OsSdSync
(
part
->
disk_id
);
if
(
result
!=
0
)
{
if
(
result
!=
ENOERR
)
{
PRINTK
(
"[ERROR]disk_cache_clear SD sync failed!
\n
"
);
return
result
;
}
...
...
@@ -1174,7 +1240,7 @@ INT32 los_disk_cache_clear(INT32 drvID)
DISK_LOCK
(
&
disk
->
disk_mutex
);
result
=
BcacheClearCache
(
disk
->
bcache
);
DISK_UNLOCK
(
&
disk
->
disk_mutex
);
#endif
return
result
;
}
...
...
@@ -1324,6 +1390,10 @@ static INT32 DiskDeinit(los_disk *disk)
#ifdef LOSCFG_FS_FAT_CACHE
DiskCacheDeinit
(
disk
);
#else
if
(
disk
->
buff
!=
NULL
)
{
free
(
disk
->
buff
);
}
#endif
disk
->
dev
=
NULL
;
...
...
@@ -1344,12 +1414,15 @@ static INT32 DiskDeinit(los_disk *disk)
return
ENOERR
;
}
static
VOID
OsDiskInitSub
(
const
CHAR
*
diskName
,
INT32
diskID
,
los_disk
*
disk
,
struct
geometry
*
diskInfo
,
struct
Vnode
*
blkDriver
)
static
UINT32
OsDiskInitSub
(
const
CHAR
*
diskName
,
INT32
diskID
,
los_disk
*
disk
,
struct
geometry
*
diskInfo
,
struct
Vnode
*
blkDriver
)
{
pthread_mutexattr_t
attr
;
#ifdef LOSCFG_FS_FAT_CACHE
OsBcache
*
bc
=
DiskCacheInit
((
UINT32
)
diskID
,
diskInfo
,
blkDriver
);
if
(
bc
==
NULL
)
{
return
VFS_ERROR
;
}
disk
->
bcache
=
bc
;
#endif
...
...
@@ -1358,6 +1431,16 @@ static VOID OsDiskInitSub(const CHAR *diskName, INT32 diskID, los_disk *disk,
(
VOID
)
pthread_mutex_init
(
&
disk
->
disk_mutex
,
&
attr
);
DiskStructInit
(
diskName
,
diskID
,
diskInfo
,
blkDriver
,
disk
);
#ifndef LOSCFG_FS_FAT_CACHE
disk
->
buff
=
malloc
(
diskInfo
->
geo_sectorsize
*
DISK_DIRECT_BUFFER_SIZE
);
if
(
disk
->
buff
==
NULL
)
{
PRINT_ERR
(
"OsDiskInitSub: direct buffer of disk init failed
\n
"
);
return
VFS_ERROR
;
}
#endif
return
ENOERR
;
}
INT32
los_disk_init
(
const
CHAR
*
diskName
,
const
struct
block_operations
*
bops
,
...
...
@@ -1382,14 +1465,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
ret
=
VnodeLookup
(
diskName
,
&
blkDriver
,
0
);
if
(
ret
<
0
)
{
VnodeDrop
();
PRINT_ERR
(
"disk_init : find %s fail!
\n
"
,
diskName
);
ret
=
ENOENT
;
goto
DISK_FIND_ERROR
;
}
struct
block_operations
*
bops2
=
(
struct
block_operations
*
)((
struct
drv_data
*
)
blkDriver
->
data
)
->
ops
;
if
((
bops2
==
NULL
)
||
(
bops2
->
geometry
==
NULL
)
||
(
bops2
->
geometry
(
blkDriver
,
&
diskInfo
)
!=
0
))
{
if
((
bops2
==
NULL
)
||
(
bops2
->
geometry
==
NULL
)
||
(
bops2
->
geometry
(
blkDriver
,
&
diskInfo
)
!=
0
))
{
goto
DISK_BLKDRIVER_ERROR
;
}
...
...
@@ -1397,7 +1478,12 @@ INT32 los_disk_init(const CHAR *diskName, const struct block_operations *bops,
goto
DISK_BLKDRIVER_ERROR
;
}
OsDiskInitSub
(
diskName
,
diskID
,
disk
,
&
diskInfo
,
blkDriver
);
ret
=
OsDiskInitSub
(
diskName
,
diskID
,
disk
,
&
diskInfo
,
blkDriver
);
if
(
ret
!=
ENOERR
)
{
(
VOID
)
DiskDeinit
(
disk
);
VnodeDrop
();
return
VFS_ERROR
;
}
VnodeDrop
();
if
(
DiskDivideAndPartitionRegister
(
info
,
disk
)
!=
ENOERR
)
{
(
VOID
)
DiskDeinit
(
disk
);
...
...
fs/fat/os_adapt/fatfs.c
浏览文件 @
5bed688c
...
...
@@ -2053,45 +2053,18 @@ static UINT get_oldest_time(DIR_FILE df[], DWORD *oldest_time, UINT len)
return
index
;
}
int
fatfs_fscheck
(
struct
Vnode
*
vp
,
struct
fs_dirent_s
*
dir
)
static
FRESULT
fscheck
(
DIR
*
dp
)
{
FATFS
*
fs
=
(
FATFS
*
)
vp
->
originMount
->
data
;
DIR_FILE
df
[
CHECK_FILE_NUM
]
=
{
0
};
DIR
*
dp
=
NULL
;
FILINFO
*
finfo
=
&
(((
DIR_FILE
*
)(
vp
->
data
))
->
fno
);
FILINFO
fno
;
DWORD
old_time
=
-
1
;
DWORD
time
;
UINT
count
;
UINT
index
=
0
;
los_part
*
part
=
NULL
;
UINT
count
;
DWORD
time
;
DWORD
old_time
=
-
1
;
FRESULT
result
;
int
ret
;
if
(
fs
->
fs_type
!=
FS_FAT32
)
{
return
-
EINVAL
;
}
if
((
finfo
->
fattrib
&
AM_DIR
)
==
0
)
{
return
-
ENOTDIR
;
}
ret
=
fatfs_opendir
(
vp
,
dir
);
if
(
ret
<
0
)
{
return
ret
;
}
ret
=
lock_fs
(
fs
);
if
(
ret
==
FALSE
)
{
result
=
FR_TIMEOUT
;
goto
ERROR_WITH_DIR
;
}
dp
=
(
DIR
*
)
dir
->
u
.
fs_dir
;
dp
->
obj
.
id
=
fs
->
id
;
for
(
count
=
0
;
count
<
CHECK_FILE_NUM
;
count
++
)
{
if
((
result
=
f_readdir
(
dp
,
&
fno
))
!=
FR_OK
)
{
goto
ERROR_UNLOCK
;
return
result
;
}
else
{
if
(
fno
.
fname
[
0
]
==
0
||
fno
.
fname
[
0
]
==
(
TCHAR
)
0xFF
)
{
break
;
...
...
@@ -2116,15 +2089,50 @@ int fatfs_fscheck(struct Vnode* vp, struct fs_dirent_s *dir)
index
=
get_oldest_time
(
df
,
&
old_time
,
CHECK_FILE_NUM
);
}
}
if
(
result
!=
FR_OK
)
{
goto
ERROR_UNLOCK
;
index
=
0
;
while
(
result
==
FR_OK
&&
index
<
count
)
{
result
=
f_fcheckfat
(
&
df
[
index
]);
++
index
;
}
for
(
index
=
0
;
index
<
count
;
index
++
)
{
result
=
f_fcheckfat
(
&
df
[
index
]);
if
(
result
!=
FR_OK
)
{
goto
ERROR_UNLOCK
;
}
return
result
;
}
int
fatfs_fscheck
(
struct
Vnode
*
vp
,
struct
fs_dirent_s
*
dir
)
{
FATFS
*
fs
=
(
FATFS
*
)
vp
->
originMount
->
data
;
DIR
*
dp
=
NULL
;
FILINFO
*
finfo
=
&
(((
DIR_FILE
*
)(
vp
->
data
))
->
fno
);
#ifdef LOSCFG_FS_FAT_CACHE
los_part
*
part
=
NULL
;
#endif
FRESULT
result
;
int
ret
;
if
(
fs
->
fs_type
!=
FS_FAT32
)
{
return
-
EINVAL
;
}
if
((
finfo
->
fattrib
&
AM_DIR
)
==
0
)
{
return
-
ENOTDIR
;
}
ret
=
fatfs_opendir
(
vp
,
dir
);
if
(
ret
<
0
)
{
return
ret
;
}
ret
=
lock_fs
(
fs
);
if
(
ret
==
FALSE
)
{
result
=
FR_TIMEOUT
;
goto
ERROR_WITH_DIR
;
}
dp
=
(
DIR
*
)
dir
->
u
.
fs_dir
;
dp
->
obj
.
id
=
fs
->
id
;
result
=
fscheck
(
dp
);
if
(
result
!=
FR_OK
)
{
goto
ERROR_UNLOCK
;
}
unlock_fs
(
fs
,
FR_OK
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录