【问题标题】:Querying free space in LocalFileSystem on the MBED board查询 MBED 板上 LocalFileSystem 中的可用空间
【发布时间】:2016-12-20 05:05:15
【问题描述】:

是否有任何受支持的 API 可以在 MBED 板上的 LocalFileSystem 中获取可用空间?我试过statvfs,但它似乎不起作用......有什么想法吗?

我想我可以简单地列出所有文件并从总大小中减去总大小,但我想知道是否有更好的方法。

这是我尝试过的:

long GetAvailableSpace(const char* path)
{
  struct statvfs stat;

  if (statvfs(path, &stat) != 0) {
    // error happens, just quits here
    return -1;
  }

  // the available size is f_bsize * f_bavail
  return stat.f_bsize * stat.f_bavail;
}

更新:

我最终遍历所有文件并计算它:

#define MAX_STORAGE 512000

int LocalFileSystemFreeSpace(){
    char filename[MAX_FILENAME];
    DIR *d;
    struct dirent *dir;
    int total = 0;

    d = opendir("/local");
    if(d){
        while((dir = readdir(d)) != NULL){
            sprintf(filename, "/local/%s", dir->d_name);
            int size = FileSize(filename);
            total += size;
            //printf("%s -> %d\r\n",filename,size);
        }
        closedir(d);
    }

//    printf("Total files: %d\r\n", total);
//    printf("Free: %d\r\n",MAX_STORAGE-total);

    return MAX_STORAGE-total;
}

int FileSize(char * filename){
    FILE * fp = fopen(filename,"r");
    if(fp==NULL){ 
        return 0; 
    }
    int prev=ftell(fp);
    fseek(fp, 0L, SEEK_END);
    int sz=ftell(fp);
    fclose(fp);
    return sz;
} 

【问题讨论】:

    标签: lpc mbed


    【解决方案1】:

    我认为现在不可能。 Semihosting 用于 LocalFileSystem API,当前实现的唯一命令是 here。没有可用的磁盘空间...

    【讨论】:

    • 谢谢 Jan,我就是这么怀疑的。
    猜你喜欢
    • 2012-08-04
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多