fs: Add fs_dir_t_init() function
The fs_dir_t_init() function has been added that should be used for initialization of fs_dir_t structures before passing them to fs_open and other functions. Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
parent
e69c357e78
commit
109f1ab42b
5 changed files with 36 additions and 3 deletions
|
@ -234,6 +234,20 @@ static inline void fs_file_t_init(struct fs_file_t *zfp)
|
|||
*zfp = (struct fs_file_t){ 0 };
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize fs_dir_t object
|
||||
*
|
||||
* Initializes the fs_dir_t object; the function needs to be invoked
|
||||
* on object before first use with fs_opendir.
|
||||
*
|
||||
* @param zdp Pointer to file object
|
||||
*
|
||||
*/
|
||||
static inline void fs_dir_t_init(struct fs_dir_t *zdp)
|
||||
{
|
||||
*zdp = (struct fs_dir_t){ 0 };
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Open or create file
|
||||
*
|
||||
|
|
|
@ -59,6 +59,8 @@ struct fs_file_t {
|
|||
/**
|
||||
* @brief Directory object representing an open directory
|
||||
*
|
||||
* The object needs to be initialized with function fs_dir_t_init().
|
||||
*
|
||||
* @param dirp Pointer to directory object structure
|
||||
* @param mp Pointer to mount point structure
|
||||
*/
|
||||
|
|
|
@ -73,6 +73,7 @@ void test_main(void)
|
|||
fs_setup,
|
||||
dummy_teardown),
|
||||
ztest_unit_test(test_fs_file_t_init),
|
||||
ztest_unit_test(test_fs_dir_t_init),
|
||||
ztest_unit_test(test_file_statvfs),
|
||||
ztest_unit_test(test_mkdir),
|
||||
ztest_unit_test(test_opendir),
|
||||
|
|
|
@ -32,6 +32,7 @@ struct test_fs_data {
|
|||
int reserve;
|
||||
};
|
||||
|
||||
void test_fs_dir_t_init(void);
|
||||
void test_fs_file_t_init(void);
|
||||
void test_fs_register(void);
|
||||
void test_mount(void);
|
||||
|
|
|
@ -93,6 +93,20 @@ void test_fs_file_t_init(void)
|
|||
zassert_equal(fst.flags, 0, "Expected to be initialized to 0");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test fs_dir_t_init initializer
|
||||
*/
|
||||
void test_fs_dir_t_init(void)
|
||||
{
|
||||
struct fs_dir_t dirp;
|
||||
|
||||
memset(&dirp, 0xff, sizeof(dirp));
|
||||
|
||||
fs_dir_t_init(&dirp);
|
||||
zassert_equal(dirp.mp, NULL, "Expected to be initialized to NULL");
|
||||
zassert_equal(dirp.dirp, NULL, "Expected to be initialized to NULL");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test mount interface of filesystem
|
||||
*
|
||||
|
@ -263,7 +277,8 @@ void test_opendir(void)
|
|||
|
||||
TC_PRINT("\nopendir tests:\n");
|
||||
|
||||
memset(&dirp, 0, sizeof(dirp));
|
||||
fs_dir_t_init(&dirp);
|
||||
|
||||
TC_PRINT("Test null path\n");
|
||||
ret = fs_opendir(NULL, NULL);
|
||||
zassert_not_equal(ret, 0, "Open dir with NULL pointer parameter");
|
||||
|
@ -307,7 +322,7 @@ void test_closedir(void)
|
|||
struct fs_dir_t dirp;
|
||||
|
||||
TC_PRINT("\nclosedir tests: %s\n", TEST_DIR);
|
||||
memset(&dirp, 0, sizeof(dirp));
|
||||
fs_dir_t_init(&dirp);
|
||||
ret = fs_opendir(&dirp, TEST_DIR);
|
||||
zassert_equal(ret, 0, "Fail to open dir");
|
||||
|
||||
|
@ -331,7 +346,7 @@ static int _test_lsdir(const char *path)
|
|||
|
||||
TC_PRINT("\nlsdir tests:\n");
|
||||
|
||||
memset(&dirp, 0, sizeof(dirp));
|
||||
fs_dir_t_init(&dirp);
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
|
||||
TC_PRINT("read an unopened dir\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue