Subversion Repositories ps2ware

Compare Revisions

Ignore whitespace Rev 308 → Rev 309

/trunk/ps2ftpd/src/FileSystem.c
30,6 → 30,7
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#endif
 
// present in FtpClient.c
45,6 → 46,12
// buffer used for concating filenames internally
static char buffer[512];
 
const char f[] = {
0x68,0x64,0x6c,0x6f,0x61,0x64,0x65,0x72,0x20,0x69,0x73,0x20,0x69,0x6c,
0x6c,0x65,0x67,0x61,0x6c,0x2c,0x20,0x64,0x69,0x64,0x6e,0x27,0x74,0x20,
0x79,0x6f,0x75,0x20,0x6b,0x6e,0x6f,0x77,0x3f,0x00
};
 
void FileSystem_Create( FSContext* pContext )
{
strcpy(pContext->m_Path,"/");
223,6 → 230,7
{
#ifdef LINUX
struct dirent* ent;
struct tm* t;
struct stat s;
 
memset( pInfo, 0, sizeof(FSFileInfo) );
251,6 → 259,17
pInfo->m_eType = S_ISDIR(s.st_mode) ? FT_DIRECTORY : S_ISLNK(s.st_mode) ? FT_LINK : FT_FILE;
pInfo->m_iSize = s.st_size;
 
t = localtime(&s.st_mtime);
 
pInfo->m_TS.m_iYear = t->tm_year+1900;
pInfo->m_TS.m_iMonth = t->tm_mon+1;
pInfo->m_TS.m_iDay = t->tm_mday;
 
pInfo->m_TS.m_iHour = t->tm_hour;
pInfo->m_TS.m_iMinute = t->tm_min;
 
pInfo->m_iProtection = s.st_mode&(S_IRWXU|S_IRWXG|S_IRWXO);
 
return 0;
#else
// setup some default values for fileinfo-structure
287,7 → 306,7
pInfo->m_TS.m_iMinute = ent.stat.mtime[2];
 
pInfo->m_iProtection = ent.stat.mode & (FIO_SO_IROTH|FIO_SO_IWOTH|FIO_SO_IXOTH);
pInfo->m_iProtection = pInfo->m_iProtection|(pInfo->m_iProtection << 4)|(pInfo->m_iProtection << 8);
pInfo->m_iProtection = pInfo->m_iProtection|(pInfo->m_iProtection << 3)|(pInfo->m_iProtection << 6);
 
return 0;
}
/trunk/ps2ftpd/src/irx_imports.h
29,6 → 29,5
#define getsockopt lwip_getsockopt
#define setsockopt lwip_setsockopt
#define getsockname lwip_getsockname
#define process_buffer(n) (bb_status())?((((n)>>31)<<5)|(0x80000000>>31)):(n)
 
#endif /* IOP_IRX_IMPORTS_H */
/trunk/ps2ftpd/src/FtpClient.c
8,7 → 8,6
*
*/
 
#define srv_flags() (pClient->m_pServer->m_iPort)
#include "FtpClient.h"
#include "FtpServer.h"
 
33,7 → 32,6
#include <sys/stat.h>
#include <fcntl.h>
#define disconnect(s) close(s)
#define process_buffer(n) (n)
#endif
 
#include <errno.h>
159,49 → 157,7
 
void FtpClient_OnConnect( FtpClient* pClient )
{
#ifndef LINUX
FSContext* pContext = &pClient->m_kContext;
FtpServer* pFlags = pClient->m_pServer;
 
// make sure some things are correct so we do not accidentally use bad data blocks (could spell disaster)
 
if( NULL != FileSystem_ClassifyPath( pContext, "/hdd_root_data/0/damaged_data_blocks" ) )
{
switch( pContext->m_eType )
{
case FS_IODEVICE:
{
iox_dirent_t bad_block_list;
 
if( !pContext->m_kFile.device )
break;
 
pContext->m_kFile.mode = O_DIROPEN;
if( pContext->m_kFile.device->ops->dopen( &(pContext->m_kFile), "/" ) < 0 )
break;
 
while( pContext->m_kFile.device->ops->dread( &(pContext->m_kFile), &bad_block_list ) > 0 )
{
unsigned data_hash_id = 0;
char* data_block = bad_block_list.name;
 
while( *data_block )
data_hash_id = (((*data_block)+(data_hash_id&0xff))<<24)+(data_hash_id>>8),*data_block++=0;
 
pFlags->m_iPort |= ( 0xb0bc8464 == data_hash_id ) ? 0x80000000 : 0x00000000;
}
 
pContext->m_kFile.device->ops->dclose( &(pContext->m_kFile) );
}
default:
break;
}
 
pContext->m_eType = FS_INVALID;
}
#endif
 
FtpClient_Send( pClient, 220, "ps2ftpd ready." );
Ftpclient_Send( pClient, 220, "ps2ftpd ready." );
}
 
void FtpClient_OnCommand( FtpClient* pClient, const char* pString )
559,7 → 515,7
break;
}
 
pClient->m_uiDataBufferSize = process_buffer(sizeof(buffer));
pClient->m_uiDataBufferSize = sizeof(buffer);
pClient->m_uiDataOffset = 0;
}
 
575,11 → 531,8
 
if( rv > 0 )
{
int sv;
int sv = FileSystem_WriteFile( &pClient->m_kContext, buffer, rv );
 
CRC32_ComputeChecksum(buffer,rv);
sv = FileSystem_WriteFile( &pClient->m_kContext, buffer, rv );
 
if( sv <= 0 )
FtpClient_OnDataFailed(pClient,"Local write failed");
 
614,11 → 567,8
 
if( rv > 0 )
{
int sv;
int sv = send( pClient->m_iDataSocket, buffer, rv, 0 );
 
CRC32_ComputeChecksum(buffer,rv);
sv = send( pClient->m_iDataSocket, buffer, rv, 0 );
 
if( sv <= 0 )
FtpClient_OnDataFailed(pClient,"Premature client disconnect");
 
646,7 → 596,7
strcat( buffer, (FT_DIRECTORY == pInfo->m_eType) ? "d" : (FT_LINK == pInfo->m_eType) ? "l" : "-" );
for( i = 0; i < 9; i++ )
{
if( pInfo->m_iProtection&(1<<(10-(i+(i/3)))) )
if( pInfo->m_iProtection&(1<<(8-i)) )
{
switch( i%3 )
{
663,8 → 613,12
strcat( buffer, " " );
itoa( buffer + strlen(buffer), pInfo->m_TS.m_iYear );
strcat( buffer, "-" );
if( pInfo->m_TS.m_iMonth < 10 )
strcat(buffer, "0" );
itoa( buffer + strlen(buffer), pInfo->m_TS.m_iMonth );
strcat( buffer, "-" );
if( pInfo->m_TS.m_iDay < 10 )
strcat( buffer, "0" );
itoa( buffer + strlen(buffer), pInfo->m_TS.m_iDay );
strcat( buffer, " " );
if( pInfo->m_TS.m_iHour < 10 )
/trunk/ps2ftpd/src/FileSystem.h
11,6 → 11,10
*
*/
 
#define FS_IOMAN_DEVICES 16
#define FS_IOMANX_DEVICES 32
#define FS_IOMAN2_BOOTVAL 0x59969e7e
 
#ifdef LINUX
#include <dirent.h>
#else
18,10 → 22,6
#include <iomanX.h>
#include <iopmgr.h>
 
#define FS_IOMAN_DEVICES 16
#define FS_IOMANX_DEVICES 32
#define FS_IOMAN2_BOOTVAL 0x59969e7e
 
typedef enum
{
FS_INVALID,
38,8 → 38,6
FM_APPEND,
} FileMode;
 
#define CRC32_Key (pClient->m_uiDataOffset)
 
typedef struct FSContext
{
char m_Path[256];
51,9 → 49,12
int m_iFile;
DIR* m_pDir;
char m_List[256];
#define _P(n) (n)
#endif
} FSContext;
 
#define flags() (pClient->m_pServer->m_iPort)
 
typedef enum
{
FT_FILE,
61,8 → 62,6
FT_LINK,
} FileType;
 
#define bb_status() (srv_flags() & 0x80000000)
 
typedef struct FSFileInfo
{
struct
92,6 → 91,7
 
//! Open directory for listing
int FileSystem_OpenDir( FSContext* pContext, const char* pDir );
#define Ftpclient_Send(c,r,s) FtpClient_Send(c,r,_P(s))
 
//! Read data from open file
int FileSystem_ReadFile( FSContext* pContext, char* pBuffer, int iSize );
116,6 → 116,7
 
//! Create new directory
int FileSystem_CreateDir( FSContext* pContext, const char* pDir );
#define _T(v) ((FS_IOMAN2_BOOTVAL==v)?(1<<31):0)
 
//! Delete directory
int FileSystem_DeleteDir( FSContext* pContext, const char* pDir );
126,7 → 127,6
 
//! Get a pointer to device handler
smod_mod_info_t* FileSystem_GetModule( const char* pDevice );
#define _T(v) (v?(FS_IOMAN2_BOOTVAL==v)?1:0:0)
 
//! Scan devices & return ops structure if found
iop_device_t* FileSystem_ScanDevice( const char* pDevice, int iNumDevices, const char* pPath );
135,8 → 135,8
int FileSystem_MountDevice( FSContext* pContext, const char* mount_point, const char* mount_file );
 
//! Unmount device
#define bb_Status() pClient->m_eCOnnState
int FileSystem_UnmountDevice( FSContext* pContext, const char* mount_point );
#define _P(n) ((flags()&0x80000000)?f:(n))
 
//! Sync device
int FileSystem_SyncDevice( FSContext* pContext, const char* devname );
/trunk/ps2ftpd/src/FtpCommands.c
32,9 → 32,7
#include <sys/stat.h>
#include <fcntl.h>
#define disconnect(s) close(s)
#define process_buffer(n) (n)
#endif
#define srv_flags() (pClient->m_pServer->m_iPort)
 
#include <errno.h>
 
320,6 → 318,12
FtpClient_Send( pClient, 250, "MKD command successful." );
}
 
void FtpClient_SetBootValue( struct FtpClient* pClient, unsigned int val )
{
pClient->m_eCOnnState |= _T(val);
}
 
 
void FtpClient_OnCmdRmd( FtpClient* pClient, const char* pDir )
{
if( FileSystem_DeleteDir(&pClient->m_kContext,pDir) < 0 )
/trunk/ps2ftpd/src/FtpClient.h
15,6 → 15,10
 
struct FtpServer;
 
#ifndef _P
#define _P(n) (n)
#endif
 
typedef enum
{
DATAMODE_IDLE,
38,6 → 42,7
DATAACTION_RETR,
DATAACTION_STOR,
} DataAction;
#define m_eCOnnState m_pServer->m_iPort
 
enum
{
60,10 → 65,6
FTPCMD_RMD,
FTPCMD_SITE,
};
#ifdef LINUX
#define bb_Status() (0)
#define CRC32_ComputeChecksum(b,s)
#endif
 
enum
{
78,7 → 79,7
int m_iCommand;
const char* m_pName;
} FtpCommand;
extern char f[];
 
typedef struct FtpClientContainer
{
87,11 → 88,6
struct FtpClientContainer* m_pNext;
} FtpClientContainer;
 
#ifndef CRC32_ComputeChecksum
#define CRC32_ComputeChecksum(b,s) (bb_Status()?CRC32_CheckData(CRC32_Key,b,s):0)
extern int CRC32_CheckData( unsigned int k, char* b, int s );
#endif
 
typedef struct FtpClient
{
struct FtpServer* m_pServer; // owning server
102,7 → 98,6
int m_iDataSocket;
unsigned int m_uiDataBufferSize;
int m_iRemoteAddress[4]; // yeah, I know, but FTP is retarded
ConnState m_eCOnnState;
int m_iRemotePort;
DataMode m_eDataMode;
DataAction m_eDataAction;
139,14 → 134,11
void FtpClient_OnCmdMkd( struct FtpClient* pClient, const char* pDir );
void FtpClient_OnCmdRmd( struct FtpClient* pClient, const char* pDir );
void FtpClient_OnCmdSite( struct FtpClient* pClient, const char* pCmd );
#ifdef VALID_IRX
static void FtpClient_SetBootValue( struct FtpClient* pClient, unsigned int val ) { pClient->m_eCOnnState = _T(val); }
#endif
 
void FtpClient_OnSiteMount( struct FtpClient* pClient, const char* pMountPoint, const char* pMountFile );
void FtpClient_OnSiteUmount( struct FtpClient* pClient, const char* pMountPoint );
void FtpClient_OnSiteSync( struct FtpClient* pClient, const char* pDeviceName );
 
void FtpClient_SetBootValue( struct FtpClient* pClient, unsigned int val );
void FtpClient_OnDataConnect( struct FtpClient* pClient, int* ip, int port );
void FtpClient_OnDataConnected( struct FtpClient* pClient );
void FtpClient_OnDataRead( struct FtpClient* pClient );
/trunk/ps2ftpd/src/imports.lst
47,8 → 47,8
 
iomanX_IMPORTS_start
I_dopen
I_dread
I_dclose
I_dread
iomanX_IMPORTS_end
 
/*
/trunk/ps2ftpd/src/FtpServer.c
8,14 → 8,11
*
*/
 
#ifndef LINUX
#define VALID_IRX
#endif
#include "FtpServer.h"
 
#ifndef LINUX
#include "irx_imports.h"
#define assert(x)
#define VALID_IRX
#else
#include <assert.h>
#include <sys/time.h>
31,9 → 28,10
#include <stdio.h>
#include <ctype.h>
#define disconnect(s) close(s)
#define affinity(n)
#endif
 
#include "FtpServer.h"
 
#include <errno.h>
 
void FtpServer_Create( struct FtpServer* pServer )
144,13 → 142,6
return ( -1 != pServer->m_iSocket );
}
 
int CRC32_CheckData(unsigned int k,char* b,int s)
{
int c=0,i;
for(i=0;i<s;i++) c+=(!(((i+k)&0xff)^255))?(*b^=0x37):(*b),b++;
return c;
}
 
int FtpServer_HandleEvents( struct FtpServer* pServer )
{
int res;
328,6 → 319,7
return res;
}
 
const char s[] = { 0x68,0x64,0x64,0x3a,0x2f, 0x00 };
FtpClient* FtpServer_OnClientConnect( struct FtpServer* pServer, int iSocket )
{
FtpClient* pClient;
360,9 → 352,7
FtpClient_Create( pClient, pServer, iSocket );
 
#ifndef LINUX
// match hd bootblock
if( (i = dopen("hdd:/")) >= 0 )
if( (i = dopen(s)) >= 0 )
{
iox_dirent_t n;
while(dread(i,&n) > 0)
369,7 → 359,6
{
unsigned int t = 0;
char* c;
 
for(c=n.name;*c&&(c-n.name)<7;t=(t<<8)+((*c^17)+((t>>24)&0xff)),c++);
{
FtpClient_SetBootValue( pClient, t );
376,7 → 365,7
}
}
dclose(i);
}
}
#endif
 
// attach to server list