#ifndef __IHE_CORE_H #define __IHE_CORE_H #include #include #include #include #include #include #include #include #include #include /******************************************************************************* BASIC FILE OPERATIONS ON FILE ******************************************************************************/ #define FD_RO O_RDONLY #define FD_WO O_WRONLY #define FD_RW O_RDWR #define FD_MNONE 0 #define FD_SEEK_CUR SEEK_CUR #define FD_SEEK_SET SEEK_SET #define FD_SEEK_END SEEK_END /*OPEN FILE BY FILE NAME*/ int fd_open( const char *filename, int flags ); /*CLOSE FILE BY FD*/ int fd_close( int fd ); /*SEEK FILE FD - file descriptor OFFSET - seek pos WHENCE - seek mode NEW_OFFSET - new pos, helps to detect if actualy moved to new pos */ int fd_seek( int fd, off_t offset, int whence ); off_t fd_pos( int fd ); off_t fd_set_pos( int fd, off_t offset ); off_t fd_size( int fd ); /* READ from file FD - file descriptor BUF - where to write readed output COUNT - how much to read RETURN - size readed */ ssize_t fd_read( int fd, void *buf, size_t count ); ssize_t fd_write( int fd, void *buf, size_t count ); /* FILE RELATED UTILITIES */ /* CHECK IF YOU HAVE PERMISSIONS TO OPEN FILE MAYBE THIS IS FILE OF USER OR LOWER PERMISSION USER */ /* CHECK IF PATCH TO FILE EXCISTS */ /* GET PATH FILE TYPE COULD BE SOME DIRECTORY OR SOME LOOP FILE? */ /* GET DEFAULT PATHES THAT WILL IS NOT SUPPORTED /dev/radnom is not good to open /dev/ttyUSB also steaming files /dev/input/mice also is not good alt to open /proc//mmap also is not alterntice to open search and check for more */ /******************************************************************************* FILE OPERATION MANAGMENT STRUCTURE ******************************************************************************/ #define DEFAULT_BLK_SIZE 256 typedef struct file_t { const char *filename; int fd; /* fd is fd */ int flags; /* file opening flags */ int mode; /* file opening mode */ off_t offset; /* last used offset */ long position; /* file cursor position */ off_t size; /* file size*/ unsigned int blk_size; /*default block size to operate with*/ } file_t; file_t *file_init(); int file_open_fn( file_t *ft, const char *filename, int mode ); int file_open( file_t *ft, const char *filename, int flags, int mode ); int file_read_blk( file_t *ft, uint8_t *buf, int sz ); int file_read( file_t *ft, uint8_t *buf, size_t count ); int file_write_blk( file_t *ft, uint8_t *buf, int sz ); int file_write( file_t *ft, uint8_t *buf, size_t count ); int file_seek( file_t *ft, off_t offset ); //seek by offset int file_seekp( file_t *ft, off_t offset ); int file_pos( file_t *ft ); int file_size( file_t *ft ); int file_resize( file_t *ft, size_t size ); int file_s_bufs( file_t *ft, unsigned int size ); int file_s_mode( file_t *ft, int mode ); int file_close( file_t *ft ); /******************************************************************************* UTILITITIES ******************************************************************************/ /* LIST DIRECTORY FILES */ uint8_t **dir_list( char *path ); #endif