]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/uIP_Demo_IAR_ARM7/uip/fs.c
Prepare for V9.0.0 release.
[freertos] / FreeRTOS / Demo / uIP_Demo_IAR_ARM7 / uip / fs.c
1 /**\r
2  * \addtogroup httpd\r
3  * @{\r
4  */\r
5 \r
6 /**\r
7  * \file\r
8  * HTTP server read-only file system code.\r
9  * \author Adam Dunkels <adam@dunkels.com>\r
10  *\r
11  * A simple read-only filesystem.\r
12  */\r
13 \r
14 /*\r
15  * Copyright (c) 2001, Swedish Institute of Computer Science.\r
16  * All rights reserved.\r
17  *\r
18  * Redistribution and use in source and binary forms, with or without\r
19  * modification, are permitted provided that the following conditions\r
20  * are met:\r
21  * 1. Redistributions of source code must retain the above copyright\r
22  *    notice, this list of conditions and the following disclaimer.\r
23  * 2. Redistributions in binary form must reproduce the above copyright\r
24  *    notice, this list of conditions and the following disclaimer in the\r
25  *    documentation and/or other materials provided with the distribution.\r
26  * 3. Neither the name of the Institute nor the names of its contributors\r
27  *    may be used to endorse or promote products derived from this software\r
28  *    without specific prior written permission.\r
29  *\r
30  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
40  * SUCH DAMAGE.\r
41  *\r
42  * This file is part of the lwIP TCP/IP stack.\r
43  *\r
44  * Author: Adam Dunkels <adam@sics.se>\r
45  *\r
46  * $Id: fs.c,v 1.7.2.3 2003/10/07 13:22:27 adam Exp $\r
47  */\r
48 \r
49 #include "uip.h"\r
50 #include "httpd.h"\r
51 #include "fs.h"\r
52 #include "fsdata.h"\r
53 \r
54 #define NULL (void *)0\r
55 #include "fsdata.c"\r
56 \r
57 #ifdef FS_STATISTICS\r
58 #if FS_STATISTICS == 1\r
59 static u16_t count[FS_NUMFILES];\r
60 #endif /* FS_STATISTICS */\r
61 #endif /* FS_STATISTICS */\r
62 \r
63 /*-----------------------------------------------------------------------------------*/\r
64 static u8_t\r
65 fs_strcmp(const char *str1, const char *str2)\r
66 {\r
67   u8_t i;\r
68   i = 0;\r
69  loop:\r
70 \r
71   if(str2[i] == 0 ||\r
72      str1[i] == '\r' ||\r
73      str1[i] == '\n') {\r
74     return 0;\r
75   }\r
76 \r
77   if(str1[i] != str2[i]) {\r
78     return 1;\r
79   }\r
80 \r
81 \r
82   ++i;\r
83   goto loop;\r
84 }\r
85 /*-----------------------------------------------------------------------------------*/\r
86 int\r
87 fs_open(const char *name, struct fs_file *file)\r
88 {\r
89 #ifdef FS_STATISTICS\r
90 #if FS_STATISTICS == 1\r
91   u16_t i = 0;\r
92 #endif /* FS_STATISTICS */\r
93 #endif /* FS_STATISTICS */\r
94   struct fsdata_file_noconst *f;\r
95 \r
96   for(f = (struct fsdata_file_noconst *)FS_ROOT;\r
97       f != NULL;\r
98       f = (struct fsdata_file_noconst *)f->next) {\r
99 \r
100     if(fs_strcmp(name, f->name) == 0) {\r
101       file->data = f->data;\r
102       file->len = f->len;\r
103 #ifdef FS_STATISTICS\r
104 #if FS_STATISTICS == 1\r
105       ++count[i];\r
106 #endif /* FS_STATISTICS */\r
107 #endif /* FS_STATISTICS */\r
108 \r
109       return 1;\r
110     }\r
111 #ifdef FS_STATISTICS\r
112 #if FS_STATISTICS == 1\r
113     ++i;\r
114 #endif /* FS_STATISTICS */\r
115 #endif /* FS_STATISTICS */\r
116 \r
117   }\r
118   return 0;\r
119 }\r
120 /*-----------------------------------------------------------------------------------*/\r
121 void\r
122 fs_init(void)\r
123 {\r
124 #ifdef FS_STATISTICS\r
125 #if FS_STATISTICS == 1\r
126   u16_t i;\r
127   for(i = 0; i < FS_NUMFILES; i++) {\r
128     count[i] = 0;\r
129   }\r
130 #endif /* FS_STATISTICS */\r
131 #endif /* FS_STATISTICS */\r
132 }\r
133 /*-----------------------------------------------------------------------------------*/\r
134 #ifdef FS_STATISTICS\r
135 #if FS_STATISTICS == 1\r
136 u16_t fs_count\r
137 (char *name)\r
138 {\r
139   struct fsdata_file_noconst *f;\r
140   u16_t i;\r
141 \r
142   i = 0;\r
143   for(f = (struct fsdata_file_noconst *)FS_ROOT;\r
144       f != NULL;\r
145       f = (struct fsdata_file_noconst *)f->next) {\r
146 \r
147     if(fs_strcmp(name, f->name) == 0) {\r
148       return count[i];\r
149     }\r
150     ++i;\r
151   }\r
152   return 0;\r
153 }\r
154 #endif /* FS_STATISTICS */\r
155 #endif /* FS_STATISTICS */\r
156 /*-----------------------------------------------------------------------------------*/\r