Changeset 374 for asp3_tinet_ecnl_arm/trunk/ntshell
- Timestamp:
- Apr 5, 2019, 9:26:53 PM (5 years ago)
- Location:
- asp3_tinet_ecnl_arm/trunk/ntshell
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ccsbcs.c
r352 r374 25 25 26 26 27 #if _CODE_PAGE == 43727 #if FF_CODE_PAGE == 437 28 28 #define _TBLDEF 1 29 29 static … … 39 39 }; 40 40 41 #elif _CODE_PAGE == 72041 #elif FF_CODE_PAGE == 720 42 42 #define _TBLDEF 1 43 43 static … … 53 53 }; 54 54 55 #elif _CODE_PAGE == 73755 #elif FF_CODE_PAGE == 737 56 56 #define _TBLDEF 1 57 57 static … … 67 67 }; 68 68 69 #elif _CODE_PAGE == 77169 #elif FF_CODE_PAGE == 771 70 70 #define _TBLDEF 1 71 71 static … … 81 81 }; 82 82 83 #elif _CODE_PAGE == 77583 #elif FF_CODE_PAGE == 775 84 84 #define _TBLDEF 1 85 85 static … … 95 95 }; 96 96 97 #elif _CODE_PAGE == 85097 #elif FF_CODE_PAGE == 850 98 98 #define _TBLDEF 1 99 99 static … … 109 109 }; 110 110 111 #elif _CODE_PAGE == 852111 #elif FF_CODE_PAGE == 852 112 112 #define _TBLDEF 1 113 113 static … … 123 123 }; 124 124 125 #elif _CODE_PAGE == 855125 #elif FF_CODE_PAGE == 855 126 126 #define _TBLDEF 1 127 127 static … … 137 137 }; 138 138 139 #elif _CODE_PAGE == 857139 #elif FF_CODE_PAGE == 857 140 140 #define _TBLDEF 1 141 141 static … … 151 151 }; 152 152 153 #elif _CODE_PAGE == 860153 #elif FF_CODE_PAGE == 860 154 154 #define _TBLDEF 1 155 155 static … … 165 165 }; 166 166 167 #elif _CODE_PAGE == 861167 #elif FF_CODE_PAGE == 861 168 168 #define _TBLDEF 1 169 169 static … … 179 179 }; 180 180 181 #elif _CODE_PAGE == 862181 #elif FF_CODE_PAGE == 862 182 182 #define _TBLDEF 1 183 183 static … … 193 193 }; 194 194 195 #elif _CODE_PAGE == 863195 #elif FF_CODE_PAGE == 863 196 196 #define _TBLDEF 1 197 197 static … … 207 207 }; 208 208 209 #elif _CODE_PAGE == 864209 #elif FF_CODE_PAGE == 864 210 210 #define _TBLDEF 1 211 211 static … … 221 221 }; 222 222 223 #elif _CODE_PAGE == 865223 #elif FF_CODE_PAGE == 865 224 224 #define _TBLDEF 1 225 225 static … … 235 235 }; 236 236 237 #elif _CODE_PAGE == 866237 #elif FF_CODE_PAGE == 866 238 238 #define _TBLDEF 1 239 239 static … … 249 249 }; 250 250 251 #elif _CODE_PAGE == 869251 #elif FF_CODE_PAGE == 869 252 252 #define _TBLDEF 1 253 253 static … … 266 266 267 267 268 #if _CODE_PAGE != 65001 && (!_TBLDEF || !_USE_LFN)268 #if FF_CODE_PAGE != 65001 && (!_TBLDEF || !FF_USE_LFN) 269 269 #error This file is not needed at current configuration. Remove from the project. 270 270 #endif … … 272 272 273 273 274 #if _CODE_PAGE != 65001274 #if FF_CODE_PAGE != 65001 275 275 WCHAR ff_convert ( /* Converted character, Returns zero on error */ 276 276 WCHAR chr, /* Character code to be converted */ -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/diskio.c
r352 r374 34 34 int get_status(volatile RD_STAT *stat) { 35 35 stat->sz_sector = SS_RAMDISK; 36 if(stat->sz_sector < _MIN_SS || stat->sz_sector >_MAX_SS) return 0;36 if(stat->sz_sector < FF_MIN_SS || stat->sz_sector > FF_MAX_SS) return 0; 37 37 stat->n_sectors = SZ_RAMDISK * 1024 / SS_RAMDISK; 38 38 stat->status = 0; -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/diskio.h
r352 r374 60 60 61 61 /* Generic command (Used by FatFs) */ 62 #define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */63 #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */64 #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS !=_MIN_SS) */65 #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */66 #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */62 #define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */ 63 #define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */ 64 #define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */ 65 #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */ 66 #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */ 67 67 68 68 /* Generic command (Not used by FatFs) */ -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.c
r369 r374 20 20 #include "ff.h" /* Declarations of FatFs API */ 21 21 #include "diskio.h" /* Declarations of disk I/O functions */ 22 #include "util/ntstdio.h"22 #include <stdio.h> 23 23 24 24 /*-------------------------------------------------------------------------- … … 34 34 35 35 /* Reentrancy related */ 36 #if _FS_REENTRANT37 #if _USE_LFN == 136 #if FF_FS_REENTRANT 37 #if FF_USE_LFN == 1 38 38 #error Static LFN work area cannot be used at thread-safe configuration 39 39 #endif … … 49 49 50 50 /* Definitions of sector size */ 51 #if ( _MAX_SS < _MIN_SS) || (_MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096) || (_MIN_SS != 512 && _MIN_SS != 1024 && _MIN_SS != 2048 &&_MIN_SS != 4096)51 #if (FF_MAX_SS < FF_MIN_SS) || (FF_MAX_SS != 512 && FF_MAX_SS != 1024 && FF_MAX_SS != 2048 && FF_MAX_SS != 4096) || (FF_MIN_SS != 512 && FF_MIN_SS != 1024 && FF_MIN_SS != 2048 && FF_MIN_SS != 4096) 52 52 #error Wrong sector size configuration 53 53 #endif 54 #if _MAX_SS ==_MIN_SS55 #define SS(fs) ((UINT) _MAX_SS) /* Fixed sector size */54 #if FF_MAX_SS == FF_MIN_SS 55 #define SS(fs) ((UINT)FF_MAX_SS) /* Fixed sector size */ 56 56 #else 57 57 #define SS(fs) ((fs)->ssize) /* Variable sector size */ … … 60 60 61 61 /* Timestamp feature */ 62 #if _FS_NORTC == 163 #if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 ||_NORTC_MDAY > 3164 #error Invalid _FS_NORTC settings65 #endif 66 #define GET_FATTIME() ((DWORD)( _NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)62 #if FF_FS_NORTC == 1 63 #if FF_NORTC_YEAR < 1980 || FF_NORTC_YEAR > 2107 || FF_NORTC_MON < 1 || FF_NORTC_MON > 12 || FF_NORTC_MDAY < 1 || FF_NORTC_MDAY > 31 64 #error Invalid FF_FS_NORTC settings 65 #endif 66 #define GET_FATTIME() ((DWORD)(FF_NORTC_YEAR - 1980) << 25 | (DWORD)FF_NORTC_MON << 21 | (DWORD)FF_NORTC_MDAY << 16) 67 67 #else 68 68 #define GET_FATTIME() get_fattime() … … 71 71 72 72 /* File access control feature */ 73 #if _FS_LOCK74 #if _FS_READONLY75 #error _FS_LOCK must be 0 at read-only configuration73 #if FF_FS_LOCK != 0 74 #if FF_FS_READONLY 75 #error FF_FS_LOCK must be 0 at read-only configuration 76 76 #endif 77 77 typedef struct { … … 87 87 /* DBCS code ranges and SBCS upper conversion tables */ 88 88 89 #if _CODE_PAGE == 932 /* Japanese Shift-JIS */89 #if FF_CODE_PAGE == 932 /* Japanese Shift-JIS */ 90 90 #define _DF1S 0x81 /* DBC 1st byte range 1 start */ 91 91 #define _DF1E 0x9F /* DBC 1st byte range 1 end */ … … 97 97 #define _DS2E 0xFC /* DBC 2nd byte range 2 end */ 98 98 99 #elif _CODE_PAGE == 936 /* Simplified Chinese GBK */99 #elif FF_CODE_PAGE == 936 /* Simplified Chinese GBK */ 100 100 #define _DF1S 0x81 101 101 #define _DF1E 0xFE … … 105 105 #define _DS2E 0xFE 106 106 107 #elif _CODE_PAGE == 949 /* Korean */107 #elif FF_CODE_PAGE == 949 /* Korean */ 108 108 #define _DF1S 0x81 109 109 #define _DF1E 0xFE … … 115 115 #define _DS3E 0xFE 116 116 117 #elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */117 #elif FF_CODE_PAGE == 950 /* Traditional Chinese Big5 */ 118 118 #define _DF1S 0x81 119 119 #define _DF1E 0xFE … … 123 123 #define _DS2E 0xFE 124 124 125 #elif _CODE_PAGE == 437 /* U.S. */125 #elif FF_CODE_PAGE == 437 /* U.S. */ 126 126 #define _DF1S 0 127 127 #define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \ … … 134 134 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 135 135 136 #elif _CODE_PAGE == 720 /* Arabic */136 #elif FF_CODE_PAGE == 720 /* Arabic */ 137 137 #define _DF1S 0 138 138 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ … … 145 145 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 146 146 147 #elif _CODE_PAGE == 737 /* Greek */147 #elif FF_CODE_PAGE == 737 /* Greek */ 148 148 #define _DF1S 0 149 149 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ … … 156 156 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 157 157 158 #elif _CODE_PAGE == 771 /* KBL */158 #elif FF_CODE_PAGE == 771 /* KBL */ 159 159 #define _DF1S 0 160 160 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ … … 167 167 0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF} 168 168 169 #elif _CODE_PAGE == 775 /* Baltic */169 #elif FF_CODE_PAGE == 775 /* Baltic */ 170 170 #define _DF1S 0 171 171 #define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F, \ … … 178 178 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 179 179 180 #elif _CODE_PAGE == 850 /* Latin 1 */180 #elif FF_CODE_PAGE == 850 /* Latin 1 */ 181 181 #define _DF1S 0 182 182 #define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \ … … 189 189 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 190 190 191 #elif _CODE_PAGE == 852 /* Latin 2 */191 #elif FF_CODE_PAGE == 852 /* Latin 2 */ 192 192 #define _DF1S 0 193 193 #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F, \ … … 200 200 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF} 201 201 202 #elif _CODE_PAGE == 855 /* Cyrillic */202 #elif FF_CODE_PAGE == 855 /* Cyrillic */ 203 203 #define _DF1S 0 204 204 #define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F, \ … … 211 211 0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF} 212 212 213 #elif _CODE_PAGE == 857 /* Turkish */213 #elif FF_CODE_PAGE == 857 /* Turkish */ 214 214 #define _DF1S 0 215 215 #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x49,0x8E,0x8F, \ … … 222 222 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 223 223 224 #elif _CODE_PAGE == 860 /* Portuguese */224 #elif FF_CODE_PAGE == 860 /* Portuguese */ 225 225 #define _DF1S 0 226 226 #define _EXCVT {0x80,0x9A,0x90,0x8F,0x8E,0x91,0x86,0x80,0x89,0x89,0x92,0x8B,0x8C,0x98,0x8E,0x8F, \ … … 233 233 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 234 234 235 #elif _CODE_PAGE == 861 /* Icelandic */235 #elif FF_CODE_PAGE == 861 /* Icelandic */ 236 236 #define _DF1S 0 237 237 #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x8B,0x8B,0x8D,0x8E,0x8F, \ … … 244 244 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 245 245 246 #elif _CODE_PAGE == 862 /* Hebrew */246 #elif FF_CODE_PAGE == 862 /* Hebrew */ 247 247 #define _DF1S 0 248 248 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ … … 255 255 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 256 256 257 #elif _CODE_PAGE == 863 /* Canadian-French */257 #elif FF_CODE_PAGE == 863 /* Canadian-French */ 258 258 #define _DF1S 0 259 259 #define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x41,0x8F, \ … … 266 266 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 267 267 268 #elif _CODE_PAGE == 864 /* Arabic */268 #elif FF_CODE_PAGE == 864 /* Arabic */ 269 269 #define _DF1S 0 270 270 #define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \ … … 277 277 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 278 278 279 #elif _CODE_PAGE == 865 /* Nordic */279 #elif FF_CODE_PAGE == 865 /* Nordic */ 280 280 #define _DF1S 0 281 281 #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \ … … 288 288 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 289 289 290 #elif _CODE_PAGE == 866 /* Russian */290 #elif FF_CODE_PAGE == 866 /* Russian */ 291 291 #define _DF1S 0 292 292 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ … … 299 299 0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} 300 300 301 #elif _CODE_PAGE == 869 /* Greek 2 */301 #elif FF_CODE_PAGE == 869 /* Greek 2 */ 302 302 #define _DF1S 0 303 303 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ … … 310 310 0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF} 311 311 312 #elif _CODE_PAGE == 1 /* ASCII (for only non-LFN cfg) */313 #if _USE_LFN312 #elif FF_CODE_PAGE == 1 /* ASCII (for only non-LFN cfg) */ 313 #if FF_USE_LFN 314 314 #error Cannot use LFN feature without valid code page. 315 315 #endif 316 316 #define _DF1S 0 317 317 318 #elif _CODE_PAGE == 65001 /* UTF-8 */319 #if _LFN_UNICODE318 #elif FF_CODE_PAGE == 65001 /* UTF-8 */ 319 #if FF_LFN_UNICODE 320 320 #error Cannot use LFN_UNICODE feature without valid code page. 321 321 #endif … … 532 532 */ 533 533 534 #if _VOLUMES < 1 ||_VOLUMES > 9535 #error Wrong _VOLUMES setting536 #endif 537 static FATFS *FatFs[ _VOLUMES]; /* Pointer to the file system objects (logical drives) */534 #if FF_VOLUMES < 1 || FF_VOLUMES > 9 535 #error Wrong FF_VOLUMES setting 536 #endif 537 static FATFS *FatFs[FF_VOLUMES]; /* Pointer to the file system objects (logical drives) */ 538 538 static WORD Fsid; /* File system mount ID */ 539 539 540 #if _FS_RPATH &&_VOLUMES >= 2540 #if FF_FS_RPATH && FF_VOLUMES >= 2 541 541 static BYTE CurrVol; /* Current drive */ 542 542 #endif 543 543 544 #if _FS_LOCK545 static FILESEM Files[ _FS_LOCK]; /* Open object lock semaphores */546 #endif 547 548 #if _USE_LFN == 0 /* Non LFN feature */544 #if FF_FS_LOCK != 0 545 static FILESEM Files[FF_FS_LOCK]; /* Open object lock semaphores */ 546 #endif 547 548 #if FF_USE_LFN == 0 /* Non LFN feature */ 549 549 #define DEFINE_NAMEBUF BYTE sfn[12] 550 550 #define INIT_BUF(dobj) (dobj).fn = sfn 551 551 #define FREE_BUF() 552 552 #else 553 #if _MAX_LFN < 12 ||_MAX_LFN > 255554 #error Wrong _MAX_LFN setting555 #endif 556 #if _USE_LFN == 1 /* LFN feature with static working buffer */557 static WCHAR LfnBuf[ _MAX_LFN + 1];553 #if FF_MAX_LFN < 12 || FF_MAX_LFN > 255 554 #error Wrong FF_MAX_LFN setting 555 #endif 556 #if FF_USE_LFN == 1 /* LFN feature with static working buffer */ 557 static WCHAR LfnBuf[FF_MAX_LFN + 1]; 558 558 #define DEFINE_NAMEBUF BYTE sfn[12] 559 559 #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; } 560 560 #define FREE_BUF() 561 #elif _USE_LFN == 2 /* LFN feature with dynamic working buffer on the stack */562 #define DEFINE_NAMEBUF BYTE sfn[12]; WCHAR lbuf[ _MAX_LFN + 1]561 #elif FF_USE_LFN == 2 /* LFN feature with dynamic working buffer on the stack */ 562 #define DEFINE_NAMEBUF BYTE sfn[12]; WCHAR lbuf[FF_MAX_LFN + 1] 563 563 #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = lbuf; } 564 564 #define FREE_BUF() 565 #elif _USE_LFN == 3 /* LFN feature with dynamic working buffer on the heap */565 #elif FF_USE_LFN == 3 /* LFN feature with dynamic working buffer on the heap */ 566 566 #define DEFINE_NAMEBUF BYTE sfn[12]; WCHAR *lfn 567 #define INIT_BUF(dobj) { lfn = ff_memalloc(( _MAX_LFN + 1) * 2); if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); (dobj).lfn = lfn; (dobj).fn = sfn; }567 #define INIT_BUF(dobj) { lfn = ff_memalloc((FF_MAX_LFN + 1) * 2); if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); (dobj).lfn = lfn; (dobj).fn = sfn; } 568 568 #define FREE_BUF() ff_memfree(lfn) 569 569 #else 570 #error Wrong _USE_LFN setting570 #error Wrong FF_USE_LFN setting 571 571 #endif 572 572 #endif … … 598 598 const BYTE *s = (const BYTE*)src; 599 599 600 #if _WORD_ACCESS == 1600 #if FF_WORD_ACCESS == 1 601 601 while (cnt >= sizeof (int)) { 602 602 *(int*)d = *(int*)s; … … 641 641 /* Request/Release grant to access the volume */ 642 642 /*-----------------------------------------------------------------------*/ 643 #if _FS_REENTRANT643 #if FF_FS_REENTRANT 644 644 static 645 645 int lock_fs ( … … 673 673 /* File lock control functions */ 674 674 /*-----------------------------------------------------------------------*/ 675 #if _FS_LOCK675 #if FF_FS_LOCK != 0 676 676 677 677 static 678 678 FRESULT chk_lock ( /* Check if the file can be accessed */ 679 DIR* dp, /* Directory object pointing the file to be checked */679 FATFS_DIR* dp, /* Directory object pointing the file to be checked */ 680 680 int acc /* Desired access type (0:Read, 1:Write, 2:Delete/Rename) */ 681 681 ) … … 684 684 685 685 /* Search file semaphore table */ 686 for (i = be = 0; i < _FS_LOCK; i++) {686 for (i = be = 0; i < FF_FS_LOCK; i++) { 687 687 if (Files[i].fs) { /* Existing entry */ 688 688 if (Files[i].fs == dp->fs && /* Check if the object matched with an open object */ … … 693 693 } 694 694 } 695 if (i == _FS_LOCK) /* The object is not opened */695 if (i == FF_FS_LOCK) /* The object is not opened */ 696 696 return (be || acc == 2) ? FR_OK : FR_TOO_MANY_OPEN_FILES; /* Is there a blank entry for new object? */ 697 697 … … 706 706 UINT i; 707 707 708 for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;709 return (i == _FS_LOCK) ? 0 : 1;708 for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; 709 return (i == FF_FS_LOCK) ? 0 : 1; 710 710 } 711 711 … … 713 713 static 714 714 UINT inc_lock ( /* Increment object open counter and returns its index (0:Internal error) */ 715 DIR* dp, /* Directory object pointing the file to register or increment */715 FATFS_DIR* dp, /* Directory object pointing the file to register or increment */ 716 716 int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */ 717 717 ) … … 720 720 721 721 722 for (i = 0; i < _FS_LOCK; i++) { /* Find the object */722 for (i = 0; i < FF_FS_LOCK; i++) { /* Find the object */ 723 723 if (Files[i].fs == dp->fs && 724 724 Files[i].clu == dp->sclust && … … 726 726 } 727 727 728 if (i == _FS_LOCK) { /* Not opened. Register it as new. */729 for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;730 if (i == _FS_LOCK) return 0; /* No free entry to register (int err) */728 if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */ 729 for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ; 730 if (i == FF_FS_LOCK) return 0; /* No free entry to register (int err) */ 731 731 Files[i].fs = dp->fs; 732 732 Files[i].clu = dp->sclust; … … 752 752 753 753 754 if (--i < _FS_LOCK) { /* Shift index number origin from 0 */754 if (--i < FF_FS_LOCK) { /* Shift index number origin from 0 */ 755 755 n = Files[i].ctr; 756 756 if (n == 0x100) n = 0; /* If write mode open, delete the entry */ … … 773 773 UINT i; 774 774 775 for (i = 0; i < _FS_LOCK; i++) {775 for (i = 0; i < FF_FS_LOCK; i++) { 776 776 if (Files[i].fs == fs) Files[i].fs = 0; 777 777 } … … 785 785 /* Move/Flush disk access window in the file system object */ 786 786 /*-----------------------------------------------------------------------*/ 787 #if ! _FS_READONLY787 #if !FF_FS_READONLY 788 788 static 789 789 FRESULT sync_window ( /* FR_OK:succeeded, !=0:error */ … … 825 825 826 826 if (sector != fs->winsect) { /* Window offset changed? */ 827 #if ! _FS_READONLY827 #if !FF_FS_READONLY 828 828 res = sync_window(fs); /* Write-back changes */ 829 829 #endif … … 845 845 /* Synchronize file system and strage device */ 846 846 /*-----------------------------------------------------------------------*/ 847 #if ! _FS_READONLY847 #if !FF_FS_READONLY 848 848 static 849 849 FRESULT sync_fs ( /* FR_OK:succeeded, !=0:error */ … … 959 959 /* Hidden API for hacks and disk tools */ 960 960 961 #if ! _FS_READONLY961 #if !FF_FS_READONLY 962 962 FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */ 963 963 FATFS* fs, /* File system object */ … … 1014 1014 return res; 1015 1015 } 1016 #endif /* ! _FS_READONLY */1016 #endif /* !FF_FS_READONLY */ 1017 1017 1018 1018 … … 1022 1022 /* FAT handling - Remove a cluster chain */ 1023 1023 /*-----------------------------------------------------------------------*/ 1024 #if ! _FS_READONLY1024 #if !FF_FS_READONLY 1025 1025 static 1026 1026 FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */ … … 1031 1031 FRESULT res; 1032 1032 DWORD nxt; 1033 #if _USE_TRIM1033 #if FF_USE_TRIM 1034 1034 DWORD scl = clst, ecl = clst, rt[2]; 1035 1035 #endif … … 1051 1051 fs->fsi_flag |= 1; 1052 1052 } 1053 #if _USE_TRIM1053 #if FF_USE_TRIM 1054 1054 if (ecl + 1 == nxt) { /* Is next cluster contiguous? */ 1055 1055 ecl = nxt; … … 1075 1075 /* FAT handling - Stretch or Create a cluster chain */ 1076 1076 /*-----------------------------------------------------------------------*/ 1077 #if ! _FS_READONLY1077 #if !FF_FS_READONLY 1078 1078 static 1079 1079 DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */ … … 1128 1128 return ncl; /* Return new cluster number or error code */ 1129 1129 } 1130 #endif /* ! _FS_READONLY */1130 #endif /* !FF_FS_READONLY */ 1131 1131 1132 1132 … … 1137 1137 /*-----------------------------------------------------------------------*/ 1138 1138 1139 #if _USE_FASTSEEK1139 #if FF_USE_FASTSEEK 1140 1140 static 1141 1141 DWORD clmt_clust ( /* <2:Error, >=2:Cluster number */ … … 1157 1157 return cl + *tbl; /* Return the cluster number */ 1158 1158 } 1159 #endif /* _USE_FASTSEEK */1159 #endif /* FF_USE_FASTSEEK */ 1160 1160 1161 1161 … … 1168 1168 static 1169 1169 FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */ 1170 DIR* dp, /* Pointer to directory object */1170 FATFS_DIR* dp, /* Pointer to directory object */ 1171 1171 UINT idx /* Index of directory table */ 1172 1172 ) … … 1216 1216 static 1217 1217 FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */ 1218 DIR* dp, /* Pointer to the directory object */1218 FATFS_DIR* dp, /* Pointer to the directory object */ 1219 1219 int stretch /* 0: Do not stretch table, 1: Stretch table if needed */ 1220 1220 ) … … 1222 1222 DWORD clst; 1223 1223 UINT i; 1224 #if ! _FS_READONLY1224 #if !FF_FS_READONLY 1225 1225 UINT c; 1226 1226 #endif … … 1244 1244 if (clst == 0xFFFFFFFF) return FR_DISK_ERR; 1245 1245 if (clst >= dp->fs->n_fatent) { /* If it reached end of dynamic table, */ 1246 #if ! _FS_READONLY1246 #if !FF_FS_READONLY 1247 1247 if (!stretch) return FR_NO_FILE; /* If do not stretch, report EOT */ 1248 1248 clst = create_chain(dp->fs, dp->clust); /* Stretch cluster chain */ … … 1284 1284 /*-----------------------------------------------------------------------*/ 1285 1285 1286 #if ! _FS_READONLY1286 #if !FF_FS_READONLY 1287 1287 static 1288 1288 FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */ 1289 DIR* dp, /* Pointer to the directory object */1289 FATFS_DIR* dp, /* Pointer to the directory object */ 1290 1290 UINT nent /* Number of contiguous entries to allocate (1-21) */ 1291 1291 ) … … 1337 1337 1338 1338 1339 #if ! _FS_READONLY1339 #if !FF_FS_READONLY 1340 1340 static 1341 1341 void st_clust ( … … 1355 1355 /* LFN handling - Test/Pick/Fit an LFN segment from/to directory entry */ 1356 1356 /*-----------------------------------------------------------------------*/ 1357 #if _USE_LFN1357 #if FF_USE_LFN 1358 1358 static 1359 1359 const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; /* Offset of LFN characters in the directory entry */ … … 1377 1377 uc = LD_WORD(dir + LfnOfs[s]); /* Pick an LFN character */ 1378 1378 if (wc) { 1379 if (i >= _MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++])) /* Compare it */1379 if (i >= FF_MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++])) /* Compare it */ 1380 1380 return 0; /* Not matched */ 1381 1381 wc = uc; … … 1410 1410 uc = LD_WORD(dir + LfnOfs[s]); /* Pick an LFN character */ 1411 1411 if (wc) { 1412 if (i >= _MAX_LFN) return 0; /* Buffer overflow? */1412 if (i >= FF_MAX_LFN) return 0; /* Buffer overflow? */ 1413 1413 lfnbuf[i++] = wc = uc; /* Store it */ 1414 1414 } else { … … 1418 1418 1419 1419 if (dir[LDIR_Ord] & LLEF) { /* Put terminator if it is the last LFN part */ 1420 if (i >= _MAX_LFN) return 0; /* Buffer overflow? */1420 if (i >= FF_MAX_LFN) return 0; /* Buffer overflow? */ 1421 1421 lfnbuf[i] = 0; 1422 1422 } … … 1426 1426 1427 1427 1428 #if ! _FS_READONLY1428 #if !FF_FS_READONLY 1429 1429 static 1430 1430 void fit_lfn ( … … 1464 1464 /* Create numbered name */ 1465 1465 /*-----------------------------------------------------------------------*/ 1466 #if _USE_LFN1466 #if FF_USE_LFN 1467 1467 static 1468 1468 void gen_numname ( … … 1523 1523 /* Calculate checksum of an SFN entry */ 1524 1524 /*-----------------------------------------------------------------------*/ 1525 #if _USE_LFN1525 #if FF_USE_LFN 1526 1526 static 1527 1527 BYTE sum_sfn ( … … 1546 1546 static 1547 1547 FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ 1548 DIR* dp /* Pointer to the directory object linked to the file name */1548 FATFS_DIR* dp /* Pointer to the directory object linked to the file name */ 1549 1549 ) 1550 1550 { 1551 1551 FRESULT res; 1552 1552 BYTE c, *dir; 1553 #if _USE_LFN1553 #if FF_USE_LFN 1554 1554 BYTE a, ord, sum; 1555 1555 #endif … … 1558 1558 if (res != FR_OK) return res; 1559 1559 1560 #if _USE_LFN1560 #if FF_USE_LFN 1561 1561 ord = sum = 0xFF; dp->lfn_idx = 0xFFFF; /* Reset LFN sequence */ 1562 1562 #endif … … 1567 1567 c = dir[DIR_Name]; 1568 1568 if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ 1569 #if _USE_LFN /* LFN configuration */1569 #if FF_USE_LFN /* LFN configuration */ 1570 1570 a = dir[DIR_Attr] & AM_MASK; 1571 1571 if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */ … … 1604 1604 /* Read an object from the directory */ 1605 1605 /*-----------------------------------------------------------------------*/ 1606 #if _FS_MINIMIZE <= 1 || _USE_LABEL ||_FS_RPATH >= 21606 #if FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2 1607 1607 static 1608 1608 FRESULT dir_read ( 1609 DIR* dp, /* Pointer to the directory object */1609 FATFS_DIR* dp, /* Pointer to the directory object */ 1610 1610 int vol /* Filtered by 0:file/directory or 1:volume label */ 1611 1611 ) … … 1613 1613 FRESULT res; 1614 1614 BYTE a, c, *dir; 1615 #if _USE_LFN1615 #if FF_USE_LFN 1616 1616 BYTE ord = 0xFF, sum = 0xFF; 1617 1617 #endif … … 1625 1625 if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ 1626 1626 a = dir[DIR_Attr] & AM_MASK; 1627 #if _USE_LFN /* LFN configuration */1628 if (c == DDEM || (! _FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */1627 #if FF_USE_LFN /* LFN configuration */ 1628 if (c == DDEM || (!FF_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */ 1629 1629 ord = 0xFF; 1630 1630 } else { … … 1644 1644 } 1645 1645 #else /* Non LFN configuration */ 1646 if (c != DDEM && ( _FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol) /* Is it a valid entry? */1646 if (c != DDEM && (FF_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol) /* Is it a valid entry? */ 1647 1647 break; 1648 1648 #endif … … 1655 1655 return res; 1656 1656 } 1657 #endif /* _FS_MINIMIZE <= 1 || _USE_LABEL ||_FS_RPATH >= 2 */1657 #endif /* FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2 */ 1658 1658 1659 1659 … … 1663 1663 /* Register an object to the directory */ 1664 1664 /*-----------------------------------------------------------------------*/ 1665 #if ! _FS_READONLY1665 #if !FF_FS_READONLY 1666 1666 static 1667 1667 FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */ 1668 DIR* dp /* Target directory with object name to be created */1668 FATFS_DIR* dp /* Target directory with object name to be created */ 1669 1669 ) 1670 1670 { 1671 1671 FRESULT res; 1672 #if _USE_LFN /* LFN configuration */1672 #if FF_USE_LFN /* LFN configuration */ 1673 1673 UINT n, nent; 1674 1674 BYTE sn[12], *fn, sum; … … 1679 1679 mem_cpy(sn, fn, 12); 1680 1680 1681 if ( _FS_RPATH && (sn[NSFLAG] & NS_DOT)) /* Cannot create dot entry */1681 if (FF_FS_RPATH && (sn[NSFLAG] & NS_DOT)) /* Cannot create dot entry */ 1682 1682 return FR_INVALID_NAME; 1683 1683 … … 1724 1724 mem_set(dp->dir, 0, SZ_DIRE); /* Clean the entry */ 1725 1725 mem_cpy(dp->dir, dp->fn, 11); /* Put SFN */ 1726 #if _USE_LFN1726 #if FF_USE_LFN 1727 1727 dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */ 1728 1728 #endif … … 1733 1733 return res; 1734 1734 } 1735 #endif /* ! _FS_READONLY */1735 #endif /* !FF_FS_READONLY */ 1736 1736 1737 1737 … … 1741 1741 /* Remove an object from the directory */ 1742 1742 /*-----------------------------------------------------------------------*/ 1743 #if ! _FS_READONLY && !_FS_MINIMIZE1743 #if !FF_FS_READONLY && !FF_FS_MINIMIZE 1744 1744 static 1745 1745 FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */ 1746 DIR* dp /* Directory object pointing the entry to be removed */1746 FATFS_DIR* dp /* Directory object pointing the entry to be removed */ 1747 1747 ) 1748 1748 { 1749 1749 FRESULT res; 1750 #if _USE_LFN /* LFN configuration */1750 #if FF_USE_LFN /* LFN configuration */ 1751 1751 UINT i; 1752 1752 … … 1780 1780 return res; 1781 1781 } 1782 #endif /* ! _FS_READONLY */1782 #endif /* !FF_FS_READONLY */ 1783 1783 1784 1784 … … 1788 1788 /* Get file information from directory entry */ 1789 1789 /*-----------------------------------------------------------------------*/ 1790 #if _FS_MINIMIZE <= 1 ||_FS_RPATH >= 21790 #if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 1791 1791 static 1792 1792 void get_fileinfo ( /* No return code */ 1793 DIR* dp, /* Pointer to the directory object */1793 FATFS_DIR* dp, /* Pointer to the directory object */ 1794 1794 FILINFO* fno /* Pointer to the file information to be filled */ 1795 1795 ) … … 1798 1798 TCHAR *p, c; 1799 1799 BYTE *dir; 1800 #if _USE_LFN1800 #if FF_USE_LFN 1801 1801 WCHAR w, *lfn; 1802 1802 #endif 1803 #if _CODE_PAGE == 650011803 #if FF_CODE_PAGE == 65001 1804 1804 unsigned char utf8_code[6]; 1805 1805 int code_size; … … 1815 1815 if (c == RDDEM) c = (TCHAR)DDEM; /* Restore replaced DDEM character */ 1816 1816 if (i == 9) *p++ = '.'; /* Insert a . if extension is exist */ 1817 #if _USE_LFN1817 #if FF_USE_LFN 1818 1818 if (IsUpper(c) && (dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY))) 1819 1819 c += 0x20; /* To lower */ 1820 #if _LFN_UNICODE1820 #if FF_LFN_UNICODE 1821 1821 if (IsDBCS1(c) && i != 8 && i != 11 && IsDBCS2(dir[i])) 1822 1822 c = c << 8 | dir[i++]; … … 1834 1834 *p = 0; /* Terminate SFN string by a \0 */ 1835 1835 1836 #if _USE_LFN1836 #if FF_USE_LFN 1837 1837 if (fno->lfname) { 1838 1838 i = 0; p = fno->lfname; … … 1840 1840 lfn = dp->lfn; 1841 1841 while ((w = *lfn++) != 0) { /* Get an LFN character */ 1842 #if ! _LFN_UNICODE1843 #if _CODE_PAGE == 650011842 #if !FF_LFN_UNICODE 1843 #if FF_CODE_PAGE == 65001 1844 1844 Utf16_to_Utf8(utf8_code, &code_size, w); 1845 1845 for (int j = 0; j < code_size - 1; j++) { … … 1862 1862 #endif 1863 1863 } 1864 #endif /* _FS_MINIMIZE <= 1 ||_FS_RPATH >= 2 */1864 #endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */ 1865 1865 1866 1866 … … 1870 1870 /* Pattern matching */ 1871 1871 /*-----------------------------------------------------------------------*/ 1872 #if _USE_FIND &&_FS_MINIMIZE <= 11872 #if FF_USE_FIND && FF_FS_MINIMIZE <= 1 1873 1873 static 1874 1874 WCHAR get_achar ( /* Get a character and advances ptr 1 or 2 */ … … 1878 1878 WCHAR chr; 1879 1879 1880 #if ! _LFN_UNICODE1881 #if _CODE_PAGE == 650011880 #if !FF_LFN_UNICODE 1881 #if FF_CODE_PAGE == 65001 1882 1882 int code_size; 1883 1883 chr = Utf8_to_Utf16(*ptr, &code_size); … … 1938 1938 return 0; 1939 1939 } 1940 #endif /* _USE_FIND &&_FS_MINIMIZE <= 1 */1940 #endif /* FF_USE_FIND && FF_FS_MINIMIZE <= 1 */ 1941 1941 1942 1942 … … 1949 1949 static 1950 1950 FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create */ 1951 DIR* dp, /* Pointer to the directory object */1951 FATFS_DIR* dp, /* Pointer to the directory object */ 1952 1952 const TCHAR** path /* Pointer to pointer to the segment in the path string */ 1953 1953 ) 1954 1954 { 1955 #if _USE_LFN /* LFN configuration */1955 #if FF_USE_LFN /* LFN configuration */ 1956 1956 BYTE b, cf; 1957 1957 WCHAR w, *lfn; 1958 1958 UINT i, ni, si, di; 1959 1959 const TCHAR *p; 1960 #if _CODE_PAGE == 650011960 #if FF_CODE_PAGE == 65001 1961 1961 unsigned char utf8_code[6]; 1962 1962 int code_size; … … 1969 1969 w = p[si++]; /* Get a character */ 1970 1970 if (w < ' ' || w == '/' || w == '\\') break; /* Break on end of segment */ 1971 if (di >= _MAX_LFN) /* Reject too long name */1971 if (di >= FF_MAX_LFN) /* Reject too long name */ 1972 1972 return FR_INVALID_NAME; 1973 #if ! _LFN_UNICODE1974 #if _CODE_PAGE == 650011973 #if !FF_LFN_UNICODE 1974 #if FF_CODE_PAGE == 65001 1975 1975 w = Utf8_to_Utf16(&p[si - 1], &code_size); 1976 1976 si += code_size - 1; … … 1993 1993 *path = &p[si]; /* Return pointer to the next segment */ 1994 1994 cf = (w < ' ') ? NS_LAST : 0; /* Set last segment flag if end of path */ 1995 #if _FS_RPATH1995 #if FF_FS_RPATH 1996 1996 if ((di == 1 && lfn[di - 1] == '.') || 1997 1997 (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { /* Is this segment a dot entry? */ … … 2040 2040 if (w) w = ExCvt[w - 0x80]; /* Convert extended character to upper (SBCS) */ 2041 2041 #else 2042 #if _CODE_PAGE == 650012042 #if FF_CODE_PAGE == 65001 2043 2043 Utf16_to_Utf8(utf8_code, &code_size, ff_wtoupper(w)); 2044 2044 #else … … 2048 2048 cf |= NS_LFN; /* Force create LFN entry */ 2049 2049 } 2050 #if _CODE_PAGE == 650012050 #if FF_CODE_PAGE == 65001 2051 2051 else 2052 2052 code_size = 1; 2053 2053 #endif 2054 2054 2055 #if _CODE_PAGE == 650012055 #if FF_CODE_PAGE == 65001 2056 2056 if (code_size > 1) { /* Is this DBC? (always false at SBCS cfg) */ 2057 2057 if (i >= ni - 1) { … … 2126 2126 mem_set(sfn, ' ', 11); 2127 2127 si = i = b = 0; ni = 8; 2128 #if _FS_RPATH2128 #if FF_FS_RPATH 2129 2129 if (p[si] == '.') { /* Is this a dot entry? */ 2130 2130 for (;;) { … … 2201 2201 static 2202 2202 FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ 2203 DIR* dp, /* Directory object to return last directory and found object */2203 FATFS_DIR* dp, /* Directory object to return last directory and found object */ 2204 2204 const TCHAR* path /* Full-path string to find a file or directory */ 2205 2205 ) … … 2209 2209 2210 2210 2211 #if _FS_RPATH2211 #if FF_FS_RPATH 2212 2212 if (*path == '/' || *path == '\\') { /* There is a heading separator */ 2213 2213 path++; dp->sclust = 0; /* Strip it and start from the root directory */ … … 2232 2232 if (res != FR_OK) { /* Failed to find the object */ 2233 2233 if (res == FR_NO_FILE) { /* Object is not found */ 2234 if ( _FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, */2234 if (FF_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, */ 2235 2235 dp->sclust = 0; dp->dir = 0; /* it is the root directory and stay there */ 2236 2236 if (!(ns & NS_LAST)) continue; /* Continue to follow if not last segment */ … … 2269 2269 UINT i; 2270 2270 int vol = -1; 2271 #if _STR_VOLUME_ID /* Find string drive id */2272 static const char* const str[] = { _VOLUME_STRS};2271 #if FF_STR_VOLUME_ID /* Find string drive id */ 2272 static const char* const str[] = {FF_VOLUME_STRS}; 2273 2273 const char *sp; 2274 2274 char c; … … 2278 2278 2279 2279 if (*path) { /* If the pointer is not a null */ 2280 for (tt = *path; (UINT)*tt >= ( _USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ; /* Find ':' in the path */2280 for (tt = *path; (UINT)*tt >= (FF_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ; /* Find ':' in the path */ 2281 2281 if (*tt == ':') { /* If a ':' is exist in the path name */ 2282 2282 tp = *path; 2283 2283 i = *tp++ - '0'; 2284 2284 if (i < 10 && tp == tt) { /* Is there a numeric drive id? */ 2285 if (i < _VOLUMES) { /* If a drive id is found, get the value and strip it */2285 if (i < FF_VOLUMES) { /* If a drive id is found, get the value and strip it */ 2286 2286 vol = (int)i; 2287 2287 *path = ++tt; 2288 2288 } 2289 2289 } 2290 #if _STR_VOLUME_ID2290 #if FF_STR_VOLUME_ID 2291 2291 else { /* No numeric drive number, find string drive id */ 2292 2292 i = 0; tt++; … … 2297 2297 if (IsLower(tc)) tc -= 0x20; 2298 2298 } while (c && (TCHAR)c == tc); 2299 } while ((c || tp != tt) && ++i < _VOLUMES); /* Repeat for each id until pattern match */2300 if (i < _VOLUMES) { /* If a drive id is found, get the value and strip it */2299 } while ((c || tp != tt) && ++i < FF_VOLUMES); /* Repeat for each id until pattern match */ 2300 if (i < FF_VOLUMES) { /* If a drive id is found, get the value and strip it */ 2301 2301 vol = (int)i; 2302 2302 *path = tt; … … 2306 2306 return vol; 2307 2307 } 2308 #if _FS_RPATH &&_VOLUMES >= 22308 #if FF_FS_RPATH && FF_VOLUMES >= 2 2309 2309 vol = CurrVol; /* Current drive */ 2310 2310 #else … … 2381 2381 stat = disk_status(fs->drv); 2382 2382 if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized */ 2383 if (! _FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check write protection if needed */2383 if (!FF_FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check write protection if needed */ 2384 2384 return FR_WRITE_PROTECTED; 2385 2385 return FR_OK; /* The file system object is valid */ … … 2395 2395 if (stat & STA_NOINIT) /* Check if the initialization succeeded */ 2396 2396 return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */ 2397 if (! _FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check disk write protection if needed */2397 if (!FF_FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check disk write protection if needed */ 2398 2398 return FR_WRITE_PROTECTED; 2399 #if _MAX_SS !=_MIN_SS /* Get sector size (multiple sector size cfg only) */2399 #if FF_MAX_SS != FF_MIN_SS /* Get sector size (multiple sector size cfg only) */ 2400 2400 if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK 2401 || SS(fs) < _MIN_SS || SS(fs) >_MAX_SS) return FR_DISK_ERR;2401 || SS(fs) < FF_MIN_SS || SS(fs) > FF_MAX_SS) return FR_DISK_ERR; 2402 2402 #endif 2403 2403 /* Find an FAT partition on the drive. Supports only generic partitioning, FDISK and SFD. */ … … 2448 2448 2449 2449 /* Determine the FAT sub type */ 2450 sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE); /* RSV + FAT + DIR */2450 sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE); /* RSV + FAT + FATFS_DIR */ 2451 2451 if (tsect < sysect) return FR_NO_FILESYSTEM; /* (Invalid volume size) */ 2452 2452 nclst = (tsect - sysect) / fs->csize; /* Number of clusters */ … … 2474 2474 return FR_NO_FILESYSTEM; 2475 2475 2476 #if ! _FS_READONLY2476 #if !FF_FS_READONLY 2477 2477 /* Initialize cluster allocation information */ 2478 2478 fs->last_clust = fs->free_clust = 0xFFFFFFFF; … … 2480 2480 /* Get fsinfo if available */ 2481 2481 fs->fsi_flag = 0x80; 2482 #if ( _FS_NOFSINFO & 3) != 32482 #if (FF_FS_NOFSINFO & 3) != 3 2483 2483 if (fmt == FS_FAT32 /* Enable FSINFO only if FAT32 and BPB_FSInfo == 1 */ 2484 2484 && LD_WORD(fs->win + BPB_FSInfo) == 1 … … 2490 2490 && LD_DWORD(fs->win + FSI_StrucSig) == 0x61417272) 2491 2491 { 2492 #if ( _FS_NOFSINFO & 1) == 02492 #if (FF_FS_NOFSINFO & 1) == 0 2493 2493 fs->free_clust = LD_DWORD(fs->win + FSI_Free_Count); 2494 2494 #endif 2495 #if ( _FS_NOFSINFO & 2) == 02495 #if (FF_FS_NOFSINFO & 2) == 0 2496 2496 fs->last_clust = LD_DWORD(fs->win + FSI_Nxt_Free); 2497 2497 #endif … … 2502 2502 fs->fs_type = fmt; /* FAT sub-type */ 2503 2503 fs->id = ++Fsid; /* File system mount ID */ 2504 #if _FS_RPATH2504 #if FF_FS_RPATH 2505 2505 fs->cdir = 0; /* Set current directory to root */ 2506 2506 #endif 2507 #if _FS_LOCK/* Clear file lock semaphores */2507 #if FF_FS_LOCK != 0 /* Clear file lock semaphores */ 2508 2508 clear_lock(fs); 2509 2509 #endif … … 2521 2521 static 2522 2522 FRESULT validate ( /* FR_OK(0): The object is valid, !=0: Invalid */ 2523 void* obj /* Pointer to the object FIL/ DIR to check validity */2524 ) 2525 { 2526 FIL *fil = (FIL*)obj; /* Assuming offset of .fs and .id in the FIL/ DIR structure is identical */2523 void* obj /* Pointer to the object FIL/FATFS_DIR to check validity */ 2524 ) 2525 { 2526 FIL *fil = (FIL*)obj; /* Assuming offset of .fs and .id in the FIL/FATFS_DIR structure is identical */ 2527 2527 2528 2528 … … 2567 2567 2568 2568 if (cfs) { 2569 #if _FS_LOCK2569 #if FF_FS_LOCK != 0 2570 2570 clear_lock(cfs); 2571 2571 #endif 2572 #if _FS_REENTRANT /* Discard sync object of the current volume */2572 #if FF_FS_REENTRANT /* Discard sync object of the current volume */ 2573 2573 if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR; 2574 2574 #endif … … 2578 2578 if (fs) { 2579 2579 fs->fs_type = 0; /* Clear new fs object */ 2580 #if _FS_REENTRANT /* Create sync object for the new volume */2580 #if FF_FS_REENTRANT /* Create sync object for the new volume */ 2581 2581 if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR; 2582 2582 #endif … … 2604 2604 { 2605 2605 FRESULT res; 2606 DIR dj;2606 FATFS_DIR dj; 2607 2607 BYTE *dir; 2608 2608 DEFINE_NAMEBUF; 2609 #if ! _FS_READONLY2609 #if !FF_FS_READONLY 2610 2610 DWORD dw, cl; 2611 2611 #endif … … 2616 2616 2617 2617 /* Get logical drive number */ 2618 #if ! _FS_READONLY2619 mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW ;2618 #if !FF_FS_READONLY 2619 mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW | FA_OPEN_APPEND; 2620 2620 res = find_volume(&dj.fs, &path, (BYTE)(mode & ~FA_READ)); 2621 2621 #else … … 2627 2627 res = follow_path(&dj, path); /* Follow the file path */ 2628 2628 dir = dj.dir; 2629 #if ! _FS_READONLY /* R/W configuration */2629 #if !FF_FS_READONLY /* R/W configuration */ 2630 2630 if (res == FR_OK) { 2631 2631 if (!dir) /* Default directory itself */ 2632 2632 res = FR_INVALID_NAME; 2633 #if _FS_LOCK2633 #if FF_FS_LOCK != 0 2634 2634 else 2635 2635 res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0); … … 2640 2640 if (res != FR_OK) { /* No file, create new */ 2641 2641 if (res == FR_NO_FILE) /* There is no file to open, create a new entry */ 2642 #if _FS_LOCK2642 #if FF_FS_LOCK != 0 2643 2643 res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES; 2644 2644 #else … … 2649 2649 } 2650 2650 else { /* Any object is already existing */ 2651 if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) { /* Cannot overwrite it (R/O or DIR) */2651 if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) { /* Cannot overwrite it (R/O or FATFS_DIR) */ 2652 2652 res = FR_DENIED; 2653 2653 } else { … … 2687 2687 if (res == FR_OK) { 2688 2688 if (mode & FA_CREATE_ALWAYS) /* Set file change flag if created or overwritten */ 2689 mode |= FA_ _WRITTEN;2689 mode |= FA_MODIFIED; 2690 2690 fp->dir_sect = dj.fs->winsect; /* Pointer to the directory entry */ 2691 2691 fp->dir_ptr = dir; 2692 #if _FS_LOCK2692 #if FF_FS_LOCK != 0 2693 2693 fp->lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0); 2694 2694 if (!fp->lockid) res = FR_INT_ERR; … … 2716 2716 fp->fptr = 0; /* File pointer */ 2717 2717 fp->dsect = 0; 2718 #if _USE_FASTSEEK2718 #if FF_USE_FASTSEEK 2719 2719 fp->cltbl = 0; /* Normal seek mode */ 2720 2720 #endif … … 2766 2766 clst = fp->sclust; /* Follow from the origin */ 2767 2767 } else { /* Middle or end of the file */ 2768 #if _USE_FASTSEEK2768 #if FF_USE_FASTSEEK 2769 2769 if (fp->cltbl) 2770 2770 clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ … … 2786 2786 if (disk_read(fp->fs->drv, rbuff, sect, cc) != RES_OK) 2787 2787 ABORT(fp->fs, FR_DISK_ERR); 2788 #if ! _FS_READONLY &&_FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */2789 #if _FS_TINY2788 #if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */ 2789 #if FF_FS_TINY 2790 2790 if (fp->fs->wflag && fp->fs->winsect - sect < cc) 2791 2791 mem_cpy(rbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), fp->fs->win, SS(fp->fs)); 2792 2792 #else 2793 if ((fp->flag & FA_ _DIRTY) && fp->dsect - sect < cc)2793 if ((fp->flag & FA_DIRTY) && fp->dsect - sect < cc) 2794 2794 mem_cpy(rbuff + ((fp->dsect - sect) * SS(fp->fs)), fp->buf, SS(fp->fs)); 2795 2795 #endif … … 2798 2798 continue; 2799 2799 } 2800 #if ! _FS_TINY2800 #if !FF_FS_TINY 2801 2801 if (fp->dsect != sect) { /* Load data sector if not in cache */ 2802 #if ! _FS_READONLY2803 if (fp->flag & FA_ _DIRTY) { /* Write-back dirty sector cache */2802 #if !FF_FS_READONLY 2803 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */ 2804 2804 if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) 2805 2805 ABORT(fp->fs, FR_DISK_ERR); 2806 fp->flag &= ~FA_ _DIRTY;2806 fp->flag &= ~FA_DIRTY; 2807 2807 } 2808 2808 #endif … … 2815 2815 rcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs)); /* Get partial sector data from sector buffer */ 2816 2816 if (rcnt > btr) rcnt = btr; 2817 #if _FS_TINY2817 #if FF_FS_TINY 2818 2818 if (move_window(fp->fs, fp->dsect) != FR_OK) /* Move sector window */ 2819 2819 ABORT(fp->fs, FR_DISK_ERR); … … 2830 2830 2831 2831 2832 #if ! _FS_READONLY2832 #if !FF_FS_READONLY 2833 2833 /*-----------------------------------------------------------------------*/ 2834 2834 /* Write File */ … … 2869 2869 clst = create_chain(fp->fs, 0); /* Create a new cluster chain */ 2870 2870 } else { /* Middle or end of the file */ 2871 #if _USE_FASTSEEK2871 #if FF_USE_FASTSEEK 2872 2872 if (fp->cltbl) 2873 2873 clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ … … 2882 2882 if (fp->sclust == 0) fp->sclust = clst; /* Set start cluster if the first write */ 2883 2883 } 2884 #if _FS_TINY2884 #if FF_FS_TINY 2885 2885 if (fp->fs->winsect == fp->dsect && sync_window(fp->fs)) /* Write-back sector cache */ 2886 2886 ABORT(fp->fs, FR_DISK_ERR); 2887 2887 #else 2888 if (fp->flag & FA_ _DIRTY) { /* Write-back sector cache */2888 if (fp->flag & FA_DIRTY) { /* Write-back sector cache */ 2889 2889 if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) 2890 2890 ABORT(fp->fs, FR_DISK_ERR); 2891 fp->flag &= ~FA_ _DIRTY;2891 fp->flag &= ~FA_DIRTY; 2892 2892 } 2893 2893 #endif … … 2901 2901 if (disk_write(fp->fs->drv, wbuff, sect, cc) != RES_OK) 2902 2902 ABORT(fp->fs, FR_DISK_ERR); 2903 #if _FS_MINIMIZE <= 22904 #if _FS_TINY2903 #if FF_FS_MINIMIZE <= 2 2904 #if FF_FS_TINY 2905 2905 if (fp->fs->winsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */ 2906 2906 mem_cpy(fp->fs->win, wbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), SS(fp->fs)); … … 2910 2910 if (fp->dsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */ 2911 2911 mem_cpy(fp->buf, wbuff + ((fp->dsect - sect) * SS(fp->fs)), SS(fp->fs)); 2912 fp->flag &= ~FA_ _DIRTY;2912 fp->flag &= ~FA_DIRTY; 2913 2913 } 2914 2914 #endif … … 2917 2917 continue; 2918 2918 } 2919 #if _FS_TINY2919 #if FF_FS_TINY 2920 2920 if (fp->fptr >= fp->fsize) { /* Avoid silly cache filling at growing edge */ 2921 2921 if (sync_window(fp->fs)) ABORT(fp->fs, FR_DISK_ERR); … … 2933 2933 wcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */ 2934 2934 if (wcnt > btw) wcnt = btw; 2935 #if _FS_TINY2935 #if FF_FS_TINY 2936 2936 if (move_window(fp->fs, fp->dsect) != FR_OK) /* Move sector window */ 2937 2937 ABORT(fp->fs, FR_DISK_ERR); … … 2940 2940 #else 2941 2941 mem_cpy(&fp->buf[fp->fptr % SS(fp->fs)], wbuff, wcnt); /* Fit partial sector */ 2942 fp->flag |= FA_ _DIRTY;2942 fp->flag |= FA_DIRTY; 2943 2943 #endif 2944 2944 } 2945 2945 2946 2946 if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */ 2947 fp->flag |= FA_ _WRITTEN; /* Set file change flag */2947 fp->flag |= FA_MODIFIED; /* Set file change flag */ 2948 2948 2949 2949 LEAVE_FF(fp->fs, FR_OK); … … 2968 2968 res = validate(fp); /* Check validity of the object */ 2969 2969 if (res == FR_OK) { 2970 if (fp->flag & FA_ _WRITTEN) { /* Is there any change to the file? */2971 #if ! _FS_TINY2972 if (fp->flag & FA_ _DIRTY) { /* Write-back cached data if needed */2970 if (fp->flag & FA_MODIFIED) { /* Is there any change to the file? */ 2971 #if !FF_FS_TINY 2972 if (fp->flag & FA_DIRTY) { /* Write-back cached data if needed */ 2973 2973 if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) 2974 2974 LEAVE_FF(fp->fs, FR_DISK_ERR); 2975 fp->flag &= ~FA_ _DIRTY;2975 fp->flag &= ~FA_DIRTY; 2976 2976 } 2977 2977 #endif … … 2986 2986 ST_DWORD(dir + DIR_WrtTime, tm); 2987 2987 ST_WORD(dir + DIR_LstAccDate, 0); 2988 fp->flag &= ~FA_ _WRITTEN;2988 fp->flag &= ~FA_MODIFIED; 2989 2989 fp->fs->wflag = 1; 2990 2990 res = sync_fs(fp->fs); … … 2996 2996 } 2997 2997 2998 #endif /* ! _FS_READONLY */2998 #endif /* !FF_FS_READONLY */ 2999 2999 3000 3000 … … 3012 3012 3013 3013 3014 #if ! _FS_READONLY3014 #if !FF_FS_READONLY 3015 3015 res = f_sync(fp); /* Flush cached data */ 3016 3016 if (res == FR_OK) … … 3019 3019 res = validate(fp); /* Lock volume */ 3020 3020 if (res == FR_OK) { 3021 #if _FS_REENTRANT3021 #if FF_FS_REENTRANT 3022 3022 FATFS *fs = fp->fs; 3023 3023 #endif 3024 #if _FS_LOCK3024 #if FF_FS_LOCK != 0 3025 3025 res = dec_lock(fp->lockid); /* Decrement file open counter */ 3026 3026 if (res == FR_OK) 3027 3027 #endif 3028 3028 fp->fs = 0; /* Invalidate file object */ 3029 #if _FS_REENTRANT3029 #if FF_FS_REENTRANT 3030 3030 unlock_fs(fs, FR_OK); /* Unlock volume */ 3031 3031 #endif … … 3042 3042 /*-----------------------------------------------------------------------*/ 3043 3043 3044 #if _FS_RPATH >= 13045 #if _VOLUMES >= 23044 #if FF_FS_RPATH >= 1 3045 #if FF_VOLUMES >= 2 3046 3046 FRESULT f_chdrive ( 3047 3047 const TCHAR* path /* Drive number */ … … 3066 3066 { 3067 3067 FRESULT res; 3068 DIR dj;3068 FATFS_DIR dj; 3069 3069 DEFINE_NAMEBUF; 3070 3070 … … 3093 3093 3094 3094 3095 #if _FS_RPATH >= 23095 #if FF_FS_RPATH >= 2 3096 3096 FRESULT f_getcwd ( 3097 3097 TCHAR* buff, /* Pointer to the directory path */ … … 3100 3100 { 3101 3101 FRESULT res; 3102 DIR dj;3102 FATFS_DIR dj; 3103 3103 UINT i, n; 3104 3104 DWORD ccl; … … 3131 3131 if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */ 3132 3132 if (res != FR_OK) break; 3133 #if _USE_LFN3133 #if FF_USE_LFN 3134 3134 fno.lfname = buff; 3135 3135 fno.lfsize = i; … … 3137 3137 get_fileinfo(&dj, &fno); /* Get the directory name and push it to the buffer */ 3138 3138 tp = fno.fname; 3139 #if _USE_LFN3139 #if FF_USE_LFN 3140 3140 if (*buff) tp = buff; 3141 3141 #endif … … 3149 3149 tp = buff; 3150 3150 if (res == FR_OK) { 3151 #if _VOLUMES >= 23151 #if FF_VOLUMES >= 2 3152 3152 *tp++ = '0' + CurrVol; /* Put drive number */ 3153 3153 *tp++ = ':'; … … 3167 3167 LEAVE_FF(dj.fs, res); 3168 3168 } 3169 #endif /* _FS_RPATH >= 2 */3170 #endif /* _FS_RPATH >= 1 */3171 3172 3173 3174 #if _FS_MINIMIZE <= 23169 #endif /* FF_FS_RPATH >= 2 */ 3170 #endif /* FF_FS_RPATH >= 1 */ 3171 3172 3173 3174 #if FF_FS_MINIMIZE <= 2 3175 3175 /*-----------------------------------------------------------------------*/ 3176 3176 /* Seek File R/W Pointer */ … … 3184 3184 FRESULT res; 3185 3185 DWORD clst, bcs, nsect, ifptr; 3186 #if _USE_FASTSEEK3186 #if FF_USE_FASTSEEK 3187 3187 DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl; 3188 3188 #endif … … 3194 3194 LEAVE_FF(fp->fs, (FRESULT)fp->err); 3195 3195 3196 #if _USE_FASTSEEK3196 #if FF_USE_FASTSEEK 3197 3197 if (fp->cltbl) { /* Fast seek */ 3198 3198 if (ofs == CREATE_LINKMAP) { /* Create CLMT */ … … 3231 3231 dsc += (ofs - 1) / SS(fp->fs) & (fp->fs->csize - 1); 3232 3232 if (fp->fptr % SS(fp->fs) && dsc != fp->dsect) { /* Refill sector cache if needed */ 3233 #if ! _FS_TINY3234 #if ! _FS_READONLY3235 if (fp->flag & FA_ _DIRTY) { /* Write-back dirty sector cache */3233 #if !FF_FS_TINY 3234 #if !FF_FS_READONLY 3235 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */ 3236 3236 if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) 3237 3237 ABORT(fp->fs, FR_DISK_ERR); 3238 fp->flag &= ~FA_ _DIRTY;3238 fp->flag &= ~FA_DIRTY; 3239 3239 } 3240 3240 #endif … … 3252 3252 { 3253 3253 if (ofs > fp->fsize /* In read-only mode, clip offset with the file size */ 3254 #if ! _FS_READONLY3254 #if !FF_FS_READONLY 3255 3255 && !(fp->flag & FA_WRITE) 3256 3256 #endif … … 3268 3268 } else { /* When seek to back cluster, */ 3269 3269 clst = fp->sclust; /* start from the first cluster */ 3270 #if ! _FS_READONLY3270 #if !FF_FS_READONLY 3271 3271 if (clst == 0) { /* If no cluster chain, create a new chain */ 3272 3272 clst = create_chain(fp->fs, 0); … … 3280 3280 if (clst != 0) { 3281 3281 while (ofs > bcs) { /* Cluster following loop */ 3282 #if ! _FS_READONLY3282 #if !FF_FS_READONLY 3283 3283 if (fp->flag & FA_WRITE) { /* Check if in write mode or not */ 3284 3284 clst = create_chain(fp->fs, clst); /* Force stretch if in write mode */ … … 3304 3304 } 3305 3305 if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) { /* Fill sector cache if needed */ 3306 #if ! _FS_TINY3307 #if ! _FS_READONLY3308 if (fp->flag & FA_ _DIRTY) { /* Write-back dirty sector cache */3306 #if !FF_FS_TINY 3307 #if !FF_FS_READONLY 3308 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */ 3309 3309 if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) 3310 3310 ABORT(fp->fs, FR_DISK_ERR); 3311 fp->flag &= ~FA_ _DIRTY;3311 fp->flag &= ~FA_DIRTY; 3312 3312 } 3313 3313 #endif … … 3317 3317 fp->dsect = nsect; 3318 3318 } 3319 #if ! _FS_READONLY3319 #if !FF_FS_READONLY 3320 3320 if (fp->fptr > fp->fsize) { /* Set file change flag if the file size is extended */ 3321 3321 fp->fsize = fp->fptr; 3322 fp->flag |= FA_ _WRITTEN;3322 fp->flag |= FA_MODIFIED; 3323 3323 } 3324 3324 #endif … … 3342 3342 } 3343 3343 3344 #if _FS_MINIMIZE <= 13344 #if FF_FS_MINIMIZE <= 1 3345 3345 /*-----------------------------------------------------------------------*/ 3346 3346 /* Create a Directory Object */ … … 3348 3348 3349 3349 FRESULT f_opendir ( 3350 DIR* dp, /* Pointer to directory object to create */3350 FATFS_DIR* dp, /* Pointer to directory object to create */ 3351 3351 const TCHAR* path /* Pointer to the directory path */ 3352 3352 ) … … 3376 3376 dp->id = fs->id; 3377 3377 res = dir_sdi(dp, 0); /* Rewind directory */ 3378 #if _FS_LOCK3378 #if FF_FS_LOCK != 0 3379 3379 if (res == FR_OK) { 3380 3380 if (dp->sclust) { … … 3404 3404 3405 3405 FRESULT f_closedir ( 3406 DIR *dp /* Pointer to the directory object to be closed */3406 FATFS_DIR *dp /* Pointer to the directory object to be closed */ 3407 3407 ) 3408 3408 { … … 3412 3412 res = validate(dp); 3413 3413 if (res == FR_OK) { 3414 #if _FS_REENTRANT3414 #if FF_FS_REENTRANT 3415 3415 FATFS *fs = dp->fs; 3416 3416 #endif 3417 #if _FS_LOCK3417 #if FF_FS_LOCK != 0 3418 3418 if (dp->lockid) /* Decrement sub-directory open counter */ 3419 3419 res = dec_lock(dp->lockid); … … 3421 3421 #endif 3422 3422 dp->fs = 0; /* Invalidate directory object */ 3423 #if _FS_REENTRANT3423 #if FF_FS_REENTRANT 3424 3424 unlock_fs(fs, FR_OK); /* Unlock volume */ 3425 3425 #endif … … 3436 3436 3437 3437 FRESULT f_readdir ( 3438 DIR* dp, /* Pointer to the open directory object */3438 FATFS_DIR* dp, /* Pointer to the open directory object */ 3439 3439 FILINFO* fno /* Pointer to file information to return */ 3440 3440 ) … … 3472 3472 3473 3473 3474 #if _USE_FIND3474 #if FF_USE_FIND 3475 3475 /*-----------------------------------------------------------------------*/ 3476 3476 /* Find next file */ … … 3478 3478 3479 3479 FRESULT f_findnext ( 3480 DIR* dp, /* Pointer to the open directory object */3480 FATFS_DIR* dp, /* Pointer to the open directory object */ 3481 3481 FILINFO* fno /* Pointer to the file information structure */ 3482 3482 ) … … 3488 3488 res = f_readdir(dp, fno); /* Get a directory item */ 3489 3489 if (res != FR_OK || !fno || !fno->fname[0]) break; /* Terminate if any error or end of directory */ 3490 #if _USE_LFN3490 #if FF_USE_LFN 3491 3491 if (fno->lfname && pattern_matching(dp->pat, fno->lfname, 0, 0)) break; /* Test for LFN if exist */ 3492 3492 #endif … … 3504 3504 3505 3505 FRESULT f_findfirst ( 3506 DIR* dp, /* Pointer to the blank directory object */3506 FATFS_DIR* dp, /* Pointer to the blank directory object */ 3507 3507 FILINFO* fno, /* Pointer to the file information structure */ 3508 3508 const TCHAR* path, /* Pointer to the directory to open */ … … 3520 3520 } 3521 3521 3522 #endif /* _USE_FIND */3523 3524 3525 3526 #if _FS_MINIMIZE == 03522 #endif /* FF_USE_FIND */ 3523 3524 3525 3526 #if FF_FS_MINIMIZE == 0 3527 3527 /*-----------------------------------------------------------------------*/ 3528 3528 /* Get File Status */ … … 3535 3535 { 3536 3536 FRESULT res; 3537 DIR dj;3537 FATFS_DIR dj; 3538 3538 DEFINE_NAMEBUF; 3539 3539 … … 3559 3559 3560 3560 3561 #if ! _FS_READONLY3561 #if !FF_FS_READONLY 3562 3562 /*-----------------------------------------------------------------------*/ 3563 3563 /* Get Number of Free Clusters */ … … 3650 3650 if (fp->fsize > fp->fptr) { 3651 3651 fp->fsize = fp->fptr; /* Set file size to current R/W point */ 3652 fp->flag |= FA_ _WRITTEN;3652 fp->flag |= FA_MODIFIED; 3653 3653 if (fp->fptr == 0) { /* When set file size to zero, remove entire cluster chain */ 3654 3654 res = remove_chain(fp->fs, fp->sclust); … … 3664 3664 } 3665 3665 } 3666 #if ! _FS_TINY3667 if (res == FR_OK && (fp->flag & FA_ _DIRTY)) {3666 #if !FF_FS_TINY 3667 if (res == FR_OK && (fp->flag & FA_DIRTY)) { 3668 3668 if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) 3669 3669 res = FR_DISK_ERR; 3670 3670 else 3671 fp->flag &= ~FA_ _DIRTY;3671 fp->flag &= ~FA_DIRTY; 3672 3672 } 3673 3673 #endif … … 3691 3691 { 3692 3692 FRESULT res; 3693 DIR dj, sdj;3693 FATFS_DIR dj, sdj; 3694 3694 BYTE *dir; 3695 3695 DWORD dclst = 0; … … 3702 3702 INIT_BUF(dj); 3703 3703 res = follow_path(&dj, path); /* Follow the file path */ 3704 if ( _FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))3704 if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) 3705 3705 res = FR_INVALID_NAME; /* Cannot remove dot entry */ 3706 #if _FS_LOCK3706 #if FF_FS_LOCK != 0 3707 3707 if (res == FR_OK) res = chk_lock(&dj, 2); /* Cannot remove open object */ 3708 3708 #endif … … 3718 3718 dclst = ld_clust(dj.fs, dir); 3719 3719 if (dclst && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-directory ? */ 3720 #if _FS_RPATH3720 #if FF_FS_RPATH 3721 3721 if (dclst == dj.fs->cdir) { /* Is it the current directory? */ 3722 3722 res = FR_DENIED; … … 3724 3724 #endif 3725 3725 { 3726 mem_cpy(&sdj, &dj, sizeof ( DIR)); /* Open the sub-directory */3726 mem_cpy(&sdj, &dj, sizeof (FATFS_DIR)); /* Open the sub-directory */ 3727 3727 sdj.sclust = dclst; 3728 3728 res = dir_sdi(&sdj, 2); … … 3760 3760 { 3761 3761 FRESULT res; 3762 DIR dj;3762 FATFS_DIR dj; 3763 3763 BYTE *dir, n; 3764 3764 DWORD dsc, dcl, pcl, tm = GET_FATTIME(); … … 3772 3772 res = follow_path(&dj, path); /* Follow the file path */ 3773 3773 if (res == FR_OK) res = FR_EXIST; /* Any object with same name is already existing */ 3774 if ( _FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT))3774 if (FF_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) 3775 3775 res = FR_INVALID_NAME; 3776 3776 if (res == FR_NO_FILE) { /* Can create a new directory */ … … 3836 3836 { 3837 3837 FRESULT res; 3838 DIR dj;3838 FATFS_DIR dj; 3839 3839 BYTE *dir; 3840 3840 DEFINE_NAMEBUF; … … 3846 3846 res = follow_path(&dj, path); /* Follow the file path */ 3847 3847 FREE_BUF(); 3848 if ( _FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))3848 if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) 3849 3849 res = FR_INVALID_NAME; 3850 3850 if (res == FR_OK) { … … 3877 3877 { 3878 3878 FRESULT res; 3879 DIR djo, djn;3879 FATFS_DIR djo, djn; 3880 3880 BYTE buf[21], *dir; 3881 3881 DWORD dw; … … 3890 3890 INIT_BUF(djo); 3891 3891 res = follow_path(&djo, path_old); /* Check old object */ 3892 if ( _FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))3892 if (FF_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT)) 3893 3893 res = FR_INVALID_NAME; 3894 #if _FS_LOCK3894 #if FF_FS_LOCK != 0 3895 3895 if (res == FR_OK) res = chk_lock(&djo, 2); 3896 3896 #endif … … 3900 3900 } else { 3901 3901 mem_cpy(buf, djo.dir + DIR_Attr, 21); /* Save information about object except name */ 3902 mem_cpy(&djn, &djo, sizeof ( DIR)); /* Duplicate the directory object */3902 mem_cpy(&djn, &djo, sizeof (FATFS_DIR)); /* Duplicate the directory object */ 3903 3903 if (get_ldnumber(&path_new) >= 0) /* Snip drive number off and ignore it */ 3904 3904 res = follow_path(&djn, path_new); /* and make sure if new object name is not conflicting */ … … 3909 3909 dir = djn.dir; 3910 3910 if (dir[DIR_Attr] & AM_DIR) { /* The new object is a directory */ 3911 temp_new_path = (TCHAR *)ff_memalloc(( _MAX_LFN + 1) * sizeof(WCHAR));3912 ntstdio_snprintf(temp_new_path,_MAX_LFN, "%s/%s", path_new, basename((char *)path_old));3911 temp_new_path = (TCHAR *)ff_memalloc((FF_MAX_LFN + 1) * sizeof(WCHAR)); 3912 snprintf(temp_new_path, FF_MAX_LFN, "%s/%s", path_new, basename((char *)path_old)); 3913 3913 res = follow_path(&djn, temp_new_path); 3914 3914 } … … 3966 3966 { 3967 3967 FRESULT res; 3968 DIR dj;3968 FATFS_DIR dj; 3969 3969 BYTE *dir; 3970 3970 DEFINE_NAMEBUF; … … 3977 3977 res = follow_path(&dj, path); /* Follow the file path */ 3978 3978 FREE_BUF(); 3979 if ( _FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))3979 if (FF_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) 3980 3980 res = FR_INVALID_NAME; 3981 3981 if (res == FR_OK) { … … 3995 3995 } 3996 3996 3997 #endif /* ! _FS_READONLY */3998 #endif /* _FS_MINIMIZE == 0 */3999 #endif /* _FS_MINIMIZE <= 1 */4000 #endif /* _FS_MINIMIZE <= 2 */4001 4002 4003 4004 4005 #if _USE_LABEL3997 #endif /* !FF_FS_READONLY */ 3998 #endif /* FF_FS_MINIMIZE == 0 */ 3999 #endif /* FF_FS_MINIMIZE <= 1 */ 4000 #endif /* FF_FS_MINIMIZE <= 2 */ 4001 4002 4003 4004 4005 #if FF_USE_LABEL 4006 4006 /*-----------------------------------------------------------------------*/ 4007 4007 /* Get volume label */ … … 4015 4015 { 4016 4016 FRESULT res; 4017 DIR dj;4017 FATFS_DIR dj; 4018 4018 UINT i, j; 4019 #if _USE_LFN &&_LFN_UNICODE4019 #if FF_USE_LFN && FF_LFN_UNICODE 4020 4020 WCHAR w; 4021 4021 #endif … … 4032 4032 res = dir_read(&dj, 1); /* Get an entry with AM_VOL */ 4033 4033 if (res == FR_OK) { /* A volume label is exist */ 4034 #if _USE_LFN &&_LFN_UNICODE4034 #if FF_USE_LFN && FF_LFN_UNICODE 4035 4035 i = j = 0; 4036 4036 do { … … 4070 4070 4071 4071 4072 #if ! _FS_READONLY4072 #if !FF_FS_READONLY 4073 4073 /*-----------------------------------------------------------------------*/ 4074 4074 /* Set volume label */ … … 4080 4080 { 4081 4081 FRESULT res; 4082 DIR dj;4082 FATFS_DIR dj; 4083 4083 BYTE vn[11]; 4084 4084 UINT i, j, sl; 4085 4085 WCHAR w; 4086 4086 DWORD tm; 4087 #if _CODE_PAGE == 650014087 #if FF_CODE_PAGE == 65001 4088 4088 int code_size; 4089 4089 unsigned char utf8_code[6]; … … 4101 4101 i = j = 0; 4102 4102 do { 4103 #if _CODE_PAGE == 650014103 #if FF_CODE_PAGE == 65001 4104 4104 w = ff_wtoupper(Utf8_to_Utf16(&label[i], &code_size)); 4105 4105 i += code_size; … … 4110 4110 vn[j++] = utf8_code[k]; 4111 4111 #else 4112 #if _USE_LFN &&_LFN_UNICODE4112 #if FF_USE_LFN && FF_LFN_UNICODE 4113 4113 w = ff_convert(ff_wtoupper(label[i++]), 0); 4114 4114 #else … … 4116 4116 if (IsDBCS1(w)) 4117 4117 w = (j < 10 && i < sl && IsDBCS2(label[i])) ? w << 8 | (BYTE)label[i++] : 0; 4118 #if _USE_LFN4118 #if FF_USE_LFN 4119 4119 w = ff_convert(ff_wtoupper(ff_convert(w, 1)), 0); 4120 4120 #else … … 4174 4174 } 4175 4175 4176 #endif /* ! _FS_READONLY */4177 #endif /* _USE_LABEL */4176 #endif /* !FF_FS_READONLY */ 4177 #endif /* FF_USE_LABEL */ 4178 4178 4179 4179 … … 4182 4182 /* Forward data to the stream directly (available on only tiny cfg) */ 4183 4183 /*-----------------------------------------------------------------------*/ 4184 #if _USE_FORWARD &&_FS_TINY4184 #if FF_USE_FORWARD && FF_FS_TINY 4185 4185 4186 4186 FRESULT f_forward ( … … 4235 4235 LEAVE_FF(fp->fs, FR_OK); 4236 4236 } 4237 #endif /* _USE_FORWARD */4238 4239 4240 4241 #if _USE_MKFS && !_FS_READONLY4237 #endif /* FF_USE_FORWARD */ 4238 4239 4240 4241 #if FF_USE_MKFS && !FF_FS_READONLY 4242 4242 /*-----------------------------------------------------------------------*/ 4243 4243 /* Create file system on the logical drive */ … … 4263 4263 FATFS *fs; 4264 4264 DSTATUS stat; 4265 #if _USE_TRIM4265 #if FF_USE_TRIM 4266 4266 DWORD eb[2]; 4267 4267 #endif … … 4282 4282 if (stat & STA_NOINIT) return FR_NOT_READY; 4283 4283 if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; 4284 #if _MAX_SS !=_MIN_SS /* Get disk sector size */4285 if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS || SS(fs) <_MIN_SS)4284 #if FF_MAX_SS != FF_MIN_SS /* Get disk sector size */ 4285 if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > FF_MAX_SS || SS(fs) < FF_MIN_SS) 4286 4286 return FR_DISK_ERR; 4287 4287 #endif 4288 if ( _MULTI_PARTITION && part) {4288 if (FF_MULTI_PARTITION && part) { 4289 4289 /* Get partition information from partition table in the MBR */ 4290 4290 if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR; … … 4308 4308 au = cst[i]; 4309 4309 } 4310 if (au >= _MIN_SS) au /= SS(fs); /* Number of sectors per cluster */4310 if (au >= FF_MIN_SS) au /= SS(fs); /* Number of sectors per cluster */ 4311 4311 if (!au) au = 1; 4312 4312 if (au > 128) au = 128; … … 4362 4362 } 4363 4363 4364 if ( _MULTI_PARTITION && part) {4364 if (FF_MULTI_PARTITION && part) { 4365 4365 /* Update system ID in the partition table */ 4366 4366 tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE]; … … 4465 4465 } while (--i); 4466 4466 4467 #if _USE_TRIM /* Erase data area if needed */4467 #if FF_USE_TRIM /* Erase data area if needed */ 4468 4468 { 4469 4469 eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1; … … 4488 4488 4489 4489 4490 #if _MULTI_PARTITION4490 #if FF_MULTI_PARTITION 4491 4491 /*-----------------------------------------------------------------------*/ 4492 4492 /* Create partition table on the physical drive */ … … 4518 4518 4519 4519 /* Create partition table */ 4520 mem_set(buf, 0, _MAX_SS);4520 mem_set(buf, 0, FF_MAX_SS); 4521 4521 p = buf + MBR_Table; b_cyl = 0; 4522 4522 for (i = 0; i < 4; i++, p += SZ_PTE) { … … 4555 4555 4556 4556 4557 #endif /* _MULTI_PARTITION */4558 #endif /* _USE_MKFS && !_FS_READONLY */4559 4560 4561 4562 4563 #if _USE_STRFUNC4557 #endif /* FF_MULTI_PARTITION */ 4558 #endif /* FF_USE_MKFS && !FF_FS_READONLY */ 4559 4560 4561 4562 4563 #if FF_USE_STRFUNC 4564 4564 /*-----------------------------------------------------------------------*/ 4565 4565 /* Get a string from the file */ … … 4579 4579 4580 4580 while (n < len - 1) { /* Read characters until buffer gets filled */ 4581 #if _USE_LFN &&_LFN_UNICODE4582 #if _STRF_ENCODE == 3 /* Read a character in UTF-8 */4581 #if FF_USE_LFN && FF_LFN_UNICODE 4582 #if FF_STRF_ENCODE == 3 /* Read a character in UTF-8 */ 4583 4583 f_read(fp, s, 1, &rc); 4584 4584 if (rc != 1) break; … … 4602 4602 } 4603 4603 } 4604 #elif _STRF_ENCODE == 2 /* Read a character in UTF-16BE */4604 #elif FF_STRF_ENCODE == 2 /* Read a character in UTF-16BE */ 4605 4605 f_read(fp, s, 2, &rc); 4606 4606 if (rc != 2) break; 4607 4607 c = s[1] + (s[0] << 8); 4608 #elif _STRF_ENCODE == 1 /* Read a character in UTF-16LE */4608 #elif FF_STRF_ENCODE == 1 /* Read a character in UTF-16LE */ 4609 4609 f_read(fp, s, 2, &rc); 4610 4610 if (rc != 2) break; … … 4627 4627 c = s[0]; 4628 4628 #endif 4629 if ( _USE_STRFUNC == 2 && c == '\r') continue; /* Strip '\r' */4629 if (FF_USE_STRFUNC == 2 && c == '\r') continue; /* Strip '\r' */ 4630 4630 *p++ = c; 4631 4631 n++; … … 4639 4639 4640 4640 4641 #if ! _FS_READONLY4641 #if !FF_FS_READONLY 4642 4642 /*-----------------------------------------------------------------------*/ 4643 4643 /* Put a character to the file */ … … 4661 4661 4662 4662 4663 if ( _USE_STRFUNC == 2 && c == '\n') /* LF -> CRLF conversion */4663 if (FF_USE_STRFUNC == 2 && c == '\n') /* LF -> CRLF conversion */ 4664 4664 putc_bfd(pb, '\r'); 4665 4665 … … 4667 4667 if (i < 0) return; 4668 4668 4669 #if _USE_LFN &&_LFN_UNICODE4670 #if _STRF_ENCODE == 3 /* Write a character in UTF-8 */4669 #if FF_USE_LFN && FF_LFN_UNICODE 4670 #if FF_STRF_ENCODE == 3 /* Write a character in UTF-8 */ 4671 4671 if (c < 0x80) { /* 7-bit */ 4672 4672 pb->buf[i++] = (BYTE)c; … … 4680 4680 pb->buf[i++] = (BYTE)(0x80 | (c & 0x3F)); 4681 4681 } 4682 #elif _STRF_ENCODE == 2 /* Write a character in UTF-16BE */4682 #elif FF_STRF_ENCODE == 2 /* Write a character in UTF-16BE */ 4683 4683 pb->buf[i++] = (BYTE)(c >> 8); 4684 4684 pb->buf[i++] = (BYTE)c; 4685 #elif _STRF_ENCODE == 1 /* Write a character in UTF-16LE */4685 #elif FF_STRF_ENCODE == 1 /* Write a character in UTF-16LE */ 4686 4686 pb->buf[i++] = (BYTE)c; 4687 4687 pb->buf[i++] = (BYTE)(c >> 8); … … 4866 4866 ret = f_vprintf(fp, fmt, arp); 4867 4867 va_end(arp); 4868 4868 4869 4869 return ret; 4870 4870 } 4871 4871 4872 #endif /* ! _FS_READONLY */4873 #endif /* _USE_STRFUNC */4872 #endif /* !FF_FS_READONLY */ 4873 #endif /* FF_USE_STRFUNC */ -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ff.h
r352 r374 28 28 #include "ffconf.h" /* FatFs configuration options */ 29 29 #include "diskio.h" 30 #if _FATFS != _FFCONF30 #if _FATFS != FFCONF_DEF 31 31 #error Wrong configuration file (ffconf.h). 32 32 #endif … … 36 36 /* Definitions of volume management */ 37 37 38 #if _MULTI_PARTITION /* Multiple partition configuration */38 #if FF_MULTI_PARTITION /* Multiple partition configuration */ 39 39 typedef struct { 40 40 BYTE pd; /* Physical drive number */ … … 55 55 /* Type of path name strings on FatFs API */ 56 56 57 #if _LFN_UNICODE /* Unicode string */58 #if ! _USE_LFN59 #error _LFN_UNICODE must be 0 at non-LFN cfg.57 #if FF_LFN_UNICODE /* Unicode string */ 58 #if !FF_USE_LFN 59 #error FF_LFN_UNICODE must be 0 at non-LFN cfg. 60 60 #endif 61 61 #ifndef _INC_TCHAR … … 87 87 WORD id; /* File system mount ID */ 88 88 WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ 89 #if _MAX_SS !=_MIN_SS89 #if FF_MAX_SS != FF_MIN_SS 90 90 WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */ 91 91 #endif 92 #if _FS_REENTRANT93 _SYNC_t sobj; /* Identifier of sync object */94 #endif 95 #if ! _FS_READONLY92 #if FF_FS_REENTRANT 93 FF_SYNC_t sobj; /* Identifier of sync object */ 94 #endif 95 #if !FF_FS_READONLY 96 96 DWORD last_clust; /* Last allocated cluster */ 97 97 DWORD free_clust; /* Number of free clusters */ 98 98 #endif 99 #if _FS_RPATH99 #if FF_FS_RPATH 100 100 DWORD cdir; /* Current directory start cluster (0:root) */ 101 101 #endif … … 107 107 DWORD database; /* Data start sector */ 108 108 DWORD winsect; /* Current sector appearing in the win[] */ 109 BYTE win[ _MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */109 BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */ 110 110 } FATFS; 111 111 … … 124 124 DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */ 125 125 DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */ 126 #if ! _FS_READONLY126 #if !FF_FS_READONLY 127 127 DWORD dir_sect; /* Sector number containing the directory entry */ 128 128 BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */ 129 129 #endif 130 #if _USE_FASTSEEK130 #if FF_USE_FASTSEEK 131 131 DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */ 132 132 #endif 133 #if _FS_LOCK133 #if FF_FS_LOCK != 0 134 134 UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */ 135 135 #endif 136 #if ! _FS_TINY137 BYTE buf[ _MAX_SS]; /* File private data read/write window */136 #if !FF_FS_TINY 137 BYTE buf[FF_MAX_SS]; /* File private data read/write window */ 138 138 #endif 139 139 } FIL; … … 141 141 142 142 143 /* Directory object structure ( DIR) */143 /* Directory object structure (FATFS_DIR) */ 144 144 145 145 typedef struct __dirstream { … … 152 152 BYTE* dir; /* Pointer to the current SFN entry in the win[] */ 153 153 BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ 154 #if _FS_LOCK154 #if FF_FS_LOCK != 0 155 155 UINT lockid; /* File lock ID (index of file semaphore table Files[]) */ 156 156 #endif 157 #if _USE_LFN157 #if FF_USE_LFN 158 158 WCHAR* lfn; /* Pointer to the LFN working buffer */ 159 159 WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */ 160 160 #endif 161 #if _USE_FIND161 #if FF_USE_FIND 162 162 const TCHAR* pat; /* Pointer to the name matching pattern */ 163 163 #endif 164 } DIR;164 } FATFS_DIR; 165 165 166 166 … … 174 174 BYTE fattrib; /* Attribute */ 175 175 TCHAR fname[13]; /* Short file name (8.3 format) */ 176 #if _USE_LFN176 #if FF_USE_LFN 177 177 TCHAR* lfname; /* Pointer to the LFN buffer */ 178 178 UINT lfsize; /* Size of LFN buffer in TCHAR */ … … 203 203 FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */ 204 204 FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ 205 FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_LOCK */205 FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */ 206 206 FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ 207 207 } FRESULT; … … 220 220 FRESULT f_truncate (FIL* fp); /* Truncate file */ 221 221 FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */ 222 FRESULT f_opendir ( DIR* dp, const TCHAR* path); /* Open a directory */223 FRESULT f_closedir ( DIR* dp); /* Close an open directory */224 FRESULT f_readdir ( DIR* dp, FILINFO* fno); /* Read a directory item */225 FRESULT f_findfirst ( DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */226 FRESULT f_findnext ( DIR* dp, FILINFO* fno); /* Find next file */222 FRESULT f_opendir (FATFS_DIR* dp, const TCHAR* path); /* Open a directory */ 223 FRESULT f_closedir (FATFS_DIR* dp); /* Close an open directory */ 224 FRESULT f_readdir (FATFS_DIR* dp, FILINFO* fno); /* Read a directory item */ 225 FRESULT f_findfirst (FATFS_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */ 226 FRESULT f_findnext (FATFS_DIR* dp, FILINFO* fno); /* Find next file */ 227 227 FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */ 228 228 FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */ … … 270 270 271 271 /* RTC function */ 272 #if ! _FS_READONLY && !_FS_NORTC272 #if !FF_FS_READONLY && !FF_FS_NORTC 273 273 DWORD get_fattime (void); 274 274 #endif 275 275 276 276 /* Unicode support functions */ 277 #if _USE_LFN /* Unicode - OEM code conversion */277 #if FF_USE_LFN /* Unicode - OEM code conversion */ 278 278 WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */ 279 279 WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */ 280 #if _USE_LFN == 3 /* Memory functions */280 #if FF_USE_LFN == 3 /* Memory functions */ 281 281 void* ff_memalloc (UINT msize); /* Allocate memory block */ 282 282 void ff_memfree (void* mblock); /* Free memory block */ … … 285 285 286 286 /* Sync functions */ 287 #if _FS_REENTRANT288 int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj); /* Create a sync object */289 int ff_req_grant ( _SYNC_t sobj); /* Lock sync object */290 void ff_rel_grant ( _SYNC_t sobj); /* Unlock sync object */291 int ff_del_syncobj ( _SYNC_t sobj); /* Delete a sync object */287 #if FF_FS_REENTRANT 288 int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */ 289 int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */ 290 void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */ 291 int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */ 292 292 #endif 293 293 … … 304 304 #define FA_OPEN_EXISTING 0x00 305 305 306 #if ! _FS_READONLY306 #if !FF_FS_READONLY 307 307 #define FA_WRITE 0x02 308 308 #define FA_CREATE_NEW 0x04 309 309 #define FA_CREATE_ALWAYS 0x08 310 310 #define FA_OPEN_ALWAYS 0x10 311 #define FA__WRITTEN 0x20 312 #define FA__DIRTY 0x40 311 #define FA_OPEN_APPEND 0x30 312 #define FA_MODIFIED 0x20 313 #define FA_DIRTY 0x40 313 314 #endif 314 315 … … 341 342 /* Multi-byte word access macros */ 342 343 343 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */344 #if FF_WORD_ACCESS == 1 /* Enable word access to the FAT structure */ 344 345 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) 345 346 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.c
r369 r374 51 51 #include "sdfs.h" 52 52 #include "ff.h" 53 #include "util/ntstdio.h"54 55 extern ntstdio_t ntstdio; 53 #include <stdio.h> 54 #include "hal/rtc_api.h" 55 #include "ffarch.h" 56 56 57 57 enum ffarch_state_t { … … 80 80 ret2 = get_tim(&now); 81 81 if (ret2 != E_OK){ 82 ntstdio_printf(&ntstdio,"[ffarch] get_tim error: %s",82 printf("[ffarch] get_tim error: %s", 83 83 itron_strerror(ret2)); 84 84 return; … … 94 94 ret = tslp_tsk(timer); 95 95 if ((ret != E_OK) && (ret != E_TMOUT)) { 96 ntstdio_printf(&ntstdio,"[ffarch] tslp_tsk error: %s %d",96 printf("[ffarch] tslp_tsk error: %s %d", 97 97 itron_strerror(ret), timer); 98 98 break; … … 101 101 ret2 = get_tim(&now); 102 102 if (ret2 != E_OK) { 103 ntstdio_printf(&ntstdio,"[ffarch] get_tim error: %s",103 printf("[ffarch] get_tim error: %s", 104 104 itron_strerror(ret2)); 105 105 break; … … 150 150 151 151 if (romdisk_init()) { 152 ntstdio_printf(&ntstdio,"ROM disk (0:) OK!\n");152 printf("ROM disk (0:) OK!\n"); 153 153 } 154 154 else { 155 ntstdio_printf(&ntstdio, "ROM disk (0:) NG!\n"); 156 } 157 158 serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV); 155 printf("ROM disk (0:) NG!\n"); 156 } 159 157 } 160 158 … … 272 270 { 273 271 DRESULT res; 274 uint32_t *dp = (uint32_t *)buff , st, ed;272 uint32_t *dp = (uint32_t *)buff; 275 273 uint8_t *ptr = (uint8_t *)buff; 276 274 … … 333 331 { 334 332 BYTE s = 0; 335 333 336 334 /* Write protected */ 337 335 if (WP()) … … 377 375 case FFS_RETRY_WAIT: 378 376 if (ffarch_retry_count == 0) { 379 ntstdio_printf(&ntstdio,"SD card (1:) initialize tired...\n");377 printf("SD card (1:) initialize tired...\n"); 380 378 381 379 ffarch_state = FFS_IDLE; … … 390 388 if ((sdfs._is_initialized & STA_NOINIT) 391 389 || (((sdfs_prev_status & STA_NODISK) != 0) && ((sdfs_new_status & STA_NODISK) == 0))) { 392 ntstdio_printf(&ntstdio,"SD card initializing ...\n");390 printf("SD card initializing ...\n"); 393 391 394 392 if (SD_begin()) { 395 ntstdio_printf(&ntstdio,"SD card (1:) OK!\n");393 printf("SD card (1:) OK!\n"); 396 394 397 395 /* uploadディレクトリを作成しておく */ … … 403 401 } 404 402 else { 405 ntstdio_printf(&ntstdio,"SD card (1:) NG!\n");403 printf("SD card (1:) NG!\n"); 406 404 ffarch_state = FFS_RETRY_WAIT; 407 405 ffarch_timer = 1000 * 1000; … … 410 408 /* SDカードが抜かれた場合 */ 411 409 else if (((sdfs_prev_status & STA_NODISK) == 0) && ((sdfs_new_status & STA_NODISK) != 0)) { 412 ntstdio_printf(&ntstdio,"SD card unmount\n");410 printf("SD card unmount\n"); 413 411 414 412 f_mount(&Sd.FatFs, "1:", 0); … … 428 426 } 429 427 430 int ff_cre_syncobj(BYTE vol, _SYNC_t* sobj)428 int ff_cre_syncobj(BYTE vol, FF_SYNC_t* sobj) 431 429 { 432 430 return 1; 433 431 } 434 432 435 int ff_req_grant( _SYNC_t sobj)433 int ff_req_grant(FF_SYNC_t sobj) 436 434 { 437 435 ER ret; … … 440 438 } 441 439 442 void ff_rel_grant( _SYNC_t sobj)440 void ff_rel_grant(FF_SYNC_t sobj) 443 441 { 444 442 sig_sem(SEM_FILESYSTEM); 445 443 } 446 444 447 int ff_del_syncobj( _SYNC_t sobj)445 int ff_del_syncobj(FF_SYNC_t sobj) 448 446 { 449 447 return 1; -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffconf.h
r352 r374 3 3 /---------------------------------------------------------------------------*/ 4 4 5 #define _FFCONF 64180 /* Revision ID */ 5 #define FFCONF_DEF 64180 /* Revision ID */ 6 7 #define FFS_DBG 0 6 8 7 9 /*---------------------------------------------------------------------------/ … … 9 11 /---------------------------------------------------------------------------*/ 10 12 11 #define _FS_READONLY 013 #define FF_FS_READONLY 0 12 14 /* This option switches read-only configuration. (0:Read/Write or 1:Read-only) 13 15 / Read-only configuration removes writing API functions, f_write(), f_sync(), … … 16 18 17 19 18 #define _FS_MINIMIZE 020 #define FF_FS_MINIMIZE 0 19 21 /* This option defines minimization level to remove some basic API functions. 20 22 / … … 26 28 27 29 28 #define _USE_STRFUNC 130 #define FF_USE_STRFUNC 1 29 31 /* This option switches string functions, f_gets(), f_putc(), f_puts() and 30 32 / f_printf(). … … 35 37 36 38 37 #define _USE_FIND 139 #define FF_USE_FIND 1 38 40 /* This option switches filtered directory read feature and related functions, 39 41 / f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */ 40 42 41 43 42 #define _USE_MKFS 144 #define FF_USE_MKFS 1 43 45 /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ 44 46 45 47 46 #define _USE_FASTSEEK 048 #define FF_USE_FASTSEEK 0 47 49 /* This option switches fast seek feature. (0:Disable or 1:Enable) */ 48 50 49 51 50 #define _USE_LABEL 152 #define FF_USE_LABEL 1 51 53 /* This option switches volume label functions, f_getlabel() and f_setlabel(). 52 54 / (0:Disable or 1:Enable) */ 53 55 54 56 55 #define _USE_FORWARD 157 #define FF_USE_FORWARD 1 56 58 /* This option switches f_forward() function. (0:Disable or 1:Enable) 57 / To enable it, also _FS_TINY need to be set to 1. */59 / To enable it, also FF_FS_TINY need to be set to 1. */ 58 60 59 61 … … 62 64 /---------------------------------------------------------------------------*/ 63 65 64 #define _CODE_PAGE 6500166 #define FF_CODE_PAGE 65001 65 67 /* This option specifies the OEM code page to be used on the target system. 66 68 / Incorrect setting of the code page can cause a file open failure. … … 91 93 92 94 93 #define _USE_LFN 394 #define _MAX_LFN 25595 /* The _USE_LFN option switches the LFN feature.96 / 97 / 0: Disable LFN feature. _MAX_LFN has no effect.95 #define FF_USE_LFN 3 96 #define FF_MAX_LFN 255 97 /* The FF_USE_LFN option switches the LFN feature. 98 / 99 / 0: Disable LFN feature. FF_MAX_LFN has no effect. 98 100 / 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. 99 101 / 2: Enable LFN with dynamic working buffer on the STACK. … … 101 103 / 102 104 / When enable the LFN feature, Unicode handling functions (option/unicode.c) must 103 / be added to the project. The LFN working buffer occupies ( _MAX_LFN + 1) * 2 bytes.105 / be added to the project. The LFN working buffer occupies (FF_MAX_LFN + 1) * 2 bytes. 104 106 / When use stack for the working buffer, take care on stack overflow. When use heap 105 107 / memory for the working buffer, memory management functions, ff_memalloc() and … … 107 109 108 110 109 #define _LFN_UNICODE 0111 #define FF_LFN_UNICODE 0 110 112 /* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode) 111 / To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE113 / To use Unicode string for the path name, enable LFN feature and set FF_LFN_UNICODE 112 114 / to 1. This option also affects behavior of string I/O functions. */ 113 115 114 116 115 #define _STRF_ENCODE 3116 /* When _LFN_UNICODE is 1, this option selects the character encoding on the file to117 #define FF_STRF_ENCODE 3 118 /* When FF_LFN_UNICODE is 1, this option selects the character encoding on the file to 117 119 / be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf(). 118 120 / … … 122 124 / 3: UTF-8 123 125 / 124 / When _LFN_UNICODE is 0, this option has no effect. */ 125 126 127 #define _FS_RPATH 2 126 / When FF_LFN_UNICODE is 0, this option has no effect. */ 127 128 129 #define FF_LFN_BUF 255 130 #define FF_SFN_BUF 12 131 /* This set of options defines size of file name members in the FILINFO structure 132 / which is used to read out directory items. These values should be suffcient for 133 / the file names to read. The maximum possible length of the read file name depends 134 / on character encoding. When LFN is not enabled, these options have no effect. */ 135 136 137 #define FF_FS_RPATH 2 128 138 /* This option configures relative path feature. 129 139 / … … 139 149 /---------------------------------------------------------------------------*/ 140 150 141 #define _VOLUMES 2151 #define FF_VOLUMES 4 142 152 /* Number of volumes (logical drives) to be used. */ 143 153 144 154 145 #define _STR_VOLUME_ID 0146 #define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"147 /* _STR_VOLUME_ID option switches string volume ID feature.148 / When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive149 / number in the path name. _VOLUME_STRS defines the drive ID strings for each150 / logical drives. Number of items must be equal to _VOLUMES. Valid characters for155 #define FF_STR_VOLUME_ID 0 156 #define FF_VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3" 157 /* FF_STR_VOLUME_ID option switches string volume ID feature. 158 / When FF_STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive 159 / number in the path name. FF_VOLUME_STRS defines the drive ID strings for each 160 / logical drives. Number of items must be equal to FF_VOLUMES. Valid characters for 151 161 / the drive ID strings are: A-Z and 0-9. */ 152 162 153 163 154 #define _MULTI_PARTITION 0164 #define FF_MULTI_PARTITION 0 155 165 /* This option switches multi-partition feature. By default (0), each logical drive 156 166 / number is bound to the same physical drive number and only an FAT volume found on … … 160 170 161 171 162 #define _MIN_SS 512163 #define _MAX_SS 512172 #define FF_MIN_SS 512 173 #define FF_MAX_SS 512 164 174 /* These options configure the range of sector size to be supported. (512, 1024, 165 175 / 2048 or 4096) Always set both 512 for most systems, all type of memory cards and 166 176 / harddisk. But a larger value may be required for on-board flash memory and some 167 / type of optical media. When _MAX_SS is larger than_MIN_SS, FatFs is configured177 / type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured 168 178 / to variable sector size and GET_SECTOR_SIZE command must be implemented to the 169 179 / disk_ioctl() function. */ 170 180 171 181 172 #define _USE_TRIM 0182 #define FF_USE_TRIM 0 173 183 /* This option switches ATA-TRIM feature. (0:Disable or 1:Enable) 174 184 / To enable Trim feature, also CTRL_TRIM command should be implemented to the … … 176 186 177 187 178 #define _FS_NOFSINFO 0188 #define FF_FS_NOFSINFO 0 179 189 /* If you need to know correct free space on the FAT32 volume, set bit 0 of this 180 190 / option, and f_getfree() function at first time after volume mount will force … … 193 203 /---------------------------------------------------------------------------*/ 194 204 195 #define _FS_TINY 1205 #define FF_FS_TINY 1 196 206 /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) 197 / At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS207 / At the tiny configuration, size of the file object (FIL) is reduced FF_MAX_SS 198 208 / bytes. Instead of private sector buffer eliminated from the file object, 199 209 / common sector buffer in the file system object (FATFS) is used for the file … … 201 211 202 212 203 #define _FS_NORTC 0204 #define _NORTC_MON 1205 #define _NORTC_MDAY 1206 #define _NORTC_YEAR 2015207 /* The _FS_NORTC option switches timestamp feature. If the system does not have208 / an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable213 #define FF_FS_NORTC 0 214 #define FF_NORTC_MON 1 215 #define FF_NORTC_MDAY 1 216 #define FF_NORTC_YEAR 2015 217 /* The FF_FS_NORTC option switches timestamp feature. If the system does not have 218 / an RTC function or valid timestamp is not needed, set FF_FS_NORTC to 1 to disable 209 219 / the timestamp feature. All objects modified by FatFs will have a fixed timestamp 210 / defined by _NORTC_MON, _NORTC_MDAY and_NORTC_YEAR.211 / When timestamp feature is enabled ( _FS_NORTC == 0), get_fattime() function need212 / to be added to the project to read current time form RTC. _NORTC_MON,213 / _NORTC_MDAY and_NORTC_YEAR have no effect.214 / These options have no effect at read-only configuration ( _FS_READONLY == 1). */215 216 217 #define _FS_LOCK 0218 /* The _FS_LOCK option switches file lock feature to control duplicated file open219 / and illegal operation to open objects. This option must be 0 when _FS_READONLY220 / defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR. 221 / When timestamp feature is enabled (FF_FS_NORTC == 0), get_fattime() function need 222 / to be added to the project to read current time form RTC. FF_NORTC_MON, 223 / FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. 224 / These options have no effect at read-only configuration (FF_FS_READONLY == 1). */ 225 226 227 #define FF_FS_LOCK 0 228 /* The FF_FS_LOCK option switches file lock feature to control duplicated file open 229 / and illegal operation to open objects. This option must be 0 when FF_FS_READONLY 220 230 / is 1. 221 231 / … … 227 237 228 238 229 #define _FS_REENTRANT 1230 #define _FS_TIMEOUT 1000231 #define _SYNC_t unsigned int232 /* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs239 #define FF_FS_REENTRANT 1 240 #define FF_FS_TIMEOUT 1000 241 #define FF_SYNC_t unsigned int 242 /* The FF_FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs 233 243 / module itself. Note that regardless of this option, file access to different 234 244 / volume is always re-entrant and volume control functions, f_mount(), f_mkfs() … … 236 246 / to the same volume is under control of this feature. 237 247 / 238 / 0: Disable re-entrancy. _FS_TIMEOUT and_SYNC_t have no effect.248 / 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect. 239 249 / 1: Enable re-entrancy. Also user provided synchronization handlers, 240 250 / ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() … … 242 252 / option/syscall.c. 243 253 / 244 / The _FS_TIMEOUT defines timeout period in unit of time tick.245 / The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,254 / The FF_FS_TIMEOUT defines timeout period in unit of time tick. 255 / The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, 246 256 / SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be 247 257 / included somewhere in the scope of ff.c. */ 248 258 249 259 250 #define _WORD_ACCESS 1251 /* The _WORD_ACCESS option is an only platform dependent option. It defines260 #define FF_WORD_ACCESS 1 261 /* The FF_WORD_ACCESS option is an only platform dependent option. It defines 252 262 / which access method is used to the word data on the FAT volume. 253 263 / … … 258 268 / * Byte order on the memory is little-endian. 259 269 / 260 / If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.270 / If it is the case, FF_WORD_ACCESS can also be set to 1 to reduce code size. 261 271 / Following table shows allowable settings of some type of processors. 262 272 / -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.c
r359 r374 118 118 //#include "mbed_debug.h" 119 119 #include "mbed_wait_api.h" 120 #include "util/ntstdio.h" 121 122 extern ntstdio_t ntstdio; 123 #define debug(...) ntstdio_printf(&ntstdio, __VA_ARGS__) 124 #define debug_if(cond, ...) if(cond){ ntstdio_printf(&ntstdio, __VA_ARGS__); } 120 #include <stdio.h> 121 122 #define debug(...) printf(__VA_ARGS__) 123 #define debug_if(cond, ...) if(cond){ printf(__VA_ARGS__); } 125 124 126 125 static int sdfs_initialise_card_v1(sdfs_t *obj); … … 137 136 #define SD_DBG 0 138 137 139 sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name)138 void sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) 140 139 { 141 140 obj->name = name; -
asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.h
r359 r374 80 80 * @param name The name used to access the virtual filesystem 81 81 */ 82 sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);82 void sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); 83 83 84 84 int sdfs_initialize(sdfs_t *obj); -
asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/usrcmd.c
r352 r374 47 47 #include "core/ntshell.h" 48 48 #include "core/ntlibc.h" 49 #include "util/ntstdio.h"50 51 extern ntstdio_t ntstdio; 49 #include <stdio.h> 50 #include <getopt.h> 51 52 52 extern int ntshell_exit; 53 54 extern int mbtowc(wchar_t *__restrict wc, const char *__restrict src, size_t n);55 56 /* musl_getopt from msul */57 char *optarg;58 int optind=1, opterr=1, optopt, optpos, optreset=0;59 extern int optind, opterr;60 61 static void ntstdio_write(ntstdio_t *handle, const char *str, int l)62 {63 for (; *str && l >= 0; l--) {64 ntstdio_putc(handle, *str++);65 }66 }67 68 static void __getopt_msg(const char *a, const char *b, const char *c, size_t l)69 {70 ntstdio_puts(&ntstdio, a);71 ntstdio_write(&ntstdio, b, strlen(b));72 ntstdio_write(&ntstdio, c, l);73 ntstdio_putc(&ntstdio, '\n');74 }75 76 static int musl_getopt(int argc, char * const argv[], const char *optstring)77 {78 int i;79 wchar_t c, d;80 int k, l;81 char *optchar;82 83 if (!optind || optreset) {84 optreset = 0;85 optpos = 0;86 optind = 1;87 }88 89 if (optind >= argc || !argv[optind])90 return -1;91 92 if (argv[optind][0] != '-') {93 if (optstring[0] == '-') {94 optarg = argv[optind++];95 return 1;96 }97 return -1;98 }99 100 if (!argv[optind][1])101 return -1;102 103 if (argv[optind][1] == '-' && !argv[optind][2])104 return optind++, -1;105 106 if (!optpos) optpos++;107 if ((k = mbtowc(&c, argv[optind]+optpos, MB_LEN_MAX)) < 0) {108 k = 1;109 c = 0xfffd; /* replacement char */110 }111 optchar = argv[optind]+optpos;112 optopt = c;113 optpos += k;114 115 if (!argv[optind][optpos]) {116 optind++;117 optpos = 0;118 }119 120 if (optstring[0] == '-' || optstring[0] == '+')121 optstring++;122 123 i = 0;124 d = 0;125 do {126 l = mbtowc(&d, optstring+i, MB_LEN_MAX);127 if (l>0) i+=l; else i++;128 } while (l && d != c);129 130 if (d != c) {131 if (optstring[0] != ':' && opterr)132 __getopt_msg(argv[0], ": unrecognized option: ", optchar, k);133 return '?';134 }135 if (optstring[i] == ':') {136 if (optstring[i+1] == ':') optarg = 0;137 else if (optind >= argc) {138 if (optstring[0] == ':') return ':';139 if (opterr) __getopt_msg(argv[0],140 ": option requires an argument: ",141 optchar, k);142 return '?';143 }144 if (optstring[i+1] != ':' || optpos) {145 optarg = argv[optind++] + optpos;146 optpos = 0;147 }148 }149 return c;150 }151 152 int shell_kill(int pid, int sig)153 {154 DebugBreak();155 return -1;156 }157 158 int shell_gettimeofday(struct timeval *tv, void *tzvp)159 {160 SYSTIM time;161 if (!tv) return 0;162 get_tim(&time);163 tv->tv_sec = time / 1000000;164 tv->tv_usec = time - (tv->tv_sec * 1000000);165 return 0;166 }167 53 168 54 void put_rc(const char *func, FRESULT rc) … … 178 64 while (*p++); 179 65 } 180 ntstdio_printf(&ntstdio,"%s() =>%u FR_%s\n", func, (UINT)rc, p);66 printf("%s() =>%u FR_%s\n", func, (UINT)rc, p); 181 67 } 182 68 … … 190 76 while (*p++); 191 77 } 192 ntstdio_printf(&ntstdio,"%s() =>%u %s\n", func, (UINT)rc, p);78 printf("%s() =>%u %s\n", func, (UINT)rc, p); 193 79 } 194 80 … … 240 126 241 127 ntlibc_strlcat(path, "\n", sizeof(path)); 242 ntstdio_printf(&ntstdio,path);128 printf(path); 243 129 244 130 return 0; … … 252 138 char *fn; 253 139 254 #if _USE_LFN140 #if FF_USE_LFN 255 141 fn = *fno->lfname ? fno->lfname : fno->fname; 256 142 #else … … 263 149 264 150 if (list_option & LS_LONG) { 265 ntstdio_printf(&ntstdio,"%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ",151 printf("%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ", 266 152 (fno->fattrib & AM_DIR) ? 'd' : '-', 267 153 (fno->fattrib & AM_RDO) ? 'r' : '-', … … 277 163 278 164 if (fno->fattrib & AM_DIR) { /* It is a directory */ 279 ntstdio_printf(&ntstdio, "%10S", " ");165 printf("%10s ", " "); 280 166 } 281 167 else { 282 ntstdio_printf(&ntstdio, "%10d", fno->fsize);168 printf("%10lu ", fno->fsize); 283 169 } 284 170 } 285 171 286 172 if (fno->fattrib & AM_DIR) { /* It is a directory */ 287 ntstdio_printf(&ntstdio,"\x1B[32m%s\x1B[0m\n", fn);173 printf("\x1B[32m%s\x1B[0m\n", fn); 288 174 } 289 175 else { 290 ntstdio_printf(&ntstdio,"%s\n", fn);291 } 292 } 293 294 #define LFN_BUF_SIZE ( _MAX_LFN + 1)176 printf("%s\n", fn); 177 } 178 } 179 180 #define LFN_BUF_SIZE (FF_MAX_LFN + 1) 295 181 /* lsコマンド dir内 表示 */ 296 182 void print_ls(char *path_p, char *pattern_p, BYTE list_option) … … 298 184 FRESULT res; 299 185 FILINFO fno; 300 DIR dir;186 FATFS_DIR dir; 301 187 char *fn; /* This function assumes non-Unicode configuration */ 302 188 … … 307 193 path_backup = ff_memalloc(LFN_BUF_SIZE); 308 194 if (path_backup == NULL) { 309 ntstdio_printf(&ntstdio,"ff_memalloc err.\n");195 printf("ff_memalloc err.\n"); 310 196 return; 311 197 } 312 198 313 #if _USE_LFN199 #if FF_USE_LFN 314 200 char *lfn = NULL; 315 201 lfn = ff_memalloc(LFN_BUF_SIZE); 316 202 if (lfn == NULL) { 317 ntstdio_printf(&ntstdio,"ff_memalloc err.\n");203 printf("ff_memalloc err.\n"); 318 204 ff_memfree(path_backup); 319 205 return; … … 333 219 334 220 while ((res == FR_OK) && (fno.fname[0] != 0)) { 335 if (pattern_p != NULL && (fno.fattrib & AM_DIR) && ((fno.fname[0] == '.') ? (pattern_p[0] == '.') : 1)) {/* DIR とパターンマッチしている場合はDIR 内部を ls する */336 #if _USE_LFN221 if (pattern_p != NULL && (fno.fattrib & AM_DIR) && ((fno.fname[0] == '.') ? (pattern_p[0] == '.') : 1)) {/* FATFS_DIR とパターンマッチしている場合は FATFS_DIR 内部を ls する */ 222 #if FF_USE_LFN 337 223 fn = *fno.lfname ? fno.lfname : fno.fname; 338 224 #else … … 351 237 } 352 238 353 ntstdio_printf(&ntstdio,"\n%s/%s:\n", path_p, fn);239 printf("\n%s/%s:\n", path_p, fn); 354 240 355 241 print_ls(fn, NULL, list_option); 356 242 357 ntstdio_printf(&ntstdio,"\n");243 printf("\n"); 358 244 359 245 if ((res = f_chdrive(path_backup)) != FR_OK) { … … 384 270 { 385 271 char *pattern_p = NULL, *basename_p = NULL, *dirname_p = NULL; 386 char default_pattern[ _MAX_LFN] = "";272 char default_pattern[FF_MAX_LFN] = ""; 387 273 int c; 388 274 BYTE list_option = 0; 389 275 390 while ((c = musl_getopt(argc, argv, "al")) != -1) {276 while ((c = getopt(argc, argv, "al")) != -1) { 391 277 switch (c) { 392 278 case 'a': … … 446 332 return 0; 447 333 448 #if _USE_LFN334 #if FF_USE_LFN 449 335 /* LFN buffer alloc */ 450 336 lfn = ff_memalloc(LFN_BUF_SIZE); 451 337 if (lfn == NULL) { 452 ntstdio_printf(&ntstdio,"alloc err.\n");338 printf("alloc err.\n"); 453 339 goto cp_end; 454 340 } … … 460 346 local_buff = ff_memalloc(64); 461 347 if (local_buff == NULL) { 462 ntstdio_printf(&ntstdio,"alloc err.\n");348 printf("alloc err.\n"); 463 349 goto cp_end; 464 350 } … … 470 356 if (res != FR_OK) { 471 357 if (res == FR_NO_FILE) 472 ntstdio_printf(&ntstdio, "src no file.\n", res);358 printf("src no file.\n"); 473 359 else 474 ntstdio_printf(&ntstdio,"src stat err(%d).\n", res);360 printf("src stat err(%d).\n", res); 475 361 goto cp_end; 476 362 } … … 481 367 res = f_open(&src_fp, src_str_p, (FA_OPEN_EXISTING | FA_READ)); 482 368 if (res != FR_OK) { 483 ntstdio_printf(&ntstdio,"src open err(%d).\n", res);369 printf("src open err(%d).\n", res); 484 370 goto cp_end; 485 371 } … … 496 382 dst_mod_str_p = ff_memalloc(LFN_BUF_SIZE); 497 383 if (dst_mod_str_p == NULL) { 498 ntstdio_printf(&ntstdio,"alloc err.\n");384 printf("alloc err.\n"); 499 385 goto cp_end; 500 386 } 501 ntstdio_snprintf(dst_mod_str_p, LFN_BUF_SIZE, "%s/%s\0", dst_str_p, src_basename_p);387 snprintf(dst_mod_str_p, LFN_BUF_SIZE, "%s/%s\0", dst_str_p, src_basename_p); 502 388 dst_str_p = dst_mod_str_p; 503 389 } 504 390 else { 505 ntstdio_printf(&ntstdio,"dst file exists.\n");391 printf("dst file exists.\n"); 506 392 goto cp_end_1; 507 393 } 508 394 } 509 395 else { 510 ntstdio_printf(&ntstdio,"src stat err(%d).\n", res);396 printf("src stat err(%d).\n", res); 511 397 goto cp_end_1; 512 398 } … … 514 400 res = f_open(&dst_fp, dst_str_p, (FA_CREATE_NEW | FA_WRITE)); 515 401 if (res != FR_OK) { 516 ntstdio_printf(&ntstdio,"dst open err(%d).\n", res);402 printf("dst open err(%d).\n", res); 517 403 goto cp_end_1; 518 404 } … … 525 411 res = f_read(&src_fp, local_buff, sizeof(local_buff), &read_size); 526 412 if (res != FR_OK) { 527 ntstdio_printf(&ntstdio,"src read err(%d).\n", res);413 printf("src read err(%d).\n", res); 528 414 goto cp_end_2; 529 415 } … … 532 418 res = f_write(&dst_fp, local_buff, read_size, &write_size); 533 419 if (res != FR_OK) { 534 ntstdio_printf(&ntstdio,"dst write err(%d).\n", res);420 printf("dst write err(%d).\n", res); 535 421 goto cp_end_2; 536 422 } 537 423 if (read_size != write_size) { 538 ntstdio_printf(&ntstdio, "dst write err(disk full).\n", res);424 printf("dst write err(disk full).\n"); 539 425 goto cp_end_2; 540 426 } … … 622 508 unsigned int op_offset = 0, op_size = 0, op_end = 0; 623 509 624 while ((op = musl_getopt(argc, argv, "hduos0123456789xX")) != -1) {510 while ((op = getopt(argc, argv, "hduos0123456789xX")) != -1) { 625 511 switch (op) { 626 512 case 'h': /* help */ 627 ntstdio_printf(&ntstdio," hexdump [OPTION] file\n");628 ntstdio_printf(&ntstdio," -h : help\n");629 ntstdio_printf(&ntstdio," -d : print all byte with convert and color [in character area] (default)\n");630 ntstdio_printf(&ntstdio," -u : try print UTF-8 code [in character area]\n");631 ntstdio_printf(&ntstdio," -oOFFSET : print start offset address from top\n");632 ntstdio_printf(&ntstdio," -sSIZE : print size\n");513 printf(" hexdump [OPTION] file\n"); 514 printf(" -h : help\n"); 515 printf(" -d : print all byte with convert and color [in character area] (default)\n"); 516 printf(" -u : try print UTF-8 code [in character area]\n"); 517 printf(" -oOFFSET : print start offset address from top\n"); 518 printf(" -sSIZE : print size\n"); 633 519 break; 634 520 case 'd': /* print one byte character [in character area] (default) */ … … 661 547 /* position adjusting */ 662 548 if (op_offset >= fsrc.fsize) { 663 ntstdio_printf(&ntstdio, "error : input offset is bigger than file size(0x%X).\n", fsrc.fsize);549 printf("error : input offset is bigger than file size(0x%lX).\n", fsrc.fsize); 664 550 return 0; 665 551 } … … 674 560 char *pos = line; 675 561 int rst = sizeof(line); 676 int len = ntstdio_snprintf(pos, rst, "%08X: ", i);562 int len = snprintf(pos, rst, "%08X: ", i); 677 563 pos += len; 678 564 rst -= len; … … 693 579 char c = data[j]; 694 580 if (j != 7) 695 len = ntstdio_snprintf(pos, rst, "%02X ", c);581 len = snprintf(pos, rst, "%02X ", c); 696 582 else 697 len = ntstdio_snprintf(pos, rst, "%02X-", c);583 len = snprintf(pos, rst, "%02X-", c); 698 584 pos += len; 699 585 rst -= len; … … 723 609 break; 724 610 if (j + k != 7) 725 len = ntstdio_snprintf(pos, rst, "%02X ", data[j + k]);611 len = snprintf(pos, rst, "%02X ", data[j + k]); 726 612 else 727 len = ntstdio_snprintf(pos, rst, "%02X-", data[j + k]);613 len = snprintf(pos, rst, "%02X-", data[j + k]); 728 614 pos += len; 729 615 rst -= len; … … 743 629 apos += len; 744 630 arst -= len; 745 len = ntstdio_snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", CCOLOR_RESET, ' ');631 len = snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", CCOLOR_RESET, ' '); 746 632 utf8_odd_bytes--; 747 633 } … … 763 649 c = '?'; 764 650 } 765 len = ntstdio_snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", ccolor, c);651 len = snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", ccolor, c); 766 652 } 767 653 … … 772 658 for (int j = br; j < 16; j++) { 773 659 if (j != 7) 774 len = ntstdio_snprintf(pos, rst, " ");660 len = snprintf(pos, rst, " "); 775 661 else 776 len = ntstdio_snprintf(pos, rst, " -");662 len = snprintf(pos, rst, " -"); 777 663 pos += len; 778 664 rst -= len; 779 665 } 780 666 781 len = ntstdio_snprintf(pos, rst, ": %s\n", ascii);667 len = snprintf(pos, rst, ": %s\n", ascii); 782 668 pos += len; 783 669 rst -= len; 784 670 785 ntstdio_puts(&ntstdio,line);671 puts(line); 786 672 } 787 673 … … 796 682 char buf[30]; 797 683 798 ret = shell_clock_gettime(CLOCK_REALTIME, &tp);684 ret = clock_gettime(CLOCK_REALTIME, &tp); 799 685 if (ret != 0) { 800 ntstdio_printf(&ntstdio,"clock_gettime error %d", ret);686 printf("clock_gettime error %d", ret); 801 687 return 0; 802 688 } … … 804 690 memset(buf, 0, sizeof(buf)); 805 691 if (ctime_r(&tp.tv_sec, buf) == NULL) { 806 ntstdio_printf(&ntstdio,"ctime_r error");692 printf("ctime_r error"); 807 693 return 0; 808 694 } … … 812 698 buf[ret - 1] = '\0'; 813 699 814 ntstdio_printf(&ntstdio, "%s .%09u\n", buf, tp.tv_nsec);700 printf("%s .%09ld\n", buf, tp.tv_nsec); 815 701 return 0; 816 702 } … … 819 705 { 820 706 if (argc != 2) { 821 ntstdio_printf(&ntstdio,"info sys\n");822 ntstdio_printf(&ntstdio,"info ver\n");707 printf("info sys\n"); 708 printf("info ver\n"); 823 709 return 0; 824 710 } 825 711 if (strcmp(argv[1], "sys") == 0) { 826 ntstdio_printf(&ntstdio,TARGET_NAME" Monitor\n");712 printf(TARGET_NAME" Monitor\n"); 827 713 return 0; 828 714 } … … 830 716 int mj, mn, bd; 831 717 ntshell_version(&mj, &mn, &bd); 832 ntstdio_printf(&ntstdio,"Version %d.%d.%d\n", mj, mn, bd);833 return 0; 834 } 835 ntstdio_printf(&ntstdio,"Unknown sub command found\n");718 printf("Version %d.%d.%d\n", mj, mn, bd); 719 return 0; 720 } 721 printf("Unknown sub command found\n"); 836 722 return -1; 837 723 } -
asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/usrcmd.h
r352 r374 56 56 int usrcmd_exit(int argc, char **argv); 57 57 58 void shell_abort();59 void shell_exit(int exitcd);60 int shell_kill(int pid, int sig);61 62 58 #endif 63 59 -
asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.h
r352 r374 78 78 int pos; 79 79 unsigned int option; 80 void *exinf; 80 81 } ntstdio_t; 81 82 -
asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c
r364 r374 68 68 #include "kernel_cfg.h" 69 69 #include <string.h> 70 71 #define IO_TYPE_FREE 0 72 #define IO_TYPE_SIO 1 73 #define IO_TYPE_FILE 2 74 #define IO_TYPE_DIR 3 75 #define IO_TYPE_TCP 4 76 #define IO_TYPE_UDP 5 77 78 static struct _IO_FILE fd_table[8 * sizeof(FLGPTN)] = { 79 { 0, IO_TYPE_SIO, 0, stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl }, 80 { 1, IO_TYPE_SIO, 0, stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl }, 81 { 2, IO_TYPE_SIO, 0, stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl }, 70 #include "util/ntstdio.h" 71 #include "hal/serial_api.h" 72 73 #ifdef _DEBUG 74 static const char THIS_FILE[] = __FILE__; 75 #endif 76 77 static int stdio_close(struct SHELL_FILE *fp); 78 static size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 79 static size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 80 static size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 81 static size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 82 static size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 83 static void stdio_delete(struct SHELL_FILE *fp); 84 85 static int sio_close(struct SHELL_FILE *fp); 86 static size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 87 static size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 88 static off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org); 89 static int sio_ioctl(struct SHELL_FILE *fp, int req, void *arg); 90 static bool_t sio_readable(struct SHELL_FILE *fp); 91 static void sio_delete(struct SHELL_FILE *fp); 92 93 IO_TYPE IO_TYPE_STDIN = { stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl, sio_readable, stdio_delete }; 94 IO_TYPE IO_TYPE_STDOUT = { stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl, sio_readable, stdio_delete }; 95 IO_TYPE IO_TYPE_STDERR = { stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl, sio_readable, stdio_delete }; 96 IO_TYPE IO_TYPE_SIO = { sio_close, sio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_delete }; 97 ntstdio_t ntstdio; 98 99 static struct SHELL_FILE fd_table[8 * sizeof(FLGPTN)] = { 100 { 0, &IO_TYPE_STDIN, 0, .exinf = &ntstdio }, 101 { 1, &IO_TYPE_STDOUT, 0, .exinf = &ntstdio }, 102 { 2, &IO_TYPE_STDERR, 0,.exinf = &ntstdio }, 82 103 }; 83 104 #define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0])) 84 105 85 static int new_fd(int type, int id) 86 { 106 extern ntstdio_t ntstdio; 107 extern serial_t stdio_uart; 108 109 unsigned char ntstdio_xi(struct ntstdio_t *handle) 110 { 111 return serial_getc((serial_t *)handle->exinf); 112 } 113 114 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c) 115 { 116 serial_putc((serial_t *)handle->exinf, c); 117 } 118 119 void sys_init(intptr_t exinf) 120 { 121 ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo); 122 ntstdio.exinf = (void *)&stdio_uart; 123 } 124 125 int stdio_close(struct SHELL_FILE *fp) 126 { 127 return -EPERM; 128 } 129 130 size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len) 131 { 132 return -EPERM; 133 } 134 135 size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len) 136 { 137 return -EPERM; 138 } 139 140 size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len) 141 { 142 int i = 0; 143 while (i < len) { 144 int c = ntstdio_getc((struct ntstdio_t *)fp->exinf); 145 data[i++] = c; 146 if ((c == EOF) || (c == '\n')) 147 break; 148 } 149 return i; 150 } 151 152 size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len) 153 { 154 for (int i = 0; i < len; i++) { 155 ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]); 156 } 157 return len; 158 } 159 160 size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len) 161 { 162 for (int i = 0; i < len; i++) { 163 ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]); 164 } 165 return len; 166 } 167 168 void stdio_delete(struct SHELL_FILE *fp) 169 { 170 } 171 172 int sio_close(struct SHELL_FILE *fp) 173 { 174 return -EPERM; 175 } 176 177 size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len) 178 { 179 return -EPERM; 180 } 181 182 size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len) 183 { 184 return -EPERM; 185 } 186 187 off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org) 188 { 189 return -EPERM; 190 } 191 192 int sio_ioctl(struct SHELL_FILE *fp, int request, void *arg) 193 { 194 switch (request) { 195 case TIOCGWINSZ: 196 return 0; 197 case TCGETS: 198 return sio_tcgetattr(fp->fd, (struct termios *)arg); 199 case TCSETS + TCSANOW: 200 case TCSETS + TCSADRAIN: 201 case TCSETS + TCSAFLUSH: 202 return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg); 203 } 204 205 return -EINVAL; 206 } 207 208 bool_t sio_readable(struct SHELL_FILE *fp) 209 { 210 return fp->readevt_w != fp->readevt_r; 211 } 212 213 void sio_delete(struct SHELL_FILE *fp) 214 { 215 free((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf); 216 ((struct ntstdio_t *)fp->exinf)->exinf = NULL; 217 free((struct ntstdio_t *)fp->exinf); 218 fp->exinf = NULL; 219 } 220 221 struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable) 222 { 223 struct SHELL_FILE *fp = NULL; 224 ER ret; 225 226 ret = wai_sem(SEM_FILEDESC); 227 if (ret < 0) { 228 syslog(LOG_ERROR, "wai_sem => %d", ret); 229 } 230 87 231 for (int fd = 3; fd < fd_table_count; fd++) { 88 struct _IO_FILE *fp = &fd_table[fd];89 if (fp->type != IO_TYPE_FREE)232 fp = &fd_table[fd]; 233 if (fp->type != NULL) 90 234 continue; 91 235 92 memset(fp, 0, sizeof(struct _IO_FILE));236 memset(fp, 0, sizeof(struct SHELL_FILE)); 93 237 fp->fd = fd; 94 238 fp->type = type; 95 239 fp->handle = id; 96 return fd; 97 } 98 99 return -ENOMEM; 100 } 101 102 static struct _IO_FILE *id_to_fd(int type, int id) 103 { 240 fp->writable = writable; 241 break; 242 } 243 244 ret = sig_sem(SEM_FILEDESC); 245 if (ret < 0) { 246 syslog(LOG_ERROR, "sig_sem => %d", ret); 247 } 248 249 return fp; 250 } 251 252 struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id) 253 { 254 struct SHELL_FILE *fp = NULL; 255 ER ret; 256 257 ret = wai_sem(SEM_FILEDESC); 258 if (ret < 0) { 259 syslog(LOG_ERROR, "wai_sem => %d", ret); 260 } 261 104 262 for (int fd = 3; fd < fd_table_count; fd++) { 105 struct _IO_FILE *fp = &fd_table[fd];263 fp = &fd_table[fd]; 106 264 if ((fp->type == type) && (fp->handle == id)) 107 return fp; 108 } 109 110 return NULL; 111 } 112 113 static int delete_fd(int type, int id) 114 { 115 struct _IO_FILE *fp = id_to_fd(type, id); 265 break; 266 } 267 268 ret = sig_sem(SEM_FILEDESC); 269 if (ret < 0) { 270 syslog(LOG_ERROR, "sig_sem => %d", ret); 271 } 272 273 return fp; 274 } 275 276 int delete_fd_by_id(IO_TYPE *type, int id) 277 { 278 struct SHELL_FILE *fp = id_to_fd(type, id); 116 279 if (fp == NULL) 117 280 return -EBADF; … … 120 283 } 121 284 122 int delete_fp(struct _IO_FILE *fp) 123 { 124 free(fp->pfile); 125 fp->pfile = NULL; 126 free(fp->pdir); 127 fp->pdir = NULL; 128 free(fp->psock); 129 fp->psock = NULL; 130 memset(fp, 0, sizeof(struct _IO_FILE)); 285 int delete_fp(struct SHELL_FILE *fp) 286 { 287 ER ret; 288 289 fp->type->delete(fp); 290 291 ret = wai_sem(SEM_FILEDESC); 292 if (ret < 0) { 293 syslog(LOG_ERROR, "wai_sem => %d", ret); 294 } 295 296 memset(fp, 0, sizeof(struct SHELL_FILE)); 297 298 ret = sig_sem(SEM_FILEDESC); 299 if (ret < 0) { 300 syslog(LOG_ERROR, "sig_sem => %d", ret); 301 } 131 302 132 303 return 0; 133 304 } 134 305 135 struct _IO_FILE *fd_to_fp(int fd)306 struct SHELL_FILE *fd_to_fp(int fd) 136 307 { 137 308 if ((fd < 0) || (fd >= fd_table_count)) … … 140 311 } 141 312 142 struct _IO_FILE *new_sio_fd(int sioid) 143 { 144 int fd = new_fd(IO_TYPE_SIO, sioid); 145 if ((fd < 0) || (fd >= fd_table_count)) 146 return NULL; 147 148 struct _IO_FILE *fp = &fd_table[fd]; 149 fp->close = sio_close; 150 fp->read = sio_read; 151 fp->write = sio_write; 152 fp->seek = sio_seek; 153 fp->ioctl = sio_ioctl; 154 fp->writable = 1; 155 156 return fp; 157 } 158 159 int delete_sio_fd(int sioid) 160 { 161 return delete_fd(IO_TYPE_SIO, sioid); 162 } 163 164 struct _IO_FILE *sioid_to_fd(int sioid) 165 { 166 return id_to_fd(IO_TYPE_SIO, sioid); 167 } 168 169 struct _IO_FILE *new_file_fd(int fileid) 170 { 171 int fd = new_fd(IO_TYPE_FILE, fileid); 172 if ((fd < 0) || (fd >= fd_table_count)) 173 return NULL; 174 175 struct _IO_FILE *fp = &fd_table[fd]; 176 fp->close = file_close; 177 fp->read = file_read; 178 fp->write = file_write; 179 fp->seek = file_seek; 180 fp->ioctl = file_ioctl; 181 fp->writable = 1; 182 fp->pfile = malloc(sizeof(FIL)); 183 memset(fp->pfile, 0, sizeof(FIL)); 184 185 return fp; 186 } 187 188 int delete_file_fd(int fileid) 189 { 190 return delete_fd(IO_TYPE_FILE, fileid); 191 } 192 193 struct _IO_FILE *fileid_to_fd(int fileid) 194 { 195 return id_to_fd(IO_TYPE_FILE, fileid); 196 } 197 198 struct _IO_FILE *new_dir_fd(int fileid) 199 { 200 int fd = new_fd(IO_TYPE_DIR, fileid); 201 if ((fd < 0) || (fd >= fd_table_count)) 202 return NULL; 203 204 struct _IO_FILE *fp = &fd_table[fd]; 205 fp->close = dir_close; 206 fp->read = dir_read; 207 fp->write = dir_write; 208 fp->seek = dir_seek; 209 fp->ioctl = dir_ioctl; 210 fp->writable = 0; 211 fp->pdir = malloc(sizeof(struct _IO_DIR)); 212 memset(fp->pdir, 0, sizeof(struct _IO_DIR)); 213 214 return fp; 215 } 216 217 int delete_dir_fd(int dirid) 218 { 219 return delete_fd(IO_TYPE_DIR, dirid); 220 } 221 222 struct _IO_FILE *dirid_to_fd(int dirid) 223 { 224 return id_to_fd(IO_TYPE_DIR, dirid); 225 } 226 227 #ifndef NTSHELL_NO_SOCKET 228 struct _IO_FILE *new_tcp_fd(int tcpid) 229 { 230 int fd = new_fd(IO_TYPE_TCP, tcpid); 231 if ((fd < 0) || (fd >= fd_table_count)) 232 return NULL; 233 234 struct _IO_FILE *fp = &fd_table[fd]; 235 fp->close = tcp_fd_close; 236 fp->read = tcp_fd_read; 237 fp->write = tcp_fd_write; 238 fp->seek = tcp_fd_seek; 239 fp->ioctl = tcp_fd_ioctl; 240 fp->writable = 0; 241 fp->psock = malloc(sizeof(socket_t)); 242 memset(fp->psock, 0, sizeof(socket_t)); 243 244 return fp; 245 } 246 247 int delete_tcp_fd(int tcpid) 248 { 249 return delete_fd(IO_TYPE_TCP, tcpid); 250 } 251 252 struct _IO_FILE *tcpid_to_fd(int tcpid) 253 { 254 return id_to_fd(IO_TYPE_TCP, tcpid); 255 } 256 257 struct _IO_FILE *new_udp_fd(int udpid) 258 { 259 int fd = new_fd(IO_TYPE_UDP, udpid); 260 if ((fd < 0) || (fd >= fd_table_count)) 261 return NULL; 262 263 struct _IO_FILE *fp = &fd_table[fd]; 264 fp->close = udp_fd_close; 265 fp->read = udp_fd_read; 266 fp->write = udp_fd_write; 267 fp->seek = udp_fd_seek; 268 fp->ioctl = udp_fd_ioctl; 269 fp->writable = 1; 270 fp->psock = malloc(sizeof(socket_t)); 271 memset(fp->psock, 0, sizeof(socket_t)); 272 273 return fp; 274 } 275 276 int delete_udp_fd(int udpid) 277 { 278 return delete_fd(IO_TYPE_UDP, udpid); 279 } 280 281 struct _IO_FILE *udpid_to_fd(int udpid) 282 { 283 return id_to_fd(IO_TYPE_UDP, udpid); 284 } 285 286 #endif 287 288 void memor(void *dst, void *src, size_t len) 313 void memand(void *dst, void *src, size_t len) 289 314 { 290 315 uint8_t *d = (uint8_t *)dst; … … 293 318 294 319 while (s < e) { 295 *d++ |= *s++;320 *d++ &= *s++; 296 321 } 297 322 } … … 336 361 337 362 ret = shell_get_evts(&evts, tmout); 338 if (rfds != NULL)339 memset(rfds, 0, sizeof(fd_set));340 if (wfds != NULL)341 memset(wfds, 0, sizeof(fd_set));342 if (efds != NULL)343 memset(efds, 0, sizeof(fd_set));344 363 if (ret == E_OK) { 345 364 if (rfds != NULL) 346 mem or(rfds, &evts.readfds, sizeof(fd_set));365 memand(rfds, &evts.readfds, sizeof(fd_set)); 347 366 if (wfds != NULL) 348 mem or(wfds, &evts.writefds, sizeof(fd_set));367 memand(wfds, &evts.writefds, sizeof(fd_set)); 349 368 if (efds != NULL) 350 mem or(efds, &evts.errorfds, sizeof(fd_set));369 memand(efds, &evts.errorfds, sizeof(fd_set)); 351 370 return evts.count; 352 371 } 353 372 if (ret == E_TMOUT) { 373 if (rfds != NULL) 374 memset(rfds, 0, sizeof(fd_set)); 375 if (wfds != NULL) 376 memset(wfds, 0, sizeof(fd_set)); 377 if (efds != NULL) 378 memset(efds, 0, sizeof(fd_set)); 354 379 return 0; 355 380 } … … 419 444 { 420 445 int fd = STDIN_FILENO; 421 struct _IO_FILE *fp = &fd_table[fd]; 422 T_SERIAL_RPOR rpor; 446 struct SHELL_FILE *fp = &fd_table[fd]; 423 447 FLGPTN flgptn = 0; 424 448 425 ER ret = serial_ref_por(SIO_PORTID, &rpor); 426 if (ret != E_OK) 427 return; 428 429 if (rpor.reacnt != 0) { 449 if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) { 430 450 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 431 451 432 452 FD_SET(fd, (fd_set *)&flgptn); 433 453 } 434 if ( rpor.wricnt != 0) {454 if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) { 435 455 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 436 456 … … 447 467 { 448 468 int fd = STDIN_FILENO; 449 struct _IO_FILE *fp = &fd_table[fd]; 450 T_SERIAL_RPOR rpor; 469 struct SHELL_FILE *fp = &fd_table[fd]; 451 470 *flgptn = 0; 452 471 453 ER ret = serial_ref_por(SIO_PORTID, &rpor); 454 if (ret != E_OK) 455 return; 456 457 if (rpor.reacnt != 0) { 472 if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) { 458 473 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 459 474 460 475 FD_SET(fd, (fd_set *)flgptn); 461 476 } 462 if ( rpor.wricnt != 0) {477 if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) { 463 478 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 464 479 … … 466 481 } 467 482 } 468 469 #ifndef NTSHELL_NO_SOCKET470 471 ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk)472 {473 struct _IO_FILE *fp = tcpid_to_fd(cepid);474 FLGPTN flgptn = 0;475 ER ret;476 int len;477 478 if (fp == NULL)479 return E_PAR;480 481 int fd = fp->fd;482 FD_SET(fd, (fd_set *)&flgptn);483 484 switch (fncd) {485 case TFN_TCP_RCV_BUF:486 len = *(int *)p_parblk;487 if (len <= 0)488 return E_OK;489 490 ret = wai_sem(SEM_FILEDESC);491 if (ret < 0) {492 syslog(LOG_ERROR, "wai_sem => %d", ret);493 }494 fp->psock->len += len;495 ret = sig_sem(SEM_FILEDESC);496 if (ret < 0) {497 syslog(LOG_ERROR, "sig_sem => %d", ret);498 }499 500 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;501 502 set_flg(FLG_SELECT_WAIT, flgptn);503 return E_OK;504 505 case TFN_TCP_RCV_DAT:506 len = *(int *)p_parblk;507 if (len <= 0)508 return E_OK;509 510 ret = wai_sem(SEM_FILEDESC);511 if (ret < 0) {512 syslog(LOG_ERROR, "wai_sem => %d", ret);513 }514 fp->psock->len += len;515 ret = sig_sem(SEM_FILEDESC);516 if (ret < 0) {517 syslog(LOG_ERROR, "sig_sem => %d", ret);518 }519 520 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;521 522 set_flg(FLG_SELECT_WAIT, flgptn);523 return E_OK;524 525 case TFN_TCP_SND_DAT:526 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;527 528 set_flg(FLG_SELECT_WAIT, flgptn);529 return E_OK;530 531 case TFN_TCP_CAN_CEP:532 if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;533 534 set_flg(FLG_SELECT_WAIT, flgptn);535 return E_OK;536 537 case TFN_TCP_DEL_REP:538 delete_tcp_rep(cepid);539 return E_OK;540 541 case TFN_TCP_DEL_CEP:542 delete_tcp_fd(cepid);543 return E_OK;544 545 default:546 return E_OK;547 }548 }549 550 ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk)551 {552 struct _IO_FILE *fp = udpid_to_fd(cepid);553 FLGPTN flgptn = 0;554 int len;555 556 if (fp == NULL)557 return E_PAR;558 559 int fd = fp->fd;560 FD_SET(fd, (fd_set *)&flgptn);561 562 switch (fncd) {563 case TEV_UDP_RCV_DAT:564 {565 T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;566 len = udppara->len;567 if (len <= 0)568 return E_OK;569 570 ER ret = wai_sem(SEM_FILEDESC);571 if (ret < 0) {572 syslog(LOG_ERROR, "wai_sem => %d", ret);573 }574 fp->psock->len = len;575 if (fp->psock->input != NULL) {576 ret = rel_net_buf(fp->psock->input);577 if (ret < 0) {578 syslog(LOG_ERROR, "rel_net_buf => %d", ret);579 }580 }581 fp->psock->input = udppara->input;582 fp->psock->buf = GET_UDP_SDU(udppara->input, udppara->off);583 memset(&fp->psock->raddr4, 0, sizeof(fp->psock->raddr4));584 fp->psock->raddr4.sin_family = AF_INET;585 fp->psock->raddr4.sin_port = htons(udppara->rep4.portno);586 fp->psock->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr);587 udppara->input->flags |= NB_FLG_NOREL_IFOUT;588 ret = sig_sem(SEM_FILEDESC);589 if (ret < 0) {590 syslog(LOG_ERROR, "sig_sem => %d", ret);591 }592 593 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;594 595 set_flg(FLG_SELECT_WAIT, flgptn);596 return E_OK;597 }598 case TFN_UDP_CRE_CEP:599 return E_OK;600 601 case TFN_UDP_RCV_DAT:602 len = *(int *)p_parblk;603 if (len <= 0)604 return E_OK;605 606 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;607 608 set_flg(FLG_SELECT_WAIT, flgptn);609 return E_OK;610 611 case TFN_UDP_SND_DAT:612 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;613 614 set_flg(FLG_SELECT_WAIT, flgptn);615 return E_OK;616 617 case TFN_UDP_CAN_CEP:618 if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;619 620 set_flg(FLG_SELECT_WAIT, flgptn);621 return E_OK;622 623 case TFN_UDP_DEL_CEP:624 delete_udp_fd(cepid);625 return E_OK;626 627 default:628 return E_OK;629 }630 }631 632 #endif633 483 634 484 ER shell_get_evts(struct fd_events *evts, TMO tmout) … … 642 492 ER ret; 643 493 FLGPTN waitptn, flgptn, readfds = 0, writefds = 0; 644 struct _IO_FILE *fp = NULL;494 struct SHELL_FILE *fp = NULL; 645 495 646 496 stdio_update_evts(); … … 656 506 #ifndef NTSHELL_NO_SOCKET 657 507 if (FD_ISSET(fd, &evts->readfds)) { 658 if ((fp->type == IO_TYPE_TCP) && (fp->psock->cepid != 0)) { 659 if (fp->psock->len == 0) { 660 ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_NBLK); 661 if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) { 662 syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret); 663 //return ret; 664 } 665 if (ret > 0) { 666 ret = wai_sem(SEM_FILEDESC); 667 if (ret < 0) { 668 syslog(LOG_ERROR, "wai_sem => %d", ret); 669 } 670 fp->psock->len += ret; 671 ret = sig_sem(SEM_FILEDESC); 672 if (ret < 0) { 673 syslog(LOG_ERROR, "sig_sem => %d", ret); 674 } 675 } 676 } 677 else ret = 1; 678 if (ret > 0) { 679 FD_SET(fd, (fd_set *)&readfds); 680 count++; 681 if (fp->readevt_w == fp->readevt_r) fp->readevt_r--; 682 } 683 } 684 else if ((fp->type == IO_TYPE_UDP) && (fp->psock->cepid != 0)) { 685 if (fp->psock->input != NULL) { 686 FD_SET(fd, (fd_set *)&readfds); 687 count++; 688 if (fp->readevt_w == fp->readevt_r) fp->readevt_r--; 689 } 508 if (fp->type->readable(fp)) { 509 FD_SET(fd, (fd_set *)&readfds); 510 count++; 511 if (fp->readevt_w == fp->readevt_r) fp->readevt_r--; 690 512 } 691 513 else { … … 786 608 void clean_fd() 787 609 { 788 struct _IO_FILE *fp = NULL;610 struct SHELL_FILE *fp = NULL; 789 611 for (int fd = 3; fd < fd_table_count; fd++) { 790 612 fp = &fd_table[fd]; … … 792 614 continue; 793 615 794 fp-> close(fp);616 fp->type->close(fp); 795 617 796 618 delete_fp(fp); … … 800 622 int shell_ioctl(int fd, int request, void *arg) 801 623 { 802 struct _IO_FILE *fp = fd_to_fp(fd);624 struct SHELL_FILE *fp = fd_to_fp(fd); 803 625 if (fp == NULL) 804 626 return -EBADF; 805 627 806 return fp-> ioctl(fp, request, arg);628 return fp->type->ioctl(fp, request, arg); 807 629 } 808 630 -
asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c
r352 r374 1 1 /* 2 2 * TOPPERS ECHONET Lite Communication Middleware 3 * 3 * 4 4 * Copyright (C) 2017 Cores Co., Ltd. Japan 5 * 5 * 6 6 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ 7 7 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改 … … 26 26 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを 27 27 * 免責すること. 28 * 28 * 29 29 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お 30 30 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的 … … 32 32 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ 33 33 * の責任を負わない. 34 * 34 * 35 35 * @(#) $Id$ 36 36 */ … … 43 43 #include <sil.h> 44 44 #include <string.h> 45 #include "syssvc/serial.h" 45 46 #include "syssvc/syslog.h" 46 47 #include "socket_stub.h" … … 49 50 #include "core/ntlibc.h" 50 51 #include "kernel_cfg.h" 52 #include "target_syssvc.h" 51 53 52 54 int fresult2errno(FRESULT res) … … 77 79 } 78 80 79 int shell_open(const char * path, int flags, void *arg) 80 { 81 FRESULT res; 82 struct _IO_FILE *fp; 81 static int file_close(struct SHELL_FILE *fp); 82 static size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 83 static size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 84 static off_t file_seek(struct SHELL_FILE *fp, off_t ofs, int org); 85 static int file_ioctl(struct SHELL_FILE *fp, int req, void *arg); 86 static bool_t file_readable(struct SHELL_FILE *fp); 87 static void file_delete(struct SHELL_FILE *fp); 88 89 static int dir_close(struct SHELL_FILE *fp); 90 static size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 91 static size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 92 static off_t dir_seek(struct SHELL_FILE *fp, off_t ofs, int org); 93 static int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg); 94 static bool_t dir_readable(struct SHELL_FILE *fp); 95 static void dir_delete(struct SHELL_FILE *fp); 96 97 IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_delete }; 98 IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_delete }; 99 100 int shell_open(const char *path, int flags, void *arg) 101 { 102 FRESULT res; 103 struct SHELL_FILE *fp; 83 104 84 105 if (flags & O_DIRECTORY) { 85 fp = new_ dir_fd(0);106 fp = new_fp(&IO_TYPE_DIR, 0, 0); 86 107 if (fp == NULL) 87 108 return -ENOMEM; 88 109 89 DIR *dir = &fp->pdir->dir; 110 fp->exinf = malloc(sizeof(struct SHELL_DIR)); 111 memset(fp->exinf, 0, sizeof(struct SHELL_DIR)); 112 113 FATFS_DIR *dir = &((struct SHELL_DIR *)fp->exinf)->dir; 90 114 FRESULT res; 91 115 if ((res = f_opendir(dir, path)) != FR_OK) { … … 95 119 } 96 120 97 fp = new_f ile_fd(0);121 fp = new_fp(&IO_TYPE_FILE, 0, 1); 98 122 if (fp == NULL) 99 123 return -ENOMEM; 124 125 fp->exinf = malloc(sizeof(FIL)); 126 memset(fp->exinf, 0, sizeof(FIL)); 100 127 101 128 BYTE fmd = 0; … … 133 160 } 134 161 135 if ((res = f_open( fp->pfile, path, fmd)) == FR_OK) {162 if ((res = f_open((FIL *)fp->exinf, path, fmd)) == FR_OK) { 136 163 fp->handle = fp->fd; 137 164 return fp->fd; … … 141 168 } 142 169 143 int file_close(struct _IO_FILE *fp)144 { 145 FRESULT res; 146 147 if ((res = f_close( fp->pfile)) == FR_OK) {170 int file_close(struct SHELL_FILE *fp) 171 { 172 FRESULT res; 173 174 if ((res = f_close((FIL *)fp->exinf)) == FR_OK) { 148 175 return 0; 149 176 } … … 152 179 } 153 180 154 size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len)181 size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len) 155 182 { 156 183 unsigned int ret = 0; 157 184 FRESULT res; 158 185 159 if ((res = f_read( fp->pfile, data, len, &ret)) != FR_OK)186 if ((res = f_read((FIL *)fp->exinf, data, len, &ret)) != FR_OK) 160 187 return -EIO; 161 188 … … 163 190 } 164 191 165 size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)192 size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len) 166 193 { 167 194 unsigned int ret = 0; 168 195 FRESULT res; 169 196 170 if ((res = f_write( fp->pfile, data, len, &ret)) != FR_OK)197 if ((res = f_write((FIL *)fp->exinf, data, len, &ret)) != FR_OK) 171 198 return -EIO; 172 199 … … 174 201 } 175 202 176 off_t file_seek(struct _IO_FILE *fp, off_t ptr, int dir)203 off_t file_seek(struct SHELL_FILE *fp, off_t ptr, int dir) 177 204 { 178 205 switch (dir) { … … 191 218 192 219 FRESULT res; 193 if ((res = f_seek( fp->pfile, ptr, dir)) != FR_OK)220 if ((res = f_seek((FIL *)fp->exinf, ptr, dir)) != FR_OK) 194 221 return -EIO; 195 222 196 return fp->pfile->fptr;197 } 198 199 int file_ioctl(struct _IO_FILE *fp, int req, void *arg)223 return ((FIL *)fp->exinf)->fptr; 224 } 225 226 int file_ioctl(struct SHELL_FILE *fp, int req, void *arg) 200 227 { 201 228 DRESULT res; 202 229 203 if ((res = disk_ioctl( fp->pfile->fs->drv, req, arg) != RES_OK))230 if ((res = disk_ioctl(((FIL *)fp->exinf)->fs->drv, req, arg) != RES_OK)) 204 231 return -EINVAL; 205 232 … … 207 234 } 208 235 236 bool_t file_readable(struct SHELL_FILE *fp) 237 { 238 return fp->readevt_w != fp->readevt_r; 239 } 240 241 void file_delete(struct SHELL_FILE *fp) 242 { 243 free((FIL *)fp->exinf); 244 fp->exinf = NULL; 245 } 246 209 247 int shell_close(int fd) 210 248 { 211 struct _IO_FILE *fp = fd_to_fp(fd);212 if (fp == NULL) 213 return -EBADF; 214 215 int ret = fp-> close(fp);249 struct SHELL_FILE *fp = fd_to_fp(fd); 250 if (fp == NULL) 251 return -EBADF; 252 253 int ret = fp->type->close(fp); 216 254 217 255 delete_fp(fp); … … 222 260 ssize_t shell_read(int fd, void *data, size_t len) 223 261 { 224 struct _IO_FILE *fp = fd_to_fp(fd);225 if (fp == NULL) 226 return -EBADF; 227 228 return fp-> read(fp, (unsigned char *)data, len);262 struct SHELL_FILE *fp = fd_to_fp(fd); 263 if (fp == NULL) 264 return -EBADF; 265 266 return fp->type->read(fp, (unsigned char *)data, len); 229 267 } 230 268 … … 232 270 { 233 271 int result = 0; 234 struct _IO_FILE *fp = fd_to_fp(fd);272 struct SHELL_FILE *fp = fd_to_fp(fd); 235 273 if (fp == NULL) 236 274 return -EBADF; … … 238 276 const struct iovec *end = &iov[iovcnt]; 239 277 for (; iov < end; iov++) { 240 result += fp-> read(fp, (unsigned char *)iov->iov_base, iov->iov_len);278 result += fp->type->read(fp, (unsigned char *)iov->iov_base, iov->iov_len); 241 279 } 242 280 … … 246 284 ssize_t shell_write(int fd, const void *data, size_t len) 247 285 { 248 struct _IO_FILE *fp = fd_to_fp(fd);249 if (fp == NULL) 250 return -EBADF; 251 252 return fp-> write(fp, (unsigned char *)data, len);286 struct SHELL_FILE *fp = fd_to_fp(fd); 287 if (fp == NULL) 288 return -EBADF; 289 290 return fp->type->write(fp, (unsigned char *)data, len); 253 291 } 254 292 … … 256 294 { 257 295 int result = 0; 258 struct _IO_FILE *fp = fd_to_fp(fd);296 struct SHELL_FILE *fp = fd_to_fp(fd); 259 297 if (fp == NULL) 260 298 return -EBADF; … … 262 300 const struct iovec *end = &iov[iovcnt]; 263 301 for (; iov < end; iov++) { 264 result += fp-> write(fp, (unsigned char *)iov->iov_base, iov->iov_len);302 result += fp->type->write(fp, (unsigned char *)iov->iov_base, iov->iov_len); 265 303 } 266 304 … … 270 308 int shell_llseek(int fd, off_t ptr, off_t *result, int dir) 271 309 { 272 struct _IO_FILE *fp = fd_to_fp(fd);273 if (fp == NULL) 274 return -EBADF; 275 276 off_t ret = fp-> seek(fp, ptr, dir);310 struct SHELL_FILE *fp = fd_to_fp(fd); 311 if (fp == NULL) 312 return -EBADF; 313 314 off_t ret = fp->type->seek(fp, ptr, dir); 277 315 if (ret < 0) 278 316 return ret; … … 284 322 int shell_fstat(int fd, struct stat * st) 285 323 { 286 struct _IO_FILE *fp = fd_to_fp(fd);324 struct SHELL_FILE *fp = fd_to_fp(fd); 287 325 if (fp == NULL) 288 326 return -EBADF; … … 296 334 int shell_fsync(int fd) 297 335 { 298 struct _IO_FILE *fp = fd_to_fp(fd);336 struct SHELL_FILE *fp = fd_to_fp(fd); 299 337 if (fp == NULL) 300 338 return -EBADF; … … 304 342 int shell_ftruncate(int fd, off_t length) 305 343 { 306 struct _IO_FILE *fp = fd_to_fp(fd);307 if (fp == NULL) 308 return -EBADF; 309 310 FRESULT res; 311 if ((res = f_truncate( fp->pfile)) != FR_OK)344 struct SHELL_FILE *fp = fd_to_fp(fd); 345 if (fp == NULL) 346 return -EBADF; 347 348 FRESULT res; 349 if ((res = f_truncate((FIL *)fp->exinf)) != FR_OK) 312 350 return fresult2errno(res); 313 351 … … 320 358 } 321 359 360 extern IO_TYPE IO_TYPE_SIO; 361 322 362 int sio_tcgetattr(int fd, struct termios *termios) 323 363 { 324 extern ntstdio_t ntstdio; 325 326 if (fd == STDIN_FILENO) { 327 memset(termios, 0, sizeof(*termios)); 328 329 if (ntstdio.option & NTSTDIO_OPTION_LINE_ECHO) { 330 termios->c_lflag |= ECHO; 364 struct SHELL_FILE *fp = fd_to_fp(fd); 365 if ((fp == NULL) || (fp->type != &IO_TYPE_SIO)) 366 return -EBADF; 367 368 ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf; 369 370 memset(termios, 0, sizeof(*termios)); 371 372 if (ntstdio->option & NTSTDIO_OPTION_LINE_ECHO) { 373 termios->c_lflag |= ECHO; 374 } 375 else { 376 termios->c_lflag &= ~ECHO; 377 } 378 if (ntstdio->option & NTSTDIO_OPTION_CANON) { 379 termios->c_lflag |= ICANON; 380 } 381 else { 382 termios->c_lflag &= ~ICANON; 383 } 384 if (ntstdio->option & NTSTDIO_OPTION_LF_CR) { 385 termios->c_iflag |= INLCR; 386 } 387 else { 388 termios->c_iflag &= ~INLCR; 389 } 390 if (ntstdio->option & NTSTDIO_OPTION_LF_CRLF) { 391 termios->c_oflag |= ONLCR; 392 } 393 else { 394 termios->c_oflag &= ~ONLCR; 395 } 396 397 return 0; 398 } 399 400 int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios) 401 { 402 struct SHELL_FILE *fp = fd_to_fp(fd); 403 if ((fp == NULL) || (fp->type != &IO_TYPE_SIO)) 404 return -EBADF; 405 406 ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf; 407 408 if (optional_actions == TCSANOW) { 409 if (termios->c_lflag & ECHO) { 410 ntstdio->option |= NTSTDIO_OPTION_LINE_ECHO; 331 411 } 332 412 else { 333 termios->c_lflag &= ~ECHO;334 } 335 if ( ntstdio.option & NTSTDIO_OPTION_CANON) {336 termios->c_lflag |= ICANON;413 ntstdio->option &= ~NTSTDIO_OPTION_LINE_ECHO; 414 } 415 if (termios->c_lflag & ICANON) { 416 ntstdio->option |= NTSTDIO_OPTION_CANON; 337 417 } 338 418 else { 339 termios->c_lflag &= ~ICANON;340 } 341 if ( ntstdio.option & NTSTDIO_OPTION_LF_CR) {342 termios->c_iflag |= INLCR;419 ntstdio->option &= ~NTSTDIO_OPTION_CANON; 420 } 421 if (termios->c_iflag & INLCR) { 422 ntstdio->option |= NTSTDIO_OPTION_LF_CR; 343 423 } 344 424 else { 345 termios->c_iflag &= ~INLCR;346 } 347 if ( ntstdio.option & NTSTDIO_OPTION_LF_CRLF) {348 termios->c_oflag |= ONLCR;425 ntstdio->option &= ~NTSTDIO_OPTION_LF_CR; 426 } 427 if (termios->c_oflag & ONLCR) { 428 ntstdio->option |= NTSTDIO_OPTION_LF_CRLF; 349 429 } 350 430 else { 351 termios->c_oflag &= ~ONLCR;431 ntstdio->option &= ~NTSTDIO_OPTION_LF_CRLF; 352 432 } 353 433 return 0; 354 434 } 355 shell_abort(); 356 return 0; 357 } 358 359 int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios) 360 { 361 extern ntstdio_t ntstdio; 362 363 if ((fd == STDIN_FILENO) && (optional_actions == TCSANOW)) { 364 if (termios->c_lflag & ECHO) { 365 ntstdio.option |= NTSTDIO_OPTION_LINE_ECHO; 366 } 367 else { 368 ntstdio.option &= ~NTSTDIO_OPTION_LINE_ECHO; 369 } 370 if (termios->c_lflag & ICANON) { 371 ntstdio.option |= NTSTDIO_OPTION_CANON; 372 } 373 else { 374 ntstdio.option &= ~NTSTDIO_OPTION_CANON; 375 } 376 if (termios->c_iflag & INLCR) { 377 ntstdio.option |= NTSTDIO_OPTION_LF_CR; 378 } 379 else{ 380 ntstdio.option &= ~NTSTDIO_OPTION_LF_CR; 381 } 382 if (termios->c_oflag & ONLCR) { 383 ntstdio.option |= NTSTDIO_OPTION_LF_CRLF; 384 } 385 else { 386 ntstdio.option &= ~NTSTDIO_OPTION_LF_CRLF; 387 } 388 return 0; 389 } 435 390 436 shell_abort(); 391 437 return 0; … … 396 442 FILINFO fi; 397 443 FRESULT ret; 398 #if _USE_LFN399 static char lfn[ _MAX_LFN + 1]; /* Buffer to store the LFN */444 #if FF_USE_LFN 445 static char lfn[FF_MAX_LFN + 1]; /* Buffer to store the LFN */ 400 446 fi.lfname = lfn; 401 447 fi.lfsize = sizeof lfn; 402 448 #endif 403 449 if (strcmp(path, ".") == 0) { 404 char cwd[ _MAX_LFN];450 char cwd[FF_MAX_LFN]; 405 451 if ((ret = f_getcwd(cwd, sizeof(cwd))) != FR_OK) { 406 452 return fresult2errno(ret); … … 426 472 st->st_mtim.tv_nsec = 0; 427 473 st->st_mtim.tv_sec = fi.fdate + fi.ftime; 428 st->st_mode 474 st->st_mode = (S_IRUSR | S_IRGRP | S_IROTH); 429 475 st->st_mode |= (fi.fattrib & AM_RDO) ? 0 : (S_IWUSR | S_IWGRP | S_IWOTH); 430 476 st->st_mode |= (fi.fattrib & (AM_DIR | AM_VOL)) ? S_IFDIR : S_IFREG; … … 485 531 BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID 486 532 487 if (mode & S_IREAD) {488 if ((mode & S_IWRITE) == 0) {533 if (mode & S_IREAD) { 534 if ((mode & S_IWRITE) == 0) { 489 535 attr |= AM_RDO; 490 536 } … … 494 540 } 495 541 496 if ((res = f_chmod(path, attr, mask)) != FR_OK) {542 if ((res = f_chmod(path, attr, mask)) != FR_OK) { 497 543 return fresult2errno(res); 498 544 } … … 507 553 BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID 508 554 509 if (mode & S_IREAD) {510 if ((mode & S_IWRITE) == 0) {555 if (mode & S_IREAD) { 556 if ((mode & S_IWRITE) == 0) { 511 557 attr |= AM_RDO; 512 558 } … … 516 562 } 517 563 518 if ((res = f_chmod(path, attr, mask)) != FR_OK) {564 if ((res = f_chmod(path, attr, mask)) != FR_OK) { 519 565 return fresult2errno(res); 520 566 } … … 526 572 { 527 573 FRESULT ret; 528 if ((ret = f_getcwd(buf, size)) != FR_OK) {574 if ((ret = f_getcwd(buf, size)) != FR_OK) { 529 575 return NULL; 530 576 } … … 549 595 } 550 596 551 int dir_close(struct _IO_FILE *fp)552 { 553 FRESULT res; 554 if ((res = f_closedir(& fp->pdir->dir)) != FR_OK) {597 int dir_close(struct SHELL_FILE *fp) 598 { 599 FRESULT res; 600 if ((res = f_closedir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) { 555 601 return fresult2errno(res); 556 602 } … … 564 610 return -EINVAL; 565 611 566 struct _IO_FILE *fp = fd_to_fp(fd);612 struct SHELL_FILE *fp = fd_to_fp(fd); 567 613 if (fp == NULL) 568 614 return -EBADF; 569 615 570 616 FILINFO fno; 571 #if _USE_LFN572 static char lfn[ _MAX_LFN + 1]; /* Buffer to store the LFN */617 #if FF_USE_LFN 618 static char lfn[FF_MAX_LFN + 1]; /* Buffer to store the LFN */ 573 619 fno.lfname = lfn; 574 620 fno.lfsize = sizeof lfn; 575 621 #endif 576 622 FRESULT res; 577 if ((res = f_readdir(& fp->pdir->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {623 if ((res = f_readdir(&((struct SHELL_DIR *)fp->exinf)->dir, &fno)) != FR_OK || fno.fname[0] == '\0') { 578 624 return fresult2errno(res); 579 625 } 580 626 581 627 memset(de, 0, sizeof(*de)); 582 #if _USE_LFN628 #if FF_USE_LFN 583 629 ntlibc_strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name)); 584 630 #else … … 589 635 } 590 636 591 size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len)637 size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len) 592 638 { 593 639 return -EPERM; 594 640 } 595 641 596 size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)642 size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len) 597 643 { 598 644 return -EPERM; 599 645 } 600 646 601 off_t dir_seek(struct _IO_FILE *fp, off_t ptr, int dir)647 off_t dir_seek(struct SHELL_FILE *fp, off_t ptr, int dir) 602 648 { 603 649 FRESULT res; … … 607 653 608 654 if (ptr == 0) { 609 if ((res = f_rewinddir(& fp->pdir->dir)) != FR_OK) {655 if ((res = f_rewinddir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) { 610 656 return fresult2errno(res); 611 657 } … … 613 659 else { 614 660 FILINFO fno; 615 #if _USE_LFN616 static char lfn[ _MAX_LFN + 1]; /* Buffer to store the LFN */661 #if FF_USE_LFN 662 static char lfn[FF_MAX_LFN + 1]; /* Buffer to store the LFN */ 617 663 fno.lfname = lfn; 618 664 fno.lfsize = sizeof lfn; 619 665 #endif 620 if ((res = f_rewinddir(& fp->pdir->dir)) != FR_OK) {666 if ((res = f_rewinddir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) { 621 667 return fresult2errno(res); 622 668 } 623 669 624 670 for (int i = 0; i < ptr; i++) { 625 if ((res = f_readdir(& fp->pdir->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {671 if ((res = f_readdir(&((struct SHELL_DIR *)fp->exinf)->dir, &fno)) != FR_OK || fno.fname[0] == '\0') { 626 672 return fresult2errno(res); 627 673 } … … 632 678 } 633 679 634 int dir_ioctl(struct _IO_FILE *fp, int req, void *arg)680 int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg) 635 681 { 636 682 return -EINVAL; 683 } 684 685 bool_t dir_readable(struct SHELL_FILE *fp) 686 { 687 return fp->readevt_w != fp->readevt_r; 688 } 689 690 void dir_delete(struct SHELL_FILE *fp) 691 { 692 free((struct SHELL_DIR *)fp->exinf); 693 fp->exinf = NULL; 637 694 } 638 695 … … 687 744 { 688 745 //if ((addr >= (void *)&__HeapBase) && (addr + len < (void *)&__HeapLimit)) { 689 return 0; 690 //} 691 //return -1; 692 } 693 694 #include "tlsf.h" 695 696 static tlsf_t sys_tlsf; 697 static pool_t sys_pool; 698 699 void sys_init(void) 700 { 701 sys_tlsf = tlsf_create(&__HeapBase); 702 if (sys_tlsf == NULL) 703 return; 704 705 sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&__HeapBase) + tlsf_size(), ((intptr_t)&__HeapLimit - (intptr_t)&__HeapBase) - tlsf_size()); 706 } 707 708 void sys_fini(void) 709 { 710 tlsf_destroy(sys_tlsf); 711 } 712 713 void *malloc(size_t size) 714 { 715 void *result; 716 wai_sem(SEM_MALLOC); 717 result = tlsf_malloc(sys_tlsf, size); 718 sig_sem(SEM_MALLOC); 719 if (result == NULL) 720 tlsf_check_pool(sys_pool); 721 return result; 722 } 723 724 void *calloc(size_t size, size_t count) 725 { 726 void *result; 727 wai_sem(SEM_MALLOC); 728 result = tlsf_malloc(sys_tlsf, count * size); 729 sig_sem(SEM_MALLOC); 730 if (result != NULL) 731 memset(result, 0, count * size); 732 else 733 tlsf_check_pool(sys_pool); 734 return result; 735 } 736 737 void *realloc(void *ptr, size_t size) 738 { 739 void *result; 740 wai_sem(SEM_MALLOC); 741 result = tlsf_realloc(sys_tlsf, ptr, size); 742 sig_sem(SEM_MALLOC); 743 if (result == NULL) 744 tlsf_check_pool(sys_pool); 745 return result; 746 } 747 748 void free(void *ptr) 749 { 750 wai_sem(SEM_MALLOC); 751 tlsf_free(sys_tlsf, ptr); 752 sig_sem(SEM_MALLOC); 753 } 754 746 return 0; 747 //} 748 //return -1; 749 } -
asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c
r359 r374 60 60 #include "kernel_cfg.h" 61 61 #include "tinet_cfg.h" 62 #include "util/ntstdio.h" 63 64 extern ntstdio_t ntstdio; 62 #include <stdio.h> 65 63 66 64 T_DHCP4_CLI_CONTEXT *dhcp4_cli_initialize(ID tskid, ID cepid); … … 97 95 98 96 get_tid(&nc->tskid); 99 ntstdio_printf(&ntstdio,"[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);97 printf("[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf); 100 98 101 99 /* 初期化 */ … … 105 103 ret = get_tim(&time); 106 104 if (ret != E_OK) { 107 ntstdio_printf(&ntstdio,"[NET MISC,%d] get_tim error: %7lu,%s",105 printf("[NET MISC,%d] get_tim error: %7lu,%s", 108 106 nc->cepid, time / SYSTIM_HZ, itron_strerror(ret)); 109 107 return; … … 119 117 error = tslp_tsk(timer); 120 118 if ((error != E_OK) && (error != E_TMOUT)) { 121 ntstdio_printf(&ntstdio,"[NET MISC,%d] tslp_tsk error: %s %d",119 printf("[NET MISC,%d] tslp_tsk error: %s %d", 122 120 nc->cepid, itron_strerror(error), timer); 123 121 break; … … 126 124 ret = get_tim(&time); 127 125 if (ret != E_OK) { 128 ntstdio_printf(&ntstdio,"[NET MISC,%d] get_tim error: %s",126 printf("[NET MISC,%d] get_tim error: %s", 129 127 nc->cepid, itron_strerror(ret)); 130 128 break; -
asp3_tinet_ecnl_arm/trunk/ntshell/src/netcmd.c
r364 r374 59 59 #include <netapp/resolver.h> 60 60 #include "core/ntlibc.h" 61 #include "util/ntstdio.h"61 #include <stdio.h> 62 62 #include "ntp_cli.h" 63 63 #include "kernel_cfg.h" 64 65 extern ntstdio_t ntstdio;66 64 67 65 #if defined(SUPPORT_INET6) … … 280 278 281 279 if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) { 282 ntstdio_printf(&ntstdio,"[PING] unknown host.\n");280 printf("[PING] unknown host.\n"); 283 281 return 0; 284 282 } … … 299 297 #if defined(SUPPORT_INET4) 300 298 if (apip == API_PROTO_IPV6) { 301 ntstdio_printf(&ntstdio,"[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));299 printf("[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr)); 302 300 ping6(&addr, (uint_t)tmo, (uint_t)size); 303 301 } 304 302 else { 305 303 addr4 = ntohl(addr.s6_addr32[3]); 306 ntstdio_printf(&ntstdio,"[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4));304 printf("[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4)); 307 305 ping4(&addr4, (uint_t)tmo, (uint_t)size); 308 306 } 309 307 #else /* of #if defined(SUPPORT_INET4) */ 310 ntstdio_printf(&ntstdio,"[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));308 printf("[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr)); 311 309 ping6(&addr, (uint_t)tmo, (uint_t)size); 312 310 #endif /* of #if defined(SUPPORT_INET4) */ 313 311 #else /* of #if defined(SUPPORT_INET6) */ 314 ntstdio_printf(&ntstdio,"[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr));312 printf("[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr)); 315 313 ping4(&addr, (uint_t)tmo, (uint_t)size); 316 314 #endif /* of #if defined(SUPPORT_INET6) */ … … 331 329 pos = str_ipv4addr(temp, sizeof(temp), &svaddr, 0); 332 330 temp[pos] = '\0'; 333 ntstdio_printf(&ntstdio,"DHCPv4 server: %s,\n", temp);334 ntstdio_printf(&ntstdio," Renew: %u:%02u:%02u,\n",331 printf("DHCPv4 server: %s,\n", temp); 332 printf(" Renew: %u:%02u:%02u,\n", 335 333 renew / 3600, (renew / 60) % 60, renew % 60); 336 ntstdio_printf(&ntstdio," Rebind: %u:%02u:%02u, Expire: %u:%02u:%02u.\n",334 printf(" Rebind: %u:%02u:%02u, Expire: %u:%02u:%02u.\n", 337 335 rebind / 3600, (rebind / 60) % 60, rebind % 60, 338 336 expire / 3600, (expire / 60) % 60, expire % 60); 339 337 } 340 338 else if (ret == E_OBJ) 341 ntstdio_printf(&ntstdio,"DHCPv4 server: not available.\n");339 printf("DHCPv4 server: not available.\n"); 342 340 } 343 341 … … 351 349 if (ntlibc_strcmp(argv[1], "rel") == 0) { 352 350 ret = dhcp4c_rel_info(); 353 ntstdio_printf(&ntstdio,"dhcp4c_rel_info %d\n", ret);351 printf("dhcp4c_rel_info %d\n", ret); 354 352 } 355 353 else if (ntlibc_strcmp(argv[1], "renew") == 0) { 356 354 ret = dhcp4c_renew_info(); 357 ntstdio_printf(&ntstdio,"dhcp4c_renew_info %d\n", ret);355 printf("dhcp4c_renew_info %d\n", ret); 358 356 } 359 357 else { … … 383 381 else { 384 382 for (c = 1; c <= *ptr; c++) 385 ntstdio_printf(&ntstdio,"%c", *(ptr + c));383 printf("%c", *(ptr + c)); 386 384 ptr += *ptr + 1; 387 385 if (*ptr) 388 ntstdio_printf(&ntstdio,".");386 printf("."); 389 387 } 390 388 } … … 406 404 return error; 407 405 408 ntstdio_printf(&ntstdio," mname: ");406 printf(" mname: "); 409 407 rn_offset = s_show_dns_domain_name(msg, offset); 410 ntstdio_putc(&ntstdio,'\n');411 ntstdio_printf(&ntstdio," rname: ");408 putchar('\n'); 409 printf(" rname: "); 412 410 s_show_dns_domain_name(msg, rn_offset); 413 ntstdio_putc(&ntstdio,'\n');414 415 ntstdio_printf(&ntstdio," serial: %d\n", soa.serial);416 ntstdio_printf(&ntstdio," refresh: %d\n", soa.refresh);417 ntstdio_printf(&ntstdio," retry: %d\n", soa.retry);418 ntstdio_printf(&ntstdio," expirel: %d\n", soa.expire);419 ntstdio_printf(&ntstdio," minimum: %d\n", soa.minimum);411 putchar('\n'); 412 413 printf(" serial: %d\n", soa.serial); 414 printf(" refresh: %d\n", soa.refresh); 415 printf(" retry: %d\n", soa.retry); 416 printf(" expirel: %d\n", soa.expire); 417 printf(" minimum: %d\n", soa.minimum); 420 418 421 419 return E_OK; … … 433 431 int scount; 434 432 435 ntstdio_printf(&ntstdio,"question section: %d\n", rslv->dns_hdr.qdcount);433 printf("question section: %d\n", rslv->dns_hdr.qdcount); 436 434 offset = rslv->qd_offset; 437 435 for (scount = 1; scount <= rslv->dns_hdr.qdcount; scount++) { … … 439 437 return error; 440 438 441 ntstdio_printf(&ntstdio,"%2d: ", scount);439 printf("%2d: ", scount); 442 440 s_show_dns_domain_name(msg, offset); 443 ntstdio_printf(&ntstdio,"\n type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class));441 printf("\n type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class)); 444 442 offset = error; 445 443 } … … 463 461 int pos; 464 462 465 ntstdio_printf(&ntstdio,"%10s section: %d\n", title, scount);463 printf("%10s section: %d\n", title, scount); 466 464 for (count = 1; count <= scount; count++) { 467 465 if ((error = dns_analyze_rr(&rr, offset, msg, length)) < 0) 468 466 return error; 469 467 470 ntstdio_printf(&ntstdio,"%2d: ", count);468 printf("%2d: ", count); 471 469 s_show_dns_domain_name(msg, offset); 472 ntstdio_printf(&ntstdio,"\n type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n",470 printf("\n type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n", 473 471 dns_strtype(rr.type), dns_strclass(rr.class), rr.ttl, rr.rdlength, rr.rdata_offset); 474 472 … … 479 477 pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0); 480 478 temp[pos] = '\0'; 481 ntstdio_printf(&ntstdio," IPv4 addr: %s\n", temp);479 printf(" IPv4 addr: %s\n", temp); 482 480 break; 483 481 case DNS_TYPE_NS: 484 ntstdio_printf(&ntstdio," host: ");482 printf(" host: "); 485 483 s_show_dns_domain_name(msg, rr.rdata_offset); 486 ntstdio_putc(&ntstdio,'\n');484 putchar('\n'); 487 485 break; 488 486 case DNS_TYPE_CNAME: 489 ntstdio_printf(&ntstdio," host: ");487 printf(" host: "); 490 488 s_show_dns_domain_name(msg, rr.rdata_offset); 491 ntstdio_putc(&ntstdio,'\n');489 putchar('\n'); 492 490 break; 493 491 case DNS_TYPE_SOA: … … 495 493 break; 496 494 case DNS_TYPE_PTR: 497 ntstdio_printf(&ntstdio," PTR: ");495 printf(" PTR: "); 498 496 s_show_dns_domain_name(msg, rr.rdata_offset); 499 ntstdio_putc(&ntstdio,'\n');497 putchar('\n'); 500 498 break; 501 499 case DNS_TYPE_AAAA: … … 503 501 pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0); 504 502 temp[pos] = '\0'; 505 ntstdio_printf(&ntstdio," IPv6 addr: %s\n", temp);503 printf(" IPv6 addr: %s\n", temp); 506 504 break; 507 505 default: 508 ntstdio_printf(&ntstdio," data: ");506 printf(" data: "); 509 507 col = 32; 510 508 for (dcount = 0; dcount < rr.rdlength; dcount++) { 511 ntstdio_printf(&ntstdio,"%02x", *(msg + rr.rdata_offset + dcount));509 printf("%02x", *(msg + rr.rdata_offset + dcount)); 512 510 if (--col == 0) { 513 ntstdio_printf(&ntstdio,"\n ");511 printf("\n "); 514 512 col = 32; 515 513 } 516 514 } 517 ntstdio_putc(&ntstdio,'\n');515 putchar('\n'); 518 516 break; 519 517 } … … 539 537 #if defined(SUPPORT_INET6) 540 538 541 ntstdio_printf(&ntstdio,"domain name: %s\n", dns_in6_get_dname());539 printf("domain name: %s\n", dns_in6_get_dname()); 542 540 543 541 #else /* of #if defined(SUPPORT_INET6) */ 544 542 545 ntstdio_printf(&ntstdio,"domain name: %s\n", dns_in4_get_dname());543 printf("domain name: %s\n", dns_in4_get_dname()); 546 544 547 545 #endif /* of #if defined(SUPPORT_INET6) */ … … 549 547 #if defined(SUPPORT_INET6) 550 548 dns_in6_get_addr(&in6_addr); 551 ntstdio_printf(&ntstdio,"IPv6 DNS server: ");549 printf("IPv6 DNS server: "); 552 550 if (IN6_IS_ADDR_UNSPECIFIED(&in6_addr)) 553 ntstdio_printf(&ntstdio,"not available.\n");551 printf("not available.\n"); 554 552 else { 555 553 pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0); 556 554 temp[pos] = '\0'; 557 ntstdio_printf(&ntstdio,"%s.\n", temp);555 printf("%s.\n", temp); 558 556 } 559 557 #endif /* of #if defined(SUPPORT_INET6) */ … … 561 559 #if defined(SUPPORT_INET4) 562 560 dns_in4_get_addr(&in4_addr); 563 ntstdio_printf(&ntstdio,"IPv4 DNS server: ");561 printf("IPv4 DNS server: "); 564 562 if (in4_addr == IPV4_ADDRANY) 565 ntstdio_printf(&ntstdio,"not available.\n");563 printf("not available.\n"); 566 564 else { 567 565 pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0); 568 566 temp[pos] = '\0'; 569 ntstdio_printf(&ntstdio,"%s.\n", temp);567 printf("%s.\n", temp); 570 568 } 571 569 #endif /* of #if defined(SUPPORT_INET4) */ … … 604 602 line = skip_blanks(resolv_options(&flags, line, DEFAULT_API_PROTO)); 605 603 if ((flags & (DNS_LUP_FLAGS_PROTO_IPV6 | DNS_LUP_FLAGS_PROTO_IPV4)) == 0) { 606 ntstdio_printf(&ntstdio,"DNS server not available.\n");604 printf("DNS server not available.\n"); 607 605 return 0; 608 606 } … … 620 618 621 619 if ((error = tget_mpf(MPF_RSLV_SRBUF, (void*)&msg, TMO_FEVR)) != E_OK) { 622 ntstdio_printf(&ntstdio,"get buffer error: %s.\n", itron_strerror(error));620 printf("get buffer error: %s.\n", itron_strerror(error)); 623 621 return 0; 624 622 } 625 623 626 624 if ((length = dns_lookup_host(flags | DNS_LUP_FLAGS_MSG, line, msg, DNS_UDP_MSG_LENGTH, &rslv)) < 0) { 627 // ntstdio_printf(&ntstdio,"error: %s.\n", itron_strerror(length));625 //printf("error: %s.\n", itron_strerror(length)); 628 626 goto err_ret; 629 627 } 630 628 631 629 dly_tsk(1 * 1000); 632 ntstdio_printf(&ntstdio,"DNS header: flags: ");630 printf("DNS header: flags: "); 633 631 if (rslv.dns_hdr.code & (DNS_QR_RESPONSE | DNS_AUTHORITATIVE | 634 632 DNS_TRUN_CATION | DNS_RECURSION_DESIRED | DNS_RECURSION_AVAILABLE)) { 635 ntstdio_printf(&ntstdio,(rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : "");636 ntstdio_printf(&ntstdio,(rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : "");637 ntstdio_printf(&ntstdio,(rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : "");638 ntstdio_printf(&ntstdio,(rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : "");639 ntstdio_printf(&ntstdio,(rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : "");640 ntstdio_printf(&ntstdio," ");641 } 642 ntstdio_printf(&ntstdio,"opcode: ");643 ntstdio_printf(&ntstdio,(rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW");644 ntstdio_printf(&ntstdio,(rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : "");645 ntstdio_printf(&ntstdio,", rcode: %s.\n",633 printf((rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : ""); 634 printf((rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : ""); 635 printf((rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : ""); 636 printf((rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : ""); 637 printf((rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : ""); 638 printf(" "); 639 } 640 printf("opcode: "); 641 printf((rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW"); 642 printf((rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : ""); 643 printf(", rcode: %s.\n", 646 644 (rslv.dns_hdr.code & DNS_RCODE_MASK) > DNS_RCODE_REFUSED 647 645 ? "6" : rcode_str[rslv.dns_hdr.code & DNS_RCODE_MASK]); 648 646 649 647 if ((offset = show_dns_qdsection(msg, length, &rslv)) < 0) { 650 ntstdio_printf(&ntstdio,"msg error: %s.\n", itron_strerror(offset));648 printf("msg error: %s.\n", itron_strerror(offset)); 651 649 } 652 650 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.ancount, rslv.an_offset, "answer")) < 0) { 653 ntstdio_printf(&ntstdio,"msg error: %s.\n", itron_strerror(offset));651 printf("msg error: %s.\n", itron_strerror(offset)); 654 652 } 655 653 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.nscount, rslv.ns_offset, "authority")) < 0) { 656 ntstdio_printf(&ntstdio,"msg error: %s.\n", itron_strerror(offset));654 printf("msg error: %s.\n", itron_strerror(offset)); 657 655 } 658 656 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.arcount, rslv.ar_offset, "additional")) < 0) { 659 ntstdio_printf(&ntstdio,"msg error: %s.\n", itron_strerror(offset));657 printf("msg error: %s.\n", itron_strerror(offset)); 660 658 } 661 659 662 660 err_ret: 663 661 if ((error = rel_mpf(MPF_RSLV_SRBUF, msg)) != E_OK) 664 ntstdio_printf(&ntstdio,"release buffer error: %s.\n", itron_strerror(error));662 printf("release buffer error: %s.\n", itron_strerror(error)); 665 663 return 0; 666 664 } -
asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c
r364 r374 50 50 #include <t_syslog.h> 51 51 #include "kernel_cfg.h" 52 #include "util/ntstdio.h" 53 54 extern ntstdio_t ntstdio; 52 #include <stdio.h> 55 53 56 54 #endif /* of #if defined(TARGET_KERNEL_ASP) */ … … 279 277 } 280 278 281 ntstdio_printf(&ntstdio,"[NTP CLI,%d] recv time: %s .%09u\n",279 printf("[NTP CLI,%d] recv time: %s .%09u\n", 282 280 nc->cepid, nc->buf, tp.tv_nsec); 283 281 } … … 311 309 line = lookup_ipaddr(&nc->ipaddr6, NTP_SRV_URL, API_PROTO_IPV4); 312 310 if (line == NULL || !in6_is_addr_ipv4mapped(&nc->ipaddr6)) { 313 ntstdio_printf(&ntstdio,"[NTP CLI,%d] sleep %d.%03u[s], unknown host.",311 printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.", 314 312 nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ); 315 313 nc->timer = SLP_ITV; … … 319 317 #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */ 320 318 if ((line = lookup_ipaddr(&nc->snd_rmt.ipaddr, NTP_SRV_URL, DEFAULT_API_PROTO)) == NULL) { 321 ntstdio_printf(&ntstdio,"[NTP CLI,%d] sleep %d.%03u[s], unknown host.",319 printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.", 322 320 nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ); 323 321 nc->timer = SLP_ITV; … … 423 421 424 422 if ((error = udp_snd_dat(nc->cepid, &nc->snd_rmt, ntp, len, TMO_NBLK)) != E_WBLK) { 425 ntstdio_printf(&ntstdio,"[NTP CLI,%d] udp_snd_dat error: %s",423 printf("[NTP CLI,%d] udp_snd_dat error: %s", 426 424 nc->cepid, itron_strerror(error)); 427 425 return error; … … 441 439 ret = get_tim(&time); 442 440 if (ret != E_OK) { 443 ntstdio_printf(&ntstdio,"[NTP CLI,%d] get_tim error: %s",441 printf("[NTP CLI,%d] get_tim error: %s", 444 442 nc->cepid, itron_strerror(ret)); 445 443 tp->tv_sec = 0; … … 461 459 ret = set_tim(time); 462 460 if (ret != E_OK) { 463 ntstdio_printf(&ntstdio,"[NTP CLI,%d] set_tim error: %s",461 printf("[NTP CLI,%d] set_tim error: %s", 464 462 nc->cepid, itron_strerror(ret)); 465 463 } … … 479 477 if (len < 0 && len != E_RLWAI) { 480 478 /* E_RLWAI 以外で、0 以下の場合は、エラーを意味している。*/ 481 ntstdio_printf(&ntstdio,"[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,479 printf("[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid, 482 480 itron_strerror(len), in_strtfn(fncd)); 483 481 } … … 486 484 if ((len = udp_rcv_dat(nc->cepid, &nc->rcv_rmt, &nc->ntp_msg, len, TMO_POL)) < 0) 487 485 { 488 ntstdio_printf(&ntstdio,"[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,486 printf("[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid, 489 487 itron_strerror(len)); 490 488 } … … 518 516 519 517 get_tid(&nc->tskid); 520 ntstdio_printf(&ntstdio,"[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);518 printf("[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf); 521 519 522 520 /* 初期化 */ … … 525 523 ret = get_tim(&time); 526 524 if (ret != E_OK) { 527 ntstdio_printf(&ntstdio,"[NTP CLI,%d] get_tim error: %7lu,%s",525 printf("[NTP CLI,%d] get_tim error: %7lu,%s", 528 526 nc->cepid, time / SYSTIM_HZ, itron_strerror(ret)); 529 527 return; … … 539 537 error = tslp_tsk(timer); 540 538 if ((error != E_OK) && (error != E_TMOUT)) { 541 ntstdio_printf(&ntstdio,"[NTP CLI,%d] tslp_tsk error: %s %d",539 printf("[NTP CLI,%d] tslp_tsk error: %s %d", 542 540 nc->cepid, itron_strerror(error), timer); 543 541 break; … … 546 544 ret = get_tim(&time); 547 545 if (ret != E_OK) { 548 ntstdio_printf(&ntstdio,"[NTP CLI,%d] get_tim error: %s",546 printf("[NTP CLI,%d] get_tim error: %s", 549 547 nc->cepid, itron_strerror(ret)); 550 548 break; -
asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c
r364 r374 59 59 #include "ntshell_main.h" 60 60 #include "socket_stub.h" 61 #include "usb_hbth.h"62 63 extern int bt_bnep_mode;64 61 65 62 char command[NTOPT_TEXT_MAXLEN]; 66 ntstdio_t ntstdio;67 63 68 64 extern uint8_t mac_addr[6]; … … 87 83 volatile int ntshell_state; 88 84 jmp_buf process_exit; 89 void sys_init(void); 90 NTSHELL_SERIAL_READ ntshell_serial_read = 0; 91 NTSHELL_SERIAL_WRITE ntshell_serial_write = 0; 92 void *ntshell_serial_extobj; 93 94 unsigned char ntstdio_xi(struct ntstdio_t *handle) 95 { 96 unsigned char buf[1]; 97 ntshell_serial_read((char *)buf, 1, ntshell_serial_extobj); 98 return buf[0]; 99 } 100 101 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c) 102 { 103 char buf[1]; 104 buf[0] = c; 105 ntshell_serial_write(buf, 1, ntshell_serial_extobj); 106 } 107 108 void ntshell_task_init(NTSHELL_SERIAL_READ func_read, 109 NTSHELL_SERIAL_WRITE func_write, void *extobj) 110 { 111 ntshell_serial_read = func_read; 112 ntshell_serial_write = func_write; 113 ntshell_serial_extobj = extobj; 114 115 sys_init(); 116 117 ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo); 85 86 void ntshell_task_init(ID portid) 87 { 88 serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV); 118 89 } 119 90 … … 177 148 const cmd_table_t *p = cmd_table_info.table; 178 149 for (int i = 0; i < cmd_table_info.count; i++) { 179 ntstdio_puts(&ntstdio, p->cmd); 180 ntstdio_puts(&ntstdio, "\t:"); 181 ntstdio_puts(&ntstdio, p->desc); 182 ntstdio_puts(&ntstdio, "\n"); 150 fwrite(p->cmd, strlen(p->cmd), 1, stdout); 151 fwrite("\t:", strlen("\t:"), 1, stdout); 152 puts(p->desc); 183 153 p++; 184 154 } … … 206 176 int execute_command(int wait) 207 177 { 178 T_RTSK rtsk; 208 179 ER ret; 209 180 … … 228 199 do { 229 200 tslp_tsk(100000); 201 202 ret = ref_tsk(NTSHELL_TASK, &rtsk); 203 if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT)) 204 ntshell_state = 3; 230 205 } while(ntshell_state == 1); 231 206 … … 237 212 ntlibc_strlcpy(command, text, sizeof(command)); 238 213 return execute_command(1); 239 }240 241 int stdio_close(struct _IO_FILE *fp)242 {243 return -EPERM;244 }245 246 size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)247 {248 return -EPERM;249 }250 251 size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)252 {253 return -EPERM;254 }255 256 size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len)257 {258 int i = 0;259 while (i < len) {260 int c = ntstdio_getc(&ntstdio);261 data[i++] = c;262 if ((c == EOF) || (c == '\n'))263 break;264 }265 return i;266 }267 268 size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)269 {270 for (int i = 0; i < len; i++) {271 ntstdio_putc(&ntstdio, data[i]);272 }273 return len;274 }275 276 size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)277 {278 for (int i = 0; i < len; i++) {279 ntstdio_putc(&ntstdio, data[i]);280 }281 return len;282 }283 284 int sio_close(struct _IO_FILE *fp)285 {286 return -EPERM;287 }288 289 size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)290 {291 return -EPERM;292 }293 294 size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)295 {296 return -EPERM;297 }298 299 off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org)300 {301 return -EPERM;302 }303 304 int sio_ioctl(struct _IO_FILE *fp, int request, void *arg)305 {306 switch (request) {307 case TIOCGWINSZ:308 return 0;309 case TCGETS:310 return sio_tcgetattr(fp->fd, (struct termios *)arg);311 case TCSETS + TCSANOW:312 case TCSETS + TCSADRAIN:313 case TCSETS + TCSAFLUSH:314 return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);315 }316 317 return -EINVAL;318 214 } 319 215 … … 456 352 } 457 353 354 int shell_kill(int pid, int sig) 355 { 356 DebugBreak(); 357 return -1; 358 } 359 360 int shell_gettimeofday(struct timeval *tv, void *tzvp) 361 { 362 SYSTIM time; 363 if (!tv) return 0; 364 get_tim(&time); 365 tv->tv_sec = time / 1000000; 366 tv->tv_usec = time - (tv->tv_sec * 1000000); 367 return 0; 368 } 369 -
asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.cfg
r364 r374 41 41 #include "ntshell_main.h" 42 42 43 CRE_TSK(NTSHELL_TASK, { TA_NULL, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL }); 43 ATT_INI({ TA_NULL, 0, sys_init }); 44 45 CRE_TSK(NTSHELL_TASK, { TA_FPU, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL }); 44 46 CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 }); 45 47 CRE_SEM(SEM_FILEDESC, { TA_TPRI, 1, 1 }); 46 CRE_SEM(SEM_MALLOC, { TA_TPRI, 1, 1 }); -
asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.h
r367 r374 76 76 extern PRI main_task_priority; 77 77 78 /* ntshellの初期化 */ 79 void sys_init(intptr_t exinf); 80 78 81 /* ntshellタスク初期化 */ 79 void ntshell_task_init(NTSHELL_SERIAL_READ func_read, 80 NTSHELL_SERIAL_WRITE func_write, void *extobj); 82 void ntshell_task_init(ID portid); 81 83 82 84 /* ntshellタスク */ -
asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h
r364 r374 134 134 135 135 // dirent.h 136 typedef struct __dirstream DIR;136 typedef struct __dirstream FATFS_DIR; 137 137 138 138 int shell_getdents(int, struct dirent *, size_t); … … 303 303 #endif 304 304 305 struct tm *gmtime_r(const time_t *t, struct tm *tm);306 305 void *malloc(size_t size); 307 306 void *calloc(size_t size, size_t count); -
asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c
r364 r374 57 57 #include <netinet/udp_var.h> 58 58 #include <net/net_buf.h> 59 //#include <netinet/tcp_var.h> 59 #include <netinet/udp.h> 60 #include <netinet/udp_var.h> 61 #include <netinet/tcp.h> 62 #include <netinet/tcp_var.h> 60 63 #include <netapp/resolver.h> 61 64 extern const ID tmax_tcp_cepid; … … 64 67 #include "kernel_cfg.h" 65 68 69 #ifdef _DEBUG 70 static const char THIS_FILE[] = __FILE__; 71 #endif 72 66 73 #define SOCKET_TIMEOUT 2000000 74 75 static int tcp_fd_close(struct SHELL_FILE *fp); 76 static size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 77 static size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 78 static off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org); 79 static int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg); 80 static bool_t tcp_fd_readable(struct SHELL_FILE *fp); 81 static void tcp_fd_delete(struct SHELL_FILE *fp); 82 83 static int udp_fd_close(struct SHELL_FILE *fp); 84 static size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len); 85 static size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len); 86 static off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org); 87 static int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg); 88 static bool_t udp_fd_readable(struct SHELL_FILE *fp); 89 static void udp_fd_delete(struct SHELL_FILE *fp); 90 91 IO_TYPE IO_TYPE_TCP = { tcp_fd_close, tcp_fd_read, tcp_fd_write, tcp_fd_seek, tcp_fd_ioctl, tcp_fd_readable, tcp_fd_delete }; 92 IO_TYPE IO_TYPE_UDP = { udp_fd_close, udp_fd_read, udp_fd_write, udp_fd_seek, udp_fd_ioctl, udp_fd_readable, udp_fd_delete }; 67 93 68 94 typedef struct id_table_t { … … 116 142 } 117 143 118 int delete_tcp_rep(int repid) 119 { 120 return delete_tcp_fd(tmax_tcp_cepid + repid); 121 } 122 123 typedef struct _IO_FILE SOCKET; 144 typedef struct SHELL_FILE SOCKET; 124 145 125 146 int shell_socket(int family, int type, int protocol) … … 141 162 switch (type) { 142 163 case SOCK_STREAM: 143 fp = new_tcp_fd(0); 164 fp = new_fp(&IO_TYPE_TCP, 0, 0); 165 if (fp == NULL) 166 return -ENOMEM; 167 168 fp->exinf = malloc(sizeof(socket_t)); 169 memset(fp->exinf, 0, sizeof(socket_t)); 144 170 break; 145 171 case SOCK_DGRAM: 146 fp = new_udp_fd(0); 172 fp = new_fp(&IO_TYPE_UDP, 0, 1); 173 if (fp == NULL) 174 return -ENOMEM; 175 176 fp->exinf = malloc(sizeof(socket_t)); 177 memset(fp->exinf, 0, sizeof(socket_t)); 147 178 break; 148 179 default: … … 150 181 } 151 182 152 if (fp == NULL) { 153 return -ENOMEM; 154 } 155 156 fp->psock->family = family; 157 fp->psock->type = type; 158 fp->psock->protocol = protocol; 159 fp->psock->flags = flags; 183 socket_t *socket = (socket_t *)fp->exinf; 184 socket->family = family; 185 socket->type = type; 186 socket->protocol = protocol; 187 socket->flags = flags; 160 188 161 189 return fp->fd; … … 167 195 if (fp == NULL) 168 196 return -EBADF; 169 if (fp->psock->family != addr->sa_family) 197 socket_t *socket = (socket_t *)fp->exinf; 198 if (socket->family != addr->sa_family) 170 199 return -EINVAL; 171 200 … … 177 206 } 178 207 struct sockaddr_in *addr_in = (struct sockaddr_in *)addr; 179 memcpy(& fp->psock->laddr4, addr, len);180 switch ( fp->psock->type) {208 memcpy(&socket->laddr4, addr, len); 209 switch (socket->type) { 181 210 case SOCK_STREAM: { 182 211 ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count); … … 184 213 return -ENOMEM; 185 214 186 fp->psock->buf_size = 512 + 512;187 fp->psock->buf = malloc(fp->psock->buf_size);215 socket->buf_size = 512 + 512; 216 socket->buf = malloc(socket->buf_size); 188 217 #ifdef _DEBUG 189 memset( fp->psock->buf, 0, fp->psock->buf_size);218 memset(socket->buf, 0, socket->buf_size); 190 219 #endif 191 T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };220 T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback }; 192 221 ret = tcp_cre_cep(cepid, &ccep); 193 222 if (ret != E_OK) { … … 196 225 } 197 226 fp->handle = cepid; 198 fp->psock->cepid = cepid;227 socket->cepid = cepid; 199 228 break; 200 229 } … … 211 240 } 212 241 fp->handle = cepid; 213 fp->psock->cepid = cepid;242 socket->cepid = cepid; 214 243 break; 215 244 } … … 223 252 return -EINVAL; 224 253 } 225 memcpy(& fp->psock->laddr4, addr, len);254 memcpy(&socket->laddr4, addr, len); 226 255 break; 227 256 } … … 236 265 if (fp == NULL) 237 266 return -EBADF; 238 if (fp->psock->type != SOCK_STREAM) 267 socket_t *socket = (socket_t *)fp->exinf; 268 if (socket->type != SOCK_STREAM) 239 269 return -EINVAL; 240 270 241 fp->psock->backlog = backlog;271 socket->backlog = backlog; 242 272 243 273 ER ret; 244 switch ( fp->psock->family) {274 switch (socket->family) { 245 275 case AF_INET: { 246 276 ID repid = new_id(tcp_repid_table, tcp_repid_table_count); … … 248 278 return -ENOMEM; 249 279 250 struct sockaddr_in *laddr = & fp->psock->laddr4;280 struct sockaddr_in *laddr = &socket->laddr4; 251 281 T_TCP_CREP crep = { 0, {ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port)} }; 252 282 ret = tcp_cre_rep(repid, &crep); … … 255 285 return -ENOMEM; 256 286 } 257 fp->psock->repid = repid;287 socket->repid = repid; 258 288 break; 259 289 } … … 271 301 if (fp == NULL) 272 302 return -EBADF; 273 if (fp->psock->type != SOCK_STREAM) 303 socket_t *socket = (socket_t *)fp->exinf; 304 if (socket->type != SOCK_STREAM) 274 305 return -EINVAL; 275 306 276 307 ER ret; 277 switch ( fp->psock->family) {308 switch (socket->family) { 278 309 case AF_INET: { 279 310 if (len < 8) { 280 311 return -EINVAL; 281 312 } 282 if ( fp->psock->cepid == 0) {313 if (socket->cepid == 0) { 283 314 ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count); 284 315 if (cepid < 0) 285 316 return -ENOMEM; 286 317 287 fp->psock->buf_size = 512 + 512;288 fp->psock->buf = malloc(fp->psock->buf_size);318 socket->buf_size = 512 + 512; 319 socket->buf = malloc(socket->buf_size); 289 320 #ifdef _DEBUG 290 memset( fp->psock->buf, 0, fp->psock->buf_size);321 memset(socket->buf, 0, socket->buf_size); 291 322 #endif 292 T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };323 T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback }; 293 324 ret = tcp_cre_cep(cepid, &ccep); 294 325 if (ret != E_OK) { … … 297 328 } 298 329 fp->handle = cepid; 299 fp->psock->cepid = cepid;300 } 301 struct sockaddr_in *laddr = & fp->psock->laddr4;302 struct sockaddr_in *raddr = & fp->psock->raddr4;330 socket->cepid = cepid; 331 } 332 struct sockaddr_in *laddr = &socket->laddr4; 333 struct sockaddr_in *raddr = &socket->raddr4; 303 334 memset(raddr, 0, sizeof(*raddr)); 304 335 memcpy(raddr, addr, len); 305 336 T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) }; 306 337 T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) }; 307 ret = tcp_con_cep( fp->psock->cepid, &lep, &rep, SOCKET_TIMEOUT);338 ret = tcp_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT); 308 339 if (ret < 0) { 309 340 return -EHOSTUNREACH; … … 324 355 if (lfp == NULL) 325 356 return -EBADF; 326 if ( lfp->psock->type != SOCK_STREAM)357 if (((socket_t *)lfp->exinf)->type != SOCK_STREAM) 327 358 return -EINVAL; 328 359 329 SOCKET *fp = new_ tcp_fd(0);330 if (fp == NULL) {360 SOCKET *fp = new_fp(&IO_TYPE_TCP, 0, 0); 361 if (fp == NULL) 331 362 return -ENOMEM; 332 } 333 334 memcpy(fp->psock, lfp->psock, offsetof(socket_t, buf_size)); 363 364 fp->exinf = malloc(sizeof(socket_t)); 365 memset(fp->exinf, 0, sizeof(socket_t)); 366 367 memcpy(fp->exinf, lfp->exinf, offsetof(socket_t, buf_size)); 335 368 336 369 ER ret; 337 switch (fp->psock->family) { 370 socket_t *socket = (socket_t *)fp->exinf; 371 switch (socket->family) { 338 372 case AF_INET: { 339 373 ID cepid; 340 if ( fp->psock->cepid == 0) {374 if (socket->cepid == 0) { 341 375 cepid = new_id(tcp_cepid_table, tcp_cepid_table_count); 342 376 if (cepid < 0) 343 377 return -ENOMEM; 344 378 345 fp->psock->buf_size = 512 + 512;346 fp->psock->buf = malloc(fp->psock->buf_size);379 socket->buf_size = 512 + 512; 380 socket->buf = malloc(socket->buf_size); 347 381 #ifdef _DEBUG 348 memset( fp->psock->buf, 0, fp->psock->buf_size);382 memset(socket->buf, 0, socket->buf_size); 349 383 #endif 350 T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };384 T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback }; 351 385 ret = tcp_cre_cep(cepid, &ccep); 352 386 if (ret != E_OK) { … … 355 389 } 356 390 fp->handle = cepid; 357 fp->psock->cepid = cepid;391 socket->cepid = cepid; 358 392 } 359 393 else { 360 cepid = lfp->psock->cepid;394 cepid = ((socket_t *)lfp->exinf)->cepid; 361 395 fp->handle = cepid; 362 lfp->handle = tmax_tcp_cepid + lfp->psock->repid;363 lfp->psock->cepid = 0;364 lfp->psock->buf_size = 0;365 lfp->psock->buf = 0;396 lfp->handle = tmax_tcp_cepid + ((socket_t *)lfp->exinf)->repid; 397 ((socket_t *)lfp->exinf)->cepid = 0; 398 ((socket_t *)lfp->exinf)->buf_size = 0; 399 ((socket_t *)lfp->exinf)->buf = 0; 366 400 } 367 401 T_IPV4EP rep = { 0, 0 }; 368 ret = tcp_acp_cep( fp->psock->cepid, fp->psock->repid, &rep, TMO_FEVR);402 ret = tcp_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR); 369 403 if (ret < 0) { 370 404 return -ENOMEM; 371 405 } 372 struct sockaddr_in *raddr = & fp->psock->raddr4;406 struct sockaddr_in *raddr = &socket->raddr4; 373 407 memset(raddr, 0, sizeof(*raddr)); 374 408 raddr->sin_family = AF_INET; … … 387 421 return -EINVAL; 388 422 } 389 struct sockaddr_in *raddr = & fp->psock->raddr4;423 struct sockaddr_in *raddr = &socket->raddr4; 390 424 if (sz > sizeof(*raddr)) 391 425 sz = sizeof(*raddr); … … 405 439 406 440 int ret = 0; 407 switch (fp->psock->family) { 441 socket_t *socket = (socket_t *)fp->exinf; 442 switch (socket->family) { 408 443 case AF_INET: { 409 switch ( fp->psock->type) {444 switch (socket->type) { 410 445 case SOCK_STREAM: { 411 446 if ((addr != NULL) || (alen != 0)) { … … 414 449 415 450 if (flags & MSG_OOB) { 416 ret = tcp_snd_oob( fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);451 ret = tcp_snd_oob(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT); 417 452 if (ret < 0) { 418 453 return -ECOMM; … … 421 456 else { 422 457 for (;;) { 423 ret = tcp_snd_dat( fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);458 ret = tcp_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT); 424 459 if (ret < 0) { 425 460 if (ret == E_TMOUT) … … 440 475 return -EINVAL; 441 476 } 442 struct sockaddr_in *raddr = & fp->psock->raddr4;477 struct sockaddr_in *raddr = &socket->raddr4; 443 478 memset(raddr, 0, sizeof(*raddr)); 444 479 memcpy(raddr, addr, sz); 445 480 T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) }; 446 ret = udp_snd_dat( fp->psock->cepid, &rep, (void *)buf, len,447 ( fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);481 ret = udp_snd_dat(socket->cepid, &rep, (void *)buf, len, 482 (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT); 448 483 if (ret < 0) { 449 484 return (ret == E_TMOUT) ? -ETIME : -ECOMM; … … 476 511 477 512 int ret = 0; 478 switch (fp->psock->family) { 513 socket_t *socket = (socket_t *)fp->exinf; 514 switch (socket->family) { 479 515 case AF_INET: { 480 switch ( fp->psock->type) {516 switch (socket->type) { 481 517 case SOCK_STREAM: { 482 518 if (flags & MSG_OOB) { 483 ret = tcp_rcv_oob( fp->psock->cepid, buf, len);519 ret = tcp_rcv_oob(socket->cepid, buf, len); 484 520 if (ret < 0) { 485 521 syslog(LOG_ERROR, "tcp_rcv_oob => %d", ret); … … 489 525 else { 490 526 int rsz, tmp; 491 if ( fp->psock->input == NULL) {527 if (socket->input == NULL) { 492 528 ret = wai_sem(SEM_FILEDESC); 493 529 if (ret < 0) { 494 530 syslog(LOG_ERROR, "wai_sem => %d", ret); 495 531 } 496 fp->psock->len = 0;532 socket->len = 0; 497 533 ret = sig_sem(SEM_FILEDESC); 498 534 if (ret < 0) { 499 535 syslog(LOG_ERROR, "sig_sem => %d", ret); 500 536 } 501 ret = tcp_rcv_buf( fp->psock->cepid, &fp->psock->input, TMO_FEVR);537 ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_FEVR); 502 538 if (ret < 0) { 503 539 syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret); … … 507 543 } 508 544 else 509 rsz = fp->psock->len;545 rsz = socket->len; 510 546 tmp = rsz; 511 547 if (rsz > len) 512 548 rsz = len; 513 549 if (rsz >= 0) { 514 memcpy(buf, fp->psock->input, rsz);550 memcpy(buf, socket->input, rsz); 515 551 ret = wai_sem(SEM_FILEDESC); 516 552 if (ret < 0) { 517 553 syslog(LOG_ERROR, "wai_sem => %d", ret); 518 554 } 519 fp->psock->len = tmp - rsz;555 socket->len = tmp - rsz; 520 556 ret = sig_sem(SEM_FILEDESC); 521 557 if (ret < 0) { … … 523 559 } 524 560 if (tmp - rsz == 0) { 525 fp->psock->input = NULL;561 socket->input = NULL; 526 562 } 527 563 else 528 fp->psock->input = (void *)&((uint8_t *)fp->psock->input)[rsz];529 ret = tcp_rel_buf( fp->psock->cepid, rsz);564 socket->input = (void *)&((uint8_t *)socket->input)[rsz]; 565 ret = tcp_rel_buf(socket->cepid, rsz); 530 566 if ((ret != E_OBJ) && (ret < 0)) { 531 567 syslog(LOG_ERROR, "tcp_rel_buf => %d", ret); … … 538 574 } 539 575 case SOCK_DGRAM: { 540 struct sockaddr_in *raddr = & fp->psock->raddr4;576 struct sockaddr_in *raddr = &socket->raddr4; 541 577 int rsz; 542 578 ret = wai_sem(SEM_FILEDESC); … … 544 580 syslog(LOG_ERROR, "wai_sem => %d", ret); 545 581 } 546 T_NET_BUF *input = fp->psock->input;582 T_NET_BUF *input = socket->input; 547 583 if (input == NULL) { 548 584 ret = sig_sem(SEM_FILEDESC); … … 552 588 553 589 T_IPV4EP rep = { 0, 0 }; 554 ret = udp_rcv_dat( fp->psock->cepid, &rep, buf, len,555 ( fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);590 ret = udp_rcv_dat(socket->cepid, &rep, buf, len, 591 (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT); 556 592 if (ret < 0) { 557 syslog(LOG_ERROR, "udp_rcv_buf => %d", ret); 593 if ((socket->flags & O_NONBLOCK) == 0) 594 syslog(LOG_ERROR, "udp_rcv_buf => %d", ret); 558 595 return (ret == E_TMOUT) ? -ETIME : -ECOMM; 559 596 } … … 565 602 } 566 603 int sz = *alen; 567 memset(raddr, 0, sizeof( fp->psock->raddr4));604 memset(raddr, 0, sizeof(socket->raddr4)); 568 605 raddr->sin_family = AF_INET; 569 606 raddr->sin_port = htons(rep.portno); 570 607 raddr->sin_addr.s_addr = htonl(rep.ipaddr); 571 if (sz > sizeof( fp->psock->raddr4))572 sz = sizeof( fp->psock->raddr4);608 if (sz > sizeof(socket->raddr4)) 609 sz = sizeof(socket->raddr4); 573 610 memcpy(addr, raddr, sz); 574 611 *alen = sz; … … 580 617 } 581 618 else { 582 rsz = fp->psock->len;583 void *pbuf = fp->psock->buf;584 fp->psock->input = NULL;585 fp->psock->len = 0;586 fp->psock->buf = NULL;619 rsz = socket->len; 620 void *pbuf = socket->buf; 621 socket->input = NULL; 622 socket->len = 0; 623 socket->buf = NULL; 587 624 if ((addr != NULL) && (alen != NULL)) { 588 625 int sz = *alen; 589 if (sz > sizeof( fp->psock->raddr4))590 sz = sizeof( fp->psock->raddr4);626 if (sz > sizeof(socket->raddr4)) 627 sz = sizeof(socket->raddr4); 591 628 memcpy(addr, raddr, sz); 592 629 *alen = sz; … … 632 669 633 670 ER ret; 634 switch (fp->psock->family) { 671 socket_t *socket = (socket_t *)fp->exinf; 672 switch (socket->family) { 635 673 case AF_INET: { 636 switch ( fp->psock->type) {674 switch (socket->type) { 637 675 case SOCK_STREAM: { 638 ret = tcp_sht_cep( fp->psock->cepid);676 ret = tcp_sht_cep(socket->cepid); 639 677 if (ret < 0) { 640 678 return -ECOMM; … … 661 699 662 700 ER ret; 663 switch (fp->psock->family) { 701 socket_t *socket = (socket_t *)fp->exinf; 702 switch (socket->family) { 664 703 case AF_INET: { 665 switch ( fp->psock->type) {704 switch (socket->type) { 666 705 case SOCK_STREAM: { 667 706 switch (level) { … … 669 708 switch (optname) { 670 709 case SO_REUSEADDR: 671 if ( fp->psock->flags & SO_REUSEADDR) {710 if (socket->flags & SO_REUSEADDR) { 672 711 *(bool *)optval = true; 673 712 } … … 677 716 break; 678 717 case SO_KEEPALIVE: 679 if ( fp->psock->flags & SO_KEEPALIVE) {718 if (socket->flags & SO_KEEPALIVE) { 680 719 *(bool *)optval = true; 681 720 } … … 692 731 break; 693 732 case IPPROTO_TCP: 694 ret = tcp_get_opt( fp->psock->cepid, optname, (void *)optval, *optlen);733 ret = tcp_get_opt(socket->cepid, optname, (void *)optval, *optlen); 695 734 if (ret < 0) { 696 735 return -EINVAL; … … 706 745 switch (level) { 707 746 case IPPROTO_UDP: 708 ret = udp_get_opt( fp->psock->cepid, optname, (void *)optval, *optlen);747 ret = udp_get_opt(socket->cepid, optname, (void *)optval, *optlen); 709 748 if (ret < 0) { 710 749 return -EINVAL; … … 736 775 737 776 ER ret; 738 switch (fp->psock->family) { 777 socket_t *socket = (socket_t *)fp->exinf; 778 switch (socket->family) { 739 779 case AF_INET: { 740 switch ( fp->psock->type) {780 switch (socket->type) { 741 781 case SOCK_STREAM: { 742 782 switch (level){ … … 745 785 case SO_REUSEADDR: 746 786 if (*(bool *)optval) { 747 fp->psock->flags |= SO_REUSEADDR;787 socket->flags |= SO_REUSEADDR; 748 788 } 749 789 else { 750 fp->psock->flags &= ~SO_REUSEADDR;790 socket->flags &= ~SO_REUSEADDR; 751 791 } 752 792 break; 753 793 case SO_KEEPALIVE: 754 794 if (*(bool *)optval) { 755 fp->psock->flags |= SO_KEEPALIVE;795 socket->flags |= SO_KEEPALIVE; 756 796 } 757 797 else { 758 fp->psock->flags &= ~SO_KEEPALIVE;798 socket->flags &= ~SO_KEEPALIVE; 759 799 } 760 800 break; … … 764 804 break; 765 805 case IPPROTO_TCP: 766 ret = tcp_set_opt( fp->psock->cepid, optname, (void *)optval, optlen);806 ret = tcp_set_opt(socket->cepid, optname, (void *)optval, optlen); 767 807 if (ret < 0) { 768 808 return -EINVAL; … … 777 817 switch (level){ 778 818 case IPPROTO_UDP: 779 ret = udp_set_opt( fp->psock->cepid, optname, (void *)optval, optlen);819 ret = udp_set_opt(socket->cepid, optname, (void *)optval, optlen); 780 820 if (ret < 0) { 781 821 return -EINVAL; … … 809 849 810 850 socklen_t size = *len; 811 switch (fp->psock->family) { 851 socket_t *socket = (socket_t *)fp->exinf; 852 switch (socket->family) { 812 853 case AF_INET: { 813 struct sockaddr_in *raddr = & fp->psock->raddr4;854 struct sockaddr_in *raddr = &socket->raddr4; 814 855 *len = sizeof(struct sockaddr_in); 815 856 if (size > sizeof(struct sockaddr_in)) … … 837 878 838 879 socklen_t size = *len; 839 switch (fp->psock->family) { 880 socket_t *socket = (socket_t *)fp->exinf; 881 switch (socket->family) { 840 882 case AF_INET: { 841 883 const T_IN4_ADDR *laddr4 = in4_get_ifaddr(0); … … 843 885 laddr.sin_family = AF_INET; 844 886 laddr.sin_addr.s_addr = htonl(*laddr4); 845 laddr.sin_port = fp->psock->laddr4.sin_port;887 laddr.sin_port = socket->laddr4.sin_port; 846 888 memset(&laddr.sin_zero, 0, sizeof(laddr.sin_zero)); 847 889 *len = sizeof(struct sockaddr_in); … … 859 901 } 860 902 861 int tcp_fd_close(struct _IO_FILE *fp)903 int tcp_fd_close(struct SHELL_FILE *fp) 862 904 { 863 905 ER ret, ret2; 864 906 865 switch (fp->psock->family) { 907 socket_t *socket = (socket_t *)fp->exinf; 908 switch (socket->family) { 866 909 case AF_INET: { 867 if ( fp->psock->cepid != 0) {868 ID cepid = fp->psock->cepid;910 if (socket->cepid != 0) { 911 ID cepid = socket->cepid; 869 912 ret = tcp_sht_cep(cepid); 870 913 if (ret < 0) { 871 914 //return -1; 872 915 } 873 ret = tcp_cls_cep(cepid, ( fp->psock->repid != 0) ? 0 : SOCKET_TIMEOUT);916 ret = tcp_cls_cep(cepid, (socket->repid != 0) ? 0 : SOCKET_TIMEOUT); 874 917 ret2 = tcp_del_cep(cepid); 875 free(fp->psock->buf); 876 fp->psock->buf = NULL; 877 delete_tcp_fd(cepid); 918 //delete_fd_by_id(&IO_TYPE_TCP, cepid); 878 919 delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid); 879 920 if ((ret < 0) || (ret2 < 0)) { … … 881 922 } 882 923 } 883 else if ( fp->psock->repid != 0) {884 ID repid = fp->psock->repid;924 else if (socket->repid != 0) { 925 ID repid = socket->repid; 885 926 ret = tcp_del_rep(repid); 886 free(fp->psock->buf); 887 fp->psock->buf = NULL; 888 delete_tcp_fd(tmax_tcp_cepid + repid); 927 //delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + repid); 889 928 delete_id(tcp_repid_table, tcp_repid_table_count, repid); 890 929 if (ret < 0) { … … 893 932 } 894 933 else { 895 free(fp->psock->buf);896 fp->psock->buf = NULL;897 934 return -EINVAL; 898 935 } … … 907 944 } 908 945 909 size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)946 size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz) 910 947 { 911 948 return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL); 912 949 } 913 950 914 size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)951 size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz) 915 952 { 916 953 return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0); 917 954 } 918 955 919 off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)956 off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org) 920 957 { 921 958 return -EPERM; 922 959 } 923 960 924 int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)961 int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg) 925 962 { 926 963 return -EINVAL; 927 964 } 928 965 929 int udp_fd_close(struct _IO_FILE *fp) 966 bool_t tcp_fd_readable(struct SHELL_FILE *fp) 967 { 968 ER ret; 969 970 socket_t *socket = (socket_t *)fp->exinf; 971 if (socket->cepid != 0) { 972 if (socket->len == 0) { 973 ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_NBLK); 974 if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) { 975 syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret); 976 //return ret; 977 } 978 if (ret > 0) { 979 ret = wai_sem(SEM_FILEDESC); 980 if (ret < 0) { 981 syslog(LOG_ERROR, "wai_sem => %d", ret); 982 } 983 socket->len += ret; 984 ret = sig_sem(SEM_FILEDESC); 985 if (ret < 0) { 986 syslog(LOG_ERROR, "sig_sem => %d", ret); 987 } 988 } 989 } 990 else ret = 1; 991 if (ret > 0) { 992 return true; 993 } 994 } 995 996 return false; 997 } 998 999 void tcp_fd_delete(struct SHELL_FILE *fp) 1000 { 1001 socket_t *socket = (socket_t *)fp->exinf; 1002 free(socket->buf); 1003 socket->buf = NULL; 1004 free(fp->exinf); 1005 fp->exinf = NULL; 1006 } 1007 1008 ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk) 1009 { 1010 struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_TCP, cepid); 1011 FLGPTN flgptn = 0; 1012 ER ret; 1013 int len; 1014 1015 if (fp == NULL) 1016 return E_PAR; 1017 1018 int fd = fp->fd; 1019 FD_SET(fd, (fd_set *)&flgptn); 1020 1021 switch (fncd) { 1022 case TFN_TCP_RCV_BUF: 1023 len = *(int *)p_parblk; 1024 if ((len <= 0) || (fp->exinf == NULL)) 1025 return E_OK; 1026 1027 ret = wai_sem(SEM_FILEDESC); 1028 if (ret < 0) { 1029 syslog(LOG_ERROR, "wai_sem => %d", ret); 1030 } 1031 socket_t *socket = (socket_t *)fp->exinf; 1032 socket->len += len; 1033 ret = sig_sem(SEM_FILEDESC); 1034 if (ret < 0) { 1035 syslog(LOG_ERROR, "sig_sem => %d", ret); 1036 } 1037 1038 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 1039 1040 set_flg(FLG_SELECT_WAIT, flgptn); 1041 return E_OK; 1042 1043 case TFN_TCP_RCV_DAT: 1044 len = *(int *)p_parblk; 1045 if ((len <= 0) || (fp->exinf == NULL)) 1046 return E_OK; 1047 1048 ret = wai_sem(SEM_FILEDESC); 1049 if (ret < 0) { 1050 syslog(LOG_ERROR, "wai_sem => %d", ret); 1051 } 1052 socket->len += len; 1053 ret = sig_sem(SEM_FILEDESC); 1054 if (ret < 0) { 1055 syslog(LOG_ERROR, "sig_sem => %d", ret); 1056 } 1057 1058 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 1059 1060 set_flg(FLG_SELECT_WAIT, flgptn); 1061 return E_OK; 1062 1063 case TFN_TCP_SND_DAT: 1064 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 1065 1066 set_flg(FLG_SELECT_WAIT, flgptn); 1067 return E_OK; 1068 1069 case TFN_TCP_CAN_CEP: 1070 if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++; 1071 1072 set_flg(FLG_SELECT_WAIT, flgptn); 1073 return E_OK; 1074 1075 case TFN_TCP_DEL_REP: 1076 delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + cepid); 1077 return E_OK; 1078 1079 case TFN_TCP_DEL_CEP: 1080 delete_fd_by_id(&IO_TYPE_TCP, cepid); 1081 return E_OK; 1082 1083 default: 1084 return E_OK; 1085 } 1086 } 1087 1088 int udp_fd_close(struct SHELL_FILE *fp) 930 1089 { 931 1090 ER ret; 932 1091 ID cepid; 933 1092 934 switch (fp->psock->family) { 1093 socket_t *socket = (socket_t *)fp->exinf; 1094 switch (socket->family) { 935 1095 case AF_INET: { 936 cepid = fp->psock->cepid;1096 cepid = socket->cepid; 937 1097 ret = udp_del_cep(cepid); 938 //free(fp->psock->buf); 939 //fp->psock->buf = NULL; 940 delete_udp_fd(cepid); 1098 //delete_fd_by_id(&IO_TYPE_UDP, cepid); 941 1099 delete_id(udp_cepid_table, udp_cepid_table_count, cepid); 942 1100 if (ret < 0) { … … 953 1111 } 954 1112 955 size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)1113 size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz) 956 1114 { 957 1115 return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL); 958 1116 } 959 1117 960 size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)1118 size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz) 961 1119 { 962 1120 return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0); 963 1121 } 964 1122 965 off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)1123 off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org) 966 1124 { 967 1125 return -EPERM; 968 1126 } 969 1127 970 int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)1128 int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg) 971 1129 { 972 1130 return -EINVAL; 1131 } 1132 1133 bool_t udp_fd_readable(struct SHELL_FILE *fp) 1134 { 1135 socket_t *socket = (socket_t *)fp->exinf; 1136 if (socket->cepid != 0) { 1137 if (socket->input != NULL) { 1138 return true; 1139 } 1140 } 1141 1142 return false; 1143 } 1144 1145 void udp_fd_delete(struct SHELL_FILE *fp) 1146 { 1147 //socket_t *socket = (socket_t *)fp->exinf; 1148 //free(socket->buf); 1149 //socket->buf = NULL; 1150 free(fp->exinf); 1151 fp->exinf = NULL; 1152 } 1153 1154 ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk) 1155 { 1156 struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_UDP, cepid); 1157 FLGPTN flgptn = 0; 1158 int len; 1159 1160 if (fp == NULL) 1161 return E_PAR; 1162 1163 int fd = fp->fd; 1164 FD_SET(fd, (fd_set *)&flgptn); 1165 1166 switch (fncd) { 1167 case TEV_UDP_RCV_DAT: 1168 { 1169 T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk; 1170 len = udppara->len; 1171 if ((len <= 0) || (fp->exinf == NULL)) 1172 return E_OK; 1173 1174 ER ret = wai_sem(SEM_FILEDESC); 1175 if (ret < 0) { 1176 syslog(LOG_ERROR, "wai_sem => %d", ret); 1177 } 1178 socket_t *socket = (socket_t *)fp->exinf; 1179 socket->len = len; 1180 if (socket->input != NULL) { 1181 ret = rel_net_buf(socket->input); 1182 if (ret < 0) { 1183 syslog(LOG_ERROR, "rel_net_buf => %d", ret); 1184 } 1185 } 1186 socket->input = udppara->input; 1187 socket->buf = GET_UDP_SDU(udppara->input, udppara->off); 1188 memset(&socket->raddr4, 0, sizeof(socket->raddr4)); 1189 socket->raddr4.sin_family = AF_INET; 1190 socket->raddr4.sin_port = htons(udppara->rep4.portno); 1191 socket->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr); 1192 udppara->input->flags |= NB_FLG_NOREL_IFOUT; 1193 ret = sig_sem(SEM_FILEDESC); 1194 if (ret < 0) { 1195 syslog(LOG_ERROR, "sig_sem => %d", ret); 1196 } 1197 1198 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 1199 1200 set_flg(FLG_SELECT_WAIT, flgptn); 1201 return E_OK; 1202 } 1203 case TFN_UDP_CRE_CEP: 1204 return E_OK; 1205 1206 case TFN_UDP_RCV_DAT: 1207 len = *(int *)p_parblk; 1208 if ((len <= 0) || (fp->exinf == NULL)) 1209 return E_OK; 1210 1211 if (fp->readevt_w == fp->readevt_r) fp->readevt_w++; 1212 1213 set_flg(FLG_SELECT_WAIT, flgptn); 1214 return E_OK; 1215 1216 case TFN_UDP_SND_DAT: 1217 if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++; 1218 1219 set_flg(FLG_SELECT_WAIT, flgptn); 1220 return E_OK; 1221 1222 case TFN_UDP_CAN_CEP: 1223 if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++; 1224 1225 set_flg(FLG_SELECT_WAIT, flgptn); 1226 return E_OK; 1227 1228 case TFN_UDP_DEL_CEP: 1229 delete_fd_by_id(&IO_TYPE_UDP, cepid); 1230 return E_OK; 1231 1232 default: 1233 return E_OK; 1234 } 973 1235 } 974 1236 -
asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h
r364 r374 103 103 } socket_t; 104 104 105 struct _IO_DIR {106 DIR dir;105 struct SHELL_DIR { 106 FATFS_DIR dir; 107 107 struct dirent dirent; 108 108 }; 109 109 110 struct _IO_FILE { 110 typedef const struct io_type_s IO_TYPE; 111 112 struct SHELL_FILE { 111 113 int fd; 112 inttype;114 IO_TYPE *type; 113 115 int handle; 114 int (*close)(struct _IO_FILE *);115 size_t (*read)(struct _IO_FILE *, unsigned char *, size_t);116 size_t (*write)(struct _IO_FILE *, const unsigned char *, size_t);117 off_t (*seek)(struct _IO_FILE *, off_t, int);118 int (*ioctl)(struct _IO_FILE *, int, void *);119 116 int readevt_r; 120 117 int readevt_w; … … 124 121 int errorevt_r; 125 122 int errorevt_w; 126 union { 127 FIL *pfile; 128 struct _IO_DIR *pdir; 129 socket_t *psock; 130 }; 123 void *exinf; 124 }; 125 126 struct io_type_s { 127 int (*close)(struct SHELL_FILE *); 128 size_t (*read)(struct SHELL_FILE *, unsigned char *, size_t); 129 size_t (*write)(struct SHELL_FILE *, const unsigned char *, size_t); 130 off_t (*seek)(struct SHELL_FILE *, off_t, int); 131 int (*ioctl)(struct SHELL_FILE *, int, void *); 132 bool_t (*readable)(struct SHELL_FILE *); 133 void (*delete)(struct SHELL_FILE *); 131 134 }; 132 135 … … 141 144 #endif 142 145 143 extern int stdio_close(struct _IO_FILE *fp); 144 extern size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len); 145 extern size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len); 146 extern size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len); 147 extern size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len); 148 extern size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len); 146 struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable); 147 int delete_fd_by_id(IO_TYPE *type, int id); 148 struct SHELL_FILE *fd_to_fp(int fd); 149 struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id); 149 150 150 extern int sio_close(struct _IO_FILE *fp); 151 extern size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len); 152 extern size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len); 153 extern off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org); 154 extern int sio_ioctl(struct _IO_FILE *fp, int req, void *arg); 155 156 extern int file_close(struct _IO_FILE *fp); 157 extern size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len); 158 extern size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len); 159 extern off_t file_seek(struct _IO_FILE *fp, off_t ofs, int org); 160 extern int file_ioctl(struct _IO_FILE *fp, int req, void *arg); 161 162 extern int dir_close(struct _IO_FILE *fp); 163 extern size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len); 164 extern size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len); 165 extern off_t dir_seek(struct _IO_FILE *fp, off_t ofs, int org); 166 extern int dir_ioctl(struct _IO_FILE *fp, int req, void *arg); 167 168 extern int tcp_fd_close(struct _IO_FILE *fp); 169 extern size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len); 170 extern size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len); 171 extern off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org); 172 extern int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg); 173 174 extern int udp_fd_close(struct _IO_FILE *fp); 175 extern size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len); 176 extern size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len); 177 extern off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org); 178 extern int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg); 179 180 struct _IO_FILE *fd_to_fp(int fd); 181 182 struct _IO_FILE *new_sio_fd(int sioid); 183 int delete_sio_fd(int sioid); 184 struct _IO_FILE *sioid_to_fd(int sioid); 185 186 struct _IO_FILE *new_file_fd(int fileid); 187 int delete_file_fd(int fileid); 188 struct _IO_FILE *fileid_to_fd(int fileid); 189 190 struct _IO_FILE *new_dir_fd(int dirid); 191 int delete_dir_fd(int dirid); 192 struct _IO_FILE *dirid_to_fd(int dirid); 193 194 struct _IO_FILE *new_tcp_fd(int tcpid); 195 int delete_tcp_fd(int tcpid); 196 struct _IO_FILE *tcpid_to_fd(int tcpid); 197 198 struct _IO_FILE *new_udp_fd(int udpid); 199 int delete_udp_fd(int udpid); 200 struct _IO_FILE *udpid_to_fd(int udpid); 201 202 int delete_fp(struct _IO_FILE *fp); 203 int delete_tcp_rep(int repid); 151 int delete_fp(struct SHELL_FILE *fp); 204 152 void clean_fd(); 205 153 -
asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c
r364 r374 48 48 49 49 /* ==== Cleaning and invalidation of the L1 data cache ==== */ 50 __v7_all_cache(2);50 L1C_CleanInvalidateDCacheAll(); 51 51 __DSB(); 52 52 53 53 /* ==== Cleaning and invalidation of the L2 cache ==== */ 54 if ( PL310->AUX_CNT & (1 << 16)) {54 if (L2C_310->AUX_CNT & (1 << 16)) { 55 55 assoc = 16; 56 56 } … … 58 58 assoc = 8; 59 59 } 60 PL310->INV_WAY = (1 << assoc) - 1;61 while ( PL310->INV_WAY & ((1 << assoc) - 1)); // poll invalidate62 PL310->CACHE_SYNC = 0x0;60 L2C_310->INV_WAY = (1 << assoc) - 1; 61 while (L2C_310->INV_WAY & ((1 << assoc) - 1)); // poll invalidate 62 L2C_310->CACHE_SYNC = 0x0; 63 63 64 64 /* ==== Invalidate all TLB entries ==== */ 65 __ca9u_inv_tlb_all();65 MMU_InvalidateTLB(); 66 66 67 67 /* ==== Invalidate the L1 instruction cache ==== */ 68 __v7_inv_icache_all();68 L1C_InvalidateICacheAll(); 69 69 __DSB(); 70 70 __ISB(); … … 184 184 } 185 185 186 long SYS_fdatasync() { 186 long SYS_fdatasync(long a) { 187 //int fdatasync(int fd) 187 188 return no_implement("fdatasync\n"); 188 189 } … … 200 201 } 201 202 202 long SYS_futex( ) {203 int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);203 long SYS_futex(long a, long b, long c, long d, long e, long f) { 204 //int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3); 204 205 return no_implement("futex\n"); 205 206 } 206 207 207 long SYS_futimesat() { 208 long SYS_futimesat(long a, long b, long c) { 209 //int futimesat(int dirfd, const char *pathname, const struct timeval times[2]) 208 210 return no_implement("futimesat\n"); 209 211 } … … 281 283 } 282 284 283 long SYS_munmap() { 285 long SYS_munmap(long a, long b) { 286 //int munmap(void *start, size_t len) 284 287 return no_implement("munmap\n"); 285 288 } … … 293 296 } 294 297 295 long SYS_pread64() { 298 long SYS_pread64(long a, long b, long c, long d) { 299 //#define pread64 pread 300 //ssize_t pread(int fd, void *buf, size_t size, off_t ofs) 296 301 return no_implement("pread64\n"); 297 302 } 298 303 299 long SYS_pwrite64() { 304 long SYS_pwrite64(long a, long b, long c, long d) { 305 //#define pwrite64 pwrite 306 //ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) 300 307 return no_implement("pwrite64\n"); 301 308 } … … 337 344 } 338 345 339 long SYS_rt_sigqueueinfo() { 346 long SYS_rt_sigqueueinfo(long a, long b, long c) { 347 //int rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *uinfo) 340 348 return no_implement("rt_sigqueueinfo\n"); 341 349 } … … 361 369 } 362 370 363 long SYS_sched_setscheduler() { 371 long SYS_sched_setscheduler(long a, long b, long c) { 372 //int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param) 364 373 return no_implement("sched_setscheduler\n"); 365 374 } 366 375 367 long SYS_set_robust_list() { 376 long SYS_set_robust_list(long a, long b) { 377 //long set_robust_list(struct robust_list_head *head, size_t len) 368 378 return no_implement("set_robust_list\n"); 369 379 } … … 401 411 } 402 412 403 long SYS_utimensat() { 413 long SYS_utimensat(long a, long b, long c, long d) { 414 //int utimensat(int fd, const char *path, const struct timespec times[2], int flags) 404 415 return no_implement("utimensat\n"); 405 416 } 406 417 407 long SYS_utimes() { 418 long SYS_utimes(long a, long b) { 419 //int utimes(const char *path, const struct timeval times[2]) 408 420 return no_implement("utimes\n"); 409 421 } … … 417 429 } 418 430 419 long SYS_dup( )420 { 431 long SYS_dup(long a) { 432 //int dup(int fd) 421 433 return no_implement("dup\n"); 422 434 } 423 435 424 long SYS_dup2( )425 { 436 long SYS_dup2(long a, long b) { 437 //int dup2(int old, int new) 426 438 return no_implement("dup2\n"); 427 439 } 428 440 429 long SYS_pipe( )430 { 441 long SYS_pipe(long a) { 442 //int pipe(int fd[2]) 431 443 return no_implement("pipe\n"); 432 444 } 433 445 434 long SYS_readlink( )435 { 446 long SYS_readlink(long a, long b, long c) { 447 //ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize) 436 448 return no_implement("readlink\n"); 437 449 } 438 450 439 long SYS_symlink( )440 { 451 long SYS_symlink(long a, long b) { 452 //int symlink(const char *existing, const char *new) 441 453 return no_implement("symlink\n"); 442 454 } 443 455 444 long SYS_umask( )445 { 456 long SYS_umask(long a) { 457 //mode_t umask(mode_t mode) 446 458 return no_implement("umask\n"); 447 459 } 448 460 449 long SYS_execve( )450 { 461 long SYS_execve(long a, long b, long c) { 462 //int execve(const char *path, char *const argv[], char *const envp[]) 451 463 return no_implement("execve\n"); 452 464 } 453 465 454 long SYS_fork() 455 { 466 long SYS_fork() { 467 //pid_t fork(void) 456 468 return no_implement("fork\n"); 457 469 } 458 470 459 long SYS_wait4( )460 { 471 long SYS_wait4(long a, long b, long c, long d) { 472 //pid_t wait4(pid_t pid, int *status, int options, struct rusage *usage) 461 473 return no_implement("wait4\n"); 462 474 } 463 475 464 long SYS_socketpair( )465 { 476 long SYS_socketpair(long a, long b, long c, long d) { 477 //int socketpair(int domain, int type, int protocol, int fd[2]) 466 478 return no_implement("socketpair\n"); 467 479 } 468 480 469 long SYS_flock( )470 { 481 long SYS_flock(long a, long b) { 482 //int flock(int fd, int op) 471 483 return no_implement("flock\n"); 484 } 485 486 long SYS_fchdir() 487 { 488 return no_implement("fchdir\n"); 489 } 490 491 long SYS_getegid32() 492 { 493 return no_implement("getegid32\n"); 494 } 495 496 long SYS_geteuid32() 497 { 498 return no_implement("geteuid32\n"); 499 } 500 501 long SYS_getgid32() 502 { 503 return no_implement("getgid32\n"); 504 } 505 506 long SYS_pipe2() 507 { 508 return no_implement("pipe2\n"); 509 } 510 511 long SYS_setgid32() 512 { 513 return no_implement("setgid32\n"); 514 } 515 516 long SYS_setpgid() 517 { 518 return no_implement("setpgid\n"); 519 } 520 521 long SYS_setsid() 522 { 523 return no_implement("setsid\n"); 524 } 525 526 long SYS_setuid32() 527 { 528 return no_implement("setuid32\n"); 529 } 530 531 long SYS_tgkill() 532 { 533 return no_implement("tgkill\n"); 534 } 535 536 long SYS_nanosleep(long a, long b) { 537 //int nanosleep(const struct timespec *req, struct timespec *rem) 538 return no_implement("nanosleep\n"); 539 } 540 541 long SYS_prlimit64(long a, long b, long c, long d) { 542 //#define prlimit64 prlimit 543 //int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit) 544 return no_implement("prlimit64\n"); 545 } 546 547 long SYS_sched_getaffinity(long a, long b, long c) { 548 //int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set) 549 return no_implement("sched_getaffinity\n"); 550 } 551 552 long SYS_sysinfo(long a) { 553 //int sysinfo(struct sysinfo *info) 554 return no_implement("sysinfo\n"); 555 } 556 557 long SYS_ugetrlimit(long a, long b) { 558 //#define SYS_getrlimit SYS_ugetrlimit 559 //int getrlimit(int resource, struct rlimit *rlim) 560 return no_implement("ugetrlimit\n"); 472 561 } 473 562 -
asp3_tinet_ecnl_arm/trunk/ntshell/tlsf/tlsf.c
r352 r374 5 5 #include <stdlib.h> 6 6 #include <string.h> 7 #include "util/ntstdio.h"7 #include <stdio.h> 8 8 9 9 #include "tlsf.h" … … 16 16 #define tlsf_decl static 17 17 #endif 18 19 extern ntstdio_t ntstdio;20 18 21 19 /* … … 889 887 { 890 888 (void)user; 891 ntstdio_printf(&ntstdio,"\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, block_from_ptr(ptr));889 printf("\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, block_from_ptr(ptr)); 892 890 } 893 891 … … 978 976 if (((ptrdiff_t)mem % ALIGN_SIZE) != 0) 979 977 { 980 ntstdio_printf(&ntstdio,"tlsf_add_pool: Memory must be aligned by %u bytes.\n",978 printf("tlsf_add_pool: Memory must be aligned by %u bytes.\n", 981 979 (unsigned int)ALIGN_SIZE); 982 980 return 0; … … 986 984 { 987 985 #if defined (TLSF_64BIT) 988 ntstdio_printf(&ntstdio,"tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n",986 printf("tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n", 989 987 (unsigned int)(pool_overhead + block_size_min), 990 988 (unsigned int)((pool_overhead + block_size_max) / 256)); 991 989 #else 992 ntstdio_printf(&ntstdio,"tlsf_add_pool: Memory size must be between %u and %u bytes.\n",990 printf("tlsf_add_pool: Memory size must be between %u and %u bytes.\n", 993 991 (unsigned int)(pool_overhead + block_size_min), 994 992 (unsigned int)(pool_overhead + block_size_max)); … … 1058 1056 if (rv) 1059 1057 { 1060 ntstdio_printf(&ntstdio,"test_ffs_fls: %x ffs/fls tests failed.\n", rv);1058 printf("test_ffs_fls: %x ffs/fls tests failed.\n", rv); 1061 1059 } 1062 1060 return rv; … … 1075 1073 if (((tlsfptr_t)mem % ALIGN_SIZE) != 0) 1076 1074 { 1077 ntstdio_printf(&ntstdio,"tlsf_create: Memory must be aligned to %u bytes.\n",1075 printf("tlsf_create: Memory must be aligned to %u bytes.\n", 1078 1076 (unsigned int)ALIGN_SIZE); 1079 1077 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.