gonzui


Format: Advanced Search

t2ex/t2ex_source/t2ex/fs/fs/src/fs_main.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T2EX Software Package
    4:  *
    5:  *    Copyright 2012 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2012/12/12.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/04.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: /*
   15:  * This software package is available for use, modification, 
   16:  * and redistribution in accordance with the terms of the attached 
   17:  * T-License 2.x.
   18:  * If you want to redistribute the source code, you need to attach 
   19:  * the T-License 2.x document.
   20:  * There's no obligation to publish the content, and no obligation 
   21:  * to disclose it to the TRON Forum if you have modified the 
   22:  * software package.
   23:  * You can also distribute the modified source code. In this case, 
   24:  * please register the modification to T-Kernel traceability service.
   25:  * People can know the history of modifications by the service, 
   26:  * and can be sure that the version you have inherited some 
   27:  * modification of a particular version or not.
   28:  *
   29:  *    http://trace.tron.org/tk/?lang=en
   30:  *    http://trace.tron.org/tk/?lang=ja
   31:  *
   32:  * As per the provisions of the T-License 2.x, TRON Forum ensures that 
   33:  * the portion of the software that is copyrighted by Ken Sakamura or 
   34:  * the TRON Forum does not infringe the copyrights of a third party.
   35:  * However, it does not make any warranty other than this.
   36:  * DISCLAIMER: TRON Forum and Ken Sakamura shall not be held
   37:  * responsible for any consequences or damages caused directly or
   38:  * indirectly by the use of this software package.
   39:  *
   40:  * The source codes in bsd_source.tar.gz in this software package are 
   41:  * derived from NetBSD or OpenBSD and not covered under T-License 2.x.
   42:  * They need to be changed or redistributed according to the 
   43:  * representation of each source header.
   44:  */
   45: 
   46: /*
   47:  *      @(#)fs_main.c
   48:  *
   49:  */
   50: 
   51: #include "fsdefs.h"
   52: 
   53: /* Default "console" file system */
   54: IMPORT  const    fs_fimp_t  fimp_consolefs_entry;
   55: LOCAL   const     B           console_name[] = "consolefs";
   56: LOCAL   const     B           console_con_name[] = "console";
   57: 
   58: /* Default "FAT" file system */
   59: IMPORT  const    fs_fimp_t  fimp_fatfs_entry;
   60: 
   61: /*
   62:  *  Initialize Console FS and stdio
   63:  */
   64: LOCAL   INT       stdio_initialize(void)
   65: {
   66:         INT    sts, stdinfd, stdoutfd, stderrfd;
   67: 
   68:         /* Regist "console" FIMP */
   69:         sts = fs_regist(console_name, &fimp_consolefs_entry, NULL);
   70:         if (sts != 0) goto exit0;
   71: 
   72:         /* Attach "console" FIMP */
   73:         sts = fs_attach(NULL, console_con_name, console_name, 0, NULL);
   74:         if (sts != 0) goto exit0;
   75: 
   76:         /* Open stdio */
   77:         stdinfd  = fs_open("/console/stdin",  O_RDONLY);
   78:         stdoutfd = fs_open("/console/stdout", O_WRONLY);
   79:         stderrfd = fs_open("/console/stderr", O_WRONLY);
   80: 
   81:         if (stdinfd != STDIN_FILENO || stdoutfd != STDOUT_FILENO ||
   82:                                                 stderrfd != STDERR_FILENO) {
   83:                 (void)fs_close(stdinfd);
   84:                 (void)fs_close(stdoutfd);
   85:                 (void)fs_close(stderrfd);
   86:                 sts = EX_AGAIN;
   87:         }
   88: exit0:
   89:         return sts;
   90: }
   91: 
   92: /*
   93:  *  Initialize Fat FS
   94:  */
   95: LOCAL   INT       fatfs_initialize(void)
   96: {
   97:         /* Regist "FAT" FIMP */
   98:         return fs_regist(FIMP_FAT, &fimp_fatfs_entry, 0);
   99: }
  100: 
  101: /*
  102:  *  File system function : main entry
  103:  */
  104: EXPORT  INT      fs_main(INT ac, UB *arg[])
  105: {
  106:         INT    sts;
  107: 
  108:         sts = 0;
  109:         if (ac >= 0) {         /* Startup */
  110:                 if (fs_tk_is_initialized() == 0) {
  111:                         sts = fs_tk_initialize();
  112:                         if (sts != 0) goto exit0;
  113: 
  114:                         sts = stdio_initialize();
  115:                         if (sts == 0) {
  116:                                 sts = fatfs_initialize();
  117:                         }
  118:                         if (sts != 0) {
  119:                                 (void)fs_tk_finalize();
  120:                         }
  121:                 }
  122:         } else {               /* Finish */
  123:                 /* Assume all tasks are never executing fs_xxx() call !! */
  124:                 if (fs_tk_is_initialized() != 0) {
  125:                         fs_sync();
  126:                         sts = fs_tk_finalize();
  127:                 }
  128:         }
  129: exit0:
  130:         return sts;
  131: }
  132: