
HTTP File Server using SD Card for Arch Max
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed
Fork of HTTP_SDcard_file_server by
filelib.h
00001 #ifndef filelib 00002 #define filelib 00003 00004 #include "mbed.h" 00005 #include <time.h> 00006 #include <ff.h> //found in lib SDFileSystem->FATFileSystem/ChaN 00007 #include "SDFileSystem.h" 00008 00009 00010 /* 00011 typedef enum { 00012 FR_OK = 0, // (0) Succeeded 00013 FR_DISK_ERR, // (1) A hard error occurred in the low level disk I/O layer 00014 FR_INT_ERR, // (2) Assertion failed 00015 FR_NOT_READY, // (3) The physical drive cannot work 00016 FR_NO_FILE, // (4) Could not find the file 00017 FR_NO_PATH, // (5) Could not find the path 00018 FR_INVALID_NAME, // (6) The path name format is invalid 00019 FR_DENIED, // (7) Access denied due to prohibited access or directory full 00020 FR_EXIST, // (8) Access denied due to prohibited access 00021 FR_INVALID_OBJECT, // (9) The file/directory object is invalid 00022 FR_WRITE_PROTECTED, // (10) The physical drive is write protected 00023 FR_INVALID_DRIVE, // (11) The logical drive number is invalid 00024 FR_NOT_ENABLED, // (12) The volume has no work area 00025 FR_NO_FILESYSTEM, // (13) There is no valid FAT volume 00026 FR_MKFS_ABORTED, // (14) The f_mkfs() aborted due to any parameter error 00027 FR_TIMEOUT, // (15) Could not get a grant to access the volume within defined period 00028 FR_LOCKED, // (16) The operation is rejected according to the file sharing policy 00029 FR_NOT_ENOUGH_CORE, // (17) LFN working buffer could not be allocated 00030 FR_TOO_MANY_OPEN_FILES, // (18) Number of open files > _FS_SHARE 00031 FR_INVALID_PARAMETER // (19) Given parameter is invalid 00032 } FRESULT; 00033 00034 */ 00035 /* 00036 mode_t values in octal 00037 S_IFREG 0100000 00038 S_IFDIR 040000 00039 S_IRUSR 0400 read permission, owner 00040 S_IWUSR 0200 write permission, owner 00041 S_IXUSR 0100 execute/search permission, owner 00042 S_IRGRP 040 read permission, group 00043 S_IWGRP 020 write permission, group 00044 S_IXGRP 010 execute/search permission, group 00045 S_IROTH 04 read permission, others 00046 S_IWOTH 02 write permission, others 00047 S_IXOTH 01 execute/search permission, others 00048 */ 00049 struct sMystat { 00050 // dev_t st_dev; /* ID of device containing file */ 00051 // ino_t st_ino; /* inode number */ 00052 mode_t st_mode; /* protection */ 00053 // nlink_t st_nlink; /* number of hard links */ 00054 // uid_t st_uid; /* user ID of owner */ 00055 // gid_t st_gid; /* group ID of owner */ 00056 // dev_t st_rdev; /* device ID (if special file) */ 00057 // off_t st_size; /* total size, in bytes */ 00058 DWORD st_size; /* total size, in bytes */ 00059 // blksize_t st_blksize; /* blocksize for file system I/O */ 00060 // blkcnt_t st_blocks; /* number of 512B blocks allocated */ 00061 // time_t st_atime; /* time of last access */ 00062 time_t st_mtime; /* time of last modification */ 00063 // time_t st_ctime; /* time of last status change */ 00064 }; 00065 00066 sMystat myStatBuf; //store info for file 00067 FILINFO finfo; //global file info struct see ff.h 00068 FATFS_DIR dinfo; //global directoty info struct see ff.h 00069 00070 FRESULT get_fileInfo(const char *path) //use finfo for get result fields 00071 { 00072 FRESULT res = f_stat(path,&finfo); /* Get file status */ 00073 if (EnDebugMSG) 00074 if (res) 00075 printf("\n-->get_fileInfo:%s ,res=%d ,Not Found!",path,res); 00076 else 00077 printf("\n-->get_fileInfo:%s ,res=%d ,Found!",path,res); 00078 return res; 00079 } 00080 00081 FRESULT get_dirInfo(const char *path) 00082 { 00083 FRESULT res= f_opendir (&dinfo,path); /* FR_OK(0): successful, !=0: error code */ 00084 if (EnDebugMSG) 00085 if (res) 00086 printf("\n-->get_dirInfo :%s res=%d ,This is Not Directory!",path,res); 00087 else 00088 printf("\n-->get_dirInfo :%s res=%d ,This is Directory!",path,res); 00089 return res; 00090 } 00091 00092 FRESULT Mystat(const char *path, struct sMystat *buf) 00093 { 00094 FRESULT res = f_stat(path,&finfo); /* Get file status */ 00095 if (res == FR_OK) { 00096 buf->st_size = finfo.fsize; 00097 buf->st_mtime = finfo.ftime; //fdate; 00098 buf->st_mode = 4; //? 00099 } 00100 if (EnDebugMSG) 00101 printf("\n--Mystat Path:%s ,filesize:%14lld ,res=%d",path, buf->st_size, res); 00102 return res; 00103 } 00104 00105 00106 static char* get_mime_type( char* filename ) 00107 { 00108 char* extension; 00109 extension = strrchr( filename, '.' ); //get string after last . 00110 if (EnDebugMSG) 00111 printf("\n-->get_mime_tipe filename:%s, extension:%s",filename, extension); 00112 if (extension !=NULL) { 00113 if (strcasecmp(extension,".htm")==0 || strcasecmp(extension,".html") ==0) 00114 return "text/html; charset=iso-8859-1"; 00115 if (strcasecmp(extension,".png")==0) 00116 return "image/png"; 00117 if (strcasecmp(extension,".css")==0) 00118 return "text/css"; 00119 if (strcasecmp(extension,".gif")==0) 00120 return "image/gif"; 00121 if (strcasecmp(extension,".jpg")==0 || strcasecmp(extension,".jpeg" )==0) 00122 return "image/jpeg"; 00123 } 00124 return "text/plain; charset=iso-8859-1"; 00125 } 00126 00127 #endif
Generated on Wed Jul 13 2022 06:12:20 by
