Просмотр исходного кода

fix: 补齐vfs相关实现的info方法

Wendal Chen 4 лет назад
Родитель
Сommit
d6b57f4ea1
5 измененных файлов с 50 добавлено и 5 удалено
  1. 16 1
      luat/vfs/luat_fs_fatfs.c
  2. 12 1
      luat/vfs/luat_fs_lfs2.c
  3. 10 1
      luat/vfs/luat_fs_luadb.c
  4. 11 1
      luat/vfs/luat_fs_posix.c
  5. 1 1
      luat/vfs/luat_vfs.c

+ 16 - 1
luat/vfs/luat_fs_fatfs.c

@@ -168,6 +168,20 @@ int luat_vfs_fatfs_rmdir(void* userdata, char const* _DirName) {
     LLOGE("not support yet : rmdir");
     return -1;
 }
+int luat_vfs_fatfs_info(void* userdata, const char* path, luat_fs_info_t *conf) {
+    DWORD fre_clust, fre_sect, tot_sect;
+    FATFS *fs = (FATFS*)userdata;
+
+    tot_sect = (fs->n_fatent - 2) * fs->csize;
+    fre_sect = fre_clust * fs->csize;
+
+    memcpy(conf->filesystem, "fatfs", strlen("fatfs")+1);
+    conf->type = 0;
+    conf->total_block = tot_sect;
+    conf->block_used = tot_sect - fre_sect;
+    conf->block_size = fs->csize;
+    return 0;
+}
 
 #define T(name) .name = luat_vfs_fatfs_##name
 const struct luat_vfs_filesystem vfs_fs_fatfs = {
@@ -181,7 +195,8 @@ const struct luat_vfs_filesystem vfs_fs_fatfs = {
         T(remove),
         T(rename),
         T(fsize),
-        T(fexist)
+        T(fexist),
+        T(info)
     },
     .fopts = {
         T(fopen),

+ 12 - 1
luat/vfs/luat_fs_lfs2.c

@@ -160,6 +160,16 @@ int luat_vfs_lfs2_rmdir(void* userdata, char const* _DirName) {
     return -1;
 }
 
+int luat_vfs_lfs2_info(void* userdata, const char* path, luat_fs_info_t *conf) {
+    lfs_t* fs = (lfs_t*)userdata;
+    memcpy(conf->filesystem, "lfs", strlen("lfs")+1);
+    conf->type = 0;
+    conf->total_block = fs->cfg->block_count;
+    conf->block_used = lfs_fs_size(fs);
+    conf->block_size = fs->cfg->block_size;
+    return 0;
+}
+
 #define T(name) .name = luat_vfs_lfs2_##name
 
 const struct luat_vfs_filesystem vfs_fs_lfs2 = {
@@ -173,7 +183,8 @@ const struct luat_vfs_filesystem vfs_fs_lfs2 = {
         T(remove),
         T(rename),
         T(fsize),
-        T(fexist)
+        T(fexist),
+        T(info)
     },
     .fopts = {
         T(fopen),

+ 10 - 1
luat/vfs/luat_fs_luadb.c

@@ -402,6 +402,14 @@ int luat_vfs_luadb_rmdir(void* userdata, char const* _DirName) {
     //LLOGE("not support yet : rmdir");
     return -1;
 }
+int luat_vfs_luadb_info(void* userdata, const char* path, luat_fs_info_t *conf) {
+    memcpy(conf->filesystem, "luadb", strlen("luadb")+1);
+    conf->type = 0;
+    conf->total_block = 0;
+    conf->block_used = 0;
+    conf->block_size = 512;
+    return 0;
+}
 
 #define T(name) .name = luat_vfs_luadb_##name
 const struct luat_vfs_filesystem vfs_fs_luadb = {
@@ -415,7 +423,8 @@ const struct luat_vfs_filesystem vfs_fs_luadb = {
         T(remove),
         T(rename),
         T(fsize),
-        T(fexist)
+        T(fexist),
+        T(info)
     },
     .fopts = {
         T(fopen),

+ 11 - 1
luat/vfs/luat_fs_posix.c

@@ -195,6 +195,15 @@ int luat_vfs_posix_rmdir(void* userdata, char const* _DirName) {
     //return rmdir(_DirName);
     return -1;
 }
+int luat_vfs_posix_info(void* userdata, const char* path, luat_fs_info_t *conf) {
+
+    memcpy(conf->filesystem, "posix", strlen("posix")+1);
+    conf->type = 0;
+    conf->total_block = 0;
+    conf->block_used = 0;
+    conf->block_size = 512;
+    return 0;
+}
 
 #define T(name) .name = luat_vfs_posix_##name
 const struct luat_vfs_filesystem vfs_fs_posix = {
@@ -208,7 +217,8 @@ const struct luat_vfs_filesystem vfs_fs_posix = {
         T(remove),
         T(rename),
         T(fsize),
-        T(fexist)
+        T(fexist),
+        T(info)
     },
     .fopts = {
         T(fopen),

+ 1 - 1
luat/vfs/luat_vfs.c

@@ -122,7 +122,7 @@ int luat_fs_info(const char* path, luat_fs_info_t *conf) {
         if (vfs.mounted[j].ok == 0)
             continue;
         if (strcmp(vfs.mounted[j].prefix, path) == 0) {
-            return vfs.mounted[j].fs->opts.info(vfs.mounted[j].userdata, path, conf);
+            return vfs.mounted[j].fs->opts.info(vfs.mounted[j].userdata, ((char*)path) + strlen(vfs.mounted[j].prefix), conf);
         }
     }
     LLOGE("no such mount point %s", path);