📄 main.c
字号:
break; } default: { err = E_RSFN; break; } } return err;}/* * System call entry */LOCAL WER SyscallEntry( VP para, W fn ){ CmdPkt pkt; /* = NIL */ ER err; /* Configure packet */ pkt.cmd.tid = tk_get_tid(); pkt.cmd.fno.w = (UW)fn; pkt.cmd.para = para; pkt.uxinfo = GetMinfo(TSK_SELF, SF_SVC); if ( pkt.uxinfo == NULL ) { err = E_SYS; goto err_ret; } pkt.exinf = NULL; /* Systemcall call */ err = PacketCall(&pkt); if ( err < E_OK ) { goto err_ret; } return pkt.cmd.ret;err_ret: DEBUG_PRINT(("SyscallEntry err=%#x\n", err)); return err;}/* * Current directory release */LOCAL ER uu_chdir( UXINFO *uxinfo ){ SF_CHDIR_PARA para; CmdPkt pkt; /* = NIL */ ER err; /* Packet configuration */ pkt.cmd.fno.w = SF_CHDIR_FN; para.path = "/"; pkt.cmd.para = ¶ pkt.uxinfo = uxinfo; pkt.exinf = NULL; /* Systemcall call */ err = PacketCall(&pkt); if ( err < E_OK ) { goto err_ret; } return pkt.cmd.ret;err_ret: DEBUG_PRINT(("uu_chdir err=%#x\n", err)); return err;}/* * File close (for clean-up) */LOCAL ER uu_close( UXINFO *uxinfo, W fildes ){ SF_CLOSE_PARA para; CmdPkt pkt; /* = NIL */ ER err; /* Packet configuration */ pkt.cmd.fno.w = SF_CLOSE_FN; para.fildes = fildes; pkt.cmd.para = ¶ pkt.uxinfo = uxinfo; pkt.exinf = NULL; /* Systemcall call */ err = PacketCall(&pkt); if ( err < E_OK ) { goto err_ret; } return pkt.cmd.ret;err_ret: DEBUG_PRINT(("uu_close err=%#x\n", err)); return err;}/* * Start-up function */LOCAL void StartupFn( ID resid, ID pid ){ UXINFO *uxinfo, *parux; PINFO *pinfo, *parp; if ( tk_get_res(resid, SF_SVC, (VP*)&uxinfo) < E_OK ) { return; } /* Acquire parent process */ if ( GetPidToPinfo(pid, &pinfo) < E_OK ) { return; } parp = pinfo->parent; /* Parent process */ /* * Configuration of the process attachment information * Takeover the current directory * and the file creation mask from the parent process * Configure the initial value if there is no parent process. */ if (( parp == NULL )|| ( PidToMinfo(parp->procid, SF_SVC, (VP*)&parux) < E_OK )) { /* Current dirtectory initial value is "/" */ uxinfo->curdir.fs = (FS*)&ROOT_FS; uxinfo->curdir.inode = NULL; /* File creation mode mask the initial value is 0 */ uxinfo->cmask = 0; } else { /* Current directory takeover */ uxinfo->curdir.fs = parux->curdir.fs; uxinfo->curdir.inode = parux->curdir.inode; if ( uxinfo->curdir.inode != NULL ) { (uxinfo->curdir.inode->refcnt)++; } /* File creation mode takeover */ uxinfo->cmask = parux->cmask; } /* Creation of file descriptor table */ uxinfo->fdtbl = Vcalloc((UW)MaxOpenF, sizeof(FD*)); if ( uxinfo->fdtbl == NULL ) { return; } /* Standard input-output initial open */ std_init(uxinfo);}/* * Clean up function */LOCAL void CleanupFn( ID resid, ID pid ){ UXINFO *uxinfo; FD *fd; W i; if ( tk_get_res(resid, SF_SVC, (VP*)&uxinfo) < E_OK ) { return; } /* Current directory release */ (void)uu_chdir(uxinfo); if ( uxinfo->fdtbl != NULL ) { /* All files close */ for ( i = 0; i < MaxOpenF; ++i ) { fd = uxinfo->fdtbl[i]; if ( fd != NULL ) { (void)uu_close(uxinfo, i); } } /* Deletion of file descriptor table */ Vfree(uxinfo->fdtbl); }}/* --------------------------------------------------------------------------- *//* * Standard file name conversion environment */EXPORT TF_CTX tf_euctotc_ctx; /* EUC -> TC */EXPORT TF_CTX tf_tctoeuc_ctx; /* TC -> EUC *//* * Standard file name conversion lock for exclusive access control */EXPORT FastLock EtoTLock;EXPORT FastLock TtoELock;/* * Acquisition of "libtf" subset standard file name conversion environment */LOCAL ER init_sf_enc( void ){ W euctotcid, tctoeucid; W undefid; ER err; /* Acquisition of conversion environment */ err = tf_open_ctx(&tf_euctotc_ctx); if ( err < E_OK ) { goto err_ret1; } err = tf_open_ctx(&tf_tctoeuc_ctx); if ( err < E_OK ) { goto err_ret2; } /* ID processing */ euctotcid = tf_to_id(TF_ID_PROFSET_CONVERTFROM, "EUC-JISX0213"); if ( euctotcid < E_OK ) { err = euctotcid; goto err_ret3; } tctoeucid = tf_to_id(TF_ID_PROFSET_CONVERTTO, "EUC-JISX0213"); if ( tctoeucid < E_OK ) { err = tctoeucid; goto err_ret3; } undefid = tf_to_id(TF_ID_OPT_CONVERT, "UNDEFINED_CHAR"); if ( undefid < E_OK ) { err = undefid; goto err_ret3; } /* Configuration of profile set */ err = tf_set_profile(tf_euctotc_ctx, euctotcid); if ( err < E_OK ) { goto err_ret3; } err = tf_set_profile(tf_tctoeuc_ctx, tctoeucid); if ( err < E_OK ) { goto err_ret3; } /* Configuration of option */ err = tf_set_options(tf_euctotc_ctx, undefid, 0); if ( err < E_OK ) { goto err_ret3; } return E_OK;err_ret3: (void)tf_close_ctx(tf_tctoeuc_ctx);err_ret2: (void)tf_close_ctx(tf_euctotc_ctx);err_ret1: DEBUG_PRINT(("init_sf_enc err=%#x\n", err)); return E_SYS;}/* * Release of "libtf" subset standard file name conversion environment */void fin_sf_enc( void ){ (void)tf_close_ctx(tf_tctoeuc_ctx); (void)tf_close_ctx(tf_euctotc_ctx);}/* --------------------------------------------------------------------------- */EXPORT FastLock UxLock; /* The lock for exclusive access control *//* * Configuration information */EXPORT W MaxOpenF; /* The number of the maximum file opens per a process */EXPORT PRI FsTskPri; /* File system task priority */EXPORT W SyncTimeOut; /* Sycronization time out *//* * Initilization sequence */LOCAL ER initialize( void ){ T_DSSY dssy; W n, val[L_SYSCONF_VAL]; ER err; /* Acquisition of system configuration information */ n = GetSysConf((UB*)"UxMaxOpenF", val); MaxOpenF = ( n == 1 )? val[0]: TSD_INS_VAL_20; /* Acquisition of task priority */ n = GetSysConf((UB*)"UxFsTskPri", val); FsTskPri = ( n == 1 )? val[0]: TSD_INS_VAL_100; /* Acquisition of synchronous time out */ n = GetSysConf((UB*)"UxSyncTimeOut", val); SyncTimeOut = ( n == 1 )? val[0]: TSD_INS_VAL_500; /* Creation of the lock for exclusive access control */ err = CreateLock(&UxLock, (UB*)"uxem"); if ( err < E_OK ) { goto err_ret; } /* Acquisition of standard file name conversion environment */ err = init_sf_enc(); if ( err < E_OK ) { goto err_ret; } /* Creation of standard file name conversion lock for exclusive access control */ err = CreateLock(&EtoTLock, (UB*)"etot"); if ( err < E_OK ) { goto err_ret; } err = CreateLock(&TtoELock, (UB*)"ttoe"); if ( err < E_OK ) { goto err_ret; } /* Manager registration */ dssy.ssyatr = TA_NULL; dssy.ssypri = SF_PRI; dssy.svchdr = (FP)SyscallEntry; dssy.breakfn = NULL; dssy.startupfn = StartupFn; dssy.cleanupfn = CleanupFn; dssy.eventfn = NULL; dssy.resblksz = UXINFO_SZ; err = tk_def_ssy(SF_SVC, &dssy); if ( err < E_OK ) { goto err_ret; } return E_OK;err_ret: DEBUG_PRINT(("initialize err = %#x\n", err)); return err;}/* * Stop sequence */LOCAL ER finish( void ){ ER err, error = E_OK; /* Manager deregistration */ err = tk_def_ssy(SF_SVC, NULL); if ( err < E_OK ) { error = err; } /* Release of standard file name conversion environment */ fin_sf_enc(); /* Deletion of the lock for exclusive access control */ DeleteLock(&UxLock); DeleteLock(&EtoTLock); DeleteLock(&TtoELock);#ifdef DEBUG if ( error < E_OK ) { DEBUG_PRINT(("finish err = %#x\n", error)); }#endif return error;}/* * Manager entry */EXPORT ER SEIOMgr( INT ac, UB *av[] ){ ER err; if ( ac >= 0 ) { /* Initilization sequence */ err = initialize(); if ( err < E_OK ) { (void)finish(); goto err_ret; } /* Execute the configuration for initialization process * Initialization process starts up prior to SEIOMgr. * Therefore, start-up function is not called. */ StartupFn(tk_get_rid(TSK_SELF), 1); } else { /* Stop sequnece */ err = finish(); }err_ret: return err;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -