📄 fileaccess.c
字号:
/* *---------------------------------------------------------------------- * T-Kernel / Standard Extension * * Copyright (C) 2006 by Ken Sakamura. All rights reserved. * T-Kernel / Standard Extension is distributed * under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * * Version: 1.00.00 * Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* * fileaccess.c (memory) * * File access routines */#include "segmgr.h"#include <sys/tkref.h>#include <extension/seio.h>#include <stdio.h>#include <tcode.h>#include <seio/fcntl.h>LOCAL void num2tc(TC *buf, UW n);#define TSD_N2T_VAL_8 8#define TSD_N2T_MSK_0X0F 0x0fU#define TSD_EFR_VAL_0X00000000 0x00000000#define TSD_N2T_SFT_4 4#define TSD_EFC_DES_M1 (-1)LOCAL const TC numtbl[] = { TK_0, TK_1, TK_2, TK_3, TK_4, TK_5, TK_6, TK_7, TK_8, TK_9, TK_a, TK_b, TK_c, TK_d, TK_e, TK_f};LOCAL void num2tc(TC *buf, UW n){ buf += TSD_N2T_VAL_8; *buf-- = TC_NULL; *buf-- = numtbl[n & TSD_N2T_MSK_0X0F]; n >>= TSD_N2T_SFT_4; *buf-- = numtbl[n & TSD_N2T_MSK_0X0F]; n >>= TSD_N2T_SFT_4; *buf-- = numtbl[n & TSD_N2T_MSK_0X0F]; n >>= TSD_N2T_SFT_4; *buf-- = numtbl[n & TSD_N2T_MSK_0X0F]; n >>= TSD_N2T_SFT_4; *buf-- = numtbl[n & TSD_N2T_MSK_0X0F]; n >>= TSD_N2T_SFT_4; *buf-- = numtbl[n & TSD_N2T_MSK_0X0F]; n >>= TSD_N2T_SFT_4; *buf-- = numtbl[n & TSD_N2T_MSK_0X0F]; n >>= TSD_N2T_SFT_4; *buf = numtbl[n & TSD_N2T_MSK_0X0F];}EXPORT ER ExecFileCheck(POBJ_HDR *pohdr){ ER er; switch (pohdr->type) { case TPA_LINK: case TMA_LINK: er = tkse_chk_fil(pohdr->src.lnk, F_EXCUTE, NULL); break; case TPA_SEIO: case TMA_SEIO: case TPA_PTR: case TMA_PTR: er = E_OK; break; default: er = E_PAR; break; } return er;}EXPORT ER ExecFileOpen(POBJ_HDR *pohdr){ ER er; switch (pohdr->type) { case TPA_LINK: case TMA_LINK: er = tkse_opn_fil(pohdr->src.lnk, F_READ|F_WEXCL, NULL); break; case TPA_SEIO: case TMA_SEIO: er = tkse_open((char*)pohdr->src.path, O_RDONLY, 0); break; case TPA_PTR: case TMA_PTR: er = ExecPtrOpen(pohdr); break; default: er = E_PAR; break; } pohdr->desc = (er >= 0) ? er : TSD_EFC_DES_M1; return er;}EXPORT ER ExecFileGetName(POBJ_HDR *pohdr, TC *name){ ER er; switch (pohdr->type) { case TPA_LINK: case TMA_LINK: er = tkse_ofl_sts(pohdr->desc, name, NULL, NULL); break; case TPA_SEIO: case TMA_SEIO: if (name != NULL) { num2tc(name, (UW)pohdr->desc); } er = E_OK; break; case TPA_PTR: case TMA_PTR: er = ExecPtrName(pohdr, name); break; default: er = E_PAR; break; } return er;}EXPORT ER ExecFileRead(POBJ_HDR *pohdr, VB *buf, W size, W ofs, W *rsize, VP exinf){ ER er; W rsz; switch (pohdr->type) { case TPA_LINK: case TMA_LINK: /* Load the first one byte separately because it cannot be loaded in to an address of 0x00000000 due to specifications of rea_rec(). */ if (buf == (VB*)TSD_EFR_VAL_0X00000000) { VB firstbyte; er = tkse_rea_rec(pohdr->desc, ofs, &firstbyte, 1, &rsz, NULL); if (er < E_OK) { goto ret; } if (rsz < 1) { er = E_REC; goto ret; } *buf++ = firstbyte; ofs++; size--; if (rsize != NULL) { *rsize = rsz; rsize = NULL; } } er = tkse_rea_rec(pohdr->desc, ofs, buf, size, rsize, (UH*)exinf); break; case TPA_SEIO: case TMA_SEIO: er = tkse_lseek(pohdr->desc, ofs, SEEK_SET); if (er < E_OK) { goto ret; } er = tkse_read(pohdr->desc, buf, (size_t)size); if (er < E_OK) { goto ret; } if (rsize != NULL) { *rsize = er; } er = E_OK; break; case TPA_PTR: case TMA_PTR: er = ExecPtrRead(pohdr, buf, size, ofs, rsize, exinf); break; default: er = E_PAR; break; } ret: return er;}EXPORT ER ExecFileClose(POBJ_HDR *pohdr){ ER er; switch (pohdr->type) { case TPA_LINK: case TMA_LINK: er = tkse_cls_fil(pohdr->desc); break; case TPA_SEIO: case TMA_SEIO: er = tkse_close(pohdr->desc); break; case TPA_PTR: case TMA_PTR: er = ExecPtrClose(pohdr); break; default: er = E_PAR; break; } pohdr->desc = TSD_EFC_DES_M1; return er;}EXPORT ER ExecFileRecInfo(POBJ_HDR *pohdr, W *offset, W *recsize, PhyBlk *block, W entry_len, W *n_entry){ ER er; switch (pohdr->type) { case TPA_LINK: case TMA_LINK: er = tkse_GetRecInfo(pohdr->desc, offset, recsize, block, entry_len, n_entry); break; case TPA_SEIO: case TMA_SEIO: case TPA_PTR: case TMA_PTR: er = 0; if (offset != NULL) { *offset = 0; } if (recsize != NULL) { *recsize = 0; } if (n_entry != NULL) { *n_entry = 0; } break; default: er = E_PAR; break; } return er;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -