Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wink
firmware
Commits
14613996
Commit
14613996
authored
5 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
feat(ff13): add some util functions
parent
a6d2a216
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/ff13/meson.build
+2
-0
2 additions, 0 deletions
lib/ff13/meson.build
lib/ff13/util/fs_util.c
+106
-0
106 additions, 0 deletions
lib/ff13/util/fs_util.c
lib/ff13/util/fs_util.h
+24
-0
24 additions, 0 deletions
lib/ff13/util/fs_util.h
with
132 additions
and
0 deletions
lib/ff13/meson.build
+
2
−
0
View file @
14613996
includes
=
include_directories
(
'./Source/'
,
'./util/'
,
)
sources
=
files
(
...
...
@@ -7,6 +8,7 @@ sources = files(
'./Source/ff.c'
,
'./Source/ffsystem.c'
,
'./Source/ffunicode.c'
,
'./util/fs_util.c'
,
)
lib
=
static_library
(
...
...
This diff is collapsed.
Click to expand it.
lib/ff13/util/fs_util.c
0 → 100644
+
106
−
0
View file @
14613996
#include
<fs_util.h>
#include
<ff.h>
#include
<stdint.h>
#include
<string.h>
FATFS
FatFs
;
/* File system object for logical drive */
FS_USAGE
FsUsage
;
int
fs_info
(
FATFS
*
fs
)
{
memcpy
(
fs
,
&
FatFs
,
sizeof
(
FATFS
));
return
0
;
}
int
fs_usage
(
FATFS
*
fs
,
FS_USAGE
*
fs_usage
)
{
FRESULT
res
;
DWORD
tot_clust
,
fre_clust
,
sec_size
;
res
=
f_getfree
(
"/"
,
&
fre_clust
,
&
fs
);
if
(
res
!=
FR_OK
)
return
-
res
;
// sectore size = sectors per cluster * sector size
#if FF_MAX_SS == FF_MIN_SS
sec_size
=
fs
->
csize
*
FF_MAX_SS
;
#else
sec_size
=
fs
->
csize
*
fs
.
ssize
;
#endif
// total/free sectors * sectore size
tot_clust
=
fs
->
n_fatent
-
2
;
fs_usage
->
total
=
tot_clust
*
sec_size
;
//FatFs.ssize;
fs_usage
->
free
=
fre_clust
*
sec_size
;
//FatFs.ssize;
return
0
;
}
int
fs_read_file
(
char
*
filename
,
void
*
data
,
int
len
){
FIL
file
;
UINT
readbytes
;
int
res
;
res
=
f_open
(
&
file
,
filename
,
FA_OPEN_EXISTING
|
FA_READ
);
if
(
res
){
return
-
1
;
};
res
=
f_read
(
&
file
,
data
,
len
,
&
readbytes
);
if
(
res
){
return
-
1
;
};
f_close
(
&
file
);
return
readbytes
;
}
int
fs_read_text_file
(
char
*
filename
,
char
*
data
,
int
len
){
int
readbytes
;
if
(
len
<
1
)
return
-
1
;
readbytes
=
fs_read_file
(
filename
,
data
,
len
-
1
);
if
(
readbytes
<
0
){
data
[
0
]
=
0
;
return
readbytes
;
};
data
[
readbytes
]
=
0
;
while
(
readbytes
>
0
&&
data
[
readbytes
-
1
]
<
0x20
){
data
[
--
readbytes
]
=
0
;
};
return
readbytes
;
}
int
fs_write_file
(
char
*
filename
,
const
void
*
data
,
int
len
){
FIL
file
;
UINT
writebytes
;
int
res
;
res
=
f_open
(
&
file
,
filename
,
FA_CREATE_ALWAYS
|
FA_WRITE
);
if
(
res
){
return
-
res
;
};
res
=
f_write
(
&
file
,
data
,
len
,
&
writebytes
);
if
(
res
){
return
-
res
;
};
f_close
(
&
file
);
return
writebytes
;
}
int
fs_get_file_size
(
char
*
filename
){
FILINFO
finfo
;
int
res
;
/// XXX: Untested
res
=
f_stat
(
filename
,
&
finfo
);
if
(
res
){
return
-
1
;
}
return
finfo
.
fsize
;
}
This diff is collapsed.
Click to expand it.
lib/ff13/util/fs_util.h
0 → 100644
+
24
−
0
View file @
14613996
#ifndef _FS_UTIL_H
#define _FS_UTIL_H 1
#include
<ff.h>
#define FLEN 13
typedef
struct
{
DWORD
total
;
DWORD
free
;
}
FS_USAGE
;
void
fsInit
(
void
);
void
fsReInit
(
void
);
int
fsInfo
(
FATFS
*
fs
);
int
fsUsage
(
FATFS
*
fs
,
FS_USAGE
*
fs_usage
);
int
readFile
(
char
*
filename
,
void
*
data
,
int
len
);
int
readTextFile
(
char
*
filename
,
char
*
data
,
int
len
);
int
writeFile
(
char
*
filename
,
const
void
*
data
,
int
len
);
int
getFileSize
(
char
*
filename
);
const
char
*
f_get_rc_string
(
FRESULT
rc
);
#endif
/* _FS_UTIL_H */
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