Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
lwip_fs.c
00001 /* 00002 * Copyright (c) 2001-2003 Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 3. The name of the author may not be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00017 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00019 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00020 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00023 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00024 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00025 * OF SUCH DAMAGE. 00026 * 00027 * This file is part of the lwIP TCP/IP stack. 00028 * 00029 * Author: Adam Dunkels <adam@sics.se> 00030 * 00031 */ 00032 00033 #include "lwip/apps/httpd_opts.h" 00034 #include "lwip/def.h" 00035 #include "lwip/apps/fs.h" 00036 #include "fsdata.h" 00037 #include <string.h> 00038 00039 00040 #if HTTPD_USE_CUSTOM_FSDATA 00041 #include "fsdata_custom.c" 00042 #else /* HTTPD_USE_CUSTOM_FSDATA */ 00043 #include "fsdata.c" 00044 #endif /* HTTPD_USE_CUSTOM_FSDATA */ 00045 00046 /*-----------------------------------------------------------------------------------*/ 00047 00048 #if LWIP_HTTPD_CUSTOM_FILES 00049 int fs_open_custom(struct fs_file *file, const char *name); 00050 void fs_close_custom(struct fs_file *file); 00051 #if LWIP_HTTPD_FS_ASYNC_READ 00052 u8_t fs_canread_custom(struct fs_file *file); 00053 u8_t fs_wait_read_custom(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg); 00054 int fs_read_async_custom(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg); 00055 #else /* LWIP_HTTPD_FS_ASYNC_READ */ 00056 int fs_read_custom(struct fs_file *file, char *buffer, int count); 00057 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00058 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00059 00060 /*-----------------------------------------------------------------------------------*/ 00061 err_t 00062 fs_open(struct fs_file *file, const char *name) 00063 { 00064 const struct fsdata_file *f; 00065 00066 if ((file == NULL) || (name == NULL)) { 00067 return ERR_ARG; 00068 } 00069 00070 #if LWIP_HTTPD_CUSTOM_FILES 00071 if (fs_open_custom(file, name)) { 00072 file->is_custom_file = 1; 00073 return ERR_OK; 00074 } 00075 file->is_custom_file = 0; 00076 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00077 00078 for (f = FS_ROOT; f != NULL; f = f->next) { 00079 if (!strcmp(name, (const char *)f->name)) { 00080 file->data = (const char *)f->data; 00081 file->len = f->len; 00082 file->index = f->len; 00083 file->pextension = NULL; 00084 file->flags = f->flags; 00085 #if HTTPD_PRECALCULATED_CHECKSUM 00086 file->chksum_count = f->chksum_count; 00087 file->chksum = f->chksum; 00088 #endif /* HTTPD_PRECALCULATED_CHECKSUM */ 00089 #if LWIP_HTTPD_FILE_STATE 00090 file->state = fs_state_init(file, name); 00091 #endif /* #if LWIP_HTTPD_FILE_STATE */ 00092 return ERR_OK; 00093 } 00094 } 00095 /* file not found */ 00096 return ERR_VAL; 00097 } 00098 00099 /*-----------------------------------------------------------------------------------*/ 00100 void 00101 fs_close(struct fs_file *file) 00102 { 00103 #if LWIP_HTTPD_CUSTOM_FILES 00104 if (file->is_custom_file) { 00105 fs_close_custom(file); 00106 } 00107 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00108 #if LWIP_HTTPD_FILE_STATE 00109 fs_state_free(file, file->state); 00110 #endif /* #if LWIP_HTTPD_FILE_STATE */ 00111 LWIP_UNUSED_ARG(file); 00112 } 00113 /*-----------------------------------------------------------------------------------*/ 00114 #if LWIP_HTTPD_DYNAMIC_FILE_READ 00115 #if LWIP_HTTPD_FS_ASYNC_READ 00116 int 00117 fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg) 00118 #else /* LWIP_HTTPD_FS_ASYNC_READ */ 00119 int 00120 fs_read(struct fs_file *file, char *buffer, int count) 00121 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00122 { 00123 int read; 00124 if(file->index == file->len) { 00125 return FS_READ_EOF; 00126 } 00127 #if LWIP_HTTPD_FS_ASYNC_READ 00128 LWIP_UNUSED_ARG(callback_fn); 00129 LWIP_UNUSED_ARG(callback_arg); 00130 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00131 #if LWIP_HTTPD_CUSTOM_FILES 00132 if (file->is_custom_file) { 00133 #if LWIP_HTTPD_FS_ASYNC_READ 00134 return fs_read_async_custom(file, buffer, count, callback_fn, callback_arg); 00135 #else /* LWIP_HTTPD_FS_ASYNC_READ */ 00136 return fs_read_custom(file, buffer, count); 00137 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00138 } 00139 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00140 00141 read = file->len - file->index; 00142 if(read > count) { 00143 read = count; 00144 } 00145 00146 MEMCPY(buffer, (file->data + file->index), read); 00147 file->index += read; 00148 00149 return(read); 00150 } 00151 #endif /* LWIP_HTTPD_DYNAMIC_FILE_READ */ 00152 /*-----------------------------------------------------------------------------------*/ 00153 #if LWIP_HTTPD_FS_ASYNC_READ 00154 int 00155 fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg) 00156 { 00157 if (file != NULL) { 00158 #if LWIP_HTTPD_FS_ASYNC_READ 00159 #if LWIP_HTTPD_CUSTOM_FILES 00160 if (!fs_canread_custom(file)) { 00161 if (fs_wait_read_custom(file, callback_fn, callback_arg)) { 00162 return 0; 00163 } 00164 } 00165 #else /* LWIP_HTTPD_CUSTOM_FILES */ 00166 LWIP_UNUSED_ARG(callback_fn); 00167 LWIP_UNUSED_ARG(callback_arg); 00168 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00169 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00170 } 00171 return 1; 00172 } 00173 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00174 /*-----------------------------------------------------------------------------------*/ 00175 int 00176 fs_bytes_left(struct fs_file *file) 00177 { 00178 return file->len - file->index; 00179 }
Generated on Fri Jul 22 2022 04:53:52 by
 1.7.2
 1.7.2 
    