Skip to content
Snippets Groups Projects
Select Git revision
  • add-utime-unix_time-expansion
  • add-monotonic-time
  • add-digiclk
  • master default protected
  • genofire/rockets-state
  • genofire/ble-follow-py
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • genofire/haule-ble-fs-deactive
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • renze/safe_mode
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
33 results

fileops.c

Blame
  • Forked from card10 / firmware
    1320 commits behind the upstream repository.
    fileops.c 3.00 KiB
    /**
     * Implemention of the epicardium epic_file_ api that operates on
     * the global EpicFileSystem instance
     *
     * All functions lock & unlock the global FS object
     *
     */
    
    #include "fs/internal.h"
    
    #if defined(__GNUC__) &&                                                       \
    	((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
    #define HAVE_STATIC_ASSERT 1
    #elif defined(__clang__)
    #define HAVE_STATIC_ASSERT 1
    #endif
    #if HAVE_STATIC_ASSERT
    _Static_assert(sizeof(struct epic_stat) == 276, "");
    #endif
    
    int epic_file_open(const char *filename, const char *mode)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_open(fs, filename, mode);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_close(int fd)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_close(fs, fd);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_read(int fd, void *buf, size_t nbytes)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_read(fs, fd, buf, nbytes);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_write(int fd, const void *buf, size_t nbytes)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_write(fs, fd, buf, nbytes);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_flush(int fd)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_flush(fs, fd);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_seek(int fd, long offset, int whence)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_seek(fs, fd, offset, whence);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_tell(int fd)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_tell(fs, fd);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_stat(const char *filename, struct epic_stat *stat)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_stat(fs, filename, stat);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_opendir(const char *path)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_opendir(fs, path);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_readdir(int fd, struct epic_stat *stat)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_readdir(fs, fd, stat);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_unlink(const char *path)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_unlink(fs, path);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_rename(const char *oldp, const char *newp)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_rename(fs, oldp, newp);
    		efs_unlock_global(fs);
    	}
    	return res;
    }
    
    int epic_file_mkdir(const char *dirname)
    {
    	EpicFileSystem *fs;
    	int res = efs_lock_global(&fs);
    	if (res == 0) {
    		res = efs_mkdir(fs, dirname);
    		efs_unlock_global(fs);
    	}
    	return res;
    }