Ignore:
Timestamp:
Apr 5, 2019, 9:26:53 PM (5 years ago)
Author:
coas-nagasima
Message:

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

Location:
asp3_tinet_ecnl_rx/trunk/ntshell
Files:
3 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/ccsbcs.c

    r337 r374  
    2525
    2626
    27 #if _CODE_PAGE == 437
     27#if FF_CODE_PAGE == 437
    2828#define _TBLDEF 1
    2929static
     
    3939};
    4040
    41 #elif _CODE_PAGE == 720
     41#elif FF_CODE_PAGE == 720
    4242#define _TBLDEF 1
    4343static
     
    5353};
    5454
    55 #elif _CODE_PAGE == 737
     55#elif FF_CODE_PAGE == 737
    5656#define _TBLDEF 1
    5757static
     
    6767};
    6868
    69 #elif _CODE_PAGE == 771
     69#elif FF_CODE_PAGE == 771
    7070#define _TBLDEF 1
    7171static
     
    8181};
    8282
    83 #elif _CODE_PAGE == 775
     83#elif FF_CODE_PAGE == 775
    8484#define _TBLDEF 1
    8585static
     
    9595};
    9696
    97 #elif _CODE_PAGE == 850
     97#elif FF_CODE_PAGE == 850
    9898#define _TBLDEF 1
    9999static
     
    109109};
    110110
    111 #elif _CODE_PAGE == 852
     111#elif FF_CODE_PAGE == 852
    112112#define _TBLDEF 1
    113113static
     
    123123};
    124124
    125 #elif _CODE_PAGE == 855
     125#elif FF_CODE_PAGE == 855
    126126#define _TBLDEF 1
    127127static
     
    137137};
    138138
    139 #elif _CODE_PAGE == 857
     139#elif FF_CODE_PAGE == 857
    140140#define _TBLDEF 1
    141141static
     
    151151};
    152152
    153 #elif _CODE_PAGE == 860
     153#elif FF_CODE_PAGE == 860
    154154#define _TBLDEF 1
    155155static
     
    165165};
    166166
    167 #elif _CODE_PAGE == 861
     167#elif FF_CODE_PAGE == 861
    168168#define _TBLDEF 1
    169169static
     
    179179};
    180180
    181 #elif _CODE_PAGE == 862
     181#elif FF_CODE_PAGE == 862
    182182#define _TBLDEF 1
    183183static
     
    193193};
    194194
    195 #elif _CODE_PAGE == 863
     195#elif FF_CODE_PAGE == 863
    196196#define _TBLDEF 1
    197197static
     
    207207};
    208208
    209 #elif _CODE_PAGE == 864
     209#elif FF_CODE_PAGE == 864
    210210#define _TBLDEF 1
    211211static
     
    221221};
    222222
    223 #elif _CODE_PAGE == 865
     223#elif FF_CODE_PAGE == 865
    224224#define _TBLDEF 1
    225225static
     
    235235};
    236236
    237 #elif _CODE_PAGE == 866
     237#elif FF_CODE_PAGE == 866
    238238#define _TBLDEF 1
    239239static
     
    249249};
    250250
    251 #elif _CODE_PAGE == 869
     251#elif FF_CODE_PAGE == 869
    252252#define _TBLDEF 1
    253253static
     
    266266
    267267
    268 #if _CODE_PAGE != 65001 && (!_TBLDEF || !_USE_LFN)
     268#if FF_CODE_PAGE != 65001 && (!_TBLDEF || !FF_USE_LFN)
    269269#error This file is not needed at current configuration. Remove from the project.
    270270#endif
     
    272272
    273273
    274 #if _CODE_PAGE != 65001
     274#if FF_CODE_PAGE != 65001
    275275WCHAR ff_convert (      /* Converted character, Returns zero on error */
    276276        WCHAR   chr,    /* Character code to be converted */
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/diskio.c

    r337 r374  
    3434int get_status(volatile RD_STAT *stat) {
    3535        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;
    3737        stat->n_sectors = SZ_RAMDISK * 1024 / SS_RAMDISK;
    3838        stat->status = 0;
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/diskio.h

    r337 r374  
    6060
    6161/* 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) */
    6767
    6868/* Generic command (Not used by FatFs) */
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/ff.c

    r369 r374  
    2020#include "ff.h"                 /* Declarations of FatFs API */
    2121#include "diskio.h"             /* Declarations of disk I/O functions */
    22 #include "util/ntstdio.h"
     22#include <stdio.h>
    2323
    2424/*--------------------------------------------------------------------------
     
    3434
    3535/* Reentrancy related */
    36 #if _FS_REENTRANT
    37 #if _USE_LFN == 1
     36#if FF_FS_REENTRANT
     37#if FF_USE_LFN == 1
    3838#error Static LFN work area cannot be used at thread-safe configuration
    3939#endif
     
    4949
    5050/* 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)
    5252#error Wrong sector size configuration
    5353#endif
    54 #if _MAX_SS == _MIN_SS
    55 #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 */
    5656#else
    5757#define SS(fs)  ((fs)->ssize)   /* Variable sector size */
     
    6060
    6161/* Timestamp feature */
    62 #if _FS_NORTC == 1
    63 #if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31
    64 #error Invalid _FS_NORTC settings
    65 #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)
    6767#else
    6868#define GET_FATTIME()   get_fattime()
     
    7171
    7272/* File access control feature */
    73 #if _FS_LOCK
    74 #if _FS_READONLY
    75 #error _FS_LOCK must be 0 at read-only configuration
     73#if FF_FS_LOCK != 0
     74#if FF_FS_READONLY
     75#error FF_FS_LOCK must be 0 at read-only configuration
    7676#endif
    7777typedef struct {
     
    8787/* DBCS code ranges and SBCS upper conversion tables */
    8888
    89 #if _CODE_PAGE == 932   /* Japanese Shift-JIS */
     89#if FF_CODE_PAGE == 932 /* Japanese Shift-JIS */
    9090#define _DF1S   0x81    /* DBC 1st byte range 1 start */
    9191#define _DF1E   0x9F    /* DBC 1st byte range 1 end */
     
    9797#define _DS2E   0xFC    /* DBC 2nd byte range 2 end */
    9898
    99 #elif _CODE_PAGE == 936 /* Simplified Chinese GBK */
     99#elif FF_CODE_PAGE == 936       /* Simplified Chinese GBK */
    100100#define _DF1S   0x81
    101101#define _DF1E   0xFE
     
    105105#define _DS2E   0xFE
    106106
    107 #elif _CODE_PAGE == 949 /* Korean */
     107#elif FF_CODE_PAGE == 949       /* Korean */
    108108#define _DF1S   0x81
    109109#define _DF1E   0xFE
     
    115115#define _DS3E   0xFE
    116116
    117 #elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */
     117#elif FF_CODE_PAGE == 950       /* Traditional Chinese Big5 */
    118118#define _DF1S   0x81
    119119#define _DF1E   0xFE
     
    123123#define _DS2E   0xFE
    124124
    125 #elif _CODE_PAGE == 437 /* U.S. */
     125#elif FF_CODE_PAGE == 437       /* U.S. */
    126126#define _DF1S   0
    127127#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
     
    134134                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    135135
    136 #elif _CODE_PAGE == 720 /* Arabic */
     136#elif FF_CODE_PAGE == 720       /* Arabic */
    137137#define _DF1S   0
    138138#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    145145                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    146146
    147 #elif _CODE_PAGE == 737 /* Greek */
     147#elif FF_CODE_PAGE == 737       /* Greek */
    148148#define _DF1S   0
    149149#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    156156                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    157157
    158 #elif _CODE_PAGE == 771 /* KBL */
     158#elif FF_CODE_PAGE == 771       /* KBL */
    159159#define _DF1S   0
    160160#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    167167                                0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF}
    168168
    169 #elif _CODE_PAGE == 775 /* Baltic */
     169#elif FF_CODE_PAGE == 775       /* Baltic */
    170170#define _DF1S   0
    171171#define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F, \
     
    178178                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    179179
    180 #elif _CODE_PAGE == 850 /* Latin 1 */
     180#elif FF_CODE_PAGE == 850       /* Latin 1 */
    181181#define _DF1S   0
    182182#define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \
     
    189189                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    190190
    191 #elif _CODE_PAGE == 852 /* Latin 2 */
     191#elif FF_CODE_PAGE == 852       /* Latin 2 */
    192192#define _DF1S   0
    193193#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F, \
     
    200200                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF}
    201201
    202 #elif _CODE_PAGE == 855 /* Cyrillic */
     202#elif FF_CODE_PAGE == 855       /* Cyrillic */
    203203#define _DF1S   0
    204204#define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F, \
     
    211211                                0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF}
    212212
    213 #elif _CODE_PAGE == 857 /* Turkish */
     213#elif FF_CODE_PAGE == 857       /* Turkish */
    214214#define _DF1S   0
    215215#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x49,0x8E,0x8F, \
     
    222222                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    223223
    224 #elif _CODE_PAGE == 860 /* Portuguese */
     224#elif FF_CODE_PAGE == 860       /* Portuguese */
    225225#define _DF1S   0
    226226#define _EXCVT {0x80,0x9A,0x90,0x8F,0x8E,0x91,0x86,0x80,0x89,0x89,0x92,0x8B,0x8C,0x98,0x8E,0x8F, \
     
    233233                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    234234
    235 #elif _CODE_PAGE == 861 /* Icelandic */
     235#elif FF_CODE_PAGE == 861       /* Icelandic */
    236236#define _DF1S   0
    237237#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x8B,0x8B,0x8D,0x8E,0x8F, \
     
    244244                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    245245
    246 #elif _CODE_PAGE == 862 /* Hebrew */
     246#elif FF_CODE_PAGE == 862       /* Hebrew */
    247247#define _DF1S   0
    248248#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    255255                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    256256
    257 #elif _CODE_PAGE == 863 /* Canadian-French */
     257#elif FF_CODE_PAGE == 863       /* Canadian-French */
    258258#define _DF1S   0
    259259#define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x41,0x8F, \
     
    266266                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    267267
    268 #elif _CODE_PAGE == 864 /* Arabic */
     268#elif FF_CODE_PAGE == 864       /* Arabic */
    269269#define _DF1S   0
    270270#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
     
    277277                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    278278
    279 #elif _CODE_PAGE == 865 /* Nordic */
     279#elif FF_CODE_PAGE == 865       /* Nordic */
    280280#define _DF1S   0
    281281#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
     
    288288                                0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    289289
    290 #elif _CODE_PAGE == 866 /* Russian */
     290#elif FF_CODE_PAGE == 866       /* Russian */
    291291#define _DF1S   0
    292292#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    299299                                0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
    300300
    301 #elif _CODE_PAGE == 869 /* Greek 2 */
     301#elif FF_CODE_PAGE == 869       /* Greek 2 */
    302302#define _DF1S   0
    303303#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
     
    310310                                0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF}
    311311
    312 #elif _CODE_PAGE == 1   /* ASCII (for only non-LFN cfg) */
    313 #if _USE_LFN
     312#elif FF_CODE_PAGE == 1 /* ASCII (for only non-LFN cfg) */
     313#if FF_USE_LFN
    314314#error Cannot use LFN feature without valid code page.
    315315#endif
    316316#define _DF1S   0
    317317
    318 #elif _CODE_PAGE == 65001 /* UTF-8 */
    319 #if _LFN_UNICODE
     318#elif FF_CODE_PAGE == 65001 /* UTF-8 */
     319#if FF_LFN_UNICODE
    320320#error Cannot use LFN_UNICODE feature without valid code page.
    321321#endif
     
    532532*/
    533533
    534 #if _VOLUMES < 1 || _VOLUMES > 9
    535 #error Wrong _VOLUMES setting
    536 #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
     537static FATFS *FatFs[FF_VOLUMES];        /* Pointer to the file system objects (logical drives) */
    538538static WORD Fsid;                               /* File system mount ID */
    539539
    540 #if _FS_RPATH && _VOLUMES >= 2
     540#if FF_FS_RPATH && FF_VOLUMES >= 2
    541541static BYTE CurrVol;                    /* Current drive */
    542542#endif
    543543
    544 #if _FS_LOCK
    545 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
     545static FILESEM Files[FF_FS_LOCK];       /* Open object lock semaphores */
     546#endif
     547
     548#if FF_USE_LFN == 0                     /* Non LFN feature */
    549549#define DEFINE_NAMEBUF          BYTE sfn[12]
    550550#define INIT_BUF(dobj)          (dobj).fn = sfn
    551551#define FREE_BUF()
    552552#else
    553 #if _MAX_LFN < 12 || _MAX_LFN > 255
    554 #error Wrong _MAX_LFN setting
    555 #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 */
     557static WCHAR LfnBuf[FF_MAX_LFN + 1];
    558558#define DEFINE_NAMEBUF          BYTE sfn[12]
    559559#define INIT_BUF(dobj)          { (dobj).fn = sfn; (dobj).lfn = LfnBuf; }
    560560#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]
    563563#define INIT_BUF(dobj)          { (dobj).fn = sfn; (dobj).lfn = lbuf; }
    564564#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 */
    566566#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; }
    568568#define FREE_BUF()                      ff_memfree(lfn)
    569569#else
    570 #error Wrong _USE_LFN setting
     570#error Wrong FF_USE_LFN setting
    571571#endif
    572572#endif
     
    598598        const BYTE *s = (const BYTE*)src;
    599599
    600 #if _WORD_ACCESS == 1
     600#if FF_WORD_ACCESS == 1
    601601        while (cnt >= sizeof (int)) {
    602602                *(int*)d = *(int*)s;
     
    641641/* Request/Release grant to access the volume                            */
    642642/*-----------------------------------------------------------------------*/
    643 #if _FS_REENTRANT
     643#if FF_FS_REENTRANT
    644644static
    645645int lock_fs (
     
    673673/* File lock control functions                                           */
    674674/*-----------------------------------------------------------------------*/
    675 #if _FS_LOCK
     675#if FF_FS_LOCK != 0
    676676
    677677static
    678678FRESULT 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 */
    680680        int acc                 /* Desired access type (0:Read, 1:Write, 2:Delete/Rename) */
    681681)
     
    684684
    685685        /* Search file semaphore table */
    686         for (i = be = 0; i < _FS_LOCK; i++) {
     686        for (i = be = 0; i < FF_FS_LOCK; i++) {
    687687                if (Files[i].fs) {      /* Existing entry */
    688688                        if (Files[i].fs == dp->fs &&            /* Check if the object matched with an open object */
     
    693693                }
    694694        }
    695         if (i == _FS_LOCK)      /* The object is not opened */
     695        if (i == FF_FS_LOCK)    /* The object is not opened */
    696696                return (be || acc == 2) ? FR_OK : FR_TOO_MANY_OPEN_FILES;       /* Is there a blank entry for new object? */
    697697
     
    706706        UINT i;
    707707
    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;
    710710}
    711711
     
    713713static
    714714UINT 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 */
    716716        int acc         /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */
    717717)
     
    720720
    721721
    722         for (i = 0; i < _FS_LOCK; i++) {        /* Find the object */
     722        for (i = 0; i < FF_FS_LOCK; i++) {      /* Find the object */
    723723                if (Files[i].fs == dp->fs &&
    724724                        Files[i].clu == dp->sclust &&
     
    726726        }
    727727
    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) */
    731731                Files[i].fs = dp->fs;
    732732                Files[i].clu = dp->sclust;
     
    752752
    753753
    754         if (--i < _FS_LOCK) {   /* Shift index number origin from 0 */
     754        if (--i < FF_FS_LOCK) { /* Shift index number origin from 0 */
    755755                n = Files[i].ctr;
    756756                if (n == 0x100) n = 0;          /* If write mode open, delete the entry */
     
    773773        UINT i;
    774774
    775         for (i = 0; i < _FS_LOCK; i++) {
     775        for (i = 0; i < FF_FS_LOCK; i++) {
    776776                if (Files[i].fs == fs) Files[i].fs = 0;
    777777        }
     
    785785/* Move/Flush disk access window in the file system object               */
    786786/*-----------------------------------------------------------------------*/
    787 #if !_FS_READONLY
     787#if !FF_FS_READONLY
    788788static
    789789FRESULT sync_window (   /* FR_OK:succeeded, !=0:error */
     
    825825
    826826        if (sector != fs->winsect) {    /* Window offset changed? */
    827 #if !_FS_READONLY
     827#if !FF_FS_READONLY
    828828                res = sync_window(fs);          /* Write-back changes */
    829829#endif
     
    845845/* Synchronize file system and strage device                             */
    846846/*-----------------------------------------------------------------------*/
    847 #if !_FS_READONLY
     847#if !FF_FS_READONLY
    848848static
    849849FRESULT sync_fs (       /* FR_OK:succeeded, !=0:error */
     
    959959/* Hidden API for hacks and disk tools */
    960960
    961 #if !_FS_READONLY
     961#if !FF_FS_READONLY
    962962FRESULT put_fat (       /* FR_OK(0):succeeded, !=0:error */
    963963        FATFS* fs,              /* File system object */
     
    10141014        return res;
    10151015}
    1016 #endif /* !_FS_READONLY */
     1016#endif /* !FF_FS_READONLY */
    10171017
    10181018
     
    10221022/* FAT handling - Remove a cluster chain                                 */
    10231023/*-----------------------------------------------------------------------*/
    1024 #if !_FS_READONLY
     1024#if !FF_FS_READONLY
    10251025static
    10261026FRESULT remove_chain (  /* FR_OK(0):succeeded, !=0:error */
     
    10311031        FRESULT res;
    10321032        DWORD nxt;
    1033 #if _USE_TRIM
     1033#if FF_USE_TRIM
    10341034        DWORD scl = clst, ecl = clst, rt[2];
    10351035#endif
     
    10511051                                fs->fsi_flag |= 1;
    10521052                        }
    1053 #if _USE_TRIM
     1053#if FF_USE_TRIM
    10541054                        if (ecl + 1 == nxt) {   /* Is next cluster contiguous? */
    10551055                                ecl = nxt;
     
    10751075/* FAT handling - Stretch or Create a cluster chain                      */
    10761076/*-----------------------------------------------------------------------*/
    1077 #if !_FS_READONLY
     1077#if !FF_FS_READONLY
    10781078static
    10791079DWORD create_chain (    /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */
     
    11281128        return ncl;             /* Return new cluster number or error code */
    11291129}
    1130 #endif /* !_FS_READONLY */
     1130#endif /* !FF_FS_READONLY */
    11311131
    11321132
     
    11371137/*-----------------------------------------------------------------------*/
    11381138
    1139 #if _USE_FASTSEEK
     1139#if FF_USE_FASTSEEK
    11401140static
    11411141DWORD clmt_clust (      /* <2:Error, >=2:Cluster number */
     
    11571157        return cl + *tbl;       /* Return the cluster number */
    11581158}
    1159 #endif  /* _USE_FASTSEEK */
     1159#endif  /* FF_USE_FASTSEEK */
    11601160
    11611161
     
    11681168static
    11691169FRESULT dir_sdi (       /* FR_OK(0):succeeded, !=0:error */
    1170         DIR* dp,                /* Pointer to directory object */
     1170        FATFS_DIR* dp,          /* Pointer to directory object */
    11711171        UINT idx                /* Index of directory table */
    11721172)
     
    12161216static
    12171217FRESULT 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 */
    12191219        int stretch             /* 0: Do not stretch table, 1: Stretch table if needed */
    12201220)
     
    12221222        DWORD clst;
    12231223        UINT i;
    1224 #if !_FS_READONLY
     1224#if !FF_FS_READONLY
    12251225        UINT c;
    12261226#endif
     
    12441244                                if (clst == 0xFFFFFFFF) return FR_DISK_ERR;
    12451245                                if (clst >= dp->fs->n_fatent) {                                 /* If it reached end of dynamic table, */
    1246 #if !_FS_READONLY
     1246#if !FF_FS_READONLY
    12471247                                        if (!stretch) return FR_NO_FILE;                        /* If do not stretch, report EOT */
    12481248                                        clst = create_chain(dp->fs, dp->clust);         /* Stretch cluster chain */
     
    12841284/*-----------------------------------------------------------------------*/
    12851285
    1286 #if !_FS_READONLY
     1286#if !FF_FS_READONLY
    12871287static
    12881288FRESULT 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 */
    12901290        UINT nent               /* Number of contiguous entries to allocate (1-21) */
    12911291)
     
    13371337
    13381338
    1339 #if !_FS_READONLY
     1339#if !FF_FS_READONLY
    13401340static
    13411341void st_clust (
     
    13551355/* LFN handling - Test/Pick/Fit an LFN segment from/to directory entry   */
    13561356/*-----------------------------------------------------------------------*/
    1357 #if _USE_LFN
     1357#if FF_USE_LFN
    13581358static
    13591359const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};      /* Offset of LFN characters in the directory entry */
     
    13771377                uc = LD_WORD(dir + LfnOfs[s]);          /* Pick an LFN character */
    13781378                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 */
    13801380                                return 0;                                       /* Not matched */
    13811381                        wc = uc;
     
    14101410                uc = LD_WORD(dir + LfnOfs[s]);          /* Pick an LFN character */
    14111411                if (wc) {
    1412                         if (i >= _MAX_LFN) return 0;    /* Buffer overflow? */
     1412                        if (i >= FF_MAX_LFN) return 0;  /* Buffer overflow? */
    14131413                        lfnbuf[i++] = wc = uc;                  /* Store it */
    14141414                } else {
     
    14181418
    14191419        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? */
    14211421                lfnbuf[i] = 0;
    14221422        }
     
    14261426
    14271427
    1428 #if !_FS_READONLY
     1428#if !FF_FS_READONLY
    14291429static
    14301430void fit_lfn (
     
    14641464/* Create numbered name                                                  */
    14651465/*-----------------------------------------------------------------------*/
    1466 #if _USE_LFN
     1466#if FF_USE_LFN
    14671467static
    14681468void gen_numname (
     
    15231523/* Calculate checksum of an SFN entry                                    */
    15241524/*-----------------------------------------------------------------------*/
    1525 #if _USE_LFN
     1525#if FF_USE_LFN
    15261526static
    15271527BYTE sum_sfn (
     
    15461546static
    15471547FRESULT 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 */
    15491549)
    15501550{
    15511551        FRESULT res;
    15521552        BYTE c, *dir;
    1553 #if _USE_LFN
     1553#if FF_USE_LFN
    15541554        BYTE a, ord, sum;
    15551555#endif
     
    15581558        if (res != FR_OK) return res;
    15591559
    1560 #if _USE_LFN
     1560#if FF_USE_LFN
    15611561        ord = sum = 0xFF; dp->lfn_idx = 0xFFFF; /* Reset LFN sequence */
    15621562#endif
     
    15671567                c = dir[DIR_Name];
    15681568                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 */
    15701570                a = dir[DIR_Attr] & AM_MASK;
    15711571                if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) {       /* An entry without valid data */
     
    16041604/* Read an object from the directory                                     */
    16051605/*-----------------------------------------------------------------------*/
    1606 #if _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2
     1606#if FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2
    16071607static
    16081608FRESULT dir_read (
    1609         DIR* dp,                /* Pointer to the directory object */
     1609        FATFS_DIR* dp,          /* Pointer to the directory object */
    16101610        int vol                 /* Filtered by 0:file/directory or 1:volume label */
    16111611)
     
    16131613        FRESULT res;
    16141614        BYTE a, c, *dir;
    1615 #if _USE_LFN
     1615#if FF_USE_LFN
    16161616        BYTE ord = 0xFF, sum = 0xFF;
    16171617#endif
     
    16251625                if (c == 0) { res = FR_NO_FILE; break; }        /* Reached to end of table */
    16261626                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 */
    16291629                        ord = 0xFF;
    16301630                } else {
     
    16441644                }
    16451645#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? */
    16471647                        break;
    16481648#endif
     
    16551655        return res;
    16561656}
    1657 #endif  /* _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2 */
     1657#endif  /* FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2 */
    16581658
    16591659
     
    16631663/* Register an object to the directory                                   */
    16641664/*-----------------------------------------------------------------------*/
    1665 #if !_FS_READONLY
     1665#if !FF_FS_READONLY
    16661666static
    16671667FRESULT 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 */
    16691669)
    16701670{
    16711671        FRESULT res;
    1672 #if _USE_LFN    /* LFN configuration */
     1672#if FF_USE_LFN  /* LFN configuration */
    16731673        UINT n, nent;
    16741674        BYTE sn[12], *fn, sum;
     
    16791679        mem_cpy(sn, fn, 12);
    16801680
    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 */
    16821682                return FR_INVALID_NAME;
    16831683
     
    17241724                        mem_set(dp->dir, 0, SZ_DIRE);   /* Clean the entry */
    17251725                        mem_cpy(dp->dir, dp->fn, 11);   /* Put SFN */
    1726 #if _USE_LFN
     1726#if FF_USE_LFN
    17271727                        dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT);       /* Put NT flag */
    17281728#endif
     
    17331733        return res;
    17341734}
    1735 #endif /* !_FS_READONLY */
     1735#endif /* !FF_FS_READONLY */
    17361736
    17371737
     
    17411741/* Remove an object from the directory                                   */
    17421742/*-----------------------------------------------------------------------*/
    1743 #if !_FS_READONLY && !_FS_MINIMIZE
     1743#if !FF_FS_READONLY && !FF_FS_MINIMIZE
    17441744static
    17451745FRESULT 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 */
    17471747)
    17481748{
    17491749        FRESULT res;
    1750 #if _USE_LFN    /* LFN configuration */
     1750#if FF_USE_LFN  /* LFN configuration */
    17511751        UINT i;
    17521752
     
    17801780        return res;
    17811781}
    1782 #endif /* !_FS_READONLY */
     1782#endif /* !FF_FS_READONLY */
    17831783
    17841784
     
    17881788/* Get file information from directory entry                             */
    17891789/*-----------------------------------------------------------------------*/
    1790 #if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2
     1790#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2
    17911791static
    17921792void get_fileinfo (             /* No return code */
    1793         DIR* dp,                        /* Pointer to the directory object */
     1793        FATFS_DIR* dp,                  /* Pointer to the directory object */
    17941794        FILINFO* fno            /* Pointer to the file information to be filled */
    17951795)
     
    17981798        TCHAR *p, c;
    17991799        BYTE *dir;
    1800 #if _USE_LFN
     1800#if FF_USE_LFN
    18011801        WCHAR w, *lfn;
    18021802#endif
    1803 #if _CODE_PAGE == 65001
     1803#if FF_CODE_PAGE == 65001
    18041804        unsigned char utf8_code[6];
    18051805        int code_size;
     
    18151815                        if (c == RDDEM) c = (TCHAR)DDEM;        /* Restore replaced DDEM character */
    18161816                        if (i == 9) *p++ = '.';                         /* Insert a . if extension is exist */
    1817 #if _USE_LFN
     1817#if FF_USE_LFN
    18181818                        if (IsUpper(c) && (dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY)))
    18191819                                c += 0x20;                      /* To lower */
    1820 #if _LFN_UNICODE
     1820#if FF_LFN_UNICODE
    18211821                        if (IsDBCS1(c) && i != 8 && i != 11 && IsDBCS2(dir[i]))
    18221822                                c = c << 8 | dir[i++];
     
    18341834        *p = 0;         /* Terminate SFN string by a \0 */
    18351835
    1836 #if _USE_LFN
     1836#if FF_USE_LFN
    18371837        if (fno->lfname) {
    18381838                i = 0; p = fno->lfname;
     
    18401840                        lfn = dp->lfn;
    18411841                        while ((w = *lfn++) != 0) {             /* Get an LFN character */
    1842 #if !_LFN_UNICODE
    1843 #if _CODE_PAGE == 65001
     1842#if !FF_LFN_UNICODE
     1843#if FF_CODE_PAGE == 65001
    18441844                                Utf16_to_Utf8(utf8_code, &code_size, w);
    18451845                                for (int j = 0; j < code_size - 1; j++) {
     
    18621862#endif
    18631863}
    1864 #endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2 */
     1864#endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */
    18651865
    18661866
     
    18701870/* Pattern matching                                                      */
    18711871/*-----------------------------------------------------------------------*/
    1872 #if _USE_FIND && _FS_MINIMIZE <= 1
     1872#if FF_USE_FIND && FF_FS_MINIMIZE <= 1
    18731873static
    18741874WCHAR get_achar (               /* Get a character and advances ptr 1 or 2 */
     
    18781878        WCHAR chr;
    18791879
    1880 #if !_LFN_UNICODE
    1881 #if _CODE_PAGE == 65001
     1880#if !FF_LFN_UNICODE
     1881#if FF_CODE_PAGE == 65001
    18821882        int code_size;
    18831883        chr = Utf8_to_Utf16(*ptr, &code_size);
     
    19381938        return 0;
    19391939}
    1940 #endif /* _USE_FIND && _FS_MINIMIZE <= 1 */
     1940#endif /* FF_USE_FIND && FF_FS_MINIMIZE <= 1 */
    19411941
    19421942
     
    19491949static
    19501950FRESULT 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 */
    19521952        const TCHAR** path      /* Pointer to pointer to the segment in the path string */
    19531953)
    19541954{
    1955 #if _USE_LFN    /* LFN configuration */
     1955#if FF_USE_LFN  /* LFN configuration */
    19561956        BYTE b, cf;
    19571957        WCHAR w, *lfn;
    19581958        UINT i, ni, si, di;
    19591959        const TCHAR *p;
    1960 #if _CODE_PAGE == 65001
     1960#if FF_CODE_PAGE == 65001
    19611961        unsigned char utf8_code[6];
    19621962        int code_size;
     
    19691969                w = p[si++];                                    /* Get a character */
    19701970                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 */
    19721972                        return FR_INVALID_NAME;
    1973 #if !_LFN_UNICODE
    1974 #if _CODE_PAGE == 65001
     1973#if !FF_LFN_UNICODE
     1974#if FF_CODE_PAGE == 65001
    19751975                w = Utf8_to_Utf16(&p[si - 1], &code_size);
    19761976                si += code_size - 1;
     
    19931993        *path = &p[si];                                         /* Return pointer to the next segment */
    19941994        cf = (w < ' ') ? NS_LAST : 0;           /* Set last segment flag if end of path */
    1995 #if _FS_RPATH
     1995#if FF_FS_RPATH
    19961996        if ((di == 1 && lfn[di - 1] == '.') ||
    19971997                (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) {        /* Is this segment a dot entry? */
     
    20402040                        if (w) w = ExCvt[w - 0x80];     /* Convert extended character to upper (SBCS) */
    20412041#else
    2042 #if _CODE_PAGE == 65001
     2042#if FF_CODE_PAGE == 65001
    20432043                        Utf16_to_Utf8(utf8_code, &code_size, ff_wtoupper(w));
    20442044#else
     
    20482048                        cf |= NS_LFN;                           /* Force create LFN entry */
    20492049                }
    2050 #if _CODE_PAGE == 65001
     2050#if FF_CODE_PAGE == 65001
    20512051                else
    20522052                        code_size = 1;
    20532053#endif
    20542054
    2055 #if _CODE_PAGE == 65001
     2055#if FF_CODE_PAGE == 65001
    20562056                if (code_size > 1) {            /* Is this DBC? (always false at SBCS cfg) */
    20572057                        if (i >= ni - 1) {
     
    21262126        mem_set(sfn, ' ', 11);
    21272127        si = i = b = 0; ni = 8;
    2128 #if _FS_RPATH
     2128#if FF_FS_RPATH
    21292129        if (p[si] == '.') { /* Is this a dot entry? */
    21302130                for (;;) {
     
    22012201static
    22022202FRESULT 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 */
    22042204        const TCHAR* path       /* Full-path string to find a file or directory */
    22052205)
     
    22092209
    22102210
    2211 #if _FS_RPATH
     2211#if FF_FS_RPATH
    22122212        if (*path == '/' || *path == '\\') {    /* There is a heading separator */
    22132213                path++; dp->sclust = 0;                         /* Strip it and start from the root directory */
     
    22322232                        if (res != FR_OK) {                             /* Failed to find the object */
    22332233                                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, */
    22352235                                                dp->sclust = 0; dp->dir = 0;    /* it is the root directory and stay there */
    22362236                                                if (!(ns & NS_LAST)) continue;  /* Continue to follow if not last segment */
     
    22692269        UINT i;
    22702270        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};
    22732273        const char *sp;
    22742274        char c;
     
    22782278
    22792279        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 */
    22812281                if (*tt == ':') {       /* If a ':' is exist in the path name */
    22822282                        tp = *path;
    22832283                        i = *tp++ - '0';
    22842284                        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 */
    22862286                                        vol = (int)i;
    22872287                                        *path = ++tt;
    22882288                                }
    22892289                        }
    2290 #if _STR_VOLUME_ID
     2290#if FF_STR_VOLUME_ID
    22912291                         else { /* No numeric drive number, find string drive id */
    22922292                                i = 0; tt++;
     
    22972297                                                if (IsLower(tc)) tc -= 0x20;
    22982298                                        } 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 */
    23012301                                        vol = (int)i;
    23022302                                        *path = tt;
     
    23062306                        return vol;
    23072307                }
    2308 #if _FS_RPATH && _VOLUMES >= 2
     2308#if FF_FS_RPATH && FF_VOLUMES >= 2
    23092309                vol = CurrVol;  /* Current drive */
    23102310#else
     
    23812381                stat = disk_status(fs->drv);
    23822382                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 */
    23842384                                return FR_WRITE_PROTECTED;
    23852385                        return FR_OK;                           /* The file system object is valid */
     
    23952395        if (stat & STA_NOINIT)                          /* Check if the initialization succeeded */
    23962396                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 */
    23982398                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) */
    24002400        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;
    24022402#endif
    24032403        /* Find an FAT partition on the drive. Supports only generic partitioning, FDISK and SFD. */
     
    24482448
    24492449        /* 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 */
    24512451        if (tsect < sysect) return FR_NO_FILESYSTEM;            /* (Invalid volume size) */
    24522452        nclst = (tsect - sysect) / fs->csize;                           /* Number of clusters */
     
    24742474                return FR_NO_FILESYSTEM;
    24752475
    2476 #if !_FS_READONLY
     2476#if !FF_FS_READONLY
    24772477        /* Initialize cluster allocation information */
    24782478        fs->last_clust = fs->free_clust = 0xFFFFFFFF;
     
    24802480        /* Get fsinfo if available */
    24812481        fs->fsi_flag = 0x80;
    2482 #if (_FS_NOFSINFO & 3) != 3
     2482#if (FF_FS_NOFSINFO & 3) != 3
    24832483        if (fmt == FS_FAT32                             /* Enable FSINFO only if FAT32 and BPB_FSInfo == 1 */
    24842484                && LD_WORD(fs->win + BPB_FSInfo) == 1
     
    24902490                        && LD_DWORD(fs->win + FSI_StrucSig) == 0x61417272)
    24912491                {
    2492 #if (_FS_NOFSINFO & 1) == 0
     2492#if (FF_FS_NOFSINFO & 1) == 0
    24932493                        fs->free_clust = LD_DWORD(fs->win + FSI_Free_Count);
    24942494#endif
    2495 #if (_FS_NOFSINFO & 2) == 0
     2495#if (FF_FS_NOFSINFO & 2) == 0
    24962496                        fs->last_clust = LD_DWORD(fs->win + FSI_Nxt_Free);
    24972497#endif
     
    25022502        fs->fs_type = fmt;      /* FAT sub-type */
    25032503        fs->id = ++Fsid;        /* File system mount ID */
    2504 #if _FS_RPATH
     2504#if FF_FS_RPATH
    25052505        fs->cdir = 0;           /* Set current directory to root */
    25062506#endif
    2507 #if _FS_LOCK                    /* Clear file lock semaphores */
     2507#if FF_FS_LOCK != 0                     /* Clear file lock semaphores */
    25082508        clear_lock(fs);
    25092509#endif
     
    25212521static
    25222522FRESULT 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 */
    25272527
    25282528
     
    25672567
    25682568        if (cfs) {
    2569 #if _FS_LOCK
     2569#if FF_FS_LOCK != 0
    25702570                clear_lock(cfs);
    25712571#endif
    2572 #if _FS_REENTRANT                                               /* Discard sync object of the current volume */
     2572#if FF_FS_REENTRANT                                             /* Discard sync object of the current volume */
    25732573                if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR;
    25742574#endif
     
    25782578        if (fs) {
    25792579                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 */
    25812581                if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR;
    25822582#endif
     
    26042604{
    26052605        FRESULT res;
    2606         DIR dj;
     2606        FATFS_DIR dj;
    26072607        BYTE *dir;
    26082608        DEFINE_NAMEBUF;
    2609 #if !_FS_READONLY
     2609#if !FF_FS_READONLY
    26102610        DWORD dw, cl;
    26112611#endif
     
    26162616
    26172617        /* Get logical drive number */
    2618 #if !_FS_READONLY
    2619         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;
    26202620        res = find_volume(&dj.fs, &path, (BYTE)(mode & ~FA_READ));
    26212621#else
     
    26272627                res = follow_path(&dj, path);   /* Follow the file path */
    26282628                dir = dj.dir;
    2629 #if !_FS_READONLY       /* R/W configuration */
     2629#if !FF_FS_READONLY     /* R/W configuration */
    26302630                if (res == FR_OK) {
    26312631                        if (!dir)       /* Default directory itself */
    26322632                                res = FR_INVALID_NAME;
    2633 #if _FS_LOCK
     2633#if FF_FS_LOCK != 0
    26342634                        else
    26352635                                res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0);
     
    26402640                        if (res != FR_OK) {                                     /* No file, create new */
    26412641                                if (res == FR_NO_FILE)                  /* There is no file to open, create a new entry */
    2642 #if _FS_LOCK
     2642#if FF_FS_LOCK != 0
    26432643                                        res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES;
    26442644#else
     
    26492649                        }
    26502650                        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) */
    26522652                                        res = FR_DENIED;
    26532653                                } else {
     
    26872687                if (res == FR_OK) {
    26882688                        if (mode & FA_CREATE_ALWAYS)            /* Set file change flag if created or overwritten */
    2689                                 mode |= FA__WRITTEN;
     2689                                mode |= FA_MODIFIED;
    26902690                        fp->dir_sect = dj.fs->winsect;          /* Pointer to the directory entry */
    26912691                        fp->dir_ptr = dir;
    2692 #if _FS_LOCK
     2692#if FF_FS_LOCK != 0
    26932693                        fp->lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0);
    26942694                        if (!fp->lockid) res = FR_INT_ERR;
     
    27162716                        fp->fptr = 0;                                           /* File pointer */
    27172717                        fp->dsect = 0;
    2718 #if _USE_FASTSEEK
     2718#if FF_USE_FASTSEEK
    27192719                        fp->cltbl = 0;                                          /* Normal seek mode */
    27202720#endif
     
    27662766                                        clst = fp->sclust;                      /* Follow from the origin */
    27672767                                } else {                                                /* Middle or end of the file */
    2768 #if _USE_FASTSEEK
     2768#if FF_USE_FASTSEEK
    27692769                                        if (fp->cltbl)
    27702770                                                clst = clmt_clust(fp, fp->fptr);        /* Get cluster# from the CLMT */
     
    27862786                                if (disk_read(fp->fs->drv, rbuff, sect, cc) != RES_OK)
    27872787                                        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_TINY
     2788#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
    27902790                                if (fp->fs->wflag && fp->fs->winsect - sect < cc)
    27912791                                        mem_cpy(rbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), fp->fs->win, SS(fp->fs));
    27922792#else
    2793                                 if ((fp->flag & FA__DIRTY) && fp->dsect - sect < cc)
     2793                                if ((fp->flag & FA_DIRTY) && fp->dsect - sect < cc)
    27942794                                        mem_cpy(rbuff + ((fp->dsect - sect) * SS(fp->fs)), fp->buf, SS(fp->fs));
    27952795#endif
     
    27982798                                continue;
    27992799                        }
    2800 #if !_FS_TINY
     2800#if !FF_FS_TINY
    28012801                        if (fp->dsect != sect) {                        /* Load data sector if not in cache */
    2802 #if !_FS_READONLY
    2803                                 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 */
    28042804                                        if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    28052805                                                ABORT(fp->fs, FR_DISK_ERR);
    2806                                         fp->flag &= ~FA__DIRTY;
     2806                                        fp->flag &= ~FA_DIRTY;
    28072807                                }
    28082808#endif
     
    28152815                rcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));      /* Get partial sector data from sector buffer */
    28162816                if (rcnt > btr) rcnt = btr;
    2817 #if _FS_TINY
     2817#if FF_FS_TINY
    28182818                if (move_window(fp->fs, fp->dsect) != FR_OK)            /* Move sector window */
    28192819                        ABORT(fp->fs, FR_DISK_ERR);
     
    28302830
    28312831
    2832 #if !_FS_READONLY
     2832#if !FF_FS_READONLY
    28332833/*-----------------------------------------------------------------------*/
    28342834/* Write File                                                            */
     
    28692869                                                clst = create_chain(fp->fs, 0); /* Create a new cluster chain */
    28702870                                } else {                                        /* Middle or end of the file */
    2871 #if _USE_FASTSEEK
     2871#if FF_USE_FASTSEEK
    28722872                                        if (fp->cltbl)
    28732873                                                clst = clmt_clust(fp, fp->fptr);        /* Get cluster# from the CLMT */
     
    28822882                                if (fp->sclust == 0) fp->sclust = clst; /* Set start cluster if the first write */
    28832883                        }
    2884 #if _FS_TINY
     2884#if FF_FS_TINY
    28852885                        if (fp->fs->winsect == fp->dsect && sync_window(fp->fs))        /* Write-back sector cache */
    28862886                                ABORT(fp->fs, FR_DISK_ERR);
    28872887#else
    2888                         if (fp->flag & FA__DIRTY) {             /* Write-back sector cache */
     2888                        if (fp->flag & FA_DIRTY) {              /* Write-back sector cache */
    28892889                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    28902890                                        ABORT(fp->fs, FR_DISK_ERR);
    2891                                 fp->flag &= ~FA__DIRTY;
     2891                                fp->flag &= ~FA_DIRTY;
    28922892                        }
    28932893#endif
     
    29012901                                if (disk_write(fp->fs->drv, wbuff, sect, cc) != RES_OK)
    29022902                                        ABORT(fp->fs, FR_DISK_ERR);
    2903 #if _FS_MINIMIZE <= 2
    2904 #if _FS_TINY
     2903#if FF_FS_MINIMIZE <= 2
     2904#if FF_FS_TINY
    29052905                                if (fp->fs->winsect - sect < cc) {      /* Refill sector cache if it gets invalidated by the direct write */
    29062906                                        mem_cpy(fp->fs->win, wbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), SS(fp->fs));
     
    29102910                                if (fp->dsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
    29112911                                        mem_cpy(fp->buf, wbuff + ((fp->dsect - sect) * SS(fp->fs)), SS(fp->fs));
    2912                                         fp->flag &= ~FA__DIRTY;
     2912                                        fp->flag &= ~FA_DIRTY;
    29132913                                }
    29142914#endif
     
    29172917                                continue;
    29182918                        }
    2919 #if _FS_TINY
     2919#if FF_FS_TINY
    29202920                        if (fp->fptr >= fp->fsize) {    /* Avoid silly cache filling at growing edge */
    29212921                                if (sync_window(fp->fs)) ABORT(fp->fs, FR_DISK_ERR);
     
    29332933                wcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */
    29342934                if (wcnt > btw) wcnt = btw;
    2935 #if _FS_TINY
     2935#if FF_FS_TINY
    29362936                if (move_window(fp->fs, fp->dsect) != FR_OK)    /* Move sector window */
    29372937                        ABORT(fp->fs, FR_DISK_ERR);
     
    29402940#else
    29412941                mem_cpy(&fp->buf[fp->fptr % SS(fp->fs)], wbuff, wcnt);  /* Fit partial sector */
    2942                 fp->flag |= FA__DIRTY;
     2942                fp->flag |= FA_DIRTY;
    29432943#endif
    29442944        }
    29452945
    29462946        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 */
    29482948
    29492949        LEAVE_FF(fp->fs, FR_OK);
     
    29682968        res = validate(fp);                                     /* Check validity of the object */
    29692969        if (res == FR_OK) {
    2970                 if (fp->flag & FA__WRITTEN) {   /* Is there any change to the file? */
    2971 #if !_FS_TINY
    2972                         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 */
    29732973                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    29742974                                        LEAVE_FF(fp->fs, FR_DISK_ERR);
    2975                                 fp->flag &= ~FA__DIRTY;
     2975                                fp->flag &= ~FA_DIRTY;
    29762976                        }
    29772977#endif
     
    29862986                                ST_DWORD(dir + DIR_WrtTime, tm);
    29872987                                ST_WORD(dir + DIR_LstAccDate, 0);
    2988                                 fp->flag &= ~FA__WRITTEN;
     2988                                fp->flag &= ~FA_MODIFIED;
    29892989                                fp->fs->wflag = 1;
    29902990                                res = sync_fs(fp->fs);
     
    29962996}
    29972997
    2998 #endif /* !_FS_READONLY */
     2998#endif /* !FF_FS_READONLY */
    29992999
    30003000
     
    30123012
    30133013
    3014 #if !_FS_READONLY
     3014#if !FF_FS_READONLY
    30153015        res = f_sync(fp);                                       /* Flush cached data */
    30163016        if (res == FR_OK)
     
    30193019                res = validate(fp);                             /* Lock volume */
    30203020                if (res == FR_OK) {
    3021 #if _FS_REENTRANT
     3021#if FF_FS_REENTRANT
    30223022                        FATFS *fs = fp->fs;
    30233023#endif
    3024 #if _FS_LOCK
     3024#if FF_FS_LOCK != 0
    30253025                        res = dec_lock(fp->lockid);     /* Decrement file open counter */
    30263026                        if (res == FR_OK)
    30273027#endif
    30283028                                fp->fs = 0;                             /* Invalidate file object */
    3029 #if _FS_REENTRANT
     3029#if FF_FS_REENTRANT
    30303030                        unlock_fs(fs, FR_OK);           /* Unlock volume */
    30313031#endif
     
    30423042/*-----------------------------------------------------------------------*/
    30433043
    3044 #if _FS_RPATH >= 1
    3045 #if _VOLUMES >= 2
     3044#if FF_FS_RPATH >= 1
     3045#if FF_VOLUMES >= 2
    30463046FRESULT f_chdrive (
    30473047        const TCHAR* path               /* Drive number */
     
    30663066{
    30673067        FRESULT res;
    3068         DIR dj;
     3068        FATFS_DIR dj;
    30693069        DEFINE_NAMEBUF;
    30703070
     
    30933093
    30943094
    3095 #if _FS_RPATH >= 2
     3095#if FF_FS_RPATH >= 2
    30963096FRESULT f_getcwd (
    30973097        TCHAR* buff,    /* Pointer to the directory path */
     
    31003100{
    31013101        FRESULT res;
    3102         DIR dj;
     3102        FATFS_DIR dj;
    31033103        UINT i, n;
    31043104        DWORD ccl;
     
    31313131                        if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */
    31323132                        if (res != FR_OK) break;
    3133 #if _USE_LFN
     3133#if FF_USE_LFN
    31343134                        fno.lfname = buff;
    31353135                        fno.lfsize = i;
     
    31373137                        get_fileinfo(&dj, &fno);                /* Get the directory name and push it to the buffer */
    31383138                        tp = fno.fname;
    3139 #if _USE_LFN
     3139#if FF_USE_LFN
    31403140                        if (*buff) tp = buff;
    31413141#endif
     
    31493149                tp = buff;
    31503150                if (res == FR_OK) {
    3151 #if _VOLUMES >= 2
     3151#if FF_VOLUMES >= 2
    31523152                        *tp++ = '0' + CurrVol;                  /* Put drive number */
    31533153                        *tp++ = ':';
     
    31673167        LEAVE_FF(dj.fs, res);
    31683168}
    3169 #endif /* _FS_RPATH >= 2 */
    3170 #endif /* _FS_RPATH >= 1 */
    3171 
    3172 
    3173 
    3174 #if _FS_MINIMIZE <= 2
     3169#endif /* FF_FS_RPATH >= 2 */
     3170#endif /* FF_FS_RPATH >= 1 */
     3171
     3172
     3173
     3174#if FF_FS_MINIMIZE <= 2
    31753175/*-----------------------------------------------------------------------*/
    31763176/* Seek File R/W Pointer                                                 */
     
    31843184        FRESULT res;
    31853185        DWORD clst, bcs, nsect, ifptr;
    3186 #if _USE_FASTSEEK
     3186#if FF_USE_FASTSEEK
    31873187        DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;
    31883188#endif
     
    31943194                LEAVE_FF(fp->fs, (FRESULT)fp->err);
    31953195
    3196 #if _USE_FASTSEEK
     3196#if FF_USE_FASTSEEK
    31973197        if (fp->cltbl) {        /* Fast seek */
    31983198                if (ofs == CREATE_LINKMAP) {    /* Create CLMT */
     
    32313231                                dsc += (ofs - 1) / SS(fp->fs) & (fp->fs->csize - 1);
    32323232                                if (fp->fptr % SS(fp->fs) && dsc != fp->dsect) {        /* Refill sector cache if needed */
    3233 #if !_FS_TINY
    3234 #if !_FS_READONLY
    3235                                         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 */
    32363236                                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    32373237                                                        ABORT(fp->fs, FR_DISK_ERR);
    3238                                                 fp->flag &= ~FA__DIRTY;
     3238                                                fp->flag &= ~FA_DIRTY;
    32393239                                        }
    32403240#endif
     
    32523252        {
    32533253                if (ofs > fp->fsize                                     /* In read-only mode, clip offset with the file size */
    3254 #if !_FS_READONLY
     3254#if !FF_FS_READONLY
    32553255                         && !(fp->flag & FA_WRITE)
    32563256#endif
     
    32683268                        } else {                                                                        /* When seek to back cluster, */
    32693269                                clst = fp->sclust;                                              /* start from the first cluster */
    3270 #if !_FS_READONLY
     3270#if !FF_FS_READONLY
    32713271                                if (clst == 0) {                                                /* If no cluster chain, create a new chain */
    32723272                                        clst = create_chain(fp->fs, 0);
     
    32803280                        if (clst != 0) {
    32813281                                while (ofs > bcs) {                                             /* Cluster following loop */
    3282 #if !_FS_READONLY
     3282#if !FF_FS_READONLY
    32833283                                        if (fp->flag & FA_WRITE) {                      /* Check if in write mode or not */
    32843284                                                clst = create_chain(fp->fs, clst);      /* Force stretch if in write mode */
     
    33043304                }
    33053305                if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) {      /* Fill sector cache if needed */
    3306 #if !_FS_TINY
    3307 #if !_FS_READONLY
    3308                         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 */
    33093309                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    33103310                                        ABORT(fp->fs, FR_DISK_ERR);
    3311                                 fp->flag &= ~FA__DIRTY;
     3311                                fp->flag &= ~FA_DIRTY;
    33123312                        }
    33133313#endif
     
    33173317                        fp->dsect = nsect;
    33183318                }
    3319 #if !_FS_READONLY
     3319#if !FF_FS_READONLY
    33203320                if (fp->fptr > fp->fsize) {                     /* Set file change flag if the file size is extended */
    33213321                        fp->fsize = fp->fptr;
    3322                         fp->flag |= FA__WRITTEN;
     3322                        fp->flag |= FA_MODIFIED;
    33233323                }
    33243324#endif
     
    33423342}
    33433343
    3344 #if _FS_MINIMIZE <= 1
     3344#if FF_FS_MINIMIZE <= 1
    33453345/*-----------------------------------------------------------------------*/
    33463346/* Create a Directory Object                                             */
     
    33483348
    33493349FRESULT f_opendir (
    3350         DIR* dp,                        /* Pointer to directory object to create */
     3350        FATFS_DIR* dp,                  /* Pointer to directory object to create */
    33513351        const TCHAR* path       /* Pointer to the directory path */
    33523352)
     
    33763376                                dp->id = fs->id;
    33773377                                res = dir_sdi(dp, 0);                   /* Rewind directory */
    3378 #if _FS_LOCK
     3378#if FF_FS_LOCK != 0
    33793379                                if (res == FR_OK) {
    33803380                                        if (dp->sclust) {
     
    34043404
    34053405FRESULT 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 */
    34073407)
    34083408{
     
    34123412        res = validate(dp);
    34133413        if (res == FR_OK) {
    3414 #if _FS_REENTRANT
     3414#if FF_FS_REENTRANT
    34153415                FATFS *fs = dp->fs;
    34163416#endif
    3417 #if _FS_LOCK
     3417#if FF_FS_LOCK != 0
    34183418                if (dp->lockid)                         /* Decrement sub-directory open counter */
    34193419                        res = dec_lock(dp->lockid);
     
    34213421#endif
    34223422                        dp->fs = 0;                             /* Invalidate directory object */
    3423 #if _FS_REENTRANT
     3423#if FF_FS_REENTRANT
    34243424                unlock_fs(fs, FR_OK);           /* Unlock volume */
    34253425#endif
     
    34363436
    34373437FRESULT f_readdir (
    3438         DIR* dp,                        /* Pointer to the open directory object */
     3438        FATFS_DIR* dp,                  /* Pointer to the open directory object */
    34393439        FILINFO* fno            /* Pointer to file information to return */
    34403440)
     
    34723472
    34733473
    3474 #if _USE_FIND
     3474#if FF_USE_FIND
    34753475/*-----------------------------------------------------------------------*/
    34763476/* Find next file                                                        */
     
    34783478
    34793479FRESULT f_findnext (
    3480         DIR* dp,                /* Pointer to the open directory object */
     3480        FATFS_DIR* dp,          /* Pointer to the open directory object */
    34813481        FILINFO* fno    /* Pointer to the file information structure */
    34823482)
     
    34883488                res = f_readdir(dp, fno);               /* Get a directory item */
    34893489                if (res != FR_OK || !fno || !fno->fname[0]) break;      /* Terminate if any error or end of directory */
    3490 #if _USE_LFN
     3490#if FF_USE_LFN
    34913491                if (fno->lfname && pattern_matching(dp->pat, fno->lfname, 0, 0)) break; /* Test for LFN if exist */
    34923492#endif
     
    35043504
    35053505FRESULT f_findfirst (
    3506         DIR* dp,                                /* Pointer to the blank directory object */
     3506        FATFS_DIR* dp,                          /* Pointer to the blank directory object */
    35073507        FILINFO* fno,                   /* Pointer to the file information structure */
    35083508        const TCHAR* path,              /* Pointer to the directory to open */
     
    35203520}
    35213521
    3522 #endif  /* _USE_FIND */
    3523 
    3524 
    3525 
    3526 #if _FS_MINIMIZE == 0
     3522#endif  /* FF_USE_FIND */
     3523
     3524
     3525
     3526#if FF_FS_MINIMIZE == 0
    35273527/*-----------------------------------------------------------------------*/
    35283528/* Get File Status                                                       */
     
    35353535{
    35363536        FRESULT res;
    3537         DIR dj;
     3537        FATFS_DIR dj;
    35383538        DEFINE_NAMEBUF;
    35393539
     
    35593559
    35603560
    3561 #if !_FS_READONLY
     3561#if !FF_FS_READONLY
    35623562/*-----------------------------------------------------------------------*/
    35633563/* Get Number of Free Clusters                                           */
     
    36503650                if (fp->fsize > fp->fptr) {
    36513651                        fp->fsize = fp->fptr;   /* Set file size to current R/W point */
    3652                         fp->flag |= FA__WRITTEN;
     3652                        fp->flag |= FA_MODIFIED;
    36533653                        if (fp->fptr == 0) {    /* When set file size to zero, remove entire cluster chain */
    36543654                                res = remove_chain(fp->fs, fp->sclust);
     
    36643664                                }
    36653665                        }
    3666 #if !_FS_TINY
    3667                         if (res == FR_OK && (fp->flag & FA__DIRTY)) {
     3666#if !FF_FS_TINY
     3667                        if (res == FR_OK && (fp->flag & FA_DIRTY)) {
    36683668                                if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
    36693669                                        res = FR_DISK_ERR;
    36703670                                else
    3671                                         fp->flag &= ~FA__DIRTY;
     3671                                        fp->flag &= ~FA_DIRTY;
    36723672                        }
    36733673#endif
     
    36913691{
    36923692        FRESULT res;
    3693         DIR dj, sdj;
     3693        FATFS_DIR dj, sdj;
    36943694        BYTE *dir;
    36953695        DWORD dclst = 0;
     
    37023702                INIT_BUF(dj);
    37033703                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))
    37053705                        res = FR_INVALID_NAME;                  /* Cannot remove dot entry */
    3706 #if _FS_LOCK
     3706#if FF_FS_LOCK != 0
    37073707                if (res == FR_OK) res = chk_lock(&dj, 2);       /* Cannot remove open object */
    37083708#endif
     
    37183718                                dclst = ld_clust(dj.fs, dir);
    37193719                                if (dclst && (dir[DIR_Attr] & AM_DIR)) {        /* Is it a sub-directory ? */
    3720 #if _FS_RPATH
     3720#if FF_FS_RPATH
    37213721                                        if (dclst == dj.fs->cdir) {                             /* Is it the current directory? */
    37223722                                                res = FR_DENIED;
     
    37243724#endif
    37253725                                        {
    3726                                                 mem_cpy(&sdj, &dj, sizeof (DIR));       /* Open the sub-directory */
     3726                                                mem_cpy(&sdj, &dj, sizeof (FATFS_DIR)); /* Open the sub-directory */
    37273727                                                sdj.sclust = dclst;
    37283728                                                res = dir_sdi(&sdj, 2);
     
    37603760{
    37613761        FRESULT res;
    3762         DIR dj;
     3762        FATFS_DIR dj;
    37633763        BYTE *dir, n;
    37643764        DWORD dsc, dcl, pcl, tm = GET_FATTIME();
     
    37723772                res = follow_path(&dj, path);                   /* Follow the file path */
    37733773                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))
    37753775                        res = FR_INVALID_NAME;
    37763776                if (res == FR_NO_FILE) {                                /* Can create a new directory */
     
    38363836{
    38373837        FRESULT res;
    3838         DIR dj;
     3838        FATFS_DIR dj;
    38393839        BYTE *dir;
    38403840        DEFINE_NAMEBUF;
     
    38463846                res = follow_path(&dj, path);           /* Follow the file path */
    38473847                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))
    38493849                        res = FR_INVALID_NAME;
    38503850                if (res == FR_OK) {
     
    38773877{
    38783878        FRESULT res;
    3879         DIR djo, djn;
     3879        FATFS_DIR djo, djn;
    38803880        BYTE buf[21], *dir;
    38813881        DWORD dw;
     
    38903890                INIT_BUF(djo);
    38913891                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))
    38933893                        res = FR_INVALID_NAME;
    3894 #if _FS_LOCK
     3894#if FF_FS_LOCK != 0
    38953895                if (res == FR_OK) res = chk_lock(&djo, 2);
    38963896#endif
     
    39003900                        } else {
    39013901                                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 */
    39033903                                if (get_ldnumber(&path_new) >= 0)               /* Snip drive number off and ignore it */
    39043904                                        res = follow_path(&djn, path_new);      /* and make sure if new object name is not conflicting */
     
    39093909                                        dir = djn.dir;
    39103910                                        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));
    39133913                                                res = follow_path(&djn, temp_new_path);
    39143914                                        }
     
    39663966{
    39673967        FRESULT res;
    3968         DIR dj;
     3968        FATFS_DIR dj;
    39693969        BYTE *dir;
    39703970        DEFINE_NAMEBUF;
     
    39773977                res = follow_path(&dj, path);   /* Follow the file path */
    39783978                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))
    39803980                        res = FR_INVALID_NAME;
    39813981                if (res == FR_OK) {
     
    39953995}
    39963996
    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_LABEL
     3997#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
    40064006/*-----------------------------------------------------------------------*/
    40074007/* Get volume label                                                      */
     
    40154015{
    40164016        FRESULT res;
    4017         DIR dj;
     4017        FATFS_DIR dj;
    40184018        UINT i, j;
    4019 #if _USE_LFN && _LFN_UNICODE
     4019#if FF_USE_LFN && FF_LFN_UNICODE
    40204020        WCHAR w;
    40214021#endif
     
    40324032                        res = dir_read(&dj, 1);         /* Get an entry with AM_VOL */
    40334033                        if (res == FR_OK) {                     /* A volume label is exist */
    4034 #if _USE_LFN && _LFN_UNICODE
     4034#if FF_USE_LFN && FF_LFN_UNICODE
    40354035                                i = j = 0;
    40364036                                do {
     
    40704070
    40714071
    4072 #if !_FS_READONLY
     4072#if !FF_FS_READONLY
    40734073/*-----------------------------------------------------------------------*/
    40744074/* Set volume label                                                      */
     
    40804080{
    40814081        FRESULT res;
    4082         DIR dj;
     4082        FATFS_DIR dj;
    40834083        BYTE vn[11];
    40844084        UINT i, j, sl;
    40854085        WCHAR w;
    40864086        DWORD tm;
    4087 #if _CODE_PAGE == 65001
     4087#if FF_CODE_PAGE == 65001
    40884088        int code_size;
    40894089        unsigned char utf8_code[6];
     
    41014101                i = j = 0;
    41024102                do {
    4103 #if _CODE_PAGE == 65001
     4103#if FF_CODE_PAGE == 65001
    41044104                        w = ff_wtoupper(Utf8_to_Utf16(&label[i], &code_size));
    41054105                        i += code_size;
     
    41104110                                vn[j++] = utf8_code[k];
    41114111#else
    4112 #if _USE_LFN && _LFN_UNICODE
     4112#if FF_USE_LFN && FF_LFN_UNICODE
    41134113                        w = ff_convert(ff_wtoupper(label[i++]), 0);
    41144114#else
     
    41164116                        if (IsDBCS1(w))
    41174117                                w = (j < 10 && i < sl && IsDBCS2(label[i])) ? w << 8 | (BYTE)label[i++] : 0;
    4118 #if _USE_LFN
     4118#if FF_USE_LFN
    41194119                        w = ff_convert(ff_wtoupper(ff_convert(w, 1)), 0);
    41204120#else
     
    41744174}
    41754175
    4176 #endif /* !_FS_READONLY */
    4177 #endif /* _USE_LABEL */
     4176#endif /* !FF_FS_READONLY */
     4177#endif /* FF_USE_LABEL */
    41784178
    41794179
     
    41824182/* Forward data to the stream directly (available on only tiny cfg)      */
    41834183/*-----------------------------------------------------------------------*/
    4184 #if _USE_FORWARD && _FS_TINY
     4184#if FF_USE_FORWARD && FF_FS_TINY
    41854185
    41864186FRESULT f_forward (
     
    42354235        LEAVE_FF(fp->fs, FR_OK);
    42364236}
    4237 #endif /* _USE_FORWARD */
    4238 
    4239 
    4240 
    4241 #if _USE_MKFS && !_FS_READONLY
     4237#endif /* FF_USE_FORWARD */
     4238
     4239
     4240
     4241#if FF_USE_MKFS && !FF_FS_READONLY
    42424242/*-----------------------------------------------------------------------*/
    42434243/* Create file system on the logical drive                               */
     
    42634263        FATFS *fs;
    42644264        DSTATUS stat;
    4265 #if _USE_TRIM
     4265#if FF_USE_TRIM
    42664266        DWORD eb[2];
    42674267#endif
     
    42824282        if (stat & STA_NOINIT) return FR_NOT_READY;
    42834283        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)
    42864286                return FR_DISK_ERR;
    42874287#endif
    4288         if (_MULTI_PARTITION && part) {
     4288        if (FF_MULTI_PARTITION && part) {
    42894289                /* Get partition information from partition table in the MBR */
    42904290                if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR;
     
    43084308                au = cst[i];
    43094309        }
    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 */
    43114311        if (!au) au = 1;
    43124312        if (au > 128) au = 128;
     
    43624362        }
    43634363
    4364         if (_MULTI_PARTITION && part) {
     4364        if (FF_MULTI_PARTITION && part) {
    43654365                /* Update system ID in the partition table */
    43664366                tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
     
    44654465        } while (--i);
    44664466
    4467 #if _USE_TRIM   /* Erase data area if needed */
     4467#if FF_USE_TRIM /* Erase data area if needed */
    44684468        {
    44694469                eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1;
     
    44884488
    44894489
    4490 #if _MULTI_PARTITION
     4490#if FF_MULTI_PARTITION
    44914491/*-----------------------------------------------------------------------*/
    44924492/* Create partition table on the physical drive                          */
     
    45184518
    45194519        /* Create partition table */
    4520         mem_set(buf, 0, _MAX_SS);
     4520        mem_set(buf, 0, FF_MAX_SS);
    45214521        p = buf + MBR_Table; b_cyl = 0;
    45224522        for (i = 0; i < 4; i++, p += SZ_PTE) {
     
    45554555
    45564556
    4557 #endif /* _MULTI_PARTITION */
    4558 #endif /* _USE_MKFS && !_FS_READONLY */
    4559 
    4560 
    4561 
    4562 
    4563 #if _USE_STRFUNC
     4557#endif /* FF_MULTI_PARTITION */
     4558#endif /* FF_USE_MKFS && !FF_FS_READONLY */
     4559
     4560
     4561
     4562
     4563#if FF_USE_STRFUNC
    45644564/*-----------------------------------------------------------------------*/
    45654565/* Get a string from the file                                            */
     
    45794579
    45804580        while (n < len - 1) {   /* Read characters until buffer gets filled */
    4581 #if _USE_LFN && _LFN_UNICODE
    4582 #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 */
    45834583                f_read(fp, s, 1, &rc);
    45844584                if (rc != 1) break;
     
    46024602                        }
    46034603                }
    4604 #elif _STRF_ENCODE == 2         /* Read a character in UTF-16BE */
     4604#elif FF_STRF_ENCODE == 2               /* Read a character in UTF-16BE */
    46054605                f_read(fp, s, 2, &rc);
    46064606                if (rc != 2) break;
    46074607                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 */
    46094609                f_read(fp, s, 2, &rc);
    46104610                if (rc != 2) break;
     
    46274627                c = s[0];
    46284628#endif
    4629                 if (_USE_STRFUNC == 2 && c == '\r') continue;   /* Strip '\r' */
     4629                if (FF_USE_STRFUNC == 2 && c == '\r') continue; /* Strip '\r' */
    46304630                *p++ = c;
    46314631                n++;
     
    46394639
    46404640
    4641 #if !_FS_READONLY
     4641#if !FF_FS_READONLY
    46424642/*-----------------------------------------------------------------------*/
    46434643/* Put a character to the file                                           */
     
    46614661
    46624662
    4663         if (_USE_STRFUNC == 2 && c == '\n')      /* LF -> CRLF conversion */
     4663        if (FF_USE_STRFUNC == 2 && c == '\n')    /* LF -> CRLF conversion */
    46644664                putc_bfd(pb, '\r');
    46654665
     
    46674667        if (i < 0) return;
    46684668
    4669 #if _USE_LFN && _LFN_UNICODE
    4670 #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 */
    46714671        if (c < 0x80) {                         /* 7-bit */
    46724672                pb->buf[i++] = (BYTE)c;
     
    46804680                pb->buf[i++] = (BYTE)(0x80 | (c & 0x3F));
    46814681        }
    4682 #elif _STRF_ENCODE == 2                 /* Write a character in UTF-16BE */
     4682#elif FF_STRF_ENCODE == 2                       /* Write a character in UTF-16BE */
    46834683        pb->buf[i++] = (BYTE)(c >> 8);
    46844684        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 */
    46864686        pb->buf[i++] = (BYTE)c;
    46874687        pb->buf[i++] = (BYTE)(c >> 8);
     
    48664866        ret = f_vprintf(fp, fmt, arp);
    48674867        va_end(arp);
    4868 
     4868       
    48694869        return ret;
    48704870}
    48714871
    4872 #endif /* !_FS_READONLY */
    4873 #endif /* _USE_STRFUNC */
     4872#endif /* !FF_FS_READONLY */
     4873#endif /* FF_USE_STRFUNC */
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/ff.h

    r337 r374  
    2828#include "ffconf.h"             /* FatFs configuration options */
    2929#include "diskio.h"
    30 #if _FATFS != _FFCONF
     30#if _FATFS != FFCONF_DEF
    3131#error Wrong configuration file (ffconf.h).
    3232#endif
     
    3636/* Definitions of volume management */
    3737
    38 #if _MULTI_PARTITION            /* Multiple partition configuration */
     38#if FF_MULTI_PARTITION          /* Multiple partition configuration */
    3939typedef struct {
    4040        BYTE pd;        /* Physical drive number */
     
    5555/* Type of path name strings on FatFs API */
    5656
    57 #if _LFN_UNICODE                        /* Unicode string */
    58 #if !_USE_LFN
    59 #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.
    6060#endif
    6161#ifndef _INC_TCHAR
     
    8787        WORD    id;                             /* File system mount ID */
    8888        WORD    n_rootdir;              /* Number of root directory entries (FAT12/16) */
    89 #if _MAX_SS != _MIN_SS
     89#if FF_MAX_SS != FF_MIN_SS
    9090        WORD    ssize;                  /* Bytes per sector (512, 1024, 2048 or 4096) */
    9191#endif
    92 #if _FS_REENTRANT
    93         _SYNC_t sobj;                   /* Identifier of sync object */
    94 #endif
    95 #if !_FS_READONLY
     92#if FF_FS_REENTRANT
     93        FF_SYNC_t       sobj;                   /* Identifier of sync object */
     94#endif
     95#if !FF_FS_READONLY
    9696        DWORD   last_clust;             /* Last allocated cluster */
    9797        DWORD   free_clust;             /* Number of free clusters */
    9898#endif
    99 #if _FS_RPATH
     99#if FF_FS_RPATH
    100100        DWORD   cdir;                   /* Current directory start cluster (0:root) */
    101101#endif
     
    107107        DWORD   database;               /* Data start sector */
    108108        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) */
    110110} FATFS;
    111111
     
    124124        DWORD   clust;                  /* Current cluster of fpter (not valid when fprt is 0) */
    125125        DWORD   dsect;                  /* Sector number appearing in buf[] (0:invalid) */
    126 #if !_FS_READONLY
     126#if !FF_FS_READONLY
    127127        DWORD   dir_sect;               /* Sector number containing the directory entry */
    128128        BYTE*   dir_ptr;                /* Pointer to the directory entry in the win[] */
    129129#endif
    130 #if _USE_FASTSEEK
     130#if FF_USE_FASTSEEK
    131131        DWORD*  cltbl;                  /* Pointer to the cluster link map table (Nulled on file open) */
    132132#endif
    133 #if _FS_LOCK
     133#if FF_FS_LOCK != 0
    134134        UINT    lockid;                 /* File lock ID origin from 1 (index of file semaphore table Files[]) */
    135135#endif
    136 #if !_FS_TINY
    137         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 */
    138138#endif
    139139} FIL;
     
    141141
    142142
    143 /* Directory object structure (DIR) */
     143/* Directory object structure (FATFS_DIR) */
    144144
    145145typedef struct __dirstream {
     
    152152        BYTE*   dir;                    /* Pointer to the current SFN entry in the win[] */
    153153        BYTE*   fn;                             /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
    154 #if _FS_LOCK
     154#if FF_FS_LOCK != 0
    155155        UINT    lockid;                 /* File lock ID (index of file semaphore table Files[]) */
    156156#endif
    157 #if _USE_LFN
     157#if FF_USE_LFN
    158158        WCHAR*  lfn;                    /* Pointer to the LFN working buffer */
    159159        WORD    lfn_idx;                /* Last matched LFN index number (0xFFFF:No LFN) */
    160160#endif
    161 #if _USE_FIND
     161#if FF_USE_FIND
    162162        const TCHAR*    pat;    /* Pointer to the name matching pattern */
    163163#endif
    164 } DIR;
     164} FATFS_DIR;
    165165
    166166
     
    174174        BYTE    fattrib;                /* Attribute */
    175175        TCHAR   fname[13];              /* Short file name (8.3 format) */
    176 #if _USE_LFN
     176#if FF_USE_LFN
    177177        TCHAR*  lfname;                 /* Pointer to the LFN buffer */
    178178        UINT    lfsize;                 /* Size of LFN buffer in TCHAR */
     
    203203        FR_LOCKED,                              /* (16) The operation is rejected according to the file sharing policy */
    204204        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 */
    206206        FR_INVALID_PARAMETER    /* (19) Given parameter is invalid */
    207207} FRESULT;
     
    220220FRESULT f_truncate (FIL* fp);                                                                           /* Truncate file */
    221221FRESULT 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 */
     222FRESULT f_opendir (FATFS_DIR* dp, const TCHAR* path);                                           /* Open a directory */
     223FRESULT f_closedir (FATFS_DIR* dp);                                                                             /* Close an open directory */
     224FRESULT f_readdir (FATFS_DIR* dp, FILINFO* fno);                                                        /* Read a directory item */
     225FRESULT f_findfirst (FATFS_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern);     /* Find first file */
     226FRESULT f_findnext (FATFS_DIR* dp, FILINFO* fno);                                                       /* Find next file */
    227227FRESULT f_mkdir (const TCHAR* path);                                                            /* Create a sub directory */
    228228FRESULT f_unlink (const TCHAR* path);                                                           /* Delete an existing file or directory */
     
    270270
    271271/* RTC function */
    272 #if !_FS_READONLY && !_FS_NORTC
     272#if !FF_FS_READONLY && !FF_FS_NORTC
    273273DWORD get_fattime (void);
    274274#endif
    275275
    276276/* Unicode support functions */
    277 #if _USE_LFN                                                    /* Unicode - OEM code conversion */
     277#if FF_USE_LFN                                                  /* Unicode - OEM code conversion */
    278278WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */
    279279WCHAR ff_wtoupper (WCHAR chr);                  /* Unicode upper-case conversion */
    280 #if _USE_LFN == 3                                               /* Memory functions */
     280#if FF_USE_LFN == 3                                             /* Memory functions */
    281281void* ff_memalloc (UINT msize);                 /* Allocate memory block */
    282282void ff_memfree (void* mblock);                 /* Free memory block */
     
    285285
    286286/* Sync functions */
    287 #if _FS_REENTRANT
    288 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
     288int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
     289int ff_req_grant (FF_SYNC_t sobj);                              /* Lock sync object */
     290void ff_rel_grant (FF_SYNC_t sobj);                             /* Unlock sync object */
     291int ff_del_syncobj (FF_SYNC_t sobj);                            /* Delete a sync object */
    292292#endif
    293293
     
    304304#define FA_OPEN_EXISTING        0x00
    305305
    306 #if !_FS_READONLY
     306#if !FF_FS_READONLY
    307307#define FA_WRITE                        0x02
    308308#define FA_CREATE_NEW           0x04
    309309#define FA_CREATE_ALWAYS        0x08
    310310#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
    313314#endif
    314315
     
    341342/* Multi-byte word access macros  */
    342343
    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 */
    344345#define LD_WORD(ptr)            (WORD)(*(WORD*)(BYTE*)(ptr))
    345346#define LD_DWORD(ptr)           (DWORD)(*(DWORD*)(BYTE*)(ptr))
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/ffarch.c

    r364 r374  
    5454#include "ff.h"
    5555#include "ffarch.h"
    56 #include "util/ntstdio.h"
    57 #include "mbed_api.h"
    58 
    59 extern ntstdio_t ntstdio;
     56#include <stdio.h>
     57#include "gpio_api.h"
     58#include "rtc_api.h"
    6059
    6160enum ffarch_state_t {
     
    8584        ret2 = get_tim(&now);
    8685        if (ret2 != E_OK){
    87                 ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s",
     86                printf("[ffarch] get_tim error: %s",
    8887                        itron_strerror(ret2));
    8988                return;
     
    9998                ret = tslp_tsk(timer);
    10099                if ((ret != E_OK) && (ret != E_TMOUT)) {
    101                         ntstdio_printf(&ntstdio, "[ffarch] tslp_tsk error: %s %d",
     100                        printf("[ffarch] tslp_tsk error: %s %d",
    102101                                itron_strerror(ret), timer);
    103102                        break;
     
    106105                ret2 = get_tim(&now);
    107106                if (ret2 != E_OK) {
    108                         ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s",
     107                        printf("[ffarch] get_tim error: %s",
    109108                                itron_strerror(ret2));
    110109                        break;
     
    151150#endif
    152151        if (romdisk_init()) {
    153                 ntstdio_printf(&ntstdio, "ROM disk (0:) OK!\n");
     152                printf("ROM disk (0:) OK!\n");
    154153        }
    155154        else {
    156                 ntstdio_printf(&ntstdio, "ROM disk (0:) NG!\n");
     155                printf("ROM disk (0:) NG!\n");
    157156        }
    158157}
     
    304303        case FFS_RETRY_WAIT:
    305304                if (ffarch_retry_count == 0) {
    306                         ntstdio_printf(&ntstdio, "SD card (1:) initialize tired...\n");
     305                        printf("SD card (1:) initialize tired...\n");
    307306
    308307                        ffarch_state = FFS_IDLE;
     
    316315                /* SDカードが入れられた場合 */
    317316                if (((mmc_rspi_prev_status & STA_NODISK) != 0) && ((mmc_rspi_status() & STA_NODISK) == 0)) {
    318                         ntstdio_printf(&ntstdio, "SD card initializing ...\n");
     317                        printf("SD card initializing ...\n");
    319318
    320319                        Sd.FatFs.fs_type = 0;
    321320                        if (SD_begin()) {
    322                                 ntstdio_printf(&ntstdio, "SD card (1:) OK!\n");
     321                                printf("SD card (1:) OK!\n");
    323322
    324323                                /* uploadディレクトリを作成しておく */
     
    330329                        }
    331330                        else {
    332                                 ntstdio_printf(&ntstdio, "SD card (1:) NG!\n");
     331                                printf("SD card (1:) NG!\n");
    333332                                ffarch_state = FFS_RETRY_WAIT;
    334333                                ffarch_timer = 1000 * 1000;
     
    337336                /* SDカードが抜かれた場合 */
    338337                else if (((mmc_rspi_prev_status & STA_NODISK) == 0) && ((mmc_rspi_status() & STA_NODISK) != 0)) {
    339                         ntstdio_printf(&ntstdio, "SD card unmount\n");
     338                        printf("SD card unmount\n");
    340339
    341340                        f_mount(&Sd.FatFs, "1:", 0);
     
    349348}
    350349
    351 int ff_cre_syncobj(BYTE vol, _SYNC_t* sobj)
     350int ff_cre_syncobj(BYTE vol, FF_SYNC_t* sobj)
    352351{
    353352        return 1;
    354353}
    355354
    356 int ff_req_grant(_SYNC_t sobj)
     355int ff_req_grant(FF_SYNC_t sobj)
    357356{
    358357        ER ret;
     
    361360}
    362361
    363 void ff_rel_grant(_SYNC_t sobj)
     362void ff_rel_grant(FF_SYNC_t sobj)
    364363{
    365364        sig_sem(SEM_FILESYSTEM);
    366365}
    367366
    368 int ff_del_syncobj(_SYNC_t sobj)
     367int ff_del_syncobj(FF_SYNC_t sobj)
    369368{
    370369        return 1;
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/ffconf.h

    r337 r374  
    33/---------------------------------------------------------------------------*/
    44
    5 #define _FFCONF 64180   /* Revision ID */
     5#define FFCONF_DEF 64180        /* Revision ID */
     6
     7#define FFS_DBG                 0
    68
    79/*---------------------------------------------------------------------------/
     
    911/---------------------------------------------------------------------------*/
    1012
    11 #define _FS_READONLY    0
     13#define FF_FS_READONLY  0
    1214/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
    1315/  Read-only configuration removes writing API functions, f_write(), f_sync(),
     
    1618
    1719
    18 #define _FS_MINIMIZE    0
     20#define FF_FS_MINIMIZE  0
    1921/* This option defines minimization level to remove some basic API functions.
    2022/
     
    2628
    2729
    28 #define _USE_STRFUNC    1
     30#define FF_USE_STRFUNC  1
    2931/* This option switches string functions, f_gets(), f_putc(), f_puts() and
    3032/  f_printf().
     
    3537
    3638
    37 #define _USE_FIND               1
     39#define FF_USE_FIND             1
    3840/* This option switches filtered directory read feature and related functions,
    3941/  f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
    4042
    4143
    42 #define _USE_MKFS               1
     44#define FF_USE_MKFS             1
    4345/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
    4446
    4547
    46 #define _USE_FASTSEEK   0
     48#define FF_USE_FASTSEEK 0
    4749/* This option switches fast seek feature. (0:Disable or 1:Enable) */
    4850
    4951
    50 #define _USE_LABEL              1
     52#define FF_USE_LABEL            1
    5153/* This option switches volume label functions, f_getlabel() and f_setlabel().
    5254/  (0:Disable or 1:Enable) */
    5355
    5456
    55 #define _USE_FORWARD    1
     57#define FF_USE_FORWARD  1
    5658/* 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. */
    5860
    5961
     
    6264/---------------------------------------------------------------------------*/
    6365
    64 #define _CODE_PAGE 65001
     66#define FF_CODE_PAGE 65001
    6567/* This option specifies the OEM code page to be used on the target system.
    6668/  Incorrect setting of the code page can cause a file open failure.
     
    9193
    9294
    93 #define _USE_LFN        3
    94 #define _MAX_LFN        255
    95 /* 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.
    98100/   1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
    99101/   2: Enable LFN with dynamic working buffer on the STACK.
     
    101103/
    102104/  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.
    104106/  When use stack for the working buffer, take care on stack overflow. When use heap
    105107/  memory for the working buffer, memory management functions, ff_memalloc() and
     
    107109
    108110
    109 #define _LFN_UNICODE    0
     111#define FF_LFN_UNICODE  0
    110112/* 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_UNICODE
     113/  To use Unicode string for the path name, enable LFN feature and set FF_LFN_UNICODE
    112114/  to 1. This option also affects behavior of string I/O functions. */
    113115
    114116
    115 #define _STRF_ENCODE    3
    116 /* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
     117#define FF_STRF_ENCODE  3
     118/* When FF_LFN_UNICODE is 1, this option selects the character encoding on the file to
    117119/  be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
    118120/
     
    122124/  3: UTF-8
    123125/
    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
    128138/* This option configures relative path feature.
    129139/
     
    139149/---------------------------------------------------------------------------*/
    140150
    141 #define _VOLUMES        2
     151#define FF_VOLUMES      4
    142152/* Number of volumes (logical drives) to be used. */
    143153
    144154
    145 #define _STR_VOLUME_ID  0
    146 #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 drive
    149 /  number in the path name. _VOLUME_STRS defines the drive ID strings for each
    150 /  logical drives. Number of items must be equal to _VOLUMES. Valid characters for
     155#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
    151161/  the drive ID strings are: A-Z and 0-9. */
    152162
    153163
    154 #define _MULTI_PARTITION        0
     164#define FF_MULTI_PARTITION      0
    155165/* This option switches multi-partition feature. By default (0), each logical drive
    156166/  number is bound to the same physical drive number and only an FAT volume found on
     
    160170
    161171
    162 #define _MIN_SS         512
    163 #define _MAX_SS         512
     172#define FF_MIN_SS               512
     173#define FF_MAX_SS               512
    164174/* These options configure the range of sector size to be supported. (512, 1024,
    165175/  2048 or 4096) Always set both 512 for most systems, all type of memory cards and
    166176/  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 configured
     177/  type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
    168178/  to variable sector size and GET_SECTOR_SIZE command must be implemented to the
    169179/  disk_ioctl() function. */
    170180
    171181
    172 #define _USE_TRIM       0
     182#define FF_USE_TRIM     0
    173183/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
    174184/  To enable Trim feature, also CTRL_TRIM command should be implemented to the
     
    176186
    177187
    178 #define _FS_NOFSINFO    0
     188#define FF_FS_NOFSINFO  0
    179189/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
    180190/  option, and f_getfree() function at first time after volume mount will force
     
    193203/---------------------------------------------------------------------------*/
    194204
    195 #define _FS_TINY        1
     205#define FF_FS_TINY      1
    196206/* 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_SS
     207/  At the tiny configuration, size of the file object (FIL) is reduced FF_MAX_SS
    198208/  bytes. Instead of private sector buffer eliminated from the file object,
    199209/  common sector buffer in the file system object (FATFS) is used for the file
     
    201211
    202212
    203 #define _FS_NORTC       0
    204 #define _NORTC_MON      1
    205 #define _NORTC_MDAY     1
    206 #define _NORTC_YEAR     2015
    207 /* The _FS_NORTC option switches timestamp feature. If the system does not have
    208 /  an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable
     213#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
    209219/  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 need
    212 /  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        0
    218 /* The _FS_LOCK option switches file lock feature to control duplicated file open
    219 /  and illegal operation to open objects. This option must be 0 when _FS_READONLY
     220/  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,
     223FF_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
    220230/  is 1.
    221231/
     
    227237
    228238
    229 #define _FS_REENTRANT   1
    230 #define _FS_TIMEOUT             1000
    231 #define _SYNC_t                 unsigned int
    232 /* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
     239#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
    233243/  module itself. Note that regardless of this option, file access to different
    234244/  volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
     
    236246/  to the same volume is under control of this feature.
    237247/
    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.
    239249/   1: Enable re-entrancy. Also user provided synchronization handlers,
    240250/      ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
     
    242252/      option/syscall.c.
    243253/
    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*,
    246256/  SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be
    247257/  included somewhere in the scope of ff.c. */
    248258
    249259
    250 #define _WORD_ACCESS    1
    251 /* The _WORD_ACCESS option is an only platform dependent option. It defines
     260#define FF_WORD_ACCESS  1
     261/* The FF_WORD_ACCESS option is an only platform dependent option. It defines
    252262/  which access method is used to the word data on the FAT volume.
    253263/
     
    258268/  * Byte order on the memory is little-endian.
    259269/
    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.
    261271/  Following table shows allowable settings of some type of processors.
    262272/
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/mmc_rspi.c

    r359 r374  
    663663                break;
    664664
    665         case CTRL_TRIM: /* Erase a block of sectors (used when _USE_TRIM == 1) */
     665        case CTRL_TRIM: /* Erase a block of sectors (used when FF_USE_TRIM == 1) */
    666666                if (!(CardType & CT_SDC)) break;                                /* Check if the card is SDC */
    667667                if (mmc_rspi_ioctl(MMC_GET_CSD, csd)) break;    /* Get CSD */
  • asp3_tinet_ecnl_rx/trunk/ntshell/ntshell/usrcmd.c

    r340 r374  
    4747#include "core/ntshell.h"
    4848#include "core/ntlibc.h"
    49 #include "util/ntstdio.h"
    50 
    51 extern ntstdio_t ntstdio;
     49#include <stdio.h>
     50#include <getopt.h>
     51
    5252extern 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 }
    16753
    16854void put_rc(const char *func, FRESULT rc)
     
    17864                while (*p++);
    17965        }
    180         ntstdio_printf(&ntstdio, "%s() =>%u FR_%s\n", func, (UINT)rc, p);
     66        printf("%s() =>%u FR_%s\n", func, (UINT)rc, p);
    18167}
    18268
     
    19076                while (*p++);
    19177        }
    192         ntstdio_printf(&ntstdio, "%s() =>%u %s\n", func, (UINT)rc, p);
     78        printf("%s() =>%u %s\n", func, (UINT)rc, p);
    19379}
    19480
     
    240126
    241127        ntlibc_strlcat(path, "\n", sizeof(path));
    242         ntstdio_printf(&ntstdio, path);
     128        printf(path);
    243129
    244130        return 0;
     
    252138        char *fn;
    253139
    254 #if _USE_LFN
     140#if FF_USE_LFN
    255141        fn = *fno->lfname ? fno->lfname : fno->fname;
    256142#else
     
    263149
    264150        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 ",
    266152                        (fno->fattrib & AM_DIR) ? 'd' : '-',
    267153                        (fno->fattrib & AM_RDO) ? 'r' : '-',
     
    277163
    278164                if (fno->fattrib & AM_DIR) {                    /* It is a directory */
    279                         ntstdio_printf(&ntstdio, "%10S ", " ");
     165                        printf("%10s ", " ");
    280166                }
    281167                else {
    282                         ntstdio_printf(&ntstdio, "%10d ", fno->fsize);
     168                        printf("%10lu ", fno->fsize);
    283169                }
    284170        }
    285171
    286172        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);
    288174        }
    289175        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)
    295181/* lsコマンド dir内 表示 */
    296182void print_ls(char *path_p, char *pattern_p, BYTE list_option)
     
    298184        FRESULT res;
    299185        FILINFO fno;
    300         DIR dir;
     186        FATFS_DIR dir;
    301187        char *fn;   /* This function assumes non-Unicode configuration */
    302188
     
    307193        path_backup = ff_memalloc(LFN_BUF_SIZE);
    308194        if (path_backup == NULL) {
    309                 ntstdio_printf(&ntstdio, "ff_memalloc err.\n");
     195                printf("ff_memalloc err.\n");
    310196                return;
    311197        }
    312198
    313 #if _USE_LFN
     199#if FF_USE_LFN
    314200        char *lfn = NULL;
    315201        lfn = ff_memalloc(LFN_BUF_SIZE);
    316202        if (lfn == NULL) {
    317                 ntstdio_printf(&ntstdio, "ff_memalloc err.\n");
     203                printf("ff_memalloc err.\n");
    318204                ff_memfree(path_backup);
    319205                return;
     
    333219
    334220        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_LFN
     221                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
    337223                        fn = *fno.lfname ? fno.lfname : fno.fname;
    338224#else
     
    351237                        }
    352238
    353                         ntstdio_printf(&ntstdio, "\n%s/%s:\n", path_p, fn);
     239                        printf("\n%s/%s:\n", path_p, fn);
    354240
    355241                        print_ls(fn, NULL, list_option);
    356242
    357                         ntstdio_printf(&ntstdio, "\n");
     243                        printf("\n");
    358244
    359245                        if ((res = f_chdrive(path_backup)) != FR_OK) {
     
    384270{
    385271        char *pattern_p = NULL, *basename_p = NULL, *dirname_p = NULL;
    386         char default_pattern[_MAX_LFN] = "";
     272        char default_pattern[FF_MAX_LFN] = "";
    387273        int c;
    388274        BYTE list_option = 0;
    389275
    390         while ((c = musl_getopt(argc, argv, "al")) != -1) {
     276        while ((c = getopt(argc, argv, "al")) != -1) {
    391277                switch (c) {
    392278                case 'a':
     
    446332                return 0;
    447333
    448 #if _USE_LFN
     334#if FF_USE_LFN
    449335        /* LFN buffer alloc */
    450336        lfn = ff_memalloc(LFN_BUF_SIZE);
    451337        if (lfn == NULL) {
    452                 ntstdio_printf(&ntstdio, "alloc err.\n");
     338                printf("alloc err.\n");
    453339                goto cp_end;
    454340        }
     
    460346        local_buff = ff_memalloc(64);
    461347        if (local_buff == NULL) {
    462                 ntstdio_printf(&ntstdio, "alloc err.\n");
     348                printf("alloc err.\n");
    463349                goto cp_end;
    464350        }
     
    470356        if (res != FR_OK) {
    471357                if (res == FR_NO_FILE)
    472                         ntstdio_printf(&ntstdio, "src no file.\n", res);
     358                        printf("src no file.\n");
    473359                else
    474                         ntstdio_printf(&ntstdio, "src stat err(%d).\n", res);
     360                        printf("src stat err(%d).\n", res);
    475361                goto cp_end;
    476362        }
     
    481367                res = f_open(&src_fp, src_str_p, (FA_OPEN_EXISTING | FA_READ));
    482368                if (res != FR_OK) {
    483                         ntstdio_printf(&ntstdio, "src open err(%d).\n", res);
     369                        printf("src open err(%d).\n", res);
    484370                        goto cp_end;
    485371                }
     
    496382                                dst_mod_str_p = ff_memalloc(LFN_BUF_SIZE);
    497383                                if (dst_mod_str_p == NULL) {
    498                                         ntstdio_printf(&ntstdio, "alloc err.\n");
     384                                        printf("alloc err.\n");
    499385                                        goto cp_end;
    500386                                }
    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);
    502388                                dst_str_p = dst_mod_str_p;
    503389                        }
    504390                        else {
    505                                 ntstdio_printf(&ntstdio, "dst file exists.\n");
     391                                printf("dst file exists.\n");
    506392                                goto cp_end_1;
    507393                        }
    508394                }
    509395                else {
    510                         ntstdio_printf(&ntstdio, "src stat err(%d).\n", res);
     396                        printf("src stat err(%d).\n", res);
    511397                        goto cp_end_1;
    512398                }
     
    514400        res = f_open(&dst_fp, dst_str_p, (FA_CREATE_NEW | FA_WRITE));
    515401        if (res != FR_OK) {
    516                 ntstdio_printf(&ntstdio, "dst open err(%d).\n", res);
     402                printf("dst open err(%d).\n", res);
    517403                goto cp_end_1;
    518404        }
     
    525411                res = f_read(&src_fp, local_buff, sizeof(local_buff), &read_size);
    526412                if (res != FR_OK) {
    527                         ntstdio_printf(&ntstdio, "src read err(%d).\n", res);
     413                        printf("src read err(%d).\n", res);
    528414                        goto cp_end_2;
    529415                }
     
    532418                res = f_write(&dst_fp, local_buff, read_size, &write_size);
    533419                if (res != FR_OK) {
    534                         ntstdio_printf(&ntstdio, "dst write err(%d).\n", res);
     420                        printf("dst write err(%d).\n", res);
    535421                        goto cp_end_2;
    536422                }
    537423                if (read_size != write_size) {
    538                         ntstdio_printf(&ntstdio, "dst write err(disk full).\n", res);
     424                        printf("dst write err(disk full).\n");
    539425                        goto cp_end_2;
    540426                }
     
    622508        unsigned int op_offset = 0, op_size = 0, op_end = 0;
    623509
    624         while ((op = musl_getopt(argc, argv, "hduos0123456789xX")) != -1) {
     510        while ((op = getopt(argc, argv, "hduos0123456789xX")) != -1) {
    625511                switch (op) {
    626512                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");
    633519                        break;
    634520                case 'd': /* print one byte character [in character area] (default) */
     
    661547        /* position adjusting */
    662548        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);
    664550                return 0;
    665551        }
     
    674560                char *pos = line;
    675561                int rst = sizeof(line);
    676                 int len = ntstdio_snprintf(pos, rst, "%08X: ", i);
     562                int len = snprintf(pos, rst, "%08X: ", i);
    677563                pos += len;
    678564                rst -= len;
     
    693579                        char c = data[j];
    694580                        if (j != 7)
    695                                 len = ntstdio_snprintf(pos, rst, "%02X ", c);
     581                                len = snprintf(pos, rst, "%02X ", c);
    696582                        else
    697                                 len = ntstdio_snprintf(pos, rst, "%02X-", c);
     583                                len = snprintf(pos, rst, "%02X-", c);
    698584                        pos += len;
    699585                        rst -= len;
     
    723609                                                                break;
    724610                                                        if (j + k != 7)
    725                                                                 len = ntstdio_snprintf(pos, rst, "%02X ", data[j + k]);
     611                                                                len = snprintf(pos, rst, "%02X ", data[j + k]);
    726612                                                        else
    727                                                                 len = ntstdio_snprintf(pos, rst, "%02X-", data[j + k]);
     613                                                                len = snprintf(pos, rst, "%02X-", data[j + k]);
    728614                                                        pos += len;
    729615                                                        rst -= len;
     
    743629                                apos += len;
    744630                                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, ' ');
    746632                                utf8_odd_bytes--;
    747633                        }
     
    763649                                        c = '?';
    764650                                }
    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);
    766652                        }
    767653
     
    772658                for (int j = br; j < 16; j++) {
    773659                        if (j != 7)
    774                                 len = ntstdio_snprintf(pos, rst, "   ");
     660                                len = snprintf(pos, rst, "   ");
    775661                        else
    776                                 len = ntstdio_snprintf(pos, rst, "  -");
     662                                len = snprintf(pos, rst, "  -");
    777663                        pos += len;
    778664                        rst -= len;
    779665                }
    780666
    781                 len = ntstdio_snprintf(pos, rst, ": %s\n", ascii);
     667                len = snprintf(pos, rst, ": %s\n", ascii);
    782668                pos += len;
    783669                rst -= len;
    784670
    785                 ntstdio_puts(&ntstdio, line);
     671                puts(line);
    786672        }
    787673
     
    796682        char buf[30];
    797683
    798         ret = shell_clock_gettime(CLOCK_REALTIME, &tp);
     684        ret = clock_gettime(CLOCK_REALTIME, &tp);
    799685        if (ret != 0) {
    800                 ntstdio_printf(&ntstdio, "clock_gettime error %d", ret);
     686                printf("clock_gettime error %d", ret);
    801687                return 0;
    802688        }
     
    804690        memset(buf, 0, sizeof(buf));
    805691        if (ctime_r(&tp.tv_sec, buf) == NULL) {
    806                 ntstdio_printf(&ntstdio, "ctime_r error");
     692                printf("ctime_r error");
    807693                return 0;
    808694        }
     
    812698        buf[ret - 1] = '\0';
    813699
    814         ntstdio_printf(&ntstdio, "%s .%09u\n", buf, tp.tv_nsec);
     700        printf("%s .%09ld\n", buf, tp.tv_nsec);
    815701        return 0;
    816702}
     
    819705{
    820706        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");
    823709                return 0;
    824710        }
    825711        if (strcmp(argv[1], "sys") == 0) {
    826                 ntstdio_printf(&ntstdio, TARGET_NAME" Monitor\n");
     712                printf(TARGET_NAME" Monitor\n");
    827713                return 0;
    828714        }
     
    830716                int mj, mn, bd;
    831717                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");
    836722        return -1;
    837723}
  • asp3_tinet_ecnl_rx/trunk/ntshell/ntshell/usrcmd.h

    r340 r374  
    5656int usrcmd_exit(int argc, char **argv);
    5757
    58 void shell_abort();
    59 void shell_exit(int exitcd);
    60 int shell_kill(int pid, int sig);
    61 
    6258#endif
    6359
  • asp3_tinet_ecnl_rx/trunk/ntshell/ntshell/util/ntstdio.h

    r337 r374  
    7878        int pos;
    7979        unsigned int option;
     80        void *exinf;
    8081} ntstdio_t;
    8182
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/fdtable.c

    r364 r374  
    6868#include "kernel_cfg.h"
    6969#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
     73static int stdio_close(struct SHELL_FILE *fp);
     74static size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     75static size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     76static size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     77static size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     78static size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     79static void stdio_delete(struct SHELL_FILE *fp);
     80
     81static int sio_close(struct SHELL_FILE *fp);
     82static size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     83static size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     84static off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org);
     85static int sio_ioctl(struct SHELL_FILE *fp, int req, void *arg);
     86static bool_t sio_readable(struct SHELL_FILE *fp);
     87static void sio_delete(struct SHELL_FILE *fp);
     88
     89IO_TYPE IO_TYPE_STDIN = { stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
     90IO_TYPE IO_TYPE_STDOUT = { stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
     91IO_TYPE IO_TYPE_STDERR = { stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
     92IO_TYPE IO_TYPE_SIO = { sio_close, sio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_delete };
     93ntstdio_t ntstdio;
     94
     95static struct SHELL_FILE fd_table[8 * sizeof(FLGPTN)] = {
     96        { 0, &IO_TYPE_STDIN, 0, .exinf = &ntstdio },
     97        { 1, &IO_TYPE_STDOUT, 0, .exinf = &ntstdio },
     98        { 2, &IO_TYPE_STDERR, 0,.exinf = &ntstdio },
    8299};
    83100#define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0]))
    84101
    85 static int new_fd(int type, int id)
    86 {
     102extern ntstdio_t ntstdio;
     103serial_t stdio_uart;
     104
     105unsigned char ntstdio_xi(struct ntstdio_t *handle)
     106{
     107        return serial_getc((serial_t *)handle->exinf);
     108}
     109
     110void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
     111{
     112        serial_putc((serial_t *)handle->exinf, c);
     113}
     114
     115void sys_init(intptr_t exinf)
     116{
     117        sys_tlsf_init();
     118
     119        serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
     120        serial_baud(&stdio_uart, UART_BAUDRATE);
     121        serial_format(&stdio_uart, 8, ParityNone, 1);
     122
     123        ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
     124        ntstdio.exinf = (void *)&stdio_uart;
     125}
     126
     127int stdio_close(struct SHELL_FILE *fp)
     128{
     129        return -EPERM;
     130}
     131
     132size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
     133{
     134        return -EPERM;
     135}
     136
     137size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
     138{
     139        return -EPERM;
     140}
     141
     142size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
     143{
     144        int i = 0;
     145        while (i < len) {
     146                int c = ntstdio_getc((struct ntstdio_t *)fp->exinf);
     147                data[i++] = c;
     148                if ((c == EOF) || (c == '\n'))
     149                        break;
     150        }
     151        return i;
     152}
     153
     154size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
     155{
     156        for (int i = 0; i < len; i++) {
     157                ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
     158        }
     159        return len;
     160}
     161
     162size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
     163{
     164        for (int i = 0; i < len; i++) {
     165                ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
     166        }
     167        return len;
     168}
     169
     170void stdio_delete(struct SHELL_FILE *fp)
     171{
     172}
     173
     174int sio_close(struct SHELL_FILE *fp)
     175{
     176        return -EPERM;
     177}
     178
     179size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
     180{
     181        return -EPERM;
     182}
     183
     184size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
     185{
     186        return -EPERM;
     187}
     188
     189off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org)
     190{
     191        return -EPERM;
     192}
     193
     194int sio_ioctl(struct SHELL_FILE *fp, int request, void *arg)
     195{
     196        switch (request) {
     197        case TIOCGWINSZ:
     198                return 0;
     199        case TCGETS:
     200                return sio_tcgetattr(fp->fd, (struct termios *)arg);
     201        case TCSETS + TCSANOW:
     202        case TCSETS + TCSADRAIN:
     203        case TCSETS + TCSAFLUSH:
     204                return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
     205        }
     206
     207        return -EINVAL;
     208}
     209
     210bool_t sio_readable(struct SHELL_FILE *fp)
     211{
     212        return fp->readevt_w != fp->readevt_r;
     213}
     214
     215void sio_delete(struct SHELL_FILE *fp)
     216{
     217        free((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf);
     218        ((struct ntstdio_t *)fp->exinf)->exinf = NULL;
     219        free((struct ntstdio_t *)fp->exinf);
     220        fp->exinf = NULL;
     221}
     222
     223struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable)
     224{
     225        struct SHELL_FILE *fp = NULL;
     226        ER ret;
     227
     228        ret = wai_sem(SEM_FILEDESC);
     229        if (ret < 0) {
     230                syslog(LOG_ERROR, "wai_sem => %d", ret);
     231        }
     232
    87233        for (int fd = 3; fd < fd_table_count; fd++) {
    88                 struct _IO_FILE *fp = &fd_table[fd];
    89                 if (fp->type != IO_TYPE_FREE)
     234                fp = &fd_table[fd];
     235                if (fp->type != NULL)
    90236                        continue;
    91237
    92                 memset(fp, 0, sizeof(struct _IO_FILE));
     238                memset(fp, 0, sizeof(struct SHELL_FILE));
    93239                fp->fd = fd;
    94240                fp->type = type;
    95241                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 {
     242                fp->writable = writable;
     243                break;
     244        }
     245
     246        ret = sig_sem(SEM_FILEDESC);
     247        if (ret < 0) {
     248                syslog(LOG_ERROR, "sig_sem => %d", ret);
     249        }
     250
     251        return fp;
     252}
     253
     254struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id)
     255{
     256        struct SHELL_FILE *fp = NULL;
     257        ER ret;
     258
     259        ret = wai_sem(SEM_FILEDESC);
     260        if (ret < 0) {
     261                syslog(LOG_ERROR, "wai_sem => %d", ret);
     262        }
     263
    104264        for (int fd = 3; fd < fd_table_count; fd++) {
    105                 struct _IO_FILE *fp = &fd_table[fd];
     265                fp = &fd_table[fd];
    106266                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);
     267                        break;
     268        }
     269
     270        ret = sig_sem(SEM_FILEDESC);
     271        if (ret < 0) {
     272                syslog(LOG_ERROR, "sig_sem => %d", ret);
     273        }
     274
     275        return fp;
     276}
     277
     278int delete_fd_by_id(IO_TYPE *type, int id)
     279{
     280        struct SHELL_FILE *fp = id_to_fd(type, id);
    116281        if (fp == NULL)
    117282                return -EBADF;
     
    120285}
    121286
    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));
     287int delete_fp(struct SHELL_FILE *fp)
     288{
     289        ER ret;
     290
     291        fp->type->delete(fp);
     292
     293        ret = wai_sem(SEM_FILEDESC);
     294        if (ret < 0) {
     295                syslog(LOG_ERROR, "wai_sem => %d", ret);
     296        }
     297
     298        memset(fp, 0, sizeof(struct SHELL_FILE));
     299
     300        ret = sig_sem(SEM_FILEDESC);
     301        if (ret < 0) {
     302                syslog(LOG_ERROR, "sig_sem => %d", ret);
     303        }
    131304
    132305        return 0;
    133306}
    134307
    135 struct _IO_FILE *fd_to_fp(int fd)
     308struct SHELL_FILE *fd_to_fp(int fd)
    136309{
    137310        if ((fd < 0) || (fd >= fd_table_count))
     
    140313}
    141314
    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)
     315void memand(void *dst, void *src, size_t len)
    289316{
    290317        uint8_t *d = (uint8_t *)dst;
     
    293320
    294321        while (s < e) {
    295                 *d++ |= *s++;
     322                *d++ &= *s++;
    296323        }
    297324}
     
    336363
    337364        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));
    344365        if (ret == E_OK) {
    345366                if (rfds != NULL)
    346                         memor(rfds, &evts.readfds, sizeof(fd_set));
     367                        memand(rfds, &evts.readfds, sizeof(fd_set));
    347368                if (wfds != NULL)
    348                         memor(wfds, &evts.writefds, sizeof(fd_set));
     369                        memand(wfds, &evts.writefds, sizeof(fd_set));
    349370                if (efds != NULL)
    350                         memor(efds, &evts.errorfds, sizeof(fd_set));
     371                        memand(efds, &evts.errorfds, sizeof(fd_set));
    351372                return evts.count;
    352373        }
    353374        if (ret == E_TMOUT) {
     375                if (rfds != NULL)
     376                        memset(rfds, 0, sizeof(fd_set));
     377                if (wfds != NULL)
     378                        memset(wfds, 0, sizeof(fd_set));
     379                if (efds != NULL)
     380                        memset(efds, 0, sizeof(fd_set));
    354381                return 0;
    355382        }
     
    419446{
    420447        int fd = STDIN_FILENO;
    421         struct _IO_FILE *fp = &fd_table[fd];
    422         T_SERIAL_RPOR rpor;
     448        struct SHELL_FILE *fp = &fd_table[fd];
    423449        FLGPTN flgptn = 0;
    424450
    425         ER ret = serial_ref_por(SIO_PORTID, &rpor);
    426         if (ret != E_OK)
    427                 return;
    428 
    429         if (rpor.reacnt != 0) {
     451        if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
    430452                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
    431453
    432454                FD_SET(fd, (fd_set *)&flgptn);
    433455        }
    434         if (rpor.wricnt != 0) {
     456        if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
    435457                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
    436458
     
    447469{
    448470        int fd = STDIN_FILENO;
    449         struct _IO_FILE *fp = &fd_table[fd];
    450         T_SERIAL_RPOR rpor;
     471        struct SHELL_FILE *fp = &fd_table[fd];
    451472        *flgptn = 0;
    452473
    453         ER ret = serial_ref_por(SIO_PORTID, &rpor);
    454         if (ret != E_OK)
    455                 return;
    456 
    457         if (rpor.reacnt != 0) {
     474        if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
    458475                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
    459476
    460477                FD_SET(fd, (fd_set *)flgptn);
    461478        }
    462         if (rpor.wricnt != 0) {
     479        if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
    463480                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
    464481
     
    466483        }
    467484}
    468 
    469 #ifndef NTSHELL_NO_SOCKET
    470 
    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 #endif
    633485
    634486ER shell_get_evts(struct fd_events *evts, TMO tmout)
     
    642494                ER ret;
    643495                FLGPTN waitptn, flgptn, readfds = 0, writefds = 0;
    644                 struct _IO_FILE *fp = NULL;
     496                struct SHELL_FILE *fp = NULL;
    645497
    646498                stdio_update_evts();
     
    656508#ifndef NTSHELL_NO_SOCKET
    657509                        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                                         }
     510                                if (fp->type->readable(fp)) {
     511                                        FD_SET(fd, (fd_set *)&readfds);
     512                                        count++;
     513                                        if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
    690514                                }
    691515                                else {
     
    786610void clean_fd()
    787611{
    788         struct _IO_FILE *fp = NULL;
     612        struct SHELL_FILE *fp = NULL;
    789613        for (int fd = 3; fd < fd_table_count; fd++) {
    790614                fp = &fd_table[fd];
     
    792616                        continue;
    793617
    794                 fp->close(fp);
     618                fp->type->close(fp);
    795619
    796620                delete_fp(fp);
     
    800624int shell_ioctl(int fd, int request, void *arg)
    801625{
    802         struct _IO_FILE *fp = fd_to_fp(fd);
     626        struct SHELL_FILE *fp = fd_to_fp(fd);
    803627        if (fp == NULL)
    804628                return -EBADF;
    805629
    806         return fp->ioctl(fp, request, arg);
     630        return fp->type->ioctl(fp, request, arg);
    807631}
    808632
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/io_stub.c

    r337 r374  
    11/*
    22 *  TOPPERS ECHONET Lite Communication Middleware
    3  * 
     3 *
    44 *  Copyright (C) 2017 Cores Co., Ltd. Japan
    5  * 
     5 *
    66 *  上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
    77 *  ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
     
    2626 *      由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
    2727 *      免責すること.
    28  * 
     28 *
    2929 *  本ソフトウェアは,無保証で提供されているものである.上記著作権者お
    3030 *  よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
     
    3232 *  アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
    3333 *  の責任を負わない.
    34  * 
     34 *
    3535 *  @(#) $Id$
    3636 */
     
    4343#include <sil.h>
    4444#include <string.h>
     45#include "syssvc/serial.h"
    4546#include "syssvc/syslog.h"
    4647#include "socket_stub.h"
     
    4950#include "core/ntlibc.h"
    5051#include "kernel_cfg.h"
     52#include "target_syssvc.h"
    5153
    5254int fresult2errno(FRESULT res)
     
    7779}
    7880
    79 int shell_open(const char * path, int flags, void *arg)
    80 {
    81         FRESULT res;
    82         struct _IO_FILE *fp;
     81static int file_close(struct SHELL_FILE *fp);
     82static size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     83static size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     84static off_t file_seek(struct SHELL_FILE *fp, off_t ofs, int org);
     85static int file_ioctl(struct SHELL_FILE *fp, int req, void *arg);
     86static bool_t file_readable(struct SHELL_FILE *fp);
     87static void file_delete(struct SHELL_FILE *fp);
     88
     89static int dir_close(struct SHELL_FILE *fp);
     90static size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     91static size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     92static off_t dir_seek(struct SHELL_FILE *fp, off_t ofs, int org);
     93static int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg);
     94static bool_t dir_readable(struct SHELL_FILE *fp);
     95static void dir_delete(struct SHELL_FILE *fp);
     96
     97IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_delete };
     98IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_delete };
     99
     100int shell_open(const char *path, int flags, void *arg)
     101{
     102        FRESULT res;
     103        struct SHELL_FILE *fp;
    83104
    84105        if (flags & O_DIRECTORY) {
    85                 fp = new_dir_fd(0);
     106                fp = new_fp(&IO_TYPE_DIR, 0, 0);
    86107                if (fp == NULL)
    87108                        return -ENOMEM;
    88109
    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;
    90114                FRESULT res;
    91115                if ((res = f_opendir(dir, path)) != FR_OK) {
     
    95119        }
    96120
    97         fp = new_file_fd(0);
     121        fp = new_fp(&IO_TYPE_FILE, 0, 1);
    98122        if (fp == NULL)
    99123                return -ENOMEM;
     124
     125        fp->exinf = malloc(sizeof(FIL));
     126        memset(fp->exinf, 0, sizeof(FIL));
    100127
    101128        BYTE fmd = 0;
     
    133160        }
    134161
    135         if ((res = f_open(fp->pfile, path, fmd)) == FR_OK) {
     162        if ((res = f_open((FIL *)fp->exinf, path, fmd)) == FR_OK) {
    136163                fp->handle = fp->fd;
    137164                return fp->fd;
     
    141168}
    142169
    143 int file_close(struct _IO_FILE *fp)
    144 {
    145         FRESULT res;
    146 
    147         if ((res = f_close(fp->pfile)) == FR_OK) {
     170int file_close(struct SHELL_FILE *fp)
     171{
     172        FRESULT res;
     173
     174        if ((res = f_close((FIL *)fp->exinf)) == FR_OK) {
    148175                return 0;
    149176        }
     
    152179}
    153180
    154 size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
     181size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
    155182{
    156183        unsigned int ret = 0;
    157184        FRESULT res;
    158185
    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)
    160187                return -EIO;
    161188
     
    163190}
    164191
    165 size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
     192size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
    166193{
    167194        unsigned int ret = 0;
    168195        FRESULT res;
    169196
    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)
    171198                return -EIO;
    172199
     
    174201}
    175202
    176 off_t file_seek(struct _IO_FILE *fp, off_t ptr, int dir)
     203off_t file_seek(struct SHELL_FILE *fp, off_t ptr, int dir)
    177204{
    178205        switch (dir) {
     
    191218
    192219        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)
    194221                return -EIO;
    195222
    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
     226int file_ioctl(struct SHELL_FILE *fp, int req, void *arg)
    200227{
    201228        DRESULT res;
    202229
    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))
    204231                return -EINVAL;
    205232
     
    207234}
    208235
     236bool_t file_readable(struct SHELL_FILE *fp)
     237{
     238        return fp->readevt_w != fp->readevt_r;
     239}
     240
     241void file_delete(struct SHELL_FILE *fp)
     242{
     243        free((FIL *)fp->exinf);
     244        fp->exinf = NULL;
     245}
     246
    209247int shell_close(int fd)
    210248{
    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);
    216254
    217255        delete_fp(fp);
     
    222260ssize_t shell_read(int fd, void *data, size_t len)
    223261{
    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);
    229267}
    230268
     
    232270{
    233271        int result = 0;
    234         struct _IO_FILE *fp = fd_to_fp(fd);
     272        struct SHELL_FILE *fp = fd_to_fp(fd);
    235273        if (fp == NULL)
    236274                return -EBADF;
     
    238276        const struct iovec *end = &iov[iovcnt];
    239277        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);
    241279        }
    242280
     
    246284ssize_t shell_write(int fd, const void *data, size_t len)
    247285{
    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);
    253291}
    254292
     
    256294{
    257295        int result = 0;
    258         struct _IO_FILE *fp = fd_to_fp(fd);
     296        struct SHELL_FILE *fp = fd_to_fp(fd);
    259297        if (fp == NULL)
    260298                return -EBADF;
     
    262300        const struct iovec *end = &iov[iovcnt];
    263301        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);
    265303        }
    266304
     
    270308int shell_llseek(int fd, off_t ptr, off_t *result, int dir)
    271309{
    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);
    277315        if (ret < 0)
    278316                return ret;
     
    284322int shell_fstat(int fd, struct stat * st)
    285323{
    286         struct _IO_FILE *fp = fd_to_fp(fd);
     324        struct SHELL_FILE *fp = fd_to_fp(fd);
    287325        if (fp == NULL)
    288326                return -EBADF;
     
    296334int shell_fsync(int fd)
    297335{
    298         struct _IO_FILE *fp = fd_to_fp(fd);
     336        struct SHELL_FILE *fp = fd_to_fp(fd);
    299337        if (fp == NULL)
    300338                return -EBADF;
     
    304342int shell_ftruncate(int fd, off_t length)
    305343{
    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)
    312350                return fresult2errno(res);
    313351
     
    320358}
    321359
     360extern IO_TYPE IO_TYPE_SIO;
     361
    322362int sio_tcgetattr(int fd, struct termios *termios)
    323363{
    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
     400int 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;
    331411                }
    332412                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;
    337417                }
    338418                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;
    343423                }
    344424                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;
    349429                }
    350430                else {
    351                         termios->c_oflag &= ~ONLCR;
     431                        ntstdio->option &= ~NTSTDIO_OPTION_LF_CRLF;
    352432                }
    353433                return 0;
    354434        }
    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
    390436        shell_abort();
    391437        return 0;
     
    396442        FILINFO fi;
    397443        FRESULT ret;
    398 #if _USE_LFN
    399         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 */
    400446        fi.lfname = lfn;
    401447        fi.lfsize = sizeof lfn;
    402448#endif
    403449        if (strcmp(path, ".") == 0) {
    404                 char cwd[_MAX_LFN];
     450                char cwd[FF_MAX_LFN];
    405451                if ((ret = f_getcwd(cwd, sizeof(cwd))) != FR_OK) {
    406452                        return fresult2errno(ret);
     
    426472        st->st_mtim.tv_nsec = 0;
    427473        st->st_mtim.tv_sec = fi.fdate + fi.ftime;
    428         st->st_mode  = (S_IRUSR | S_IRGRP | S_IROTH);
     474        st->st_mode = (S_IRUSR | S_IRGRP | S_IROTH);
    429475        st->st_mode |= (fi.fattrib & AM_RDO) ? 0 : (S_IWUSR | S_IWGRP | S_IWOTH);
    430476        st->st_mode |= (fi.fattrib & (AM_DIR | AM_VOL)) ? S_IFDIR : S_IFREG;
     
    485531        BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
    486532
    487         if(mode & S_IREAD) {
    488                 if((mode & S_IWRITE) == 0) {
     533        if (mode & S_IREAD) {
     534                if ((mode & S_IWRITE) == 0) {
    489535                        attr |= AM_RDO;
    490536                }
     
    494540        }
    495541
    496         if((res = f_chmod(path, attr, mask)) != FR_OK) {
     542        if ((res = f_chmod(path, attr, mask)) != FR_OK) {
    497543                return fresult2errno(res);
    498544        }
     
    507553        BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
    508554
    509         if(mode & S_IREAD) {
    510                 if((mode & S_IWRITE) == 0) {
     555        if (mode & S_IREAD) {
     556                if ((mode & S_IWRITE) == 0) {
    511557                        attr |= AM_RDO;
    512558                }
     
    516562        }
    517563
    518         if((res = f_chmod(path, attr, mask)) != FR_OK) {
     564        if ((res = f_chmod(path, attr, mask)) != FR_OK) {
    519565                return fresult2errno(res);
    520566        }
     
    526572{
    527573        FRESULT ret;
    528         if((ret = f_getcwd(buf, size)) != FR_OK) {
     574        if ((ret = f_getcwd(buf, size)) != FR_OK) {
    529575                return NULL;
    530576        }
     
    549595}
    550596
    551 int dir_close(struct _IO_FILE *fp)
    552 {
    553         FRESULT res;
    554         if ((res = f_closedir(&fp->pdir->dir)) != FR_OK) {
     597int dir_close(struct SHELL_FILE *fp)
     598{
     599        FRESULT res;
     600        if ((res = f_closedir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
    555601                return fresult2errno(res);
    556602        }
     
    564610                return -EINVAL;
    565611
    566         struct _IO_FILE *fp = fd_to_fp(fd);
     612        struct SHELL_FILE *fp = fd_to_fp(fd);
    567613        if (fp == NULL)
    568614                return -EBADF;
    569615
    570616        FILINFO fno;
    571 #if _USE_LFN
    572         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 */
    573619        fno.lfname = lfn;
    574620        fno.lfsize = sizeof lfn;
    575621#endif
    576622        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') {
    578624                return fresult2errno(res);
    579625        }
    580626
    581627        memset(de, 0, sizeof(*de));
    582 #if _USE_LFN
     628#if FF_USE_LFN
    583629        ntlibc_strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name));
    584630#else
     
    589635}
    590636
    591 size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
     637size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
    592638{
    593639        return -EPERM;
    594640}
    595641
    596 size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
     642size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
    597643{
    598644        return -EPERM;
    599645}
    600646
    601 off_t dir_seek(struct _IO_FILE *fp, off_t ptr, int dir)
     647off_t dir_seek(struct SHELL_FILE *fp, off_t ptr, int dir)
    602648{
    603649        FRESULT res;
     
    607653
    608654        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) {
    610656                        return fresult2errno(res);
    611657                }
     
    613659        else {
    614660                FILINFO fno;
    615 #if _USE_LFN
    616                 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 */
    617663                fno.lfname = lfn;
    618664                fno.lfsize = sizeof lfn;
    619665#endif
    620                 if ((res = f_rewinddir(&fp->pdir->dir)) != FR_OK) {
     666                if ((res = f_rewinddir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
    621667                        return fresult2errno(res);
    622668                }
    623669
    624670                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') {
    626672                                return fresult2errno(res);
    627673                        }
     
    632678}
    633679
    634 int dir_ioctl(struct _IO_FILE *fp, int req, void *arg)
     680int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg)
    635681{
    636682        return -EINVAL;
     683}
     684
     685bool_t dir_readable(struct SHELL_FILE *fp)
     686{
     687        return fp->readevt_w != fp->readevt_r;
     688}
     689
     690void dir_delete(struct SHELL_FILE *fp)
     691{
     692        free((struct SHELL_DIR *)fp->exinf);
     693        fp->exinf = NULL;
    637694}
    638695
     
    687744{
    688745        //if ((addr >= (void *)&_HeapBase) && (addr + len < (void *)&_HeapLimit)) {
    689                 return 0;
    690         //}
    691         //return -1;
     746        return 0;
     747//}
     748//return -1;
    692749}
    693750
     
    697754static pool_t sys_pool;
    698755
    699 void sys_init(void)
     756void sys_tlsf_init(void)
    700757{
    701758        sys_tlsf = tlsf_create(&_HeapBase);
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/net_misc.c

    r359 r374  
    6060#include "kernel_cfg.h"
    6161#include "tinet_cfg.h"
    62 #include "util/ntstdio.h"
    63 
    64 extern ntstdio_t ntstdio;
     62#include <stdio.h>
    6563
    6664T_DHCP4_CLI_CONTEXT *dhcp4_cli_initialize(ID tskid, ID cepid);
     
    9795
    9896        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);
    10098
    10199        /* 初期化 */
     
    105103        ret = get_tim(&time);
    106104        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",
    108106                        nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
    109107                return;
     
    119117                error = tslp_tsk(timer);
    120118                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",
    122120                                nc->cepid, itron_strerror(error), timer);
    123121                        break;
     
    126124                ret = get_tim(&time);
    127125                if (ret != E_OK) {
    128                         ntstdio_printf(&ntstdio, "[NET MISC,%d] get_tim error: %s",
     126                        printf("[NET MISC,%d] get_tim error: %s",
    129127                                nc->cepid, itron_strerror(ret));
    130128                        break;
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/netcmd.c

    r364 r374  
    5959#include <netapp/resolver.h>
    6060#include "core/ntlibc.h"
    61 #include "util/ntstdio.h"
     61#include <stdio.h>
    6262#include "ntp_cli.h"
    6363#include "kernel_cfg.h"
    64 
    65 extern ntstdio_t ntstdio;
    6664
    6765#if defined(SUPPORT_INET6)
     
    280278
    281279        if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
    282                 ntstdio_printf(&ntstdio, "[PING] unknown host.\n");
     280                printf("[PING] unknown host.\n");
    283281                return 0;
    284282        }
     
    299297#if defined(SUPPORT_INET4)
    300298        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));
    302300                ping6(&addr, (uint_t)tmo, (uint_t)size);
    303301        }
    304302        else {
    305303                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));
    307305                ping4(&addr4, (uint_t)tmo, (uint_t)size);
    308306        }
    309307#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));
    311309        ping6(&addr, (uint_t)tmo, (uint_t)size);
    312310#endif  /* of #if defined(SUPPORT_INET4) */
    313311#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));
    315313        ping4(&addr, (uint_t)tmo, (uint_t)size);
    316314#endif  /* of #if defined(SUPPORT_INET6) */
     
    331329                pos = str_ipv4addr(temp, sizeof(temp), &svaddr, 0);
    332330                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",
    335333                        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",
    337335                        rebind / 3600, (rebind / 60) % 60, rebind % 60,
    338336                        expire / 3600, (expire / 60) % 60, expire % 60);
    339337        }
    340338        else if (ret == E_OBJ)
    341                 ntstdio_printf(&ntstdio, "DHCPv4 server: not available.\n");
     339                printf("DHCPv4 server: not available.\n");
    342340}
    343341
     
    351349        if (ntlibc_strcmp(argv[1], "rel") == 0) {
    352350                ret = dhcp4c_rel_info();
    353                 ntstdio_printf(&ntstdio, "dhcp4c_rel_info %d\n", ret);
     351                printf("dhcp4c_rel_info %d\n", ret);
    354352        }
    355353        else if (ntlibc_strcmp(argv[1], "renew") == 0) {
    356354                ret = dhcp4c_renew_info();
    357                 ntstdio_printf(&ntstdio, "dhcp4c_renew_info %d\n", ret);
     355                printf("dhcp4c_renew_info %d\n", ret);
    358356        }
    359357        else {
     
    383381                else {
    384382                        for (c = 1; c <= *ptr; c++)
    385                                 ntstdio_printf(&ntstdio, "%c", *(ptr + c));
     383                                printf("%c", *(ptr + c));
    386384                        ptr += *ptr + 1;
    387385                        if (*ptr)
    388                                 ntstdio_printf(&ntstdio, ".");
     386                                printf(".");
    389387                }
    390388        }
     
    406404                return error;
    407405
    408         ntstdio_printf(&ntstdio, "    mname:   ");
     406        printf("    mname:   ");
    409407        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:   ");
    412410        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);
    420418
    421419        return E_OK;
     
    433431        int             scount;
    434432
    435         ntstdio_printf(&ntstdio, "question   section: %d\n", rslv->dns_hdr.qdcount);
     433        printf("question   section: %d\n", rslv->dns_hdr.qdcount);
    436434        offset = rslv->qd_offset;
    437435        for (scount = 1; scount <= rslv->dns_hdr.qdcount; scount++) {
     
    439437                        return error;
    440438
    441                 ntstdio_printf(&ntstdio, "%2d: ", scount);
     439                printf("%2d: ", scount);
    442440                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));
    444442                offset = error;
    445443        }
     
    463461        int pos;
    464462
    465         ntstdio_printf(&ntstdio, "%10s section: %d\n", title, scount);
     463        printf("%10s section: %d\n", title, scount);
    466464        for (count = 1; count <= scount; count++) {
    467465                if ((error = dns_analyze_rr(&rr, offset, msg, length)) < 0)
    468466                        return error;
    469467
    470                 ntstdio_printf(&ntstdio, "%2d: ", count);
     468                printf("%2d: ", count);
    471469                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",
    473471                        dns_strtype(rr.type), dns_strclass(rr.class), rr.ttl, rr.rdlength, rr.rdata_offset);
    474472
     
    479477                        pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
    480478                        temp[pos] = '\0';
    481                         ntstdio_printf(&ntstdio, "    IPv4 addr: %s\n", temp);
     479                        printf("    IPv4 addr: %s\n", temp);
    482480                        break;
    483481                case DNS_TYPE_NS:
    484                         ntstdio_printf(&ntstdio, "    host: ");
     482                        printf("    host: ");
    485483                        s_show_dns_domain_name(msg, rr.rdata_offset);
    486                         ntstdio_putc(&ntstdio, '\n');
     484                        putchar('\n');
    487485                        break;
    488486                case DNS_TYPE_CNAME:
    489                         ntstdio_printf(&ntstdio, "    host: ");
     487                        printf("    host: ");
    490488                        s_show_dns_domain_name(msg, rr.rdata_offset);
    491                         ntstdio_putc(&ntstdio, '\n');
     489                        putchar('\n');
    492490                        break;
    493491                case DNS_TYPE_SOA:
     
    495493                        break;
    496494                case DNS_TYPE_PTR:
    497                         ntstdio_printf(&ntstdio, "     PTR: ");
     495                        printf("     PTR: ");
    498496                        s_show_dns_domain_name(msg, rr.rdata_offset);
    499                         ntstdio_putc(&ntstdio, '\n');
     497                        putchar('\n');
    500498                        break;
    501499                case DNS_TYPE_AAAA:
     
    503501                        pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
    504502                        temp[pos] = '\0';
    505                         ntstdio_printf(&ntstdio, "    IPv6 addr: %s\n", temp);
     503                        printf("    IPv6 addr: %s\n", temp);
    506504                        break;
    507505                default:
    508                         ntstdio_printf(&ntstdio, "    data: ");
     506                        printf("    data: ");
    509507                        col = 32;
    510508                        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));
    512510                                if (--col == 0) {
    513                                         ntstdio_printf(&ntstdio, "\n          ");
     511                                        printf("\n          ");
    514512                                        col = 32;
    515513                                }
    516514                        }
    517                         ntstdio_putc(&ntstdio, '\n');
     515                        putchar('\n');
    518516                        break;
    519517                }
     
    539537#if defined(SUPPORT_INET6)
    540538
    541         ntstdio_printf(&ntstdio, "domain name:     %s\n", dns_in6_get_dname());
     539        printf("domain name:     %s\n", dns_in6_get_dname());
    542540
    543541#else   /* of #if defined(SUPPORT_INET6) */
    544542
    545         ntstdio_printf(&ntstdio, "domain name:     %s\n", dns_in4_get_dname());
     543        printf("domain name:     %s\n", dns_in4_get_dname());
    546544
    547545#endif  /* of #if defined(SUPPORT_INET6) */
     
    549547#if defined(SUPPORT_INET6)
    550548        dns_in6_get_addr(&in6_addr);
    551         ntstdio_printf(&ntstdio, "IPv6 DNS server: ");
     549        printf("IPv6 DNS server: ");
    552550        if (IN6_IS_ADDR_UNSPECIFIED(&in6_addr))
    553                 ntstdio_printf(&ntstdio, "not available.\n");
     551                printf("not available.\n");
    554552        else {
    555553                pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
    556554                temp[pos] = '\0';
    557                 ntstdio_printf(&ntstdio, "%s.\n", temp);
     555                printf("%s.\n", temp);
    558556        }
    559557#endif  /* of #if defined(SUPPORT_INET6) */
     
    561559#if defined(SUPPORT_INET4)
    562560        dns_in4_get_addr(&in4_addr);
    563         ntstdio_printf(&ntstdio, "IPv4 DNS server: ");
     561        printf("IPv4 DNS server: ");
    564562        if (in4_addr == IPV4_ADDRANY)
    565                 ntstdio_printf(&ntstdio, "not available.\n");
     563                printf("not available.\n");
    566564        else {
    567565                pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
    568566                temp[pos] = '\0';
    569                 ntstdio_printf(&ntstdio, "%s.\n", temp);
     567                printf("%s.\n", temp);
    570568        }
    571569#endif  /* of #if defined(SUPPORT_INET4) */
     
    604602        line = skip_blanks(resolv_options(&flags, line, DEFAULT_API_PROTO));
    605603        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");
    607605                return 0;
    608606        }
     
    620618
    621619        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));
    623621                return 0;
    624622        }
    625623
    626624        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));
    628626                goto err_ret;
    629627        }
    630628
    631629        dly_tsk(1 * 1000);
    632         ntstdio_printf(&ntstdio, "DNS header: flags: ");
     630        printf("DNS header: flags: ");
    633631        if (rslv.dns_hdr.code & (DNS_QR_RESPONSE | DNS_AUTHORITATIVE |
    634632                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",
    646644                (rslv.dns_hdr.code & DNS_RCODE_MASK) > DNS_RCODE_REFUSED
    647645                ? "6" : rcode_str[rslv.dns_hdr.code & DNS_RCODE_MASK]);
    648646
    649647        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));
    651649        }
    652650        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));
    654652        }
    655653        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));
    657655        }
    658656        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));
    660658        }
    661659
    662660err_ret:
    663661        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));
    665663        return 0;
    666664}
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/ntp_cli.c

    r364 r374  
    5050#include <t_syslog.h>
    5151#include "kernel_cfg.h"
    52 #include "util/ntstdio.h"
    53 
    54 extern ntstdio_t ntstdio;
     52#include <stdio.h>
    5553
    5654#endif  /* of #if defined(TARGET_KERNEL_ASP) */
     
    279277        }
    280278
    281         ntstdio_printf(&ntstdio, "[NTP CLI,%d] recv time: %s .%09u\n",
     279        printf("[NTP CLI,%d] recv time: %s .%09u\n",
    282280                nc->cepid, nc->buf, tp.tv_nsec);
    283281}
     
    311309                line = lookup_ipaddr(&nc->ipaddr6, NTP_SRV_URL, API_PROTO_IPV4);
    312310                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.",
    314312                                nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
    315313                        nc->timer = SLP_ITV;
     
    319317#else   /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
    320318                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.",
    322320                                nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
    323321                        nc->timer = SLP_ITV;
     
    423421
    424422        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",
    426424                        nc->cepid, itron_strerror(error));
    427425                return error;
     
    441439        ret = get_tim(&time);
    442440        if (ret != E_OK) {
    443                 ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s",
     441                printf("[NTP CLI,%d] get_tim error: %s",
    444442                        nc->cepid, itron_strerror(ret));
    445443                tp->tv_sec = 0;
     
    461459        ret = set_tim(time);
    462460        if (ret != E_OK) {
    463                 ntstdio_printf(&ntstdio, "[NTP CLI,%d] set_tim error: %s",
     461                printf("[NTP CLI,%d] set_tim error: %s",
    464462                        nc->cepid, itron_strerror(ret));
    465463        }
     
    479477        if (len < 0 && len != E_RLWAI) {
    480478                /* 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,
    482480                        itron_strerror(len), in_strtfn(fncd));
    483481        }
     
    486484                        if ((len = udp_rcv_dat(nc->cepid, &nc->rcv_rmt, &nc->ntp_msg, len, TMO_POL)) < 0)
    487485                        {
    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,
    489487                                        itron_strerror(len));
    490488                        }
     
    518516
    519517        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);
    521519
    522520        /* 初期化 */
     
    525523        ret = get_tim(&time);
    526524        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",
    528526                        nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
    529527                return;
     
    539537                error = tslp_tsk(timer);
    540538                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",
    542540                                nc->cepid, itron_strerror(error), timer);
    543541                        break;
     
    546544                ret = get_tim(&time);
    547545                if (ret != E_OK) {
    548                         ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s",
     546                        printf("[NTP CLI,%d] get_tim error: %s",
    549547                                nc->cepid, itron_strerror(ret));
    550548                        break;
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/ntshell_main.c

    r364 r374  
    5959#include "ntshell_main.h"
    6060#include "socket_stub.h"
    61 #include "usb_hbth.h"
    62 #include "mbed_api.h"
    63 
    64 extern int bt_bnep_mode;
    6561
    6662char command[NTOPT_TEXT_MAXLEN];
    67 ntstdio_t ntstdio;
    6863
    6964extern uint8_t mac_addr[6];
     
    8883volatile int ntshell_state;
    8984jmp_buf process_exit;
    90 void sys_init(void);
    91 NTSHELL_SERIAL_READ ntshell_serial_read = 0;
    92 NTSHELL_SERIAL_WRITE ntshell_serial_write = 0;
    93 void *ntshell_serial_extobj;
    94 
    95 unsigned char ntstdio_xi(struct ntstdio_t *handle)
    96 {
    97         unsigned char buf[1];
    98         ntshell_serial_read((char *)buf, 1, ntshell_serial_extobj);
    99         return buf[0];
    100 }
    101 
    102 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
    103 {
    104         char buf[1];
    105         buf[0] = c;
    106         ntshell_serial_write(buf, 1, ntshell_serial_extobj);
    107 }
    108 
    109 void ntshell_task_init(NTSHELL_SERIAL_READ func_read,
    110         NTSHELL_SERIAL_WRITE func_write, void *extobj)
    111 {
    112         ntshell_serial_read = func_read;
    113         ntshell_serial_write = func_write;
    114         ntshell_serial_extobj = extobj;
    115 
    116         sys_init();
    117 
    118         ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
     85
     86void ntshell_task_init(ID portid)
     87{
     88        serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
    11989}
    12090
     
    178148        const cmd_table_t *p = cmd_table_info.table;
    179149        for (int i = 0; i < cmd_table_info.count; i++) {
    180                 ntstdio_puts(&ntstdio, p->cmd);
    181                 ntstdio_puts(&ntstdio, "\t:");
    182                 ntstdio_puts(&ntstdio, p->desc);
    183                 ntstdio_puts(&ntstdio, "\n");
     150                fwrite(p->cmd, strlen(p->cmd), 1, stdout);
     151                fwrite("\t:", strlen("\t:"), 1, stdout);
     152                puts(p->desc);
    184153                p++;
    185154        }
     
    207176int execute_command(int wait)
    208177{
     178        T_RTSK rtsk;
    209179        ER ret;
    210180
     
    229199        do {
    230200                tslp_tsk(100000);
     201
     202                ret = ref_tsk(NTSHELL_TASK, &rtsk);
     203                if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT))
     204                        ntshell_state = 3;
    231205        } while(ntshell_state == 1);
    232206
     
    238212        ntlibc_strlcpy(command, text, sizeof(command));
    239213        return execute_command(1);
    240 }
    241 
    242 int stdio_close(struct _IO_FILE *fp)
    243 {
    244         return -EPERM;
    245 }
    246 
    247 size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    248 {
    249         return -EPERM;
    250 }
    251 
    252 size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    253 {
    254         return -EPERM;
    255 }
    256 
    257 size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    258 {
    259         int i = 0;
    260         while (i < len) {
    261                 int c = ntstdio_getc(&ntstdio);
    262                 data[i++] = c;
    263                 if ((c == EOF) || (c == '\n'))
    264                         break;
    265         }
    266         return i;
    267 }
    268 
    269 size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    270 {
    271         for (int i = 0; i < len; i++) {
    272                 ntstdio_putc(&ntstdio, data[i]);
    273         }
    274         return len;
    275 }
    276 
    277 size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    278 {
    279         for (int i = 0; i < len; i++) {
    280                 ntstdio_putc(&ntstdio, data[i]);
    281         }
    282         return len;
    283 }
    284 
    285 int sio_close(struct _IO_FILE *fp)
    286 {
    287         return -EPERM;
    288 }
    289 
    290 size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    291 {
    292         return -EPERM;
    293 }
    294 
    295 size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    296 {
    297         return -EPERM;
    298 }
    299 
    300 off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org)
    301 {
    302         return -EPERM;
    303 }
    304 
    305 int sio_ioctl(struct _IO_FILE *fp, int request, void *arg)
    306 {
    307         switch (request) {
    308         case TIOCGWINSZ:
    309                 return 0;
    310         case TCGETS:
    311                 return sio_tcgetattr(fp->fd, (struct termios *)arg);
    312         case TCSETS + TCSANOW:
    313         case TCSETS + TCSADRAIN:
    314         case TCSETS + TCSAFLUSH:
    315                 return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
    316         }
    317 
    318         return -EINVAL;
    319214}
    320215
     
    457352}
    458353
     354int shell_kill(int pid, int sig)
     355{
     356        DebugBreak();
     357        return -1;
     358}
     359
     360int 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_rx/trunk/ntshell/src/ntshell_main.cfg

    r364 r374  
    4141#include "ntshell_main.h"
    4242
     43ATT_INI({ TA_NULL, 0, sys_init });
     44
    4345CRE_TSK(NTSHELL_TASK, { TA_NULL, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL });
    4446CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 });
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/ntshell_main.h

    r367 r374  
    7676extern PRI main_task_priority;
    7777
     78/* ntshellの初期化 */
     79void sys_init(intptr_t exinf);
     80
    7881/* ntshellタスク初期化 */
    79 void ntshell_task_init(NTSHELL_SERIAL_READ func_read,
    80         NTSHELL_SERIAL_WRITE func_write, void *extobj);
     82void ntshell_task_init(ID portid);
    8183
    8284/* ntshellタスク */
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/shellif.h

    r364 r374  
    134134
    135135// dirent.h
    136 typedef struct __dirstream DIR;
     136typedef struct __dirstream FATFS_DIR;
    137137
    138138int shell_getdents(int, struct dirent *, size_t);
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/socket_stub.c

    r364 r374  
    5757#include <netinet/udp_var.h>
    5858#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>
    6063#include <netapp/resolver.h>
    6164extern const ID tmax_tcp_cepid;
     
    6568
    6669#define SOCKET_TIMEOUT 2000000
     70
     71#define tcp6_cre_cep tcp_cre_cep
     72#define tcp6_del_cep tcp_del_cep
     73#define tcp6_del_rep tcp_del_rep
     74#define tcp6_sht_cep tcp_sht_cep
     75#define tcp6_cls_cep tcp_cls_cep
     76#define tcp6_snd_oob tcp_snd_oob
     77#define tcp6_snd_dat tcp_snd_dat
     78#define tcp6_rcv_oob tcp_rcv_oob
     79#define tcp6_rcv_buf tcp_rcv_buf
     80#define tcp6_rel_buf tcp_rel_buf
     81#define tcp6_get_opt tcp_get_opt
     82#define tcp6_set_opt tcp_set_opt
     83
     84#define udp6_del_cep udp_del_cep
     85#define udp6_get_opt udp_get_opt
     86#define udp6_set_opt udp_set_opt
     87
     88#ifndef SUPPORT_INET6
     89
     90ER      tcp6_cre_rep (ID repid, T_TCP6_CREP *pk_crep) { return E_SYS; }
     91ER      tcp6_acp_cep (ID cepid, ID repid, T_IPV6EP *p_dstaddr, TMO tmout) { return E_SYS; }
     92ER      tcp6_con_cep (ID cepid, T_IPV6EP *p_myaddr, T_IPV6EP *p_dstaddr, TMO tmout) { return E_SYS; }
     93
     94ER      udp6_cre_cep (ID cepid, T_UDP6_CCEP *pk_ccep) { return E_SYS; }
     95ER_UINT udp6_snd_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout) { return E_SYS; }
     96ER_UINT udp6_rcv_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout) { return E_SYS; }
     97
     98const T_IN6_ADDR *in6_get_ifaddr (int_t index) { return NULL; }
     99
     100#endif
     101
     102ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk);
     103ER socket_tcp6_callback(ID cepid, FN fncd, void *p_parblk);
     104ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk);
     105ER socket_udp6_callback(ID cepid, FN fncd, void *p_parblk);
     106
     107static int tcp_fd_close(struct SHELL_FILE *fp);
     108static size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     109static size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     110static off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
     111static int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
     112static bool_t tcp_fd_readable(struct SHELL_FILE *fp);
     113static void tcp_fd_delete(struct SHELL_FILE *fp);
     114
     115static int udp_fd_close(struct SHELL_FILE *fp);
     116static size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     117static size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     118static off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
     119static int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
     120static bool_t udp_fd_readable(struct SHELL_FILE *fp);
     121static void udp_fd_delete(struct SHELL_FILE *fp);
     122
     123IO_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 };
     124IO_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 };
    67125
    68126typedef struct id_table_t {
     
    84142#define tcp_cepid_table_count (sizeof(tcp_cepid_table) / sizeof(tcp_cepid_table[0]))
    85143
     144#ifdef SUPPORT_INET6
     145
     146id_table_t tcp6_repid_table[] = {
     147        {0, USR_TCP6_REP1}, {0, USR_TCP6_REP2}, {0, USR_TCP6_REP3}, {0, USR_TCP6_REP4}
     148};
     149#define tcp6_repid_table_count (sizeof(tcp6_repid_table) / sizeof(tcp6_repid_table[0]))
     150
     151id_table_t tcp6_cepid_table[] = {
     152        {0, USR_TCP6_CEP1}, {0, USR_TCP6_CEP2}, {0, USR_TCP6_CEP3}, {0, USR_TCP6_CEP4},
     153#ifndef TOPPERS_GRSAKURA
     154        {0, USR_TCP6_CEP5}, {0, USR_TCP6_CEP6}, {0, USR_TCP6_CEP7}, {0, USR_TCP6_CEP8}
     155#endif
     156};
     157#define tcp6_cepid_table_count (sizeof(tcp6_cepid_table) / sizeof(tcp6_cepid_table[0]))
     158
     159#else
     160
     161#define tcp6_repid_table NULL
     162#define tcp6_repid_table_count 0
     163
     164#define tcp6_cepid_table NULL
     165#define tcp6_cepid_table_count 0
     166
     167#endif
     168
    86169id_table_t udp_cepid_table[] = {
    87170        {0, USR_UDP_CEP1}, {0, USR_UDP_CEP2}, {0, USR_UDP_CEP3}, {0, USR_UDP_CEP4}
     
    89172#define udp_cepid_table_count (sizeof(udp_cepid_table) / sizeof(udp_cepid_table[0]))
    90173
     174#ifdef SUPPORT_INET6
     175
     176id_table_t udp6_cepid_table[] = {
     177        {0, USR_UDP6_CEP1}, {0, USR_UDP6_CEP2}, {0, USR_UDP6_CEP3}, {0, USR_UDP6_CEP4}
     178};
     179#define udp6_cepid_table_count (sizeof(udp6_cepid_table) / sizeof(udp6_cepid_table[0]))
     180
     181#else
     182
     183#define udp6_cepid_table NULL
     184#define udp6_cepid_table_count 0
     185
     186#endif
     187
    91188ID new_id(id_table_t *table, int count)
    92189{
     
    116213}
    117214
    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;
     215typedef struct SHELL_FILE SOCKET;
    124216
    125217int shell_socket(int family, int type, int protocol)
     
    141233        switch (type) {
    142234        case SOCK_STREAM:
    143                 fp = new_tcp_fd(0);
     235                fp = new_fp(&IO_TYPE_TCP, 0, 0);
     236                if (fp == NULL)
     237                        return -ENOMEM;
     238
     239                fp->exinf = malloc(sizeof(socket_t));
     240                memset(fp->exinf, 0, sizeof(socket_t));
    144241                break;
    145242        case SOCK_DGRAM:
    146                 fp = new_udp_fd(0);
     243                fp = new_fp(&IO_TYPE_UDP, 0, 1);
     244                if (fp == NULL)
     245                        return -ENOMEM;
     246
     247                fp->exinf = malloc(sizeof(socket_t));
     248                memset(fp->exinf, 0, sizeof(socket_t));
    147249                break;
    148250        default:
     
    150252        }
    151253
    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;
     254        socket_t *socket = (socket_t *)fp->exinf;
     255        socket->family = family;
     256        socket->type = type;
     257        socket->protocol = protocol;
     258        socket->flags = flags;
    160259
    161260        return fp->fd;
     
    167266        if (fp == NULL)
    168267                return -EBADF;
    169         if (fp->psock->family != addr->sa_family)
     268        socket_t *socket = (socket_t *)fp->exinf;
     269        if (socket->family != addr->sa_family)
    170270                return -EINVAL;
    171271
     
    177277                }
    178278                struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
    179                 memcpy(&fp->psock->laddr4, addr, len);
    180                 switch (fp->psock->type) {
     279                memcpy(&socket->laddr4, addr, len);
     280                switch (socket->type) {
    181281                case SOCK_STREAM: {
    182282                        ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
     
    184284                                return -ENOMEM;
    185285
    186                         fp->psock->buf_size = 512 + 512;
    187                         fp->psock->buf = malloc(fp->psock->buf_size);
     286                        socket->buf_size = 512 + 512;
     287                        socket->buf = malloc(socket->buf_size);
    188288#ifdef _DEBUG
    189                         memset(fp->psock->buf, 0, fp->psock->buf_size);
     289                        memset(socket->buf, 0, socket->buf_size);
    190290#endif
    191                         T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
     291                        T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
    192292                        ret = tcp_cre_cep(cepid, &ccep);
    193293                        if (ret != E_OK) {
     
    196296                        }
    197297                        fp->handle = cepid;
    198                         fp->psock->cepid = cepid;
     298                        socket->cepid = cepid;
    199299                        break;
    200300                }
     
    211311                        }
    212312                        fp->handle = cepid;
    213                         fp->psock->cepid = cepid;
     313                        socket->cepid = cepid;
    214314                        break;
    215315                }
     
    223323                        return -EINVAL;
    224324                }
    225                 memcpy(&fp->psock->laddr4, addr, len);
    226                 break;
    227         }
     325                struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr;
     326                memcpy(&socket->laddr6, addr, len);
     327                switch (socket->type) {
     328                case SOCK_STREAM: {
     329                        ID cepid = new_id(tcp6_cepid_table, tcp6_cepid_table_count);
     330                        if (cepid < 0)
     331                                return -ENOMEM;
     332
     333                        socket->buf_size = 512 + 512;
     334                        socket->buf = malloc(socket->buf_size);
     335#ifdef _DEBUG
     336                        memset(socket->buf, 0, socket->buf_size);
     337#endif
     338                        T_TCP6_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp6_callback };
     339                        ret = tcp6_cre_cep(cepid, &ccep);
     340                        if (ret != E_OK) {
     341                                delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid);
     342                                return -ENOMEM;
     343                        }
     344                        fp->handle = cepid;
     345                        socket->cepid = cepid;
     346                        break;
     347                }
     348                case SOCK_DGRAM: {
     349                        ID cepid = new_id(udp_cepid_table, udp_cepid_table_count);
     350                        if (cepid < 0)
     351                                return -ENOMEM;
     352
     353                        T_UDP6_CCEP ccep = { 0, {ntohl(addr_in6->sin6_addr.__in6_union.__s6_addr), ntohs(addr_in6->sin6_port)}, (FP)socket_udp6_callback };
     354                        ret = udp6_cre_cep(cepid, &ccep);
     355                        if (ret != E_OK) {
     356                                delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
     357                                return -ENOMEM;
     358                        }
     359                        fp->handle = cepid;
     360                        socket->cepid = cepid;
     361                        break;
     362                }
     363                default:
     364                        return -ENOPROTOOPT;
     365                }
     366                break;
     367        }
     368        default:
     369                return -ENOPROTOOPT;
    228370        }
    229371
     
    236378        if (fp == NULL)
    237379                return -EBADF;
    238         if (fp->psock->type != SOCK_STREAM)
     380        socket_t *socket = (socket_t *)fp->exinf;
     381        if (socket->type != SOCK_STREAM)
    239382                return -EINVAL;
    240383
    241         fp->psock->backlog = backlog;
     384        socket->backlog = backlog;
    242385
    243386        ER ret;
    244         switch (fp->psock->family) {
     387        switch (socket->family) {
    245388        case AF_INET: {
    246389                ID repid = new_id(tcp_repid_table, tcp_repid_table_count);
     
    248391                        return -ENOMEM;
    249392
    250                 struct sockaddr_in *laddr = &fp->psock->laddr4;
     393                struct sockaddr_in *laddr = &socket->laddr4;
    251394                T_TCP_CREP crep = { 0, {ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port)} };
    252395                ret = tcp_cre_rep(repid, &crep);
     
    255398                        return -ENOMEM;
    256399                }
    257                 fp->psock->repid = repid;
     400                socket->repid = repid;
    258401                break;
    259402        }
    260403        case AF_INET6: {
    261                 break;
    262         }
     404                ID repid = new_id(tcp6_repid_table, tcp6_repid_table_count);
     405                if (repid < 0)
     406                        return -ENOMEM;
     407
     408                struct sockaddr_in6 *laddr = &socket->laddr6;
     409                T_TCP6_CREP crep = { 0, {ntohl(laddr->sin6_addr.__in6_union.__s6_addr), ntohs(laddr->sin6_port)} };
     410                ret = tcp6_cre_rep(repid, &crep);
     411                if (ret != E_OK) {
     412                        delete_id(tcp6_repid_table, tcp6_repid_table_count, repid);
     413                        return -ENOMEM;
     414                }
     415                socket->repid = repid;
     416                break;
     417        }
     418        default:
     419                return -ENOPROTOOPT;
    263420        }
    264421
     
    271428        if (fp == NULL)
    272429                return -EBADF;
    273         if (fp->psock->type != SOCK_STREAM)
     430        socket_t *socket = (socket_t *)fp->exinf;
     431        if (socket->type != SOCK_STREAM)
    274432                return -EINVAL;
    275433
    276434        ER ret;
    277         switch (fp->psock->family) {
     435        switch (socket->family) {
    278436        case AF_INET: {
    279437                if (len < 8) {
    280438                        return -EINVAL;
    281439                }
    282                 if (fp->psock->cepid == 0) {
     440                if (socket->cepid == 0) {
    283441                        ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
    284442                        if (cepid < 0)
    285443                                return -ENOMEM;
    286444
    287                         fp->psock->buf_size = 512 + 512;
    288                         fp->psock->buf = malloc(fp->psock->buf_size);
     445                        socket->buf_size = 512 + 512;
     446                        socket->buf = malloc(socket->buf_size);
    289447#ifdef _DEBUG
    290                         memset(fp->psock->buf, 0, fp->psock->buf_size);
     448                        memset(socket->buf, 0, socket->buf_size);
    291449#endif
    292                         T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
     450                        T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
    293451                        ret = tcp_cre_cep(cepid, &ccep);
    294452                        if (ret != E_OK) {
     
    297455                        }
    298456                        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;
     457                        socket->cepid = cepid;
     458                }
     459                struct sockaddr_in *laddr = &socket->laddr4;
     460                struct sockaddr_in *raddr = &socket->raddr4;
    303461                memset(raddr, 0, sizeof(*raddr));
    304462                memcpy(raddr, addr, len);
    305463                T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) };
    306464                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);
     465                ret = tcp_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT);
    308466                if (ret < 0) {
    309467                        return -EHOSTUNREACH;
     
    312470        }
    313471        case AF_INET6: {
    314                 break;
    315         }
     472                if (len < 20) {
     473                        return -EINVAL;
     474                }
     475                if (socket->cepid == 0) {
     476                        ID cepid = new_id(tcp6_cepid_table, tcp6_cepid_table_count);
     477                        if (cepid < 0)
     478                                return -ENOMEM;
     479
     480                        socket->buf_size = 512 + 512;
     481                        socket->buf = malloc(socket->buf_size);
     482#ifdef _DEBUG
     483                        memset(socket->buf, 0, socket->buf_size);
     484#endif
     485                        T_TCP6_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp6_callback };
     486                        ret = tcp6_cre_cep(cepid, &ccep);
     487                        if (ret != E_OK) {
     488                                delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid);
     489                                return -ENOMEM;
     490                        }
     491                        fp->handle = cepid;
     492                        socket->cepid = cepid;
     493                }
     494                struct sockaddr_in6 *laddr = &socket->laddr6;
     495                struct sockaddr_in6 *raddr = &socket->raddr6;
     496                memset(raddr, 0, sizeof(*raddr));
     497                memcpy(raddr, addr, len);
     498                T_IPV6EP lep = { ntohl(laddr->sin6_addr.__in6_union.__s6_addr), ntohs(laddr->sin6_port) };
     499                T_IPV6EP rep = { ntohl(raddr->sin6_addr.__in6_union.__s6_addr), ntohs(raddr->sin6_port) };
     500                ret = tcp6_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT);
     501                if (ret < 0) {
     502                        return -EHOSTUNREACH;
     503                }
     504                break;
     505        }
     506        default:
     507                return -ENOPROTOOPT;
    316508        }
    317509
     
    324516        if (lfp == NULL)
    325517                return -EBADF;
    326         if (lfp->psock->type != SOCK_STREAM)
     518        if (((socket_t *)lfp->exinf)->type != SOCK_STREAM)
    327519                return -EINVAL;
    328520
    329         SOCKET *fp = new_tcp_fd(0);
    330         if (fp == NULL) {
     521        SOCKET *fp = new_fp(&IO_TYPE_TCP, 0, 0);
     522        if (fp == NULL)
    331523                return -ENOMEM;
    332         }
    333 
    334         memcpy(fp->psock, lfp->psock, offsetof(socket_t, buf_size));
     524
     525        fp->exinf = malloc(sizeof(socket_t));
     526        memset(fp->exinf, 0, sizeof(socket_t));
     527
     528        memcpy(fp->exinf, lfp->exinf, offsetof(socket_t, buf_size));
    335529
    336530        ER ret;
    337         switch (fp->psock->family) {
     531        socket_t *socket = (socket_t *)fp->exinf;
     532        switch (socket->family) {
    338533        case AF_INET: {
    339534                ID cepid;
    340                 if (fp->psock->cepid == 0) {
     535                if (socket->cepid == 0) {
    341536                        cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
    342537                        if (cepid < 0)
    343538                                return -ENOMEM;
    344539
    345                         fp->psock->buf_size = 512 + 512;
    346                         fp->psock->buf = malloc(fp->psock->buf_size);
     540                        socket->buf_size = 512 + 512;
     541                        socket->buf = malloc(socket->buf_size);
    347542#ifdef _DEBUG
    348                         memset(fp->psock->buf, 0, fp->psock->buf_size);
     543                        memset(socket->buf, 0, socket->buf_size);
    349544#endif
    350                         T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
     545                        T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
    351546                        ret = tcp_cre_cep(cepid, &ccep);
    352547                        if (ret != E_OK) {
     
    355550                        }
    356551                        fp->handle = cepid;
    357                         fp->psock->cepid = cepid;
     552                        socket->cepid = cepid;
    358553                }
    359554                else {
    360                         cepid = lfp->psock->cepid;
     555                        cepid = ((socket_t *)lfp->exinf)->cepid;
    361556                        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;
     557                        lfp->handle = tmax_tcp_cepid + ((socket_t *)lfp->exinf)->repid;
     558                        ((socket_t *)lfp->exinf)->cepid = 0;
     559                        ((socket_t *)lfp->exinf)->buf_size = 0;
     560                        ((socket_t *)lfp->exinf)->buf = 0;
    366561                }
    367562                T_IPV4EP rep = { 0, 0 };
    368                 ret = tcp_acp_cep(fp->psock->cepid, fp->psock->repid, &rep, TMO_FEVR);
     563                ret = tcp_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR);
    369564                if (ret < 0) {
    370565                        return -ENOMEM;
    371566                }
    372                 struct sockaddr_in *raddr = &fp->psock->raddr4;
     567                struct sockaddr_in *raddr = &socket->raddr4;
    373568                memset(raddr, 0, sizeof(*raddr));
    374569                raddr->sin_family = AF_INET;
    375570                raddr->sin_port = htons(rep.portno);
    376571                raddr->sin_addr.s_addr = htonl(rep.ipaddr);
     572
     573                if (addr != NULL && len != NULL) {
     574                        int sz = *len;
     575                        if (sz < 8) {
     576                                return -EINVAL;
     577                        }
     578                        struct sockaddr_in *raddr = &socket->raddr4;
     579                        if (sz > sizeof(*raddr))
     580                                sz = sizeof(*raddr);
     581                        memcpy(addr, raddr, sz);
     582                        *len = sizeof(*raddr);
     583                }
    377584                break;
    378585        }
    379586        case AF_INET6: {
    380                 return -EAFNOSUPPORT;
    381         }
    382         }
    383 
    384         if (addr != NULL && len != NULL) {
    385                 int sz = *len;
    386                 if (sz < 8) {
    387                         return -EINVAL;
    388                 }
    389                 struct sockaddr_in *raddr = &fp->psock->raddr4;
    390                 if (sz > sizeof(*raddr))
    391                         sz = sizeof(*raddr);
    392                 memcpy(addr, raddr, sz);
    393                 *len = sizeof(*raddr);
     587                ID cepid;
     588                if (socket->cepid == 0) {
     589                        cepid = new_id(tcp6_cepid_table, tcp6_cepid_table_count);
     590                        if (cepid < 0)
     591                                return -ENOMEM;
     592
     593                        socket->buf_size = 512 + 512;
     594                        socket->buf = malloc(socket->buf_size);
     595#ifdef _DEBUG
     596                        memset(socket->buf, 0, socket->buf_size);
     597#endif
     598                        T_TCP6_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp6_callback };
     599                        ret = tcp6_cre_cep(cepid, &ccep);
     600                        if (ret != E_OK) {
     601                                delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid);
     602                                return -ENOMEM;
     603                        }
     604                        fp->handle = cepid;
     605                        socket->cepid = cepid;
     606                }
     607                else {
     608                        cepid = ((socket_t *)lfp->exinf)->cepid;
     609                        fp->handle = cepid;
     610                        lfp->handle = tmax_tcp6_cepid + ((socket_t *)lfp->exinf)->repid;
     611                        ((socket_t *)lfp->exinf)->cepid = 0;
     612                        ((socket_t *)lfp->exinf)->buf_size = 0;
     613                        ((socket_t *)lfp->exinf)->buf = 0;
     614                }
     615                T_IPV6EP rep = { 0, 0 };
     616                ret = tcp6_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR);
     617                if (ret < 0) {
     618                        return -ENOMEM;
     619                }
     620                struct sockaddr_in6 *raddr = &socket->raddr6;
     621                memset(raddr, 0, sizeof(*raddr));
     622                raddr->sin6_family = AF_INET;
     623                raddr->sin6_port = htons(rep.portno);
     624#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
     625                memcpy(raddr->sin6_addr.__in6_union.__s6_addr, rep.ipaddr.__u6_addr.__u6_addr8, 16);
     626#else
     627                for (int i = 0; i < 16; i++)
     628                        raddr->sin6_addr.__in6_union.__s6_addr[i] = rep.ipaddr.__u6_addr.__u6_addr8[i];
     629#endif
     630
     631                if (addr != NULL && len != NULL) {
     632                        int sz = *len;
     633                        if (sz < 8) {
     634                                return -EINVAL;
     635                        }
     636                        struct sockaddr_in6 *raddr = &socket->raddr6;
     637                        if (sz > sizeof(*raddr))
     638                                sz = sizeof(*raddr);
     639                        memcpy(addr, raddr, sz);
     640                        *len = sizeof(*raddr);
     641                }
     642                break;
     643        }
     644        default:
     645                return -ENOPROTOOPT;
    394646        }
    395647
     
    405657
    406658        int ret = 0;
    407         switch (fp->psock->family) {
     659        socket_t *socket = (socket_t *)fp->exinf;
     660        switch (socket->family) {
    408661        case AF_INET: {
    409                 switch (fp->psock->type) {
     662                switch (socket->type) {
    410663                case SOCK_STREAM: {
    411664                        if ((addr != NULL) || (alen != 0)) {
     
    414667
    415668                        if (flags & MSG_OOB) {
    416                                 ret = tcp_snd_oob(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
     669                                ret = tcp_snd_oob(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
    417670                                if (ret < 0) {
    418671                                        return -ECOMM;
     
    421674                        else {
    422675                                for (;;) {
    423                                         ret = tcp_snd_dat(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
     676                                        ret = tcp_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
    424677                                        if (ret < 0) {
    425678                                                if (ret == E_TMOUT)
     
    440693                                return -EINVAL;
    441694                        }
    442                         struct sockaddr_in *raddr = &fp->psock->raddr4;
     695                        struct sockaddr_in *raddr = &socket->raddr4;
    443696                        memset(raddr, 0, sizeof(*raddr));
    444697                        memcpy(raddr, addr, sz);
    445698                        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);
     699                        ret = udp_snd_dat(socket->cepid, &rep, (void *)buf, len,
     700                                (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
    448701                        if (ret < 0) {
    449702                                return (ret == E_TMOUT) ? -ETIME : -ECOMM;
     
    455708        }
    456709        case AF_INET6: {
    457                 return -EAFNOSUPPORT;
    458         }
     710                switch (socket->type) {
     711                case SOCK_STREAM: {
     712                        if ((addr != NULL) || (alen != 0)) {
     713                                return -EISCONN;
     714                        }
     715
     716                        if (flags & MSG_OOB) {
     717                                ret = tcp6_snd_oob(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
     718                                if (ret < 0) {
     719                                        return -ECOMM;
     720                                }
     721                        }
     722                        else {
     723                                for (;;) {
     724                                        ret = tcp6_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
     725                                        if (ret < 0) {
     726                                                if (ret == E_TMOUT)
     727                                                        return -ETIME;
     728                                                return -ECOMM;
     729                                        }
     730                                        len -= ret;
     731                                        if (len <= 0)
     732                                                break;
     733                                        buf = (const void *)&((uint8_t *)buf)[ret];
     734                                }
     735                        }
     736                        break;
     737                }
     738                case SOCK_DGRAM: {
     739                        int sz = alen;
     740                        if ((addr == NULL) || (sz < 8)) {
     741                                return -EINVAL;
     742                        }
     743                        struct sockaddr_in6 *raddr = &socket->raddr6;
     744                        memset(raddr, 0, sizeof(*raddr));
     745                        memcpy(raddr, addr, sz);
     746                        T_IPV6EP rep = { ntohl(raddr->sin6_addr.__in6_union.__s6_addr), ntohs(raddr->sin6_port) };
     747                        ret = udp6_snd_dat(socket->cepid, &rep, (void *)buf, len,
     748                                (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
     749                        if (ret < 0) {
     750                                return (ret == E_TMOUT) ? -ETIME : -ECOMM;
     751                        }
     752                        break;
     753                }
     754                }
     755                break;
     756        }
     757        default:
     758                return -ENOPROTOOPT;
    459759        }
    460760
     
    476776
    477777        int ret = 0;
    478         switch (fp->psock->family) {
     778        socket_t *socket = (socket_t *)fp->exinf;
     779        switch (socket->family) {
    479780        case AF_INET: {
    480                 switch (fp->psock->type) {
     781                switch (socket->type) {
    481782                case SOCK_STREAM: {
    482783                        if (flags & MSG_OOB) {
    483                                 ret = tcp_rcv_oob(fp->psock->cepid, buf, len);
     784                                ret = tcp_rcv_oob(socket->cepid, buf, len);
    484785                                if (ret < 0) {
    485786                                        syslog(LOG_ERROR, "tcp_rcv_oob => %d", ret);
     
    489790                        else {
    490791                                int rsz, tmp;
    491                                 if (fp->psock->input == NULL) {
     792                                if (socket->input == NULL) {
    492793                                        ret = wai_sem(SEM_FILEDESC);
    493794                                        if (ret < 0) {
    494795                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
    495796                                        }
    496                                         fp->psock->len = 0;
     797                                        socket->len = 0;
    497798                                        ret = sig_sem(SEM_FILEDESC);
    498799                                        if (ret < 0) {
    499800                                                syslog(LOG_ERROR, "sig_sem => %d", ret);
    500801                                        }
    501                                         ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_FEVR);
     802                                        ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_FEVR);
    502803                                        if (ret < 0) {
    503804                                                syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
     
    507808                                }
    508809                                else
    509                                         rsz = fp->psock->len;
     810                                        rsz = socket->len;
    510811                                tmp = rsz;
    511812                                if (rsz > len)
    512813                                        rsz = len;
    513814                                if (rsz >= 0) {
    514                                         memcpy(buf, fp->psock->input, rsz);
     815                                        memcpy(buf, socket->input, rsz);
    515816                                        ret = wai_sem(SEM_FILEDESC);
    516817                                        if (ret < 0) {
    517818                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
    518819                                        }
    519                                         fp->psock->len = tmp - rsz;
     820                                        socket->len = tmp - rsz;
    520821                                        ret = sig_sem(SEM_FILEDESC);
    521822                                        if (ret < 0) {
     
    523824                                        }
    524825                                        if (tmp - rsz == 0) {
    525                                                 fp->psock->input = NULL;
     826                                                socket->input = NULL;
    526827                                        }
    527828                                        else
    528                                                 fp->psock->input = (void *)&((uint8_t *)fp->psock->input)[rsz];
    529                                         ret = tcp_rel_buf(fp->psock->cepid, rsz);
     829                                                socket->input = (void *)&((uint8_t *)socket->input)[rsz];
     830                                        ret = tcp_rel_buf(socket->cepid, rsz);
    530831                                        if ((ret != E_OBJ) && (ret < 0)) {
    531832                                                syslog(LOG_ERROR, "tcp_rel_buf => %d", ret);
     
    538839                }
    539840                case SOCK_DGRAM: {
    540                         struct sockaddr_in *raddr = &fp->psock->raddr4;
     841                        struct sockaddr_in *raddr = &socket->raddr4;
    541842                        int rsz;
    542843                        ret = wai_sem(SEM_FILEDESC);
     
    544845                                syslog(LOG_ERROR, "wai_sem => %d", ret);
    545846                        }
    546                         T_NET_BUF *input = fp->psock->input;
     847                        T_NET_BUF *input = socket->input;
    547848                        if (input == NULL) {
    548849                                ret = sig_sem(SEM_FILEDESC);
     
    552853
    553854                                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);
     855                                ret = udp_rcv_dat(socket->cepid, &rep, buf, len,
     856                                        (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
    556857                                if (ret < 0) {
    557                                         syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
     858                                        if ((socket->flags & O_NONBLOCK) == 0)
     859                                                syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
    558860                                        return (ret == E_TMOUT) ? -ETIME : -ECOMM;
    559861                                }
     
    565867                                        }
    566868                                        int sz = *alen;
    567                                         memset(raddr, 0, sizeof(fp->psock->raddr4));
     869                                        memset(raddr, 0, sizeof(socket->raddr4));
    568870                                        raddr->sin_family = AF_INET;
    569871                                        raddr->sin_port = htons(rep.portno);
    570872                                        raddr->sin_addr.s_addr = htonl(rep.ipaddr);
    571                                         if (sz > sizeof(fp->psock->raddr4))
    572                                                 sz = sizeof(fp->psock->raddr4);
     873                                        if (sz > sizeof(socket->raddr4))
     874                                                sz = sizeof(socket->raddr4);
    573875                                        memcpy(addr, raddr, sz);
    574876                                        *alen = sz;
     
    580882                        }
    581883                        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;
     884                                rsz = socket->len;
     885                                void *pbuf = socket->buf;
     886                                socket->input = NULL;
     887                                socket->len = 0;
     888                                socket->buf = NULL;
    587889                                if ((addr != NULL) && (alen != NULL)) {
    588890                                        int sz = *alen;
    589                                         if (sz > sizeof(fp->psock->raddr4))
    590                                                 sz = sizeof(fp->psock->raddr4);
     891                                        if (sz > sizeof(socket->raddr4))
     892                                                sz = sizeof(socket->raddr4);
    591893                                        memcpy(addr, raddr, sz);
    592894                                        *alen = sz;
     
    611913        }
    612914        case AF_INET6: {
    613                 return -EAFNOSUPPORT;
    614         }
     915                switch (socket->type) {
     916                case SOCK_STREAM: {
     917                        if (flags & MSG_OOB) {
     918                                ret = tcp6_rcv_oob(socket->cepid, buf, len);
     919                                if (ret < 0) {
     920                                        syslog(LOG_ERROR, "tcp6_rcv_oob => %d", ret);
     921                                        return -ECOMM;
     922                                }
     923                        }
     924                        else {
     925                                int rsz, tmp;
     926                                if (socket->input == NULL) {
     927                                        ret = wai_sem(SEM_FILEDESC);
     928                                        if (ret < 0) {
     929                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
     930                                        }
     931                                        socket->len = 0;
     932                                        ret = sig_sem(SEM_FILEDESC);
     933                                        if (ret < 0) {
     934                                                syslog(LOG_ERROR, "sig_sem => %d", ret);
     935                                        }
     936                                        ret = tcp6_rcv_buf(socket->cepid, &socket->input, TMO_FEVR);
     937                                        if (ret < 0) {
     938                                                syslog(LOG_ERROR, "tcp6_rcv_buf => %d", ret);
     939                                                return -ECOMM;
     940                                        }
     941                                        rsz = ret;
     942                                }
     943                                else
     944                                        rsz = socket->len;
     945                                tmp = rsz;
     946                                if (rsz > len)
     947                                        rsz = len;
     948                                if (rsz >= 0) {
     949                                        memcpy(buf, socket->input, rsz);
     950                                        ret = wai_sem(SEM_FILEDESC);
     951                                        if (ret < 0) {
     952                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
     953                                        }
     954                                        socket->len = tmp - rsz;
     955                                        ret = sig_sem(SEM_FILEDESC);
     956                                        if (ret < 0) {
     957                                                syslog(LOG_ERROR, "sig_sem => %d", ret);
     958                                        }
     959                                        if (tmp - rsz == 0) {
     960                                                socket->input = NULL;
     961                                        }
     962                                        else
     963                                                socket->input = (void *)&((uint8_t *)socket->input)[rsz];
     964                                        ret = tcp6_rel_buf(socket->cepid, rsz);
     965                                        if ((ret != E_OBJ) && (ret < 0)) {
     966                                                syslog(LOG_ERROR, "tcp6_rel_buf => %d", ret);
     967                                                //return -ECOMM;
     968                                        }
     969                                }
     970                                ret = rsz;
     971                        }
     972                        break;
     973                }
     974                case SOCK_DGRAM: {
     975                        struct sockaddr_in6 *raddr = &socket->raddr6;
     976                        int rsz;
     977                        ret = wai_sem(SEM_FILEDESC);
     978                        if (ret < 0) {
     979                                syslog(LOG_ERROR, "wai_sem => %d", ret);
     980                        }
     981                        T_NET_BUF *input = socket->input;
     982                        if (input == NULL) {
     983                                ret = sig_sem(SEM_FILEDESC);
     984                                if (ret < 0) {
     985                                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     986                                }
     987
     988                                T_IPV6EP rep = { 0, 0 };
     989                                ret = udp6_rcv_dat(socket->cepid, &rep, buf, len,
     990                                        (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
     991                                if (ret < 0) {
     992                                        if ((socket->flags & O_NONBLOCK) == 0)
     993                                                syslog(LOG_ERROR, "udp6_rcv_buf => %d", ret);
     994                                        return (ret == E_TMOUT) ? -ETIME : -ECOMM;
     995                                }
     996                                rsz = ret;
     997                                if ((addr != NULL) && (alen != NULL)) {
     998                                        ret = wai_sem(SEM_FILEDESC);
     999                                        if (ret < 0) {
     1000                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
     1001                                        }
     1002                                        int sz = *alen;
     1003                                        memset(raddr, 0, sizeof(socket->raddr6));
     1004                                        raddr->sin6_family = AF_INET;
     1005                                        raddr->sin6_port = htons(rep.portno);
     1006#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
     1007                                        memcpy(raddr->sin6_addr.__in6_union.__s6_addr, rep.ipaddr.__u6_addr.__u6_addr8, 16);
     1008#else
     1009                                        for (int i = 0; i < 16; i++)
     1010                                                raddr->sin6_addr.__in6_union.__s6_addr[i] = rep.ipaddr.__u6_addr.__u6_addr8[i];
     1011#endif
     1012                                        if (sz > sizeof(socket->raddr6))
     1013                                                sz = sizeof(socket->raddr6);
     1014                                        memcpy(addr, raddr, sz);
     1015                                        *alen = sz;
     1016                                        ret = sig_sem(SEM_FILEDESC);
     1017                                        if (ret < 0) {
     1018                                                syslog(LOG_ERROR, "sig_sem => %d", ret);
     1019                                        }
     1020                                }
     1021                        }
     1022                        else {
     1023                                rsz = socket->len;
     1024                                void *pbuf = socket->buf;
     1025                                socket->input = NULL;
     1026                                socket->len = 0;
     1027                                socket->buf = NULL;
     1028                                if ((addr != NULL) && (alen != NULL)) {
     1029                                        int sz = *alen;
     1030                                        if (sz > sizeof(socket->raddr6))
     1031                                                sz = sizeof(socket->raddr6);
     1032                                        memcpy(addr, raddr, sz);
     1033                                        *alen = sz;
     1034                                }
     1035                                ret = sig_sem(SEM_FILEDESC);
     1036                                if (ret < 0) {
     1037                                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1038                                }
     1039                                if (rsz > len)
     1040                                        rsz = len;
     1041                                memcpy(buf, pbuf, rsz);
     1042                                ret = rel_net_buf(input);
     1043                                if (ret < 0) {
     1044                                        syslog(LOG_ERROR, "rel_net_buf => %d", ret);
     1045                                        //return -ECOMM;
     1046                                }
     1047                        }
     1048                        ret = rsz;
     1049                }
     1050                }
     1051                break;
     1052        }
     1053        default:
     1054                return -ENOPROTOOPT;
    6151055        }
    6161056
     
    6321072
    6331073        ER ret;
    634         switch (fp->psock->family) {
     1074        socket_t *socket = (socket_t *)fp->exinf;
     1075        switch (socket->family) {
    6351076        case AF_INET: {
    636                 switch (fp->psock->type) {
     1077                switch (socket->type) {
    6371078                case SOCK_STREAM: {
    638                         ret = tcp_sht_cep(fp->psock->cepid);
     1079                        ret = tcp_sht_cep(socket->cepid);
    6391080                        if (ret < 0) {
    6401081                                return -ECOMM;
     
    6461087        }
    6471088        case AF_INET6: {
    648                 return -EAFNOSUPPORT;
    649         }
     1089                switch (socket->type) {
     1090                case SOCK_STREAM: {
     1091                        ret = tcp6_sht_cep(socket->cepid);
     1092                        if (ret < 0) {
     1093                                return -ECOMM;
     1094                        }
     1095                        break;
     1096                }
     1097                }
     1098                break;
     1099        }
     1100        default:
     1101                return -ENOPROTOOPT;
    6501102        }
    6511103
     
    6611113
    6621114        ER ret;
    663         switch (fp->psock->family) {
     1115        socket_t *socket = (socket_t *)fp->exinf;
     1116        switch (socket->family) {
    6641117        case AF_INET: {
    665                 switch (fp->psock->type) {
     1118                switch (socket->type) {
    6661119                case SOCK_STREAM: {
    6671120                        switch (level) {
     
    6691122                                switch (optname) {
    6701123                                case SO_REUSEADDR:
    671                                         if (fp->psock->flags & SO_REUSEADDR) {
     1124                                        if (socket->flags & SO_REUSEADDR) {
    6721125                                                *(bool *)optval = true;
    6731126                                        }
     
    6771130                                        break;
    6781131                                case SO_KEEPALIVE:
    679                                         if (fp->psock->flags & SO_KEEPALIVE) {
     1132                                        if (socket->flags & SO_KEEPALIVE) {
    6801133                                                *(bool *)optval = true;
    6811134                                        }
     
    6921145                                break;
    6931146                        case IPPROTO_TCP:
    694                                 ret = tcp_get_opt(fp->psock->cepid, optname, (void *)optval, *optlen);
     1147                                ret = tcp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
    6951148                                if (ret < 0) {
    6961149                                        return -EINVAL;
     
    7061159                        switch (level) {
    7071160                        case IPPROTO_UDP:
    708                                 ret = udp_get_opt(fp->psock->cepid, optname, (void *)optval, *optlen);
     1161                                ret = udp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
    7091162                                if (ret < 0) {
    7101163                                        return -EINVAL;
     
    7211174        }
    7221175        case AF_INET6: {
    723                 return -EAFNOSUPPORT;
    724         }
     1176                switch (socket->type) {
     1177                case SOCK_STREAM: {
     1178                        switch (level) {
     1179                        case SOL_SOCKET:
     1180                                switch (optname) {
     1181                                case SO_REUSEADDR:
     1182                                        if (socket->flags & SO_REUSEADDR) {
     1183                                                *(bool *)optval = true;
     1184                                        }
     1185                                        else {
     1186                                                *(bool *)optval = false;
     1187                                        }
     1188                                        break;
     1189                                case SO_KEEPALIVE:
     1190                                        if (socket->flags & SO_KEEPALIVE) {
     1191                                                *(bool *)optval = true;
     1192                                        }
     1193                                        else {
     1194                                                *(bool *)optval = false;
     1195                                        }
     1196                                        break;
     1197                                case SO_ERROR:
     1198                                        *(int *)optval = 0;
     1199                                        break;
     1200                                default:
     1201                                        return -EINVAL;
     1202                                }
     1203                                break;
     1204                        case IPPROTO_TCP:
     1205                                ret = tcp6_get_opt(socket->cepid, optname, (void *)optval, *optlen);
     1206                                if (ret < 0) {
     1207                                        return -EINVAL;
     1208                                }
     1209                                *optlen = ret;
     1210                                break;
     1211                        default:
     1212                                return -EINVAL;
     1213                        }
     1214                        break;
     1215                }
     1216                case SOCK_DGRAM: {
     1217                        switch (level) {
     1218                        case IPPROTO_UDP:
     1219                                ret = udp6_get_opt(socket->cepid, optname, (void *)optval, *optlen);
     1220                                if (ret < 0) {
     1221                                        return -EINVAL;
     1222                                }
     1223                                *optlen = ret;
     1224                                break;
     1225                        default:
     1226                                return -EINVAL;
     1227                        }
     1228                        break;
     1229                }
     1230                }
     1231                break;
     1232        }
     1233        default:
     1234                return -ENOPROTOOPT;
    7251235        }
    7261236
     
    7361246
    7371247        ER ret;
    738         switch (fp->psock->family) {
     1248        socket_t *socket = (socket_t *)fp->exinf;
     1249        switch (socket->family) {
    7391250        case AF_INET: {
    740                 switch (fp->psock->type) {
     1251                switch (socket->type) {
    7411252                case SOCK_STREAM: {
    7421253                        switch (level){
     
    7451256                                case SO_REUSEADDR:
    7461257                                        if (*(bool *)optval) {
    747                                                 fp->psock->flags |= SO_REUSEADDR;
     1258                                                socket->flags |= SO_REUSEADDR;
    7481259                                        }
    7491260                                        else {
    750                                                 fp->psock->flags &= ~SO_REUSEADDR;
     1261                                                socket->flags &= ~SO_REUSEADDR;
    7511262                                        }
    7521263                                        break;
    7531264                                case SO_KEEPALIVE:
    7541265                                        if (*(bool *)optval) {
    755                                                 fp->psock->flags |= SO_KEEPALIVE;
     1266                                                socket->flags |= SO_KEEPALIVE;
    7561267                                        }
    7571268                                        else {
    758                                                 fp->psock->flags &= ~SO_KEEPALIVE;
     1269                                                socket->flags &= ~SO_KEEPALIVE;
    7591270                                        }
    7601271                                        break;
     
    7641275                                break;
    7651276                        case IPPROTO_TCP:
    766                                 ret = tcp_set_opt(fp->psock->cepid, optname, (void *)optval, optlen);
     1277                                ret = tcp_set_opt(socket->cepid, optname, (void *)optval, optlen);
    7671278                                if (ret < 0) {
    7681279                                        return -EINVAL;
     
    7771288                        switch (level){
    7781289                        case IPPROTO_UDP:
    779                                 ret = udp_set_opt(fp->psock->cepid, optname, (void *)optval, optlen);
     1290                                ret = udp_set_opt(socket->cepid, optname, (void *)optval, optlen);
    7801291                                if (ret < 0) {
    7811292                                        return -EINVAL;
     
    7911302        }
    7921303        case AF_INET6: {
    793                 return -EAFNOSUPPORT;
    794         }
     1304                switch (socket->type) {
     1305                case SOCK_STREAM: {
     1306                        switch (level){
     1307                        case SOL_SOCKET:
     1308                                switch (optname) {
     1309                                case SO_REUSEADDR:
     1310                                        if (*(bool *)optval) {
     1311                                                socket->flags |= SO_REUSEADDR;
     1312                                        }
     1313                                        else {
     1314                                                socket->flags &= ~SO_REUSEADDR;
     1315                                        }
     1316                                        break;
     1317                                case SO_KEEPALIVE:
     1318                                        if (*(bool *)optval) {
     1319                                                socket->flags |= SO_KEEPALIVE;
     1320                                        }
     1321                                        else {
     1322                                                socket->flags &= ~SO_KEEPALIVE;
     1323                                        }
     1324                                        break;
     1325                                default:
     1326                                        return -EINVAL;
     1327                                }
     1328                                break;
     1329                        case IPPROTO_TCP:
     1330                                ret = tcp6_set_opt(socket->cepid, optname, (void *)optval, optlen);
     1331                                if (ret < 0) {
     1332                                        return -EINVAL;
     1333                                }
     1334                                break;
     1335                        default:
     1336                                return -EINVAL;
     1337                        }
     1338                        break;
     1339                }
     1340                case SOCK_DGRAM: {
     1341                        switch (level){
     1342                        case IPPROTO_UDP:
     1343                                ret = udp6_set_opt(socket->cepid, optname, (void *)optval, optlen);
     1344                                if (ret < 0) {
     1345                                        return -EINVAL;
     1346                                }
     1347                                break;
     1348                        default:
     1349                                return -EINVAL;
     1350                        }
     1351                        break;
     1352                }
     1353                }
     1354                break;
     1355        }
     1356        default:
     1357                return -ENOPROTOOPT;
    7951358        }
    7961359
     
    8091372
    8101373        socklen_t size = *len;
    811         switch (fp->psock->family) {
     1374        socket_t *socket = (socket_t *)fp->exinf;
     1375        switch (socket->family) {
    8121376        case AF_INET: {
    813                 struct sockaddr_in *raddr = &fp->psock->raddr4;
     1377                struct sockaddr_in *raddr = &socket->raddr4;
    8141378                *len = sizeof(struct sockaddr_in);
    8151379                if (size > sizeof(struct sockaddr_in))
     
    8191383        }
    8201384        case AF_INET6: {
    821                 return -EAFNOSUPPORT;
    822         }
     1385                struct sockaddr_in6 *raddr = &socket->raddr6;
     1386                *len = sizeof(struct sockaddr_in6);
     1387                if (size > sizeof(struct sockaddr_in6))
     1388                        size = sizeof(struct sockaddr_in6);
     1389                memcpy(addr, raddr, size);
     1390                break;
     1391        }
     1392        default:
     1393                return -ENOPROTOOPT;
    8231394        }
    8241395
     
    8371408
    8381409        socklen_t size = *len;
    839         switch (fp->psock->family) {
     1410        socket_t *socket = (socket_t *)fp->exinf;
     1411        switch (socket->family) {
    8401412        case AF_INET: {
    8411413                const T_IN4_ADDR *laddr4 = in4_get_ifaddr(0);
     
    8431415                laddr.sin_family = AF_INET;
    8441416                laddr.sin_addr.s_addr = htonl(*laddr4);
    845                 laddr.sin_port = fp->psock->laddr4.sin_port;
     1417                laddr.sin_port = socket->laddr4.sin_port;
    8461418                memset(&laddr.sin_zero, 0, sizeof(laddr.sin_zero));
    8471419                *len = sizeof(struct sockaddr_in);
     
    8521424        }
    8531425        case AF_INET6: {
    854                 return -EAFNOSUPPORT;
    855         }
     1426                const T_IN6_ADDR *laddr6 = in6_get_ifaddr(0);
     1427                struct sockaddr_in6 laddr;
     1428                laddr.sin6_family = AF_INET;
     1429#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
     1430                memcpy(laddr.sin6_addr.__in6_union.__s6_addr, laddr6->__u6_addr.__u6_addr8, 16);
     1431#else
     1432                for (int i = 0; i < 16; i++)
     1433                        laddr.sin6_addr.__in6_union.__s6_addr[i] = laddr6->__u6_addr.__u6_addr8[i];
     1434#endif
     1435                laddr.sin6_port = socket->laddr6.sin6_port;
     1436                *len = sizeof(struct sockaddr_in6);
     1437                if (size > sizeof(struct sockaddr_in6))
     1438                        size = sizeof(struct sockaddr_in6);
     1439                memcpy(addr, &laddr, size);
     1440                break;
     1441        }
     1442        default:
     1443                return -ENOPROTOOPT;
    8561444        }
    8571445
     
    8591447}
    8601448
    861 int tcp_fd_close(struct _IO_FILE *fp)
     1449int tcp_fd_close(struct SHELL_FILE *fp)
    8621450{
    8631451        ER ret, ret2;
    8641452
    865         switch (fp->psock->family) {
     1453        socket_t *socket = (socket_t *)fp->exinf;
     1454        switch (socket->family) {
    8661455        case AF_INET: {
    867                 if (fp->psock->cepid != 0) {
    868                         ID cepid = fp->psock->cepid;
     1456                if (socket->cepid != 0) {
     1457                        ID cepid = socket->cepid;
    8691458                        ret = tcp_sht_cep(cepid);
    8701459                        if (ret < 0) {
    8711460                                //return -1;
    8721461                        }
    873                         ret = tcp_cls_cep(cepid, (fp->psock->repid != 0) ? 0 : SOCKET_TIMEOUT);
     1462                        ret = tcp_cls_cep(cepid, (socket->repid != 0) ? 0 : SOCKET_TIMEOUT);
    8741463                        ret2 = tcp_del_cep(cepid);
    875                         free(fp->psock->buf);
    876                         fp->psock->buf = NULL;
    877                         delete_tcp_fd(cepid);
     1464                        //delete_fd_by_id(&IO_TYPE_TCP, cepid);
    8781465                        delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
    8791466                        if ((ret < 0) || (ret2 < 0)) {
     
    8811468                        }
    8821469                }
    883                 else if (fp->psock->repid != 0) {
    884                         ID repid = fp->psock->repid;
     1470                else if (socket->repid != 0) {
     1471                        ID repid = socket->repid;
    8851472                        ret = tcp_del_rep(repid);
    886                         free(fp->psock->buf);
    887                         fp->psock->buf = NULL;
    888                         delete_tcp_fd(tmax_tcp_cepid + repid);
     1473                        //delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + repid);
    8891474                        delete_id(tcp_repid_table, tcp_repid_table_count, repid);
    8901475                        if (ret < 0) {
     
    8931478                }
    8941479                else {
    895                         free(fp->psock->buf);
    896                         fp->psock->buf = NULL;
    8971480                        return -EINVAL;
    8981481                }
     
    9001483        }
    9011484        case AF_INET6: {
    902                 return -EAFNOSUPPORT;
    903         }
     1485                if (socket->cepid != 0) {
     1486                        ID cepid = socket->cepid;
     1487                        ret = tcp6_sht_cep(cepid);
     1488                        if (ret < 0) {
     1489                                //return -1;
     1490                        }
     1491                        ret = tcp6_cls_cep(cepid, (socket->repid != 0) ? 0 : SOCKET_TIMEOUT);
     1492                        ret2 = tcp6_del_cep(cepid);
     1493                        //delete_fd_by_id(&IO_TYPE_TCP, cepid);
     1494                        delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid);
     1495                        if ((ret < 0) || (ret2 < 0)) {
     1496                                return (ret == E_TMOUT) ? -ETIME : -EINVAL;
     1497                        }
     1498                }
     1499                else if (socket->repid != 0) {
     1500                        ID repid = socket->repid;
     1501                        ret = tcp6_del_rep(repid);
     1502                        //delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp6_cepid + repid);
     1503                        delete_id(tcp6_repid_table, tcp6_repid_table_count, repid);
     1504                        if (ret < 0) {
     1505                                return -EINVAL;
     1506                        }
     1507                }
     1508                else {
     1509                        return -EINVAL;
     1510                }
     1511                break;
     1512        }
     1513        default:
     1514                return -ENOPROTOOPT;
    9041515        }
    9051516
     
    9071518}
    9081519
    909 size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
     1520size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
    9101521{
    9111522        return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
    9121523}
    9131524
    914 size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
     1525size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
    9151526{
    9161527        return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
    9171528}
    9181529
    919 off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
     1530off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
    9201531{
    9211532        return -EPERM;
    9221533}
    9231534
    924 int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
     1535int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
    9251536{
    9261537        return -EINVAL;
    9271538}
    9281539
    929 int udp_fd_close(struct _IO_FILE *fp)
     1540bool_t tcp_fd_readable(struct SHELL_FILE *fp)
     1541{
     1542        ER ret;
     1543
     1544        socket_t *socket = (socket_t *)fp->exinf;
     1545        if (socket->cepid != 0) {
     1546                if (socket->len == 0) {
     1547                        ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_NBLK);
     1548                        if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) {
     1549                                syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
     1550                                //return ret;
     1551                        }
     1552                        if (ret > 0) {
     1553                                ret = wai_sem(SEM_FILEDESC);
     1554                                if (ret < 0) {
     1555                                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1556                                }
     1557                                socket->len += ret;
     1558                                ret = sig_sem(SEM_FILEDESC);
     1559                                if (ret < 0) {
     1560                                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1561                                }
     1562                        }
     1563                }
     1564                else ret = 1;
     1565                if (ret > 0) {
     1566                        return true;
     1567                }
     1568        }
     1569
     1570        return false;
     1571}
     1572
     1573void tcp_fd_delete(struct SHELL_FILE *fp)
     1574{
     1575        socket_t *socket = (socket_t *)fp->exinf;
     1576        free(socket->buf);
     1577        socket->buf = NULL;
     1578        free(fp->exinf);
     1579        fp->exinf = NULL;
     1580}
     1581
     1582ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk)
     1583{
     1584        struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_TCP, cepid);
     1585        FLGPTN flgptn = 0;
     1586        ER ret;
     1587        int len;
     1588
     1589        if (fp == NULL)
     1590                return E_PAR;
     1591
     1592        int fd = fp->fd;
     1593        FD_SET(fd, (fd_set *)&flgptn);
     1594
     1595        switch (fncd) {
     1596        case TFN_TCP_RCV_BUF:
     1597                len = *(int *)p_parblk;
     1598                if ((len <= 0) || (fp->exinf == NULL))
     1599                        return E_OK;
     1600
     1601                ret = wai_sem(SEM_FILEDESC);
     1602                if (ret < 0) {
     1603                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1604                }
     1605                socket_t *socket = (socket_t *)fp->exinf;
     1606                socket->len += len;
     1607                ret = sig_sem(SEM_FILEDESC);
     1608                if (ret < 0) {
     1609                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1610                }
     1611
     1612                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1613
     1614                set_flg(FLG_SELECT_WAIT, flgptn);
     1615                return E_OK;
     1616
     1617        case TFN_TCP_RCV_DAT:
     1618                len = *(int *)p_parblk;
     1619                if ((len <= 0) || (fp->exinf == NULL))
     1620                        return E_OK;
     1621
     1622                ret = wai_sem(SEM_FILEDESC);
     1623                if (ret < 0) {
     1624                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1625                }
     1626                socket->len += len;
     1627                ret = sig_sem(SEM_FILEDESC);
     1628                if (ret < 0) {
     1629                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1630                }
     1631
     1632                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1633
     1634                set_flg(FLG_SELECT_WAIT, flgptn);
     1635                return E_OK;
     1636
     1637        case TFN_TCP_SND_DAT:
     1638                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
     1639
     1640                set_flg(FLG_SELECT_WAIT, flgptn);
     1641                return E_OK;
     1642
     1643        case TFN_TCP_CAN_CEP:
     1644                if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
     1645
     1646                set_flg(FLG_SELECT_WAIT, flgptn);
     1647                return E_OK;
     1648
     1649        case TFN_TCP_DEL_REP:
     1650                delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + cepid);
     1651                return E_OK;
     1652
     1653        case TFN_TCP_DEL_CEP:
     1654                delete_fd_by_id(&IO_TYPE_TCP, cepid);
     1655                return E_OK;
     1656
     1657        default:
     1658                return E_OK;
     1659        }
     1660}
     1661
     1662ER socket_tcp6_callback(ID cepid, FN fncd, void *p_parblk)
     1663{
     1664        struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_TCP, cepid);
     1665        FLGPTN flgptn = 0;
     1666        ER ret;
     1667        int len;
     1668
     1669        if (fp == NULL)
     1670                return E_PAR;
     1671
     1672        int fd = fp->fd;
     1673        FD_SET(fd, (fd_set *)&flgptn);
     1674
     1675        switch (fncd) {
     1676        case TFN_TCP_RCV_BUF:
     1677                len = *(int *)p_parblk;
     1678                if ((len <= 0) || (fp->exinf == NULL))
     1679                        return E_OK;
     1680
     1681                ret = wai_sem(SEM_FILEDESC);
     1682                if (ret < 0) {
     1683                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1684                }
     1685                socket_t *socket = (socket_t *)fp->exinf;
     1686                socket->len += len;
     1687                ret = sig_sem(SEM_FILEDESC);
     1688                if (ret < 0) {
     1689                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1690                }
     1691
     1692                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1693
     1694                set_flg(FLG_SELECT_WAIT, flgptn);
     1695                return E_OK;
     1696
     1697        case TFN_TCP_RCV_DAT:
     1698                len = *(int *)p_parblk;
     1699                if ((len <= 0) || (fp->exinf == NULL))
     1700                        return E_OK;
     1701
     1702                ret = wai_sem(SEM_FILEDESC);
     1703                if (ret < 0) {
     1704                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1705                }
     1706                socket->len += len;
     1707                ret = sig_sem(SEM_FILEDESC);
     1708                if (ret < 0) {
     1709                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1710                }
     1711
     1712                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1713
     1714                set_flg(FLG_SELECT_WAIT, flgptn);
     1715                return E_OK;
     1716
     1717        case TFN_TCP_SND_DAT:
     1718                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
     1719
     1720                set_flg(FLG_SELECT_WAIT, flgptn);
     1721                return E_OK;
     1722
     1723        case TFN_TCP_CAN_CEP:
     1724                if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
     1725
     1726                set_flg(FLG_SELECT_WAIT, flgptn);
     1727                return E_OK;
     1728
     1729        case TFN_TCP_DEL_REP:
     1730                delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + cepid);
     1731                return E_OK;
     1732
     1733        case TFN_TCP_DEL_CEP:
     1734                delete_fd_by_id(&IO_TYPE_TCP, cepid);
     1735                return E_OK;
     1736
     1737        default:
     1738                return E_OK;
     1739        }
     1740}
     1741
     1742int udp_fd_close(struct SHELL_FILE *fp)
    9301743{
    9311744        ER ret;
    9321745        ID cepid;
    9331746
    934         switch (fp->psock->family) {
     1747        socket_t *socket = (socket_t *)fp->exinf;
     1748        switch (socket->family) {
    9351749        case AF_INET: {
    936                 cepid = fp->psock->cepid;
     1750                cepid = socket->cepid;
    9371751                ret = udp_del_cep(cepid);
    938                 //free(fp->psock->buf);
    939                 //fp->psock->buf = NULL;
    940                 delete_udp_fd(cepid);
     1752                //delete_fd_by_id(&IO_TYPE_UDP, cepid);
    9411753                delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
    9421754                if (ret < 0) {
     
    9461758        }
    9471759        case AF_INET6: {
    948                 return -EAFNOSUPPORT;
    949         }
     1760                cepid = socket->cepid;
     1761                ret = udp6_del_cep(cepid);
     1762                //delete_fd_by_id(&IO_TYPE_UDP, cepid);
     1763                delete_id(udp6_cepid_table, udp6_cepid_table_count, cepid);
     1764                if (ret < 0) {
     1765                        return -EINVAL;
     1766                }
     1767                break;
     1768        }
     1769        default:
     1770                return -ENOPROTOOPT;
    9501771        }
    9511772
     
    9531774}
    9541775
    955 size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
     1776size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
    9561777{
    9571778        return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
    9581779}
    9591780
    960 size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
     1781size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
    9611782{
    9621783        return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
    9631784}
    9641785
    965 off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
     1786off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
    9661787{
    9671788        return -EPERM;
    9681789}
    9691790
    970 int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
     1791int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
    9711792{
    9721793        return -EINVAL;
     1794}
     1795
     1796bool_t udp_fd_readable(struct SHELL_FILE *fp)
     1797{
     1798        socket_t *socket = (socket_t *)fp->exinf;
     1799        if (socket->cepid != 0) {
     1800                if (socket->input != NULL) {
     1801                        return true;
     1802                }
     1803        }
     1804
     1805        return false;
     1806}
     1807
     1808void udp_fd_delete(struct SHELL_FILE *fp)
     1809{
     1810        //socket_t *socket = (socket_t *)fp->exinf;
     1811        //free(socket->buf);
     1812        //socket->buf = NULL;
     1813        free(fp->exinf);
     1814        fp->exinf = NULL;
     1815}
     1816
     1817ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk)
     1818{
     1819        struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_UDP, cepid);
     1820        FLGPTN flgptn = 0;
     1821        int len;
     1822
     1823        if (fp == NULL)
     1824                return E_PAR;
     1825
     1826        int fd = fp->fd;
     1827        FD_SET(fd, (fd_set *)&flgptn);
     1828
     1829        switch (fncd) {
     1830        case TEV_UDP_RCV_DAT:
     1831        {
     1832                T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
     1833                len = udppara->len;
     1834                if ((len <= 0) || (fp->exinf == NULL))
     1835                        return E_OK;
     1836
     1837                ER ret = wai_sem(SEM_FILEDESC);
     1838                if (ret < 0) {
     1839                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1840                }
     1841                socket_t *socket = (socket_t *)fp->exinf;
     1842                socket->len = len;
     1843                if (socket->input != NULL) {
     1844                        ret = rel_net_buf(socket->input);
     1845                        if (ret < 0) {
     1846                                syslog(LOG_ERROR, "rel_net_buf => %d", ret);
     1847                        }
     1848                }
     1849                socket->input = udppara->input;
     1850                socket->buf = GET_UDP_SDU(udppara->input, udppara->off);
     1851                memset(&socket->raddr4, 0, sizeof(socket->raddr4));
     1852                socket->raddr4.sin_family = AF_INET;
     1853                socket->raddr4.sin_port = htons(udppara->rep4.portno);
     1854                socket->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr);
     1855                udppara->input->flags |= NB_FLG_NOREL_IFOUT;
     1856                ret = sig_sem(SEM_FILEDESC);
     1857                if (ret < 0) {
     1858                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1859                }
     1860
     1861                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1862
     1863                set_flg(FLG_SELECT_WAIT, flgptn);
     1864                return E_OK;
     1865        }
     1866        case TFN_UDP_CRE_CEP:
     1867                return E_OK;
     1868
     1869        case TFN_UDP_RCV_DAT:
     1870                len = *(int *)p_parblk;
     1871                if ((len <= 0) || (fp->exinf == NULL))
     1872                        return E_OK;
     1873
     1874                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1875
     1876                set_flg(FLG_SELECT_WAIT, flgptn);
     1877                return E_OK;
     1878
     1879        case TFN_UDP_SND_DAT:
     1880                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
     1881
     1882                set_flg(FLG_SELECT_WAIT, flgptn);
     1883                return E_OK;
     1884
     1885        case TFN_UDP_CAN_CEP:
     1886                if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
     1887
     1888                set_flg(FLG_SELECT_WAIT, flgptn);
     1889                return E_OK;
     1890
     1891        case TFN_UDP_DEL_CEP:
     1892                delete_fd_by_id(&IO_TYPE_UDP, cepid);
     1893                return E_OK;
     1894
     1895        default:
     1896                return E_OK;
     1897        }
     1898}
     1899
     1900ER socket_udp6_callback(ID cepid, FN fncd, void *p_parblk)
     1901{
     1902        struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_UDP, cepid);
     1903        FLGPTN flgptn = 0;
     1904        int len;
     1905
     1906        if (fp == NULL)
     1907                return E_PAR;
     1908
     1909        int fd = fp->fd;
     1910        FD_SET(fd, (fd_set *)&flgptn);
     1911
     1912        switch (fncd) {
     1913        case TEV_UDP_RCV_DAT:
     1914        {
     1915                T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
     1916                len = udppara->len;
     1917                if ((len <= 0) || (fp->exinf == NULL))
     1918                        return E_OK;
     1919
     1920                ER ret = wai_sem(SEM_FILEDESC);
     1921                if (ret < 0) {
     1922                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1923                }
     1924                socket_t *socket = (socket_t *)fp->exinf;
     1925                socket->len = len;
     1926                if (socket->input != NULL) {
     1927                        ret = rel_net_buf(socket->input);
     1928                        if (ret < 0) {
     1929                                syslog(LOG_ERROR, "rel_net_buf => %d", ret);
     1930                        }
     1931                }
     1932                socket->input = udppara->input;
     1933                socket->buf = GET_UDP_SDU(udppara->input, udppara->off);
     1934                memset(&socket->raddr6, 0, sizeof(socket->raddr6));
     1935                socket->raddr6.sin6_family = AF_INET;
     1936                socket->raddr6.sin6_port = htons(udppara->rep6.portno);
     1937#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
     1938                memcpy(socket->raddr6.sin6_addr.__in6_union.__s6_addr, udppara->rep6.ipaddr.__u6_addr.__u6_addr8, 16);
     1939#else
     1940                for (int i = 0; i < 16; i++)
     1941                        socket->raddr6.sin6_addr.__in6_union.__s6_addr[i] = udppara->rep6.ipaddr.__u6_addr.__u6_addr8[i];
     1942#endif
     1943                udppara->input->flags |= NB_FLG_NOREL_IFOUT;
     1944                ret = sig_sem(SEM_FILEDESC);
     1945                if (ret < 0) {
     1946                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1947                }
     1948
     1949                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1950
     1951                set_flg(FLG_SELECT_WAIT, flgptn);
     1952                return E_OK;
     1953        }
     1954        case TFN_UDP_CRE_CEP:
     1955                return E_OK;
     1956
     1957        case TFN_UDP_RCV_DAT:
     1958                len = *(int *)p_parblk;
     1959                if ((len <= 0) || (fp->exinf == NULL))
     1960                        return E_OK;
     1961
     1962                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1963
     1964                set_flg(FLG_SELECT_WAIT, flgptn);
     1965                return E_OK;
     1966
     1967        case TFN_UDP_SND_DAT:
     1968                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
     1969
     1970                set_flg(FLG_SELECT_WAIT, flgptn);
     1971                return E_OK;
     1972
     1973        case TFN_UDP_CAN_CEP:
     1974                if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
     1975
     1976                set_flg(FLG_SELECT_WAIT, flgptn);
     1977                return E_OK;
     1978
     1979        case TFN_UDP_DEL_CEP:
     1980                delete_fd_by_id(&IO_TYPE_UDP, cepid);
     1981                return E_OK;
     1982
     1983        default:
     1984                return E_OK;
     1985        }
    9731986}
    9741987
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/socket_stub.h

    r364 r374  
    103103} socket_t;
    104104
    105 struct _IO_DIR {
    106         DIR dir;
     105struct SHELL_DIR {
     106        FATFS_DIR dir;
    107107        struct dirent dirent;
    108108};
    109109
    110 struct _IO_FILE {
     110typedef const struct io_type_s IO_TYPE;
     111
     112struct SHELL_FILE {
    111113        int fd;
    112         int type;
     114        IO_TYPE *type;
    113115        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 *);
    119116        int readevt_r;
    120117        int readevt_w;
     
    124121        int errorevt_r;
    125122        int errorevt_w;
    126         union {
    127                 FIL *pfile;
    128                 struct _IO_DIR *pdir;
    129                 socket_t *psock;
    130         };
     123        void *exinf;
     124};
     125
     126struct 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 *);
    131134};
    132135
     
    141144#endif
    142145
    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);
     146struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable);
     147int delete_fd_by_id(IO_TYPE *type, int id);
     148struct SHELL_FILE *fd_to_fp(int fd);
     149struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id);
    149150
    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);
     151int delete_fp(struct SHELL_FILE *fp);
    204152void clean_fd();
    205153
    206 ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk);
    207 ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk);
     154void sys_tlsf_init(void);
    208155
    209156#endif // !SOCKET_STUB_H
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/syscall.c

    r364 r374  
    442442        return no_implement("flock\n");
    443443}
     444
     445long SYS_fchdir()
     446{
     447        return no_implement("fchdir\n");
     448}
     449
     450long SYS_getegid32()
     451{
     452        return no_implement("getegid32\n");
     453}
     454
     455long SYS_geteuid32()
     456{
     457        return no_implement("geteuid32\n");
     458}
     459
     460long SYS_getgid32()
     461{
     462        return no_implement("getgid32\n");
     463}
     464
     465long SYS_pipe2()
     466{
     467        return no_implement("pipe2\n");
     468}
     469
     470long SYS_setgid32()
     471{
     472        return no_implement("setgid32\n");
     473}
     474
     475long SYS_setpgid()
     476{
     477        return no_implement("setpgid\n");
     478}
     479
     480long SYS_setsid()
     481{
     482        return no_implement("setsid\n");
     483}
     484
     485long SYS_setuid32()
     486{
     487        return no_implement("setuid32\n");
     488}
     489
     490long SYS_tgkill()
     491{
     492        return no_implement("tgkill\n");
     493}
  • asp3_tinet_ecnl_rx/trunk/ntshell/tlsf/tlsf.c

    r337 r374  
    55#include <stdlib.h>
    66#include <string.h>
    7 #include "util/ntstdio.h"
     7#include <stdio.h>
    88
    99#include "tlsf.h"
     
    1616#define tlsf_decl static
    1717#endif
    18 
    19 extern ntstdio_t ntstdio;
    2018
    2119/*
     
    889887{
    890888        (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));
    892890}
    893891
     
    978976        if (((ptrdiff_t)mem % ALIGN_SIZE) != 0)
    979977        {
    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",
    981979                        (unsigned int)ALIGN_SIZE);
    982980                return 0;
     
    986984        {
    987985#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",
    989987                        (unsigned int)(pool_overhead + block_size_min),
    990988                        (unsigned int)((pool_overhead + block_size_max) / 256));
    991989#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",
    993991                        (unsigned int)(pool_overhead + block_size_min),
    994992                        (unsigned int)(pool_overhead + block_size_max));
     
    10581056        if (rv)
    10591057        {
    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);
    10611059        }
    10621060        return rv;
     
    10751073        if (((tlsfptr_t)mem % ALIGN_SIZE) != 0)
    10761074        {
    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",
    10781076                        (unsigned int)ALIGN_SIZE);
    10791077                return 0;
Note: See TracChangeset for help on using the changeset viewer.