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

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

Location:
asp3_tinet_ecnl_arm/trunk/ntshell
Files:
25 edited

Legend:

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

    r352 r374  
    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_arm/trunk/ntshell/fatfs/diskio.c

    r352 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_arm/trunk/ntshell/fatfs/diskio.h

    r352 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_arm/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_arm/trunk/ntshell/fatfs/ff.h

    r352 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_arm/trunk/ntshell/fatfs/ffarch.c

    r369 r374  
    5151#include "sdfs.h"
    5252#include "ff.h"
    53 #include "util/ntstdio.h"
    54 
    55 extern ntstdio_t ntstdio;
     53#include <stdio.h>
     54#include "hal/rtc_api.h"
     55#include "ffarch.h"
    5656
    5757enum ffarch_state_t {
     
    8080        ret2 = get_tim(&now);
    8181        if (ret2 != E_OK){
    82                 ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s",
     82                printf("[ffarch] get_tim error: %s",
    8383                        itron_strerror(ret2));
    8484                return;
     
    9494                ret = tslp_tsk(timer);
    9595                if ((ret != E_OK) && (ret != E_TMOUT)) {
    96                         ntstdio_printf(&ntstdio, "[ffarch] tslp_tsk error: %s %d",
     96                        printf("[ffarch] tslp_tsk error: %s %d",
    9797                                itron_strerror(ret), timer);
    9898                        break;
     
    101101                ret2 = get_tim(&now);
    102102                if (ret2 != E_OK) {
    103                         ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s",
     103                        printf("[ffarch] get_tim error: %s",
    104104                                itron_strerror(ret2));
    105105                        break;
     
    150150
    151151        if (romdisk_init()) {
    152                 ntstdio_printf(&ntstdio, "ROM disk (0:) OK!\n");
     152                printf("ROM disk (0:) OK!\n");
    153153        }
    154154        else {
    155                 ntstdio_printf(&ntstdio, "ROM disk (0:) NG!\n");
    156         }
    157 
    158         serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV);
     155                printf("ROM disk (0:) NG!\n");
     156        }
    159157}
    160158
     
    272270{
    273271        DRESULT res;
    274         uint32_t *dp = (uint32_t *)buff, st, ed;
     272        uint32_t *dp = (uint32_t *)buff;
    275273        uint8_t *ptr = (uint8_t *)buff;
    276274
     
    333331{
    334332        BYTE s = 0;
    335 
     333             
    336334        /* Write protected */
    337335        if (WP())
     
    377375        case FFS_RETRY_WAIT:
    378376                if (ffarch_retry_count == 0) {
    379                         ntstdio_printf(&ntstdio, "SD card (1:) initialize tired...\n");
     377                        printf("SD card (1:) initialize tired...\n");
    380378
    381379                        ffarch_state = FFS_IDLE;
     
    390388                if ((sdfs._is_initialized & STA_NOINIT)
    391389                        || (((sdfs_prev_status & STA_NODISK) != 0) && ((sdfs_new_status & STA_NODISK) == 0))) {
    392                         ntstdio_printf(&ntstdio, "SD card initializing ...\n");
     390                        printf("SD card initializing ...\n");
    393391
    394392                        if (SD_begin()) {
    395                                 ntstdio_printf(&ntstdio, "SD card (1:) OK!\n");
     393                                printf("SD card (1:) OK!\n");
    396394
    397395                                /* uploadディレクトリを作成しておく */
     
    403401                        }
    404402                        else {
    405                                 ntstdio_printf(&ntstdio, "SD card (1:) NG!\n");
     403                                printf("SD card (1:) NG!\n");
    406404                                ffarch_state = FFS_RETRY_WAIT;
    407405                                ffarch_timer = 1000 * 1000;
     
    410408                /* SDカードが抜かれた場合 */
    411409                else if (((sdfs_prev_status & STA_NODISK) == 0) && ((sdfs_new_status & STA_NODISK) != 0)) {
    412                         ntstdio_printf(&ntstdio, "SD card unmount\n");
     410                        printf("SD card unmount\n");
    413411
    414412                        f_mount(&Sd.FatFs, "1:", 0);
     
    428426}
    429427
    430 int ff_cre_syncobj(BYTE vol, _SYNC_t* sobj)
     428int ff_cre_syncobj(BYTE vol, FF_SYNC_t* sobj)
    431429{
    432430        return 1;
    433431}
    434432
    435 int ff_req_grant(_SYNC_t sobj)
     433int ff_req_grant(FF_SYNC_t sobj)
    436434{
    437435        ER ret;
     
    440438}
    441439
    442 void ff_rel_grant(_SYNC_t sobj)
     440void ff_rel_grant(FF_SYNC_t sobj)
    443441{
    444442        sig_sem(SEM_FILESYSTEM);
    445443}
    446444
    447 int ff_del_syncobj(_SYNC_t sobj)
     445int ff_del_syncobj(FF_SYNC_t sobj)
    448446{
    449447        return 1;
  • asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffconf.h

    r352 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_arm/trunk/ntshell/fatfs/sdfs.c

    r359 r374  
    118118//#include "mbed_debug.h"
    119119#include "mbed_wait_api.h"
    120 #include "util/ntstdio.h"
    121 
    122 extern ntstdio_t ntstdio;
    123 #define debug(...) ntstdio_printf(&ntstdio, __VA_ARGS__)
    124 #define debug_if(cond, ...) if(cond){ ntstdio_printf(&ntstdio, __VA_ARGS__); }
     120#include <stdio.h>
     121
     122#define debug(...) printf(__VA_ARGS__)
     123#define debug_if(cond, ...) if(cond){ printf(__VA_ARGS__); }
    125124
    126125static int sdfs_initialise_card_v1(sdfs_t *obj);
     
    137136#define SD_DBG             0
    138137
    139 sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name)
     138void sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name)
    140139{
    141140        obj->name = name;
  • asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/sdfs.h

    r359 r374  
    8080        * @param name The name used to access the virtual filesystem
    8181        */
    82 sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
     82void sdfs_init(sdfs_t *obj, PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
    8383
    8484int sdfs_initialize(sdfs_t *obj);
  • asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/usrcmd.c

    r352 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_arm/trunk/ntshell/ntshell/usrcmd.h

    r352 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_arm/trunk/ntshell/ntshell/util/ntstdio.h

    r352 r374  
    7878        int pos;
    7979        unsigned int option;
     80        void *exinf;
    8081} ntstdio_t;
    8182
  • asp3_tinet_ecnl_arm/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
     73#ifdef _DEBUG
     74static const char THIS_FILE[] = __FILE__;
     75#endif
     76
     77static int stdio_close(struct SHELL_FILE *fp);
     78static size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     79static size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     80static size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     81static size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     82static size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     83static void stdio_delete(struct SHELL_FILE *fp);
     84
     85static int sio_close(struct SHELL_FILE *fp);
     86static size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     87static size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     88static off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org);
     89static int sio_ioctl(struct SHELL_FILE *fp, int req, void *arg);
     90static bool_t sio_readable(struct SHELL_FILE *fp);
     91static void sio_delete(struct SHELL_FILE *fp);
     92
     93IO_TYPE IO_TYPE_STDIN = { stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
     94IO_TYPE IO_TYPE_STDOUT = { stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
     95IO_TYPE IO_TYPE_STDERR = { stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
     96IO_TYPE IO_TYPE_SIO = { sio_close, sio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_delete };
     97ntstdio_t ntstdio;
     98
     99static struct SHELL_FILE fd_table[8 * sizeof(FLGPTN)] = {
     100        { 0, &IO_TYPE_STDIN, 0, .exinf = &ntstdio },
     101        { 1, &IO_TYPE_STDOUT, 0, .exinf = &ntstdio },
     102        { 2, &IO_TYPE_STDERR, 0,.exinf = &ntstdio },
    82103};
    83104#define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0]))
    84105
    85 static int new_fd(int type, int id)
    86 {
     106extern ntstdio_t ntstdio;
     107extern serial_t stdio_uart;
     108
     109unsigned char ntstdio_xi(struct ntstdio_t *handle)
     110{
     111        return serial_getc((serial_t *)handle->exinf);
     112}
     113
     114void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
     115{
     116        serial_putc((serial_t *)handle->exinf, c);
     117}
     118
     119void sys_init(intptr_t exinf)
     120{
     121        ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
     122        ntstdio.exinf = (void *)&stdio_uart;
     123}
     124
     125int stdio_close(struct SHELL_FILE *fp)
     126{
     127        return -EPERM;
     128}
     129
     130size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
     131{
     132        return -EPERM;
     133}
     134
     135size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
     136{
     137        return -EPERM;
     138}
     139
     140size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
     141{
     142        int i = 0;
     143        while (i < len) {
     144                int c = ntstdio_getc((struct ntstdio_t *)fp->exinf);
     145                data[i++] = c;
     146                if ((c == EOF) || (c == '\n'))
     147                        break;
     148        }
     149        return i;
     150}
     151
     152size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
     153{
     154        for (int i = 0; i < len; i++) {
     155                ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
     156        }
     157        return len;
     158}
     159
     160size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
     161{
     162        for (int i = 0; i < len; i++) {
     163                ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
     164        }
     165        return len;
     166}
     167
     168void stdio_delete(struct SHELL_FILE *fp)
     169{
     170}
     171
     172int sio_close(struct SHELL_FILE *fp)
     173{
     174        return -EPERM;
     175}
     176
     177size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
     178{
     179        return -EPERM;
     180}
     181
     182size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
     183{
     184        return -EPERM;
     185}
     186
     187off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org)
     188{
     189        return -EPERM;
     190}
     191
     192int sio_ioctl(struct SHELL_FILE *fp, int request, void *arg)
     193{
     194        switch (request) {
     195        case TIOCGWINSZ:
     196                return 0;
     197        case TCGETS:
     198                return sio_tcgetattr(fp->fd, (struct termios *)arg);
     199        case TCSETS + TCSANOW:
     200        case TCSETS + TCSADRAIN:
     201        case TCSETS + TCSAFLUSH:
     202                return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
     203        }
     204
     205        return -EINVAL;
     206}
     207
     208bool_t sio_readable(struct SHELL_FILE *fp)
     209{
     210        return fp->readevt_w != fp->readevt_r;
     211}
     212
     213void sio_delete(struct SHELL_FILE *fp)
     214{
     215        free((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf);
     216        ((struct ntstdio_t *)fp->exinf)->exinf = NULL;
     217        free((struct ntstdio_t *)fp->exinf);
     218        fp->exinf = NULL;
     219}
     220
     221struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable)
     222{
     223        struct SHELL_FILE *fp = NULL;
     224        ER ret;
     225
     226        ret = wai_sem(SEM_FILEDESC);
     227        if (ret < 0) {
     228                syslog(LOG_ERROR, "wai_sem => %d", ret);
     229        }
     230
    87231        for (int fd = 3; fd < fd_table_count; fd++) {
    88                 struct _IO_FILE *fp = &fd_table[fd];
    89                 if (fp->type != IO_TYPE_FREE)
     232                fp = &fd_table[fd];
     233                if (fp->type != NULL)
    90234                        continue;
    91235
    92                 memset(fp, 0, sizeof(struct _IO_FILE));
     236                memset(fp, 0, sizeof(struct SHELL_FILE));
    93237                fp->fd = fd;
    94238                fp->type = type;
    95239                fp->handle = id;
    96                 return fd;
    97         }
    98 
    99         return -ENOMEM;
    100 }
    101 
    102 static struct _IO_FILE *id_to_fd(int type, int id)
    103 {
     240                fp->writable = writable;
     241                break;
     242        }
     243
     244        ret = sig_sem(SEM_FILEDESC);
     245        if (ret < 0) {
     246                syslog(LOG_ERROR, "sig_sem => %d", ret);
     247        }
     248
     249        return fp;
     250}
     251
     252struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id)
     253{
     254        struct SHELL_FILE *fp = NULL;
     255        ER ret;
     256
     257        ret = wai_sem(SEM_FILEDESC);
     258        if (ret < 0) {
     259                syslog(LOG_ERROR, "wai_sem => %d", ret);
     260        }
     261
    104262        for (int fd = 3; fd < fd_table_count; fd++) {
    105                 struct _IO_FILE *fp = &fd_table[fd];
     263                fp = &fd_table[fd];
    106264                if ((fp->type == type) && (fp->handle == id))
    107                         return fp;
    108         }
    109 
    110         return NULL;
    111 }
    112 
    113 static int delete_fd(int type, int id)
    114 {
    115         struct _IO_FILE *fp = id_to_fd(type, id);
     265                        break;
     266        }
     267
     268        ret = sig_sem(SEM_FILEDESC);
     269        if (ret < 0) {
     270                syslog(LOG_ERROR, "sig_sem => %d", ret);
     271        }
     272
     273        return fp;
     274}
     275
     276int delete_fd_by_id(IO_TYPE *type, int id)
     277{
     278        struct SHELL_FILE *fp = id_to_fd(type, id);
    116279        if (fp == NULL)
    117280                return -EBADF;
     
    120283}
    121284
    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));
     285int delete_fp(struct SHELL_FILE *fp)
     286{
     287        ER ret;
     288
     289        fp->type->delete(fp);
     290
     291        ret = wai_sem(SEM_FILEDESC);
     292        if (ret < 0) {
     293                syslog(LOG_ERROR, "wai_sem => %d", ret);
     294        }
     295
     296        memset(fp, 0, sizeof(struct SHELL_FILE));
     297
     298        ret = sig_sem(SEM_FILEDESC);
     299        if (ret < 0) {
     300                syslog(LOG_ERROR, "sig_sem => %d", ret);
     301        }
    131302
    132303        return 0;
    133304}
    134305
    135 struct _IO_FILE *fd_to_fp(int fd)
     306struct SHELL_FILE *fd_to_fp(int fd)
    136307{
    137308        if ((fd < 0) || (fd >= fd_table_count))
     
    140311}
    141312
    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)
     313void memand(void *dst, void *src, size_t len)
    289314{
    290315        uint8_t *d = (uint8_t *)dst;
     
    293318
    294319        while (s < e) {
    295                 *d++ |= *s++;
     320                *d++ &= *s++;
    296321        }
    297322}
     
    336361
    337362        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));
    344363        if (ret == E_OK) {
    345364                if (rfds != NULL)
    346                         memor(rfds, &evts.readfds, sizeof(fd_set));
     365                        memand(rfds, &evts.readfds, sizeof(fd_set));
    347366                if (wfds != NULL)
    348                         memor(wfds, &evts.writefds, sizeof(fd_set));
     367                        memand(wfds, &evts.writefds, sizeof(fd_set));
    349368                if (efds != NULL)
    350                         memor(efds, &evts.errorfds, sizeof(fd_set));
     369                        memand(efds, &evts.errorfds, sizeof(fd_set));
    351370                return evts.count;
    352371        }
    353372        if (ret == E_TMOUT) {
     373                if (rfds != NULL)
     374                        memset(rfds, 0, sizeof(fd_set));
     375                if (wfds != NULL)
     376                        memset(wfds, 0, sizeof(fd_set));
     377                if (efds != NULL)
     378                        memset(efds, 0, sizeof(fd_set));
    354379                return 0;
    355380        }
     
    419444{
    420445        int fd = STDIN_FILENO;
    421         struct _IO_FILE *fp = &fd_table[fd];
    422         T_SERIAL_RPOR rpor;
     446        struct SHELL_FILE *fp = &fd_table[fd];
    423447        FLGPTN flgptn = 0;
    424448
    425         ER ret = serial_ref_por(SIO_PORTID, &rpor);
    426         if (ret != E_OK)
    427                 return;
    428 
    429         if (rpor.reacnt != 0) {
     449        if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
    430450                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
    431451
    432452                FD_SET(fd, (fd_set *)&flgptn);
    433453        }
    434         if (rpor.wricnt != 0) {
     454        if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
    435455                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
    436456
     
    447467{
    448468        int fd = STDIN_FILENO;
    449         struct _IO_FILE *fp = &fd_table[fd];
    450         T_SERIAL_RPOR rpor;
     469        struct SHELL_FILE *fp = &fd_table[fd];
    451470        *flgptn = 0;
    452471
    453         ER ret = serial_ref_por(SIO_PORTID, &rpor);
    454         if (ret != E_OK)
    455                 return;
    456 
    457         if (rpor.reacnt != 0) {
     472        if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
    458473                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
    459474
    460475                FD_SET(fd, (fd_set *)flgptn);
    461476        }
    462         if (rpor.wricnt != 0) {
     477        if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
    463478                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
    464479
     
    466481        }
    467482}
    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
    633483
    634484ER shell_get_evts(struct fd_events *evts, TMO tmout)
     
    642492                ER ret;
    643493                FLGPTN waitptn, flgptn, readfds = 0, writefds = 0;
    644                 struct _IO_FILE *fp = NULL;
     494                struct SHELL_FILE *fp = NULL;
    645495
    646496                stdio_update_evts();
     
    656506#ifndef NTSHELL_NO_SOCKET
    657507                        if (FD_ISSET(fd, &evts->readfds)) {
    658                                 if ((fp->type == IO_TYPE_TCP) && (fp->psock->cepid != 0)) {
    659                                         if (fp->psock->len == 0) {
    660                                                 ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_NBLK);
    661                                                 if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) {
    662                                                         syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
    663                                                         //return ret;
    664                                                 }
    665                                                 if (ret > 0) {
    666                                                         ret = wai_sem(SEM_FILEDESC);
    667                                                         if (ret < 0) {
    668                                                                 syslog(LOG_ERROR, "wai_sem => %d", ret);
    669                                                         }
    670                                                         fp->psock->len += ret;
    671                                                         ret = sig_sem(SEM_FILEDESC);
    672                                                         if (ret < 0) {
    673                                                                 syslog(LOG_ERROR, "sig_sem => %d", ret);
    674                                                         }
    675                                                 }
    676                                         }
    677                                         else ret = 1;
    678                                         if (ret > 0) {
    679                                                 FD_SET(fd, (fd_set *)&readfds);
    680                                                 count++;
    681                                                 if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
    682                                         }
    683                                 }
    684                                 else if ((fp->type == IO_TYPE_UDP) && (fp->psock->cepid != 0)) {
    685                                         if (fp->psock->input != NULL) {
    686                                                 FD_SET(fd, (fd_set *)&readfds);
    687                                                 count++;
    688                                                 if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
    689                                         }
     508                                if (fp->type->readable(fp)) {
     509                                        FD_SET(fd, (fd_set *)&readfds);
     510                                        count++;
     511                                        if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
    690512                                }
    691513                                else {
     
    786608void clean_fd()
    787609{
    788         struct _IO_FILE *fp = NULL;
     610        struct SHELL_FILE *fp = NULL;
    789611        for (int fd = 3; fd < fd_table_count; fd++) {
    790612                fp = &fd_table[fd];
     
    792614                        continue;
    793615
    794                 fp->close(fp);
     616                fp->type->close(fp);
    795617
    796618                delete_fp(fp);
     
    800622int shell_ioctl(int fd, int request, void *arg)
    801623{
    802         struct _IO_FILE *fp = fd_to_fp(fd);
     624        struct SHELL_FILE *fp = fd_to_fp(fd);
    803625        if (fp == NULL)
    804626                return -EBADF;
    805627
    806         return fp->ioctl(fp, request, arg);
     628        return fp->type->ioctl(fp, request, arg);
    807629}
    808630
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c

    r352 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;
    692 }
    693 
    694 #include "tlsf.h"
    695 
    696 static tlsf_t sys_tlsf;
    697 static pool_t sys_pool;
    698 
    699 void sys_init(void)
    700 {
    701         sys_tlsf = tlsf_create(&__HeapBase);
    702         if (sys_tlsf == NULL)
    703                 return;
    704 
    705         sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&__HeapBase) + tlsf_size(), ((intptr_t)&__HeapLimit - (intptr_t)&__HeapBase) - tlsf_size());
    706 }
    707 
    708 void sys_fini(void)
    709 {
    710         tlsf_destroy(sys_tlsf);
    711 }
    712 
    713 void *malloc(size_t size)
    714 {
    715         void *result;
    716         wai_sem(SEM_MALLOC);
    717         result = tlsf_malloc(sys_tlsf, size);
    718         sig_sem(SEM_MALLOC);
    719         if (result == NULL)
    720                 tlsf_check_pool(sys_pool);
    721         return result;
    722 }
    723 
    724 void *calloc(size_t size, size_t count)
    725 {
    726         void *result;
    727         wai_sem(SEM_MALLOC);
    728         result = tlsf_malloc(sys_tlsf, count * size);
    729         sig_sem(SEM_MALLOC);
    730         if (result != NULL)
    731                 memset(result, 0, count * size);
    732         else
    733                 tlsf_check_pool(sys_pool);
    734         return result;
    735 }
    736 
    737 void *realloc(void *ptr, size_t size)
    738 {
    739         void *result;
    740         wai_sem(SEM_MALLOC);
    741         result = tlsf_realloc(sys_tlsf, ptr, size);
    742         sig_sem(SEM_MALLOC);
    743         if (result == NULL)
    744                 tlsf_check_pool(sys_pool);
    745         return result;
    746 }
    747 
    748 void free(void *ptr)
    749 {
    750         wai_sem(SEM_MALLOC);
    751         tlsf_free(sys_tlsf, ptr);
    752         sig_sem(SEM_MALLOC);
    753 }
    754 
     746        return 0;
     747//}
     748//return -1;
     749}
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c

    r359 r374  
    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_arm/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_arm/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_arm/trunk/ntshell/src/ntshell_main.c

    r364 r374  
    5959#include "ntshell_main.h"
    6060#include "socket_stub.h"
    61 #include "usb_hbth.h"
    62 
    63 extern int bt_bnep_mode;
    6461
    6562char command[NTOPT_TEXT_MAXLEN];
    66 ntstdio_t ntstdio;
    6763
    6864extern uint8_t mac_addr[6];
     
    8783volatile int ntshell_state;
    8884jmp_buf process_exit;
    89 void sys_init(void);
    90 NTSHELL_SERIAL_READ ntshell_serial_read = 0;
    91 NTSHELL_SERIAL_WRITE ntshell_serial_write = 0;
    92 void *ntshell_serial_extobj;
    93 
    94 unsigned char ntstdio_xi(struct ntstdio_t *handle)
    95 {
    96         unsigned char buf[1];
    97         ntshell_serial_read((char *)buf, 1, ntshell_serial_extobj);
    98         return buf[0];
    99 }
    100 
    101 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
    102 {
    103         char buf[1];
    104         buf[0] = c;
    105         ntshell_serial_write(buf, 1, ntshell_serial_extobj);
    106 }
    107 
    108 void ntshell_task_init(NTSHELL_SERIAL_READ func_read,
    109         NTSHELL_SERIAL_WRITE func_write, void *extobj)
    110 {
    111         ntshell_serial_read = func_read;
    112         ntshell_serial_write = func_write;
    113         ntshell_serial_extobj = extobj;
    114 
    115         sys_init();
    116 
    117         ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
     85
     86void ntshell_task_init(ID portid)
     87{
     88        serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
    11889}
    11990
     
    177148        const cmd_table_t *p = cmd_table_info.table;
    178149        for (int i = 0; i < cmd_table_info.count; i++) {
    179                 ntstdio_puts(&ntstdio, p->cmd);
    180                 ntstdio_puts(&ntstdio, "\t:");
    181                 ntstdio_puts(&ntstdio, p->desc);
    182                 ntstdio_puts(&ntstdio, "\n");
     150                fwrite(p->cmd, strlen(p->cmd), 1, stdout);
     151                fwrite("\t:", strlen("\t:"), 1, stdout);
     152                puts(p->desc);
    183153                p++;
    184154        }
     
    206176int execute_command(int wait)
    207177{
     178        T_RTSK rtsk;
    208179        ER ret;
    209180
     
    228199        do {
    229200                tslp_tsk(100000);
     201
     202                ret = ref_tsk(NTSHELL_TASK, &rtsk);
     203                if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT))
     204                        ntshell_state = 3;
    230205        } while(ntshell_state == 1);
    231206
     
    237212        ntlibc_strlcpy(command, text, sizeof(command));
    238213        return execute_command(1);
    239 }
    240 
    241 int stdio_close(struct _IO_FILE *fp)
    242 {
    243         return -EPERM;
    244 }
    245 
    246 size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    247 {
    248         return -EPERM;
    249 }
    250 
    251 size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    252 {
    253         return -EPERM;
    254 }
    255 
    256 size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    257 {
    258         int i = 0;
    259         while (i < len) {
    260                 int c = ntstdio_getc(&ntstdio);
    261                 data[i++] = c;
    262                 if ((c == EOF) || (c == '\n'))
    263                         break;
    264         }
    265         return i;
    266 }
    267 
    268 size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    269 {
    270         for (int i = 0; i < len; i++) {
    271                 ntstdio_putc(&ntstdio, data[i]);
    272         }
    273         return len;
    274 }
    275 
    276 size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    277 {
    278         for (int i = 0; i < len; i++) {
    279                 ntstdio_putc(&ntstdio, data[i]);
    280         }
    281         return len;
    282 }
    283 
    284 int sio_close(struct _IO_FILE *fp)
    285 {
    286         return -EPERM;
    287 }
    288 
    289 size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    290 {
    291         return -EPERM;
    292 }
    293 
    294 size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    295 {
    296         return -EPERM;
    297 }
    298 
    299 off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org)
    300 {
    301         return -EPERM;
    302 }
    303 
    304 int sio_ioctl(struct _IO_FILE *fp, int request, void *arg)
    305 {
    306         switch (request) {
    307         case TIOCGWINSZ:
    308                 return 0;
    309         case TCGETS:
    310                 return sio_tcgetattr(fp->fd, (struct termios *)arg);
    311         case TCSETS + TCSANOW:
    312         case TCSETS + TCSADRAIN:
    313         case TCSETS + TCSAFLUSH:
    314                 return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
    315         }
    316 
    317         return -EINVAL;
    318214}
    319215
     
    456352}
    457353
     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_arm/trunk/ntshell/src/ntshell_main.cfg

    r364 r374  
    4141#include "ntshell_main.h"
    4242
    43 CRE_TSK(NTSHELL_TASK, { TA_NULL, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL });
     43ATT_INI({ TA_NULL, 0, sys_init });
     44
     45CRE_TSK(NTSHELL_TASK, { TA_FPU, 0, ntshell_task, NTSHELL_PRIORITY, NTSHELL_STACK_SIZE, NULL });
    4446CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 });
    4547CRE_SEM(SEM_FILEDESC, { TA_TPRI, 1, 1 });
    46 CRE_SEM(SEM_MALLOC, { TA_TPRI, 1, 1 });
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.h

    r367 r374  
    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_arm/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);
     
    303303#endif
    304304
    305 struct tm *gmtime_r(const time_t *t, struct tm *tm);
    306305void *malloc(size_t size);
    307306void *calloc(size_t size, size_t count);
  • asp3_tinet_ecnl_arm/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;
     
    6467#include "kernel_cfg.h"
    6568
     69#ifdef _DEBUG
     70static const char THIS_FILE[] = __FILE__;
     71#endif
     72
    6673#define SOCKET_TIMEOUT 2000000
     74
     75static int tcp_fd_close(struct SHELL_FILE *fp);
     76static size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     77static size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     78static off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
     79static int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
     80static bool_t tcp_fd_readable(struct SHELL_FILE *fp);
     81static void tcp_fd_delete(struct SHELL_FILE *fp);
     82
     83static int udp_fd_close(struct SHELL_FILE *fp);
     84static size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
     85static size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
     86static off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
     87static int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
     88static bool_t udp_fd_readable(struct SHELL_FILE *fp);
     89static void udp_fd_delete(struct SHELL_FILE *fp);
     90
     91IO_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 };
     92IO_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 };
    6793
    6894typedef struct id_table_t {
     
    116142}
    117143
    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;
     144typedef struct SHELL_FILE SOCKET;
    124145
    125146int shell_socket(int family, int type, int protocol)
     
    141162        switch (type) {
    142163        case SOCK_STREAM:
    143                 fp = new_tcp_fd(0);
     164                fp = new_fp(&IO_TYPE_TCP, 0, 0);
     165                if (fp == NULL)
     166                        return -ENOMEM;
     167
     168                fp->exinf = malloc(sizeof(socket_t));
     169                memset(fp->exinf, 0, sizeof(socket_t));
    144170                break;
    145171        case SOCK_DGRAM:
    146                 fp = new_udp_fd(0);
     172                fp = new_fp(&IO_TYPE_UDP, 0, 1);
     173                if (fp == NULL)
     174                        return -ENOMEM;
     175
     176                fp->exinf = malloc(sizeof(socket_t));
     177                memset(fp->exinf, 0, sizeof(socket_t));
    147178                break;
    148179        default:
     
    150181        }
    151182
    152         if (fp == NULL) {
    153                 return -ENOMEM;
    154         }
    155 
    156         fp->psock->family = family;
    157         fp->psock->type = type;
    158         fp->psock->protocol = protocol;
    159         fp->psock->flags = flags;
     183        socket_t *socket = (socket_t *)fp->exinf;
     184        socket->family = family;
     185        socket->type = type;
     186        socket->protocol = protocol;
     187        socket->flags = flags;
    160188
    161189        return fp->fd;
     
    167195        if (fp == NULL)
    168196                return -EBADF;
    169         if (fp->psock->family != addr->sa_family)
     197        socket_t *socket = (socket_t *)fp->exinf;
     198        if (socket->family != addr->sa_family)
    170199                return -EINVAL;
    171200
     
    177206                }
    178207                struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
    179                 memcpy(&fp->psock->laddr4, addr, len);
    180                 switch (fp->psock->type) {
     208                memcpy(&socket->laddr4, addr, len);
     209                switch (socket->type) {
    181210                case SOCK_STREAM: {
    182211                        ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
     
    184213                                return -ENOMEM;
    185214
    186                         fp->psock->buf_size = 512 + 512;
    187                         fp->psock->buf = malloc(fp->psock->buf_size);
     215                        socket->buf_size = 512 + 512;
     216                        socket->buf = malloc(socket->buf_size);
    188217#ifdef _DEBUG
    189                         memset(fp->psock->buf, 0, fp->psock->buf_size);
     218                        memset(socket->buf, 0, socket->buf_size);
    190219#endif
    191                         T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
     220                        T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
    192221                        ret = tcp_cre_cep(cepid, &ccep);
    193222                        if (ret != E_OK) {
     
    196225                        }
    197226                        fp->handle = cepid;
    198                         fp->psock->cepid = cepid;
     227                        socket->cepid = cepid;
    199228                        break;
    200229                }
     
    211240                        }
    212241                        fp->handle = cepid;
    213                         fp->psock->cepid = cepid;
     242                        socket->cepid = cepid;
    214243                        break;
    215244                }
     
    223252                        return -EINVAL;
    224253                }
    225                 memcpy(&fp->psock->laddr4, addr, len);
     254                memcpy(&socket->laddr4, addr, len);
    226255                break;
    227256        }
     
    236265        if (fp == NULL)
    237266                return -EBADF;
    238         if (fp->psock->type != SOCK_STREAM)
     267        socket_t *socket = (socket_t *)fp->exinf;
     268        if (socket->type != SOCK_STREAM)
    239269                return -EINVAL;
    240270
    241         fp->psock->backlog = backlog;
     271        socket->backlog = backlog;
    242272
    243273        ER ret;
    244         switch (fp->psock->family) {
     274        switch (socket->family) {
    245275        case AF_INET: {
    246276                ID repid = new_id(tcp_repid_table, tcp_repid_table_count);
     
    248278                        return -ENOMEM;
    249279
    250                 struct sockaddr_in *laddr = &fp->psock->laddr4;
     280                struct sockaddr_in *laddr = &socket->laddr4;
    251281                T_TCP_CREP crep = { 0, {ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port)} };
    252282                ret = tcp_cre_rep(repid, &crep);
     
    255285                        return -ENOMEM;
    256286                }
    257                 fp->psock->repid = repid;
     287                socket->repid = repid;
    258288                break;
    259289        }
     
    271301        if (fp == NULL)
    272302                return -EBADF;
    273         if (fp->psock->type != SOCK_STREAM)
     303        socket_t *socket = (socket_t *)fp->exinf;
     304        if (socket->type != SOCK_STREAM)
    274305                return -EINVAL;
    275306
    276307        ER ret;
    277         switch (fp->psock->family) {
     308        switch (socket->family) {
    278309        case AF_INET: {
    279310                if (len < 8) {
    280311                        return -EINVAL;
    281312                }
    282                 if (fp->psock->cepid == 0) {
     313                if (socket->cepid == 0) {
    283314                        ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
    284315                        if (cepid < 0)
    285316                                return -ENOMEM;
    286317
    287                         fp->psock->buf_size = 512 + 512;
    288                         fp->psock->buf = malloc(fp->psock->buf_size);
     318                        socket->buf_size = 512 + 512;
     319                        socket->buf = malloc(socket->buf_size);
    289320#ifdef _DEBUG
    290                         memset(fp->psock->buf, 0, fp->psock->buf_size);
     321                        memset(socket->buf, 0, socket->buf_size);
    291322#endif
    292                         T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
     323                        T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
    293324                        ret = tcp_cre_cep(cepid, &ccep);
    294325                        if (ret != E_OK) {
     
    297328                        }
    298329                        fp->handle = cepid;
    299                         fp->psock->cepid = cepid;
    300                 }
    301                 struct sockaddr_in *laddr = &fp->psock->laddr4;
    302                 struct sockaddr_in *raddr = &fp->psock->raddr4;
     330                        socket->cepid = cepid;
     331                }
     332                struct sockaddr_in *laddr = &socket->laddr4;
     333                struct sockaddr_in *raddr = &socket->raddr4;
    303334                memset(raddr, 0, sizeof(*raddr));
    304335                memcpy(raddr, addr, len);
    305336                T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) };
    306337                T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
    307                 ret = tcp_con_cep(fp->psock->cepid, &lep, &rep, SOCKET_TIMEOUT);
     338                ret = tcp_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT);
    308339                if (ret < 0) {
    309340                        return -EHOSTUNREACH;
     
    324355        if (lfp == NULL)
    325356                return -EBADF;
    326         if (lfp->psock->type != SOCK_STREAM)
     357        if (((socket_t *)lfp->exinf)->type != SOCK_STREAM)
    327358                return -EINVAL;
    328359
    329         SOCKET *fp = new_tcp_fd(0);
    330         if (fp == NULL) {
     360        SOCKET *fp = new_fp(&IO_TYPE_TCP, 0, 0);
     361        if (fp == NULL)
    331362                return -ENOMEM;
    332         }
    333 
    334         memcpy(fp->psock, lfp->psock, offsetof(socket_t, buf_size));
     363
     364        fp->exinf = malloc(sizeof(socket_t));
     365        memset(fp->exinf, 0, sizeof(socket_t));
     366
     367        memcpy(fp->exinf, lfp->exinf, offsetof(socket_t, buf_size));
    335368
    336369        ER ret;
    337         switch (fp->psock->family) {
     370        socket_t *socket = (socket_t *)fp->exinf;
     371        switch (socket->family) {
    338372        case AF_INET: {
    339373                ID cepid;
    340                 if (fp->psock->cepid == 0) {
     374                if (socket->cepid == 0) {
    341375                        cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
    342376                        if (cepid < 0)
    343377                                return -ENOMEM;
    344378
    345                         fp->psock->buf_size = 512 + 512;
    346                         fp->psock->buf = malloc(fp->psock->buf_size);
     379                        socket->buf_size = 512 + 512;
     380                        socket->buf = malloc(socket->buf_size);
    347381#ifdef _DEBUG
    348                         memset(fp->psock->buf, 0, fp->psock->buf_size);
     382                        memset(socket->buf, 0, socket->buf_size);
    349383#endif
    350                         T_TCP_CCEP ccep = { 0, fp->psock->buf, 512, &fp->psock->buf[512], 512, (FP)socket_tcp_callback };
     384                        T_TCP_CCEP ccep = { 0, socket->buf, 512, &socket->buf[512], 512, (FP)socket_tcp_callback };
    351385                        ret = tcp_cre_cep(cepid, &ccep);
    352386                        if (ret != E_OK) {
     
    355389                        }
    356390                        fp->handle = cepid;
    357                         fp->psock->cepid = cepid;
     391                        socket->cepid = cepid;
    358392                }
    359393                else {
    360                         cepid = lfp->psock->cepid;
     394                        cepid = ((socket_t *)lfp->exinf)->cepid;
    361395                        fp->handle = cepid;
    362                         lfp->handle = tmax_tcp_cepid + lfp->psock->repid;
    363                         lfp->psock->cepid = 0;
    364                         lfp->psock->buf_size = 0;
    365                         lfp->psock->buf = 0;
     396                        lfp->handle = tmax_tcp_cepid + ((socket_t *)lfp->exinf)->repid;
     397                        ((socket_t *)lfp->exinf)->cepid = 0;
     398                        ((socket_t *)lfp->exinf)->buf_size = 0;
     399                        ((socket_t *)lfp->exinf)->buf = 0;
    366400                }
    367401                T_IPV4EP rep = { 0, 0 };
    368                 ret = tcp_acp_cep(fp->psock->cepid, fp->psock->repid, &rep, TMO_FEVR);
     402                ret = tcp_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR);
    369403                if (ret < 0) {
    370404                        return -ENOMEM;
    371405                }
    372                 struct sockaddr_in *raddr = &fp->psock->raddr4;
     406                struct sockaddr_in *raddr = &socket->raddr4;
    373407                memset(raddr, 0, sizeof(*raddr));
    374408                raddr->sin_family = AF_INET;
     
    387421                        return -EINVAL;
    388422                }
    389                 struct sockaddr_in *raddr = &fp->psock->raddr4;
     423                struct sockaddr_in *raddr = &socket->raddr4;
    390424                if (sz > sizeof(*raddr))
    391425                        sz = sizeof(*raddr);
     
    405439
    406440        int ret = 0;
    407         switch (fp->psock->family) {
     441        socket_t *socket = (socket_t *)fp->exinf;
     442        switch (socket->family) {
    408443        case AF_INET: {
    409                 switch (fp->psock->type) {
     444                switch (socket->type) {
    410445                case SOCK_STREAM: {
    411446                        if ((addr != NULL) || (alen != 0)) {
     
    414449
    415450                        if (flags & MSG_OOB) {
    416                                 ret = tcp_snd_oob(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
     451                                ret = tcp_snd_oob(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
    417452                                if (ret < 0) {
    418453                                        return -ECOMM;
     
    421456                        else {
    422457                                for (;;) {
    423                                         ret = tcp_snd_dat(fp->psock->cepid, (void *)buf, len, SOCKET_TIMEOUT);
     458                                        ret = tcp_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
    424459                                        if (ret < 0) {
    425460                                                if (ret == E_TMOUT)
     
    440475                                return -EINVAL;
    441476                        }
    442                         struct sockaddr_in *raddr = &fp->psock->raddr4;
     477                        struct sockaddr_in *raddr = &socket->raddr4;
    443478                        memset(raddr, 0, sizeof(*raddr));
    444479                        memcpy(raddr, addr, sz);
    445480                        T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
    446                         ret = udp_snd_dat(fp->psock->cepid, &rep, (void *)buf, len,
    447                                 (fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
     481                        ret = udp_snd_dat(socket->cepid, &rep, (void *)buf, len,
     482                                (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
    448483                        if (ret < 0) {
    449484                                return (ret == E_TMOUT) ? -ETIME : -ECOMM;
     
    476511
    477512        int ret = 0;
    478         switch (fp->psock->family) {
     513        socket_t *socket = (socket_t *)fp->exinf;
     514        switch (socket->family) {
    479515        case AF_INET: {
    480                 switch (fp->psock->type) {
     516                switch (socket->type) {
    481517                case SOCK_STREAM: {
    482518                        if (flags & MSG_OOB) {
    483                                 ret = tcp_rcv_oob(fp->psock->cepid, buf, len);
     519                                ret = tcp_rcv_oob(socket->cepid, buf, len);
    484520                                if (ret < 0) {
    485521                                        syslog(LOG_ERROR, "tcp_rcv_oob => %d", ret);
     
    489525                        else {
    490526                                int rsz, tmp;
    491                                 if (fp->psock->input == NULL) {
     527                                if (socket->input == NULL) {
    492528                                        ret = wai_sem(SEM_FILEDESC);
    493529                                        if (ret < 0) {
    494530                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
    495531                                        }
    496                                         fp->psock->len = 0;
     532                                        socket->len = 0;
    497533                                        ret = sig_sem(SEM_FILEDESC);
    498534                                        if (ret < 0) {
    499535                                                syslog(LOG_ERROR, "sig_sem => %d", ret);
    500536                                        }
    501                                         ret = tcp_rcv_buf(fp->psock->cepid, &fp->psock->input, TMO_FEVR);
     537                                        ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_FEVR);
    502538                                        if (ret < 0) {
    503539                                                syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
     
    507543                                }
    508544                                else
    509                                         rsz = fp->psock->len;
     545                                        rsz = socket->len;
    510546                                tmp = rsz;
    511547                                if (rsz > len)
    512548                                        rsz = len;
    513549                                if (rsz >= 0) {
    514                                         memcpy(buf, fp->psock->input, rsz);
     550                                        memcpy(buf, socket->input, rsz);
    515551                                        ret = wai_sem(SEM_FILEDESC);
    516552                                        if (ret < 0) {
    517553                                                syslog(LOG_ERROR, "wai_sem => %d", ret);
    518554                                        }
    519                                         fp->psock->len = tmp - rsz;
     555                                        socket->len = tmp - rsz;
    520556                                        ret = sig_sem(SEM_FILEDESC);
    521557                                        if (ret < 0) {
     
    523559                                        }
    524560                                        if (tmp - rsz == 0) {
    525                                                 fp->psock->input = NULL;
     561                                                socket->input = NULL;
    526562                                        }
    527563                                        else
    528                                                 fp->psock->input = (void *)&((uint8_t *)fp->psock->input)[rsz];
    529                                         ret = tcp_rel_buf(fp->psock->cepid, rsz);
     564                                                socket->input = (void *)&((uint8_t *)socket->input)[rsz];
     565                                        ret = tcp_rel_buf(socket->cepid, rsz);
    530566                                        if ((ret != E_OBJ) && (ret < 0)) {
    531567                                                syslog(LOG_ERROR, "tcp_rel_buf => %d", ret);
     
    538574                }
    539575                case SOCK_DGRAM: {
    540                         struct sockaddr_in *raddr = &fp->psock->raddr4;
     576                        struct sockaddr_in *raddr = &socket->raddr4;
    541577                        int rsz;
    542578                        ret = wai_sem(SEM_FILEDESC);
     
    544580                                syslog(LOG_ERROR, "wai_sem => %d", ret);
    545581                        }
    546                         T_NET_BUF *input = fp->psock->input;
     582                        T_NET_BUF *input = socket->input;
    547583                        if (input == NULL) {
    548584                                ret = sig_sem(SEM_FILEDESC);
     
    552588
    553589                                T_IPV4EP rep = { 0, 0 };
    554                                 ret = udp_rcv_dat(fp->psock->cepid, &rep, buf, len,
    555                                         (fp->psock->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
     590                                ret = udp_rcv_dat(socket->cepid, &rep, buf, len,
     591                                        (socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
    556592                                if (ret < 0) {
    557                                         syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
     593                                        if ((socket->flags & O_NONBLOCK) == 0)
     594                                                syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
    558595                                        return (ret == E_TMOUT) ? -ETIME : -ECOMM;
    559596                                }
     
    565602                                        }
    566603                                        int sz = *alen;
    567                                         memset(raddr, 0, sizeof(fp->psock->raddr4));
     604                                        memset(raddr, 0, sizeof(socket->raddr4));
    568605                                        raddr->sin_family = AF_INET;
    569606                                        raddr->sin_port = htons(rep.portno);
    570607                                        raddr->sin_addr.s_addr = htonl(rep.ipaddr);
    571                                         if (sz > sizeof(fp->psock->raddr4))
    572                                                 sz = sizeof(fp->psock->raddr4);
     608                                        if (sz > sizeof(socket->raddr4))
     609                                                sz = sizeof(socket->raddr4);
    573610                                        memcpy(addr, raddr, sz);
    574611                                        *alen = sz;
     
    580617                        }
    581618                        else {
    582                                 rsz = fp->psock->len;
    583                                 void *pbuf = fp->psock->buf;
    584                                 fp->psock->input = NULL;
    585                                 fp->psock->len = 0;
    586                                 fp->psock->buf = NULL;
     619                                rsz = socket->len;
     620                                void *pbuf = socket->buf;
     621                                socket->input = NULL;
     622                                socket->len = 0;
     623                                socket->buf = NULL;
    587624                                if ((addr != NULL) && (alen != NULL)) {
    588625                                        int sz = *alen;
    589                                         if (sz > sizeof(fp->psock->raddr4))
    590                                                 sz = sizeof(fp->psock->raddr4);
     626                                        if (sz > sizeof(socket->raddr4))
     627                                                sz = sizeof(socket->raddr4);
    591628                                        memcpy(addr, raddr, sz);
    592629                                        *alen = sz;
     
    632669
    633670        ER ret;
    634         switch (fp->psock->family) {
     671        socket_t *socket = (socket_t *)fp->exinf;
     672        switch (socket->family) {
    635673        case AF_INET: {
    636                 switch (fp->psock->type) {
     674                switch (socket->type) {
    637675                case SOCK_STREAM: {
    638                         ret = tcp_sht_cep(fp->psock->cepid);
     676                        ret = tcp_sht_cep(socket->cepid);
    639677                        if (ret < 0) {
    640678                                return -ECOMM;
     
    661699
    662700        ER ret;
    663         switch (fp->psock->family) {
     701        socket_t *socket = (socket_t *)fp->exinf;
     702        switch (socket->family) {
    664703        case AF_INET: {
    665                 switch (fp->psock->type) {
     704                switch (socket->type) {
    666705                case SOCK_STREAM: {
    667706                        switch (level) {
     
    669708                                switch (optname) {
    670709                                case SO_REUSEADDR:
    671                                         if (fp->psock->flags & SO_REUSEADDR) {
     710                                        if (socket->flags & SO_REUSEADDR) {
    672711                                                *(bool *)optval = true;
    673712                                        }
     
    677716                                        break;
    678717                                case SO_KEEPALIVE:
    679                                         if (fp->psock->flags & SO_KEEPALIVE) {
     718                                        if (socket->flags & SO_KEEPALIVE) {
    680719                                                *(bool *)optval = true;
    681720                                        }
     
    692731                                break;
    693732                        case IPPROTO_TCP:
    694                                 ret = tcp_get_opt(fp->psock->cepid, optname, (void *)optval, *optlen);
     733                                ret = tcp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
    695734                                if (ret < 0) {
    696735                                        return -EINVAL;
     
    706745                        switch (level) {
    707746                        case IPPROTO_UDP:
    708                                 ret = udp_get_opt(fp->psock->cepid, optname, (void *)optval, *optlen);
     747                                ret = udp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
    709748                                if (ret < 0) {
    710749                                        return -EINVAL;
     
    736775
    737776        ER ret;
    738         switch (fp->psock->family) {
     777        socket_t *socket = (socket_t *)fp->exinf;
     778        switch (socket->family) {
    739779        case AF_INET: {
    740                 switch (fp->psock->type) {
     780                switch (socket->type) {
    741781                case SOCK_STREAM: {
    742782                        switch (level){
     
    745785                                case SO_REUSEADDR:
    746786                                        if (*(bool *)optval) {
    747                                                 fp->psock->flags |= SO_REUSEADDR;
     787                                                socket->flags |= SO_REUSEADDR;
    748788                                        }
    749789                                        else {
    750                                                 fp->psock->flags &= ~SO_REUSEADDR;
     790                                                socket->flags &= ~SO_REUSEADDR;
    751791                                        }
    752792                                        break;
    753793                                case SO_KEEPALIVE:
    754794                                        if (*(bool *)optval) {
    755                                                 fp->psock->flags |= SO_KEEPALIVE;
     795                                                socket->flags |= SO_KEEPALIVE;
    756796                                        }
    757797                                        else {
    758                                                 fp->psock->flags &= ~SO_KEEPALIVE;
     798                                                socket->flags &= ~SO_KEEPALIVE;
    759799                                        }
    760800                                        break;
     
    764804                                break;
    765805                        case IPPROTO_TCP:
    766                                 ret = tcp_set_opt(fp->psock->cepid, optname, (void *)optval, optlen);
     806                                ret = tcp_set_opt(socket->cepid, optname, (void *)optval, optlen);
    767807                                if (ret < 0) {
    768808                                        return -EINVAL;
     
    777817                        switch (level){
    778818                        case IPPROTO_UDP:
    779                                 ret = udp_set_opt(fp->psock->cepid, optname, (void *)optval, optlen);
     819                                ret = udp_set_opt(socket->cepid, optname, (void *)optval, optlen);
    780820                                if (ret < 0) {
    781821                                        return -EINVAL;
     
    809849
    810850        socklen_t size = *len;
    811         switch (fp->psock->family) {
     851        socket_t *socket = (socket_t *)fp->exinf;
     852        switch (socket->family) {
    812853        case AF_INET: {
    813                 struct sockaddr_in *raddr = &fp->psock->raddr4;
     854                struct sockaddr_in *raddr = &socket->raddr4;
    814855                *len = sizeof(struct sockaddr_in);
    815856                if (size > sizeof(struct sockaddr_in))
     
    837878
    838879        socklen_t size = *len;
    839         switch (fp->psock->family) {
     880        socket_t *socket = (socket_t *)fp->exinf;
     881        switch (socket->family) {
    840882        case AF_INET: {
    841883                const T_IN4_ADDR *laddr4 = in4_get_ifaddr(0);
     
    843885                laddr.sin_family = AF_INET;
    844886                laddr.sin_addr.s_addr = htonl(*laddr4);
    845                 laddr.sin_port = fp->psock->laddr4.sin_port;
     887                laddr.sin_port = socket->laddr4.sin_port;
    846888                memset(&laddr.sin_zero, 0, sizeof(laddr.sin_zero));
    847889                *len = sizeof(struct sockaddr_in);
     
    859901}
    860902
    861 int tcp_fd_close(struct _IO_FILE *fp)
     903int tcp_fd_close(struct SHELL_FILE *fp)
    862904{
    863905        ER ret, ret2;
    864906
    865         switch (fp->psock->family) {
     907        socket_t *socket = (socket_t *)fp->exinf;
     908        switch (socket->family) {
    866909        case AF_INET: {
    867                 if (fp->psock->cepid != 0) {
    868                         ID cepid = fp->psock->cepid;
     910                if (socket->cepid != 0) {
     911                        ID cepid = socket->cepid;
    869912                        ret = tcp_sht_cep(cepid);
    870913                        if (ret < 0) {
    871914                                //return -1;
    872915                        }
    873                         ret = tcp_cls_cep(cepid, (fp->psock->repid != 0) ? 0 : SOCKET_TIMEOUT);
     916                        ret = tcp_cls_cep(cepid, (socket->repid != 0) ? 0 : SOCKET_TIMEOUT);
    874917                        ret2 = tcp_del_cep(cepid);
    875                         free(fp->psock->buf);
    876                         fp->psock->buf = NULL;
    877                         delete_tcp_fd(cepid);
     918                        //delete_fd_by_id(&IO_TYPE_TCP, cepid);
    878919                        delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
    879920                        if ((ret < 0) || (ret2 < 0)) {
     
    881922                        }
    882923                }
    883                 else if (fp->psock->repid != 0) {
    884                         ID repid = fp->psock->repid;
     924                else if (socket->repid != 0) {
     925                        ID repid = socket->repid;
    885926                        ret = tcp_del_rep(repid);
    886                         free(fp->psock->buf);
    887                         fp->psock->buf = NULL;
    888                         delete_tcp_fd(tmax_tcp_cepid + repid);
     927                        //delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + repid);
    889928                        delete_id(tcp_repid_table, tcp_repid_table_count, repid);
    890929                        if (ret < 0) {
     
    893932                }
    894933                else {
    895                         free(fp->psock->buf);
    896                         fp->psock->buf = NULL;
    897934                        return -EINVAL;
    898935                }
     
    907944}
    908945
    909 size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
     946size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
    910947{
    911948        return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
    912949}
    913950
    914 size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
     951size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
    915952{
    916953        return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
    917954}
    918955
    919 off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
     956off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
    920957{
    921958        return -EPERM;
    922959}
    923960
    924 int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
     961int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
    925962{
    926963        return -EINVAL;
    927964}
    928965
    929 int udp_fd_close(struct _IO_FILE *fp)
     966bool_t tcp_fd_readable(struct SHELL_FILE *fp)
     967{
     968        ER ret;
     969
     970        socket_t *socket = (socket_t *)fp->exinf;
     971        if (socket->cepid != 0) {
     972                if (socket->len == 0) {
     973                        ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_NBLK);
     974                        if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) {
     975                                syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
     976                                //return ret;
     977                        }
     978                        if (ret > 0) {
     979                                ret = wai_sem(SEM_FILEDESC);
     980                                if (ret < 0) {
     981                                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     982                                }
     983                                socket->len += ret;
     984                                ret = sig_sem(SEM_FILEDESC);
     985                                if (ret < 0) {
     986                                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     987                                }
     988                        }
     989                }
     990                else ret = 1;
     991                if (ret > 0) {
     992                        return true;
     993                }
     994        }
     995
     996        return false;
     997}
     998
     999void tcp_fd_delete(struct SHELL_FILE *fp)
     1000{
     1001        socket_t *socket = (socket_t *)fp->exinf;
     1002        free(socket->buf);
     1003        socket->buf = NULL;
     1004        free(fp->exinf);
     1005        fp->exinf = NULL;
     1006}
     1007
     1008ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk)
     1009{
     1010        struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_TCP, cepid);
     1011        FLGPTN flgptn = 0;
     1012        ER ret;
     1013        int len;
     1014
     1015        if (fp == NULL)
     1016                return E_PAR;
     1017
     1018        int fd = fp->fd;
     1019        FD_SET(fd, (fd_set *)&flgptn);
     1020
     1021        switch (fncd) {
     1022        case TFN_TCP_RCV_BUF:
     1023                len = *(int *)p_parblk;
     1024                if ((len <= 0) || (fp->exinf == NULL))
     1025                        return E_OK;
     1026
     1027                ret = wai_sem(SEM_FILEDESC);
     1028                if (ret < 0) {
     1029                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1030                }
     1031                socket_t *socket = (socket_t *)fp->exinf;
     1032                socket->len += len;
     1033                ret = sig_sem(SEM_FILEDESC);
     1034                if (ret < 0) {
     1035                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1036                }
     1037
     1038                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1039
     1040                set_flg(FLG_SELECT_WAIT, flgptn);
     1041                return E_OK;
     1042
     1043        case TFN_TCP_RCV_DAT:
     1044                len = *(int *)p_parblk;
     1045                if ((len <= 0) || (fp->exinf == NULL))
     1046                        return E_OK;
     1047
     1048                ret = wai_sem(SEM_FILEDESC);
     1049                if (ret < 0) {
     1050                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1051                }
     1052                socket->len += len;
     1053                ret = sig_sem(SEM_FILEDESC);
     1054                if (ret < 0) {
     1055                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1056                }
     1057
     1058                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1059
     1060                set_flg(FLG_SELECT_WAIT, flgptn);
     1061                return E_OK;
     1062
     1063        case TFN_TCP_SND_DAT:
     1064                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
     1065
     1066                set_flg(FLG_SELECT_WAIT, flgptn);
     1067                return E_OK;
     1068
     1069        case TFN_TCP_CAN_CEP:
     1070                if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
     1071
     1072                set_flg(FLG_SELECT_WAIT, flgptn);
     1073                return E_OK;
     1074
     1075        case TFN_TCP_DEL_REP:
     1076                delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + cepid);
     1077                return E_OK;
     1078
     1079        case TFN_TCP_DEL_CEP:
     1080                delete_fd_by_id(&IO_TYPE_TCP, cepid);
     1081                return E_OK;
     1082
     1083        default:
     1084                return E_OK;
     1085        }
     1086}
     1087
     1088int udp_fd_close(struct SHELL_FILE *fp)
    9301089{
    9311090        ER ret;
    9321091        ID cepid;
    9331092
    934         switch (fp->psock->family) {
     1093        socket_t *socket = (socket_t *)fp->exinf;
     1094        switch (socket->family) {
    9351095        case AF_INET: {
    936                 cepid = fp->psock->cepid;
     1096                cepid = socket->cepid;
    9371097                ret = udp_del_cep(cepid);
    938                 //free(fp->psock->buf);
    939                 //fp->psock->buf = NULL;
    940                 delete_udp_fd(cepid);
     1098                //delete_fd_by_id(&IO_TYPE_UDP, cepid);
    9411099                delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
    9421100                if (ret < 0) {
     
    9531111}
    9541112
    955 size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
     1113size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
    9561114{
    9571115        return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
    9581116}
    9591117
    960 size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
     1118size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
    9611119{
    9621120        return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
    9631121}
    9641122
    965 off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
     1123off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
    9661124{
    9671125        return -EPERM;
    9681126}
    9691127
    970 int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
     1128int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
    9711129{
    9721130        return -EINVAL;
     1131}
     1132
     1133bool_t udp_fd_readable(struct SHELL_FILE *fp)
     1134{
     1135        socket_t *socket = (socket_t *)fp->exinf;
     1136        if (socket->cepid != 0) {
     1137                if (socket->input != NULL) {
     1138                        return true;
     1139                }
     1140        }
     1141
     1142        return false;
     1143}
     1144
     1145void udp_fd_delete(struct SHELL_FILE *fp)
     1146{
     1147        //socket_t *socket = (socket_t *)fp->exinf;
     1148        //free(socket->buf);
     1149        //socket->buf = NULL;
     1150        free(fp->exinf);
     1151        fp->exinf = NULL;
     1152}
     1153
     1154ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk)
     1155{
     1156        struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_UDP, cepid);
     1157        FLGPTN flgptn = 0;
     1158        int len;
     1159
     1160        if (fp == NULL)
     1161                return E_PAR;
     1162
     1163        int fd = fp->fd;
     1164        FD_SET(fd, (fd_set *)&flgptn);
     1165
     1166        switch (fncd) {
     1167        case TEV_UDP_RCV_DAT:
     1168        {
     1169                T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
     1170                len = udppara->len;
     1171                if ((len <= 0) || (fp->exinf == NULL))
     1172                        return E_OK;
     1173
     1174                ER ret = wai_sem(SEM_FILEDESC);
     1175                if (ret < 0) {
     1176                        syslog(LOG_ERROR, "wai_sem => %d", ret);
     1177                }
     1178                socket_t *socket = (socket_t *)fp->exinf;
     1179                socket->len = len;
     1180                if (socket->input != NULL) {
     1181                        ret = rel_net_buf(socket->input);
     1182                        if (ret < 0) {
     1183                                syslog(LOG_ERROR, "rel_net_buf => %d", ret);
     1184                        }
     1185                }
     1186                socket->input = udppara->input;
     1187                socket->buf = GET_UDP_SDU(udppara->input, udppara->off);
     1188                memset(&socket->raddr4, 0, sizeof(socket->raddr4));
     1189                socket->raddr4.sin_family = AF_INET;
     1190                socket->raddr4.sin_port = htons(udppara->rep4.portno);
     1191                socket->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr);
     1192                udppara->input->flags |= NB_FLG_NOREL_IFOUT;
     1193                ret = sig_sem(SEM_FILEDESC);
     1194                if (ret < 0) {
     1195                        syslog(LOG_ERROR, "sig_sem => %d", ret);
     1196                }
     1197
     1198                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1199
     1200                set_flg(FLG_SELECT_WAIT, flgptn);
     1201                return E_OK;
     1202        }
     1203        case TFN_UDP_CRE_CEP:
     1204                return E_OK;
     1205
     1206        case TFN_UDP_RCV_DAT:
     1207                len = *(int *)p_parblk;
     1208                if ((len <= 0) || (fp->exinf == NULL))
     1209                        return E_OK;
     1210
     1211                if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
     1212
     1213                set_flg(FLG_SELECT_WAIT, flgptn);
     1214                return E_OK;
     1215
     1216        case TFN_UDP_SND_DAT:
     1217                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
     1218
     1219                set_flg(FLG_SELECT_WAIT, flgptn);
     1220                return E_OK;
     1221
     1222        case TFN_UDP_CAN_CEP:
     1223                if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
     1224
     1225                set_flg(FLG_SELECT_WAIT, flgptn);
     1226                return E_OK;
     1227
     1228        case TFN_UDP_DEL_CEP:
     1229                delete_fd_by_id(&IO_TYPE_UDP, cepid);
     1230                return E_OK;
     1231
     1232        default:
     1233                return E_OK;
     1234        }
    9731235}
    9741236
  • asp3_tinet_ecnl_arm/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
  • asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c

    r364 r374  
    4848
    4949        /* ==== Cleaning and invalidation of the L1 data cache ==== */
    50         __v7_all_cache(2);
     50        L1C_CleanInvalidateDCacheAll();
    5151        __DSB();
    5252
    5353        /* ==== Cleaning and invalidation of the L2 cache ==== */
    54         if (PL310->AUX_CNT & (1 << 16)) {
     54        if (L2C_310->AUX_CNT & (1 << 16)) {
    5555                assoc = 16;
    5656        }
     
    5858                assoc = 8;
    5959        }
    60         PL310->INV_WAY = (1 << assoc) - 1;
    61         while (PL310->INV_WAY & ((1 << assoc) - 1)); // poll invalidate
    62         PL310->CACHE_SYNC = 0x0;
     60        L2C_310->INV_WAY = (1 << assoc) - 1;
     61        while (L2C_310->INV_WAY & ((1 << assoc) - 1)); // poll invalidate
     62        L2C_310->CACHE_SYNC = 0x0;
    6363
    6464        /* ==== Invalidate all TLB entries ==== */
    65         __ca9u_inv_tlb_all();
     65        MMU_InvalidateTLB();
    6666
    6767        /* ==== Invalidate the L1 instruction cache ==== */
    68         __v7_inv_icache_all();
     68        L1C_InvalidateICacheAll();
    6969        __DSB();
    7070        __ISB();
     
    184184}
    185185
    186 long SYS_fdatasync() {
     186long SYS_fdatasync(long a) {
     187        //int fdatasync(int fd)
    187188        return no_implement("fdatasync\n");
    188189}
     
    200201}
    201202
    202 long SYS_futex() {
    203         int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);
     203long SYS_futex(long a, long b, long c, long d, long e, long f) {
     204        //int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);
    204205        return no_implement("futex\n");
    205206}
    206207
    207 long SYS_futimesat() {
     208long SYS_futimesat(long a, long b, long c) {
     209        //int futimesat(int dirfd, const char *pathname, const struct timeval times[2])
    208210        return no_implement("futimesat\n");
    209211}
     
    281283}
    282284
    283 long SYS_munmap() {
     285long SYS_munmap(long a, long b) {
     286        //int munmap(void *start, size_t len)
    284287        return no_implement("munmap\n");
    285288}
     
    293296}
    294297
    295 long SYS_pread64() {
     298long SYS_pread64(long a, long b, long c, long d) {
     299        //#define pread64 pread
     300        //ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
    296301        return no_implement("pread64\n");
    297302}
    298303
    299 long SYS_pwrite64() {
     304long SYS_pwrite64(long a, long b, long c, long d) {
     305        //#define pwrite64 pwrite
     306        //ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
    300307        return no_implement("pwrite64\n");
    301308}
     
    337344}
    338345
    339 long SYS_rt_sigqueueinfo() {
     346long SYS_rt_sigqueueinfo(long a, long b, long c) {
     347        //int rt_sigqueueinfo(pid_t tgid, int sig, siginfo_t *uinfo)
    340348        return no_implement("rt_sigqueueinfo\n");
    341349}
     
    361369}
    362370
    363 long SYS_sched_setscheduler() {
     371long SYS_sched_setscheduler(long a, long b, long c) {
     372        //int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param)
    364373        return no_implement("sched_setscheduler\n");
    365374}
    366375
    367 long SYS_set_robust_list() {
     376long SYS_set_robust_list(long a, long b) {
     377        //long set_robust_list(struct robust_list_head *head, size_t len)
    368378        return no_implement("set_robust_list\n");
    369379}
     
    401411}
    402412
    403 long SYS_utimensat() {
     413long SYS_utimensat(long a, long b, long c, long d) {
     414        //int utimensat(int fd, const char *path, const struct timespec times[2], int flags)
    404415        return no_implement("utimensat\n");
    405416}
    406417
    407 long SYS_utimes() {
     418long SYS_utimes(long a, long b) {
     419        //int utimes(const char *path, const struct timeval times[2])
    408420        return no_implement("utimes\n");
    409421}
     
    417429}
    418430
    419 long SYS_dup()
    420 {
     431long SYS_dup(long a) {
     432        //int dup(int fd)
    421433        return no_implement("dup\n");
    422434}
    423435
    424 long SYS_dup2()
    425 {
     436long SYS_dup2(long a, long b) {
     437        //int dup2(int old, int new)
    426438        return no_implement("dup2\n");
    427439}
    428440
    429 long SYS_pipe()
    430 {
     441long SYS_pipe(long a) {
     442        //int pipe(int fd[2])
    431443        return no_implement("pipe\n");
    432444}
    433445
    434 long SYS_readlink()
    435 {
     446long SYS_readlink(long a, long b, long c) {
     447        //ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
    436448        return no_implement("readlink\n");
    437449}
    438450
    439 long SYS_symlink()
    440 {
     451long SYS_symlink(long a, long b) {
     452        //int symlink(const char *existing, const char *new)
    441453        return no_implement("symlink\n");
    442454}
    443455
    444 long SYS_umask()
    445 {
     456long SYS_umask(long a) {
     457        //mode_t umask(mode_t mode)
    446458        return no_implement("umask\n");
    447459}
    448460
    449 long SYS_execve()
    450 {
     461long SYS_execve(long a, long b, long c) {
     462        //int execve(const char *path, char *const argv[], char *const envp[])
    451463        return no_implement("execve\n");
    452464}
    453465
    454 long SYS_fork()
    455 {
     466long SYS_fork() {
     467        //pid_t fork(void)
    456468        return no_implement("fork\n");
    457469}
    458470
    459 long SYS_wait4()
    460 {
     471long SYS_wait4(long a, long b, long c, long d) {
     472        //pid_t wait4(pid_t pid, int *status, int options, struct rusage *usage)
    461473        return no_implement("wait4\n");
    462474}
    463475
    464 long SYS_socketpair()
    465 {
     476long SYS_socketpair(long a, long b, long c, long d) {
     477        //int socketpair(int domain, int type, int protocol, int fd[2])
    466478        return no_implement("socketpair\n");
    467479}
    468480
    469 long SYS_flock()
    470 {
     481long SYS_flock(long a, long b) {
     482        //int flock(int fd, int op)
    471483        return no_implement("flock\n");
     484}
     485
     486long SYS_fchdir()
     487{
     488        return no_implement("fchdir\n");
     489}
     490
     491long SYS_getegid32()
     492{
     493        return no_implement("getegid32\n");
     494}
     495
     496long SYS_geteuid32()
     497{
     498        return no_implement("geteuid32\n");
     499}
     500
     501long SYS_getgid32()
     502{
     503        return no_implement("getgid32\n");
     504}
     505
     506long SYS_pipe2()
     507{
     508        return no_implement("pipe2\n");
     509}
     510
     511long SYS_setgid32()
     512{
     513        return no_implement("setgid32\n");
     514}
     515
     516long SYS_setpgid()
     517{
     518        return no_implement("setpgid\n");
     519}
     520
     521long SYS_setsid()
     522{
     523        return no_implement("setsid\n");
     524}
     525
     526long SYS_setuid32()
     527{
     528        return no_implement("setuid32\n");
     529}
     530
     531long SYS_tgkill()
     532{
     533        return no_implement("tgkill\n");
     534}
     535
     536long SYS_nanosleep(long a, long b) {
     537        //int nanosleep(const struct timespec *req, struct timespec *rem)
     538        return no_implement("nanosleep\n");
     539}
     540
     541long SYS_prlimit64(long a, long b, long c, long d) {
     542        //#define prlimit64 prlimit
     543        //int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit)
     544        return no_implement("prlimit64\n");
     545}
     546
     547long SYS_sched_getaffinity(long a, long b, long c) {
     548        //int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
     549        return no_implement("sched_getaffinity\n");
     550}
     551
     552long SYS_sysinfo(long a) {
     553        //int sysinfo(struct sysinfo *info)
     554        return no_implement("sysinfo\n");
     555}
     556
     557long SYS_ugetrlimit(long a, long b) {
     558        //#define SYS_getrlimit SYS_ugetrlimit
     559        //int getrlimit(int resource, struct rlimit *rlim)
     560        return no_implement("ugetrlimit\n");
    472561}
    473562
  • asp3_tinet_ecnl_arm/trunk/ntshell/tlsf/tlsf.c

    r352 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.