コード例 #1
0
ファイル: FATFileSystem.cpp プロジェクト: helmut64/mbed-os
int FATFileSystem::rename(const char *oldpath, const char *newpath) {
    Deferred<const char*> oldfpath = fat_path_prefix(_id, oldpath);
    Deferred<const char*> newfpath = fat_path_prefix(_id, newpath);

    lock();
    FRESULT res = f_rename(oldfpath, newfpath);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_rename() failed: %d\n", res);
    }
    return fat_error_remap(res);
}
コード例 #2
0
ファイル: FATFileSystem.cpp プロジェクト: OpenNuvoton/mbed
int FATFileSystem::stat(const char *path, struct stat *st)
{
    Deferred<const char*> fpath = fat_path_prefix(_id, path);

    lock();
    FILINFO f;
    memset(&f, 0, sizeof(f));

    FRESULT res = f_stat(fpath, &f);
    if (res != FR_OK) {
        unlock();
        return fat_error_remap(res);
    }

    /* ARMCC doesnt support stat(), and these symbols are not defined by the toolchain. */
#ifdef TOOLCHAIN_GCC
    st->st_size = f.fsize;
    st->st_mode = 0;
    st->st_mode |= (f.fattrib & AM_DIR) ? S_IFDIR : S_IFREG;
    st->st_mode |= (f.fattrib & AM_RDO) ?
        (S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) :
        (S_IRWXU | S_IRWXG | S_IRWXO);
#endif /* TOOLCHAIN_GCC */
    unlock();

    return 0;
}
コード例 #3
0
ファイル: FATFileSystem.cpp プロジェクト: helmut64/mbed-os
int FATFileSystem::mkdir(const char *path, mode_t mode) {
    Deferred<const char*> fpath = fat_path_prefix(_id, path);

    lock();
    FRESULT res = f_mkdir(fpath);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_mkdir() failed: %d\n", res);
    }
    return fat_error_remap(res);
}
コード例 #4
0
ファイル: FATFileSystem.cpp プロジェクト: betzw/mbed
int FATFileSystem::remove(const char *path)
{
    Deferred<const char*> fpath = fat_path_prefix(_id, path);

    lock();
    FRESULT res = f_unlink(fpath);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_unlink() failed: %d\n", res);
        if (res == FR_DENIED) {
            return -ENOTEMPTY;
        }
    }
    return fat_error_remap(res);
}
コード例 #5
0
ファイル: FATFileSystem.cpp プロジェクト: helmut64/mbed-os
////// Dir operations //////
int FATFileSystem::dir_open(fs_dir_t *dir, const char *path) {
    FATFS_DIR *dh = new FATFS_DIR;
    Deferred<const char*> fpath = fat_path_prefix(_id, path);

    lock();
    FRESULT res = f_opendir(dh, fpath);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_opendir() failed: %d\n", res);
        delete dh;
        return fat_error_remap(res);
    }

    *dir = dh;
    return 0;
}
コード例 #6
0
ファイル: FATFileSystem.cpp プロジェクト: OpenNuvoton/mbed
////// File operations //////
int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags)
{
    debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%s]\n", path, getName(), _id);

    FIL *fh = new FIL;
    Deferred<const char*> fpath = fat_path_prefix(_id, path);

    /* POSIX flags -> FatFS open mode */
    BYTE openmode;
    if (flags & O_RDWR) {
        openmode = FA_READ | FA_WRITE;
    } else if (flags & O_WRONLY) {
        openmode = FA_WRITE;
    } else {
        openmode = FA_READ;
    }

    if (flags & O_CREAT) {
        if (flags & O_TRUNC) {
            openmode |= FA_CREATE_ALWAYS;
        } else {
            openmode |= FA_OPEN_ALWAYS;
        }
    }

    if (flags & O_APPEND) {
        openmode |= FA_OPEN_APPEND;
    }

    lock();
    FRESULT res = f_open(fh, fpath, openmode);

    if (res != FR_OK) {
        unlock();
        debug_if(FFS_DBG, "f_open('w') failed: %d\n", res);
        delete fh;
        return fat_error_remap(res);
    }

    unlock();

    *file = fh;
    return 0;
}