Skip to content

Commit 1869c54

Browse files
zhuzhuzhuszhujiale
and
zhujiale
authored
[fix]fix tmpfs bug (#8970)
* first * second * thrid * Update SConscript * tmpfs testcase default n * Update dfs_tmpfs.c * format document --------- Co-authored-by: zhujiale <[email protected]>
1 parent 58e42ca commit 1869c54

File tree

5 files changed

+92
-6
lines changed

5 files changed

+92
-6
lines changed

Diff for: components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,17 @@ struct tmpfs_file *dfs_tmpfs_lookup(struct tmpfs_sb *superblock,
294294

295295
static ssize_t dfs_tmpfs_read(struct dfs_file *file, void *buf, size_t count, off_t *pos)
296296
{
297-
rt_size_t length;
297+
ssize_t length;
298298
struct tmpfs_file *d_file;
299-
300299
d_file = (struct tmpfs_file *)file->vnode->data;
301300
RT_ASSERT(d_file != NULL);
302301

303302
rt_mutex_take(&file->vnode->lock, RT_WAITING_FOREVER);
304-
305-
if (count < file->vnode->size - *pos)
303+
ssize_t size = (ssize_t)file->vnode->size;
304+
if ((ssize_t)count < size - *pos)
306305
length = count;
307306
else
308-
length = file->vnode->size - *pos;
307+
length = size - *pos;
309308

310309
if (length > 0)
311310
memcpy(buf, &(d_file->data[*pos]), length);

Diff for: examples/utest/testcases/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ source "$RTT_DIR/examples/utest/testcases/drivers/serial_v2/Kconfig"
1414
source "$RTT_DIR/examples/utest/testcases/drivers/ipc/Kconfig"
1515
source "$RTT_DIR/examples/utest/testcases/posix/Kconfig"
1616
source "$RTT_DIR/examples/utest/testcases/mm/Kconfig"
17-
17+
source "$RTT_DIR/examples/utest/testcases/tmpfs/Kconfig"
1818
endif
1919

2020
endmenu

Diff for: examples/utest/testcases/tmpfs/Kconfig

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
menu "Tmpfs Testcase"
2+
3+
config UTEST_TMPFS_CP
4+
bool "tmpfs cp test"
5+
default n
6+
endmenu

Diff for: examples/utest/testcases/tmpfs/SConscript

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Import('rtconfig')
2+
from building import *
3+
4+
cwd = GetCurrentDir()
5+
src = []
6+
CPPPATH = [cwd]
7+
8+
if GetDepend(['RT_USING_SMART','UTEST_TMPFS_CP']):
9+
src += ['tmpfs.c']
10+
11+
group = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES'], CPPPATH = CPPPATH)
12+
13+
Return('group')

Diff for: examples/utest/testcases/tmpfs/tmpfs.c

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2024-5-20 Zhujiale the first version
9+
*/
10+
#include <rtthread.h>
11+
#include <stdlib.h>
12+
#include <msh.h>
13+
#include "utest.h"
14+
#include "utest_assert.h"
15+
#include "common.h"
16+
17+
void run_copy()
18+
{
19+
int ret = 0;
20+
ret = msh_exec("cd /tmp", 7);
21+
if (ret != 0)
22+
{
23+
LOG_E("errno=%d, ret=%d\n", errno, ret);
24+
LOG_E("cd /tmp error");
25+
uassert_false(1);
26+
}
27+
uassert_true(1);
28+
ret = msh_exec("touch test", 10);
29+
if (ret != 0)
30+
{
31+
LOG_E("errno=%d, ret=%d\n", errno, ret);
32+
LOG_E("touch test error");
33+
uassert_false(1);
34+
}
35+
uassert_true(1);
36+
ret = msh_exec("echo this_is_a_test_file test", 29);
37+
if (ret != 0)
38+
{
39+
LOG_E("errno=%d, ret=%d\n", errno, ret);
40+
LOG_E("echo this_is_a_test_file test error");
41+
uassert_false(1);
42+
}
43+
uassert_true(1);
44+
ret = msh_exec("cp test test1", 13);
45+
if (ret != 0)
46+
{
47+
LOG_E("errno=%d, ret=%d\n", errno, ret);
48+
LOG_E("cp test test1 error");
49+
uassert_false(1);
50+
}
51+
52+
uassert_true(1);
53+
}
54+
55+
static rt_err_t utest_tc_init(void)
56+
{
57+
return RT_EOK;
58+
}
59+
60+
static rt_err_t utest_tc_cleanup(void)
61+
{
62+
return RT_EOK;
63+
}
64+
static void testcase(void)
65+
{
66+
UTEST_UNIT_RUN(run_copy);
67+
}
68+
UTEST_TC_EXPORT(testcase, "testcase.tfs.tmpfs", utest_tc_init, utest_tc_cleanup, 10);

0 commit comments

Comments
 (0)