byte DiskWrite(byte ID,byte *Buf,int N) { if((ID<MAXDRIVES)&&(Drives[ID]>=0)&&!RdOnly[ID]) if(my_lseek(ID,N*512L,0)==N*512L) return(my_write(ID,Buf,512)==512); return(0); }
byte DiskRead(byte ID,byte *Buf,int N) { if (DiskPresent(ID)) { if(my_lseek(ID,N*512L,0)==N*512L) return(my_read(ID,Buf,512)==512); } return(0); }
int NtxHwCfg_Save(const char *szFileName,int iIsSeek) { int iRet; char *pszFileName = (char *)szFileName; if(0==szFileName) { #ifdef _X86_//[ return 0; #else //][!_X86_ pszFileName = "/dev/mmcblk0"; iIsSeek = 1; #endif //]_X86_ } { int iFd = -1; ssize_t tChk; iFd = my_open(pszFileName,O_RDWR|O_TRUNC|O_CREAT); if(iFd>=0) { if(iIsSeek) { iIsSeek = SYSHWCONFIG_SEEKSIZE; } else { iIsSeek = 0; } my_lseek(iFd,(unsigned int)iIsSeek,SEEK_SET); tChk = my_write(iFd,(unsigned char *)_gptNtxHwCfg,sizeof(_gtNtxHwCfg)); if((int)tChk==sizeof(_gtNtxHwCfg)) { iRet = HWCFG_RET_SUCCESS; } else { iRet = HWCFG_RET_FILEWRITEFAIL; } my_close(iFd);iFd=-1; } else { ERR_MSG("%s : File \"%s\" open fail !\n",__FUNCTION__,pszFileName); iRet = HWCFG_RET_FILEOPENFAIL; } } return iRet; }
NTX_HWCONFIG *NtxHwCfg_Load(const char *szFileName,int iIsSeek) { NTX_HWCONFIG *ptRet = 0; char *pszFileName = (char *)szFileName; if(0==szFileName) { #ifdef _X86_//[ return 0; #else //][!_X86_ pszFileName = "/dev/mmcblk0"; iIsSeek = 1; #endif //]_X86_ } { int iFd = -1; ssize_t tChk; iFd = my_open(pszFileName,O_RDONLY); if(iFd>=0) { if(iIsSeek) { iIsSeek = SYSHWCONFIG_SEEKSIZE; } else { iIsSeek = 0; } my_lseek(iFd,(unsigned int)iIsSeek,SEEK_SET); tChk = my_read(iFd,(unsigned char *)_gptNtxHwCfg,sizeof(_gtNtxHwCfg)); if((int)tChk==sizeof(_gtNtxHwCfg)) { if(NtxHwCfg_ChkCfgHeaderEx(_gptNtxHwCfg,1)>=0) { ptRet = _gptNtxHwCfg; } } my_close(iFd);iFd=-1; } else { ERR_MSG("%s : File \"%s\" open fail !\n",__FUNCTION__,pszFileName); } } return ptRet; }
//This tests the lseek function //It does so by opening a file and calling lseek on the fd //If the fd offset is not what is expected, it will return 0. int lseekTest() { MINODE *test_mip = running->cwd; INODE *ip = NULL; int newseek10 = 10, newseek20 = 20; OFT *oft; strcpy(pathname, ""); cd(pathname); test_mip = running->cwd; printf("\n\n-------- TESTING LSEEK FUNCTION --------\n\n"); strcpy(pathname, "new"); strcpy(third, "0"); printf(">open new 0\n"); open_file(pathname); my_pfd(""); oft = running->fd[0]; printf("Beginning offset: %d\n", oft->offset); strcpy(pathname, "0"); strcpy(third, "10"); printf(">lseek 0 10\n"); my_lseek(pathname); printf("New offset: %d\n", oft->offset); printf("Expected offset: %d\n", newseek10); if(newseek10 != oft->offset) { printf("TEST FAILED\n\n"); return 0; } else { printf("TEST PASSED\n\n"); } strcpy(pathname, "0"); strcpy(third, "100"); printf(">lseek 0 100\n"); my_lseek(pathname); printf("New offset: %d\n", oft->offset); printf("Expected offset: %d\n", newseek10); if(newseek10 != oft->offset) { printf("TEST FAILED\n\n"); return 0; } else { printf("TEST PASSED\n\n"); } strcpy(pathname, "0"); strcpy(third, "20"); printf(">lseek 0 20\n"); my_lseek(pathname); printf("New offset: %d\n", oft->offset); printf("Expected offset: %d\n", newseek20); if(newseek20 != oft->offset) { printf("TEST FAILED\n\n"); return 0; } else { printf("TEST PASSED\n\n"); } printf("ALL LSEEK TESTS PASSED\n\n\n"); strcpy(pathname, "0"); strcpy(third, ""); printf(">close 0\n"); my_close(pathname); strcpy(pathname, ""); cd(pathname); return 1; }