summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2022-05-09 21:31:45 -0400
committerJoey Castillo <joeycastillo@utexas.edu>2022-05-09 21:33:45 -0400
commit3a9dd0df085292871ff9b124475ac1cfa3846301 (patch)
tree7f14f92a65d64cd4ab67edeb70dc0f0cd7e3a6d0
parent8455bfc9a5b07d58fcabf35bba6f32837ea91f46 (diff)
downloadSensor-Watch-3a9dd0df085292871ff9b124475ac1cfa3846301.tar.gz
Sensor-Watch-3a9dd0df085292871ff9b124475ac1cfa3846301.tar.bz2
Sensor-Watch-3a9dd0df085292871ff9b124475ac1cfa3846301.zip
unify on 32-bit signed lengths
-rw-r--r--movement/filesystem.c10
-rw-r--r--movement/filesystem.h8
2 files changed, 12 insertions, 6 deletions
diff --git a/movement/filesystem.c b/movement/filesystem.c
index dc1f98c6..d122a7fa 100644
--- a/movement/filesystem.c
+++ b/movement/filesystem.c
@@ -60,7 +60,7 @@ static int _traverse_df_cb(void *p, lfs_block_t block) {
return 0;
}
-int filesystem_get_free_space(void) {
+int32_t filesystem_get_free_space(void) {
int err;
uint32_t free_blocks = 0;
@@ -71,7 +71,7 @@ int filesystem_get_free_space(void) {
uint32_t available = cfg.block_count * cfg.block_size - free_blocks * cfg.block_size;
- return available;
+ return (int32_t)available;
}
static int filesystem_ls(lfs_t *lfs, const char *path) {
@@ -121,7 +121,7 @@ bool filesystem_init(void) {
err = lfs_format(&lfs, &cfg);
if (err < 0) return false;
err = lfs_mount(&lfs, &cfg) == LFS_ERR_OK;
- printf("Filesystem mounted with %d bytes free.\n", filesystem_get_free_space());
+ printf("Filesystem mounted with %ld bytes free.\n", filesystem_get_free_space());
}
return err == LFS_ERR_OK;
@@ -144,7 +144,7 @@ bool filesystem_rm(char *filename) {
}
}
-static int32_t filesystem_get_file_size(char *filename) {
+int32_t filesystem_get_file_size(char *filename) {
if (filesystem_file_exists(filename)) {
return info.size; // info struct was just populated by filesystem_file_exists
}
@@ -210,7 +210,7 @@ void filesystem_process_command(char *line) {
filesystem_cat(filename);
}
} else if (strcmp(command, "df") == 0) {
- printf("free space: %d bytes\n", filesystem_get_free_space());
+ printf("free space: %ld bytes\n", filesystem_get_free_space());
} else if (strcmp(command, "rm") == 0) {
char *filename = strtok(NULL, " \n");
if (filename == NULL) {
diff --git a/movement/filesystem.h b/movement/filesystem.h
index c9a5804c..b0fb7f58 100644
--- a/movement/filesystem.h
+++ b/movement/filesystem.h
@@ -36,7 +36,7 @@ bool filesystem_init(void);
/** @brief Gets the space available on the filesystem.
* @return the free space in bytes
*/
-int filesystem_get_free_space(void);
+int32_t filesystem_get_free_space(void);
/** @brief Checks for the existence of a file on the filesystem.
* @param filename the file you wish to check
@@ -50,6 +50,12 @@ bool filesystem_file_exists(char *filename);
*/
bool filesystem_rm(char *filename);
+/** @brief Gets the size of a file on the filesystem.
+ * @param filename the file whose size you wish to determine
+ * @return the file's size in bytes, or -1 if the file does not exist.
+ */
+int32_t filesystem_get_file_size(char *filename);
+
/** @brief Reads a file from the filesystem into a buffer
* @param filename the file you wish to read
* @param buf A buffer of at least length bytes; the file will be read into this buffer