Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
5fb07e89
Commit
5fb07e89
authored
7 years ago
by
Joakim Nohlgård
Browse files
Options
Downloads
Patches
Plain Diff
pkg/fatfs: refactor absolute path handling
parent
b378bd4e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/fatfs/fatfs_vfs/fatfs_vfs.c
+25
-23
25 additions, 23 deletions
pkg/fatfs/fatfs_vfs/fatfs_vfs.c
with
25 additions
and
23 deletions
pkg/fatfs/fatfs_vfs/fatfs_vfs.c
+
25
−
23
View file @
5fb07e89
...
@@ -36,6 +36,17 @@
...
@@ -36,6 +36,17 @@
static
int
fatfs_err_to_errno
(
int32_t
err
);
static
int
fatfs_err_to_errno
(
int32_t
err
);
static
void
_fatfs_time_to_timespec
(
WORD
fdate
,
WORD
ftime
,
time_t
*
time
);
static
void
_fatfs_time_to_timespec
(
WORD
fdate
,
WORD
ftime
,
time_t
*
time
);
/**
* @brief Concatenate drive number and path into the buffer provided by fs_desc
*
* Most FatFs library file operations need an absolute path.
*/
static
void
_build_abs_path
(
fatfs_desc_t
*
fs_desc
,
const
char
*
name
)
{
snprintf
(
fs_desc
->
abs_path_str_buff
,
FATFS_MAX_ABS_PATH_SIZE
,
"%u:/%s"
,
fs_desc
->
vol_idx
,
name
);
}
static
int
_mount
(
vfs_mount_t
*
mountp
)
static
int
_mount
(
vfs_mount_t
*
mountp
)
{
{
/* if one of the lines below fail to compile you probably need to adjust
/* if one of the lines below fail to compile you probably need to adjust
...
@@ -45,13 +56,12 @@ static int _mount(vfs_mount_t *mountp)
...
@@ -45,13 +56,12 @@ static int _mount(vfs_mount_t *mountp)
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
char
volume_str
[
FATFS_MAX_VOL_STR_LEN
];
_build_abs_path
(
fs_desc
,
""
);
snprintf
(
volume_str
,
sizeof
(
volume_str
),
"%d:/"
,
fs_desc
->
vol_idx
);
memset
(
&
fs_desc
->
fat_fs
,
0
,
sizeof
(
fs_desc
->
fat_fs
));
memset
(
&
fs_desc
->
fat_fs
,
0
,
sizeof
(
fs_desc
->
fat_fs
));
DEBUG
(
"mounting file system of volume '%s'
\n
"
,
volume_str
);
DEBUG
(
"mounting file system of volume '%s'
\n
"
,
fs_desc
->
abs_path_str_buff
);
FRESULT
res
=
f_mount
(
&
fs_desc
->
fat_fs
,
volume_str
,
1
);
FRESULT
res
=
f_mount
(
&
fs_desc
->
fat_fs
,
fs_desc
->
abs_path_str_buff
,
1
);
if
(
res
==
FR_OK
)
{
if
(
res
==
FR_OK
)
{
DEBUG
(
"[OK]"
);
DEBUG
(
"[OK]"
);
...
@@ -69,11 +79,10 @@ static int _umount(vfs_mount_t *mountp)
...
@@ -69,11 +79,10 @@ static int _umount(vfs_mount_t *mountp)
DEBUG
(
"fatfs_vfs.c: _umount: private_data = %p
\n
"
,
mountp
->
private_data
);
DEBUG
(
"fatfs_vfs.c: _umount: private_data = %p
\n
"
,
mountp
->
private_data
);
char
volume_str
[
FATFS_MAX_VOL_STR_LEN
];
_build_abs_path
(
fs_desc
,
""
);
snprintf
(
volume_str
,
sizeof
(
volume_str
),
"%d:/"
,
fs_desc
->
vol_idx
);
DEBUG
(
"unmounting file system of volume '%s'
\n
"
,
volume_str
);
DEBUG
(
"unmounting file system of volume '%s'
\n
"
,
fs_desc
->
abs_path_str_buff
);
FRESULT
res
=
f_unmount
(
volume_str
);
FRESULT
res
=
f_unmount
(
fs_desc
->
abs_path_str_buff
);
if
(
res
==
FR_OK
)
{
if
(
res
==
FR_OK
)
{
DEBUG
(
"[OK]"
);
DEBUG
(
"[OK]"
);
...
@@ -90,8 +99,7 @@ static int _unlink(vfs_mount_t *mountp, const char *name)
...
@@ -90,8 +99,7 @@ static int _unlink(vfs_mount_t *mountp, const char *name)
{
{
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
snprintf
(
fs_desc
->
abs_path_str_buff
,
FATFS_MAX_ABS_PATH_SIZE
,
"%d:/%s"
,
_build_abs_path
(
fs_desc
,
name
);
fs_desc
->
vol_idx
,
name
);
return
fatfs_err_to_errno
(
f_unlink
(
fs_desc
->
abs_path_str_buff
));
return
fatfs_err_to_errno
(
f_unlink
(
fs_desc
->
abs_path_str_buff
));
}
}
...
@@ -102,10 +110,9 @@ static int _rename(vfs_mount_t *mountp, const char *from_path,
...
@@ -102,10 +110,9 @@ static int _rename(vfs_mount_t *mountp, const char *from_path,
char
fatfs_abs_path_to
[
FATFS_MAX_ABS_PATH_SIZE
];
char
fatfs_abs_path_to
[
FATFS_MAX_ABS_PATH_SIZE
];
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
snprintf
(
fs_desc
->
abs_path_str_buff
,
FATFS_MAX_ABS_PATH_SIZE
,
"%d:/%s"
,
_build_abs_path
(
fs_desc
,
from_path
);
fs_desc
->
vol_idx
,
from_path
);
snprintf
(
fatfs_abs_path_to
,
sizeof
(
fatfs_abs_path_to
),
"%
d
:/%s"
,
snprintf
(
fatfs_abs_path_to
,
sizeof
(
fatfs_abs_path_to
),
"%
u
:/%s"
,
fs_desc
->
vol_idx
,
to_path
);
fs_desc
->
vol_idx
,
to_path
);
return
fatfs_err_to_errno
(
f_rename
(
fs_desc
->
abs_path_str_buff
,
return
fatfs_err_to_errno
(
f_rename
(
fs_desc
->
abs_path_str_buff
,
...
@@ -117,8 +124,7 @@ static int _open(vfs_file_t *filp, const char *name, int flags, mode_t mode,
...
@@ -117,8 +124,7 @@ static int _open(vfs_file_t *filp, const char *name, int flags, mode_t mode,
{
{
fatfs_file_desc_t
*
fd
=
(
fatfs_file_desc_t
*
)
&
filp
->
private_data
.
buffer
[
0
];
fatfs_file_desc_t
*
fd
=
(
fatfs_file_desc_t
*
)
&
filp
->
private_data
.
buffer
[
0
];
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
filp
->
mp
->
private_data
;
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
filp
->
mp
->
private_data
;
snprintf
(
fs_desc
->
abs_path_str_buff
,
FATFS_MAX_ABS_PATH_SIZE
,
"%d:/%s"
,
_build_abs_path
(
fs_desc
,
name
);
fs_desc
->
vol_idx
,
name
);
(
void
)
abs_path
;
(
void
)
abs_path
;
(
void
)
mode
;
/* fatfs can't use mode param with f_open*/
(
void
)
mode
;
/* fatfs can't use mode param with f_open*/
...
@@ -251,8 +257,7 @@ static int _fstat(vfs_file_t *filp, struct stat *buf)
...
@@ -251,8 +257,7 @@ static int _fstat(vfs_file_t *filp, struct stat *buf)
FILINFO
fi
;
FILINFO
fi
;
FRESULT
res
;
FRESULT
res
;
snprintf
(
fs_desc
->
abs_path_str_buff
,
FATFS_MAX_ABS_PATH_SIZE
,
"%d:/%s"
,
_build_abs_path
(
fs_desc
,
fd
->
fname
);
fs_desc
->
vol_idx
,
fd
->
fname
);
memset
(
buf
,
0
,
sizeof
(
*
buf
));
memset
(
buf
,
0
,
sizeof
(
*
buf
));
...
@@ -295,8 +300,7 @@ static int _opendir(vfs_DIR *dirp, const char *dirname, const char *abs_path)
...
@@ -295,8 +300,7 @@ static int _opendir(vfs_DIR *dirp, const char *dirname, const char *abs_path)
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
dirp
->
mp
->
private_data
;
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
dirp
->
mp
->
private_data
;
(
void
)
abs_path
;
(
void
)
abs_path
;
snprintf
(
fs_desc
->
abs_path_str_buff
,
FATFS_MAX_ABS_PATH_SIZE
,
"%d:/%s"
,
_build_abs_path
(
fs_desc
,
dirname
);
fs_desc
->
vol_idx
,
dirname
);
return
fatfs_err_to_errno
(
f_opendir
(
dir
,
fs_desc
->
abs_path_str_buff
));
return
fatfs_err_to_errno
(
f_opendir
(
dir
,
fs_desc
->
abs_path_str_buff
));
}
}
...
@@ -334,8 +338,7 @@ static int _mkdir (vfs_mount_t *mountp, const char *name, mode_t mode)
...
@@ -334,8 +338,7 @@ static int _mkdir (vfs_mount_t *mountp, const char *name, mode_t mode)
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
(
void
)
mode
;
(
void
)
mode
;
snprintf
(
fs_desc
->
abs_path_str_buff
,
FATFS_MAX_ABS_PATH_SIZE
,
"%d:/%s"
,
_build_abs_path
(
fs_desc
,
name
);
fs_desc
->
vol_idx
,
name
);
return
fatfs_err_to_errno
(
f_mkdir
(
fs_desc
->
abs_path_str_buff
));
return
fatfs_err_to_errno
(
f_mkdir
(
fs_desc
->
abs_path_str_buff
));
}
}
...
@@ -344,8 +347,7 @@ static int _rmdir (vfs_mount_t *mountp, const char *name)
...
@@ -344,8 +347,7 @@ static int _rmdir (vfs_mount_t *mountp, const char *name)
{
{
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
fatfs_desc_t
*
fs_desc
=
(
fatfs_desc_t
*
)
mountp
->
private_data
;
snprintf
(
fs_desc
->
abs_path_str_buff
,
FATFS_MAX_ABS_PATH_SIZE
,
"%d:/%s"
,
_build_abs_path
(
fs_desc
,
name
);
fs_desc
->
vol_idx
,
name
);
return
fatfs_err_to_errno
(
f_unlink
(
fs_desc
->
abs_path_str_buff
));
return
fatfs_err_to_errno
(
f_unlink
(
fs_desc
->
abs_path_str_buff
));
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment