Exemplo n.º 1
0
u64 FileSize( std::string path, u8 depth )
{
	u64 ret = 0;
	sysFSStat stat;
	if( sysFsStat( path.c_str(), &stat ) )
		return 0;
	//its a directory
	if( stat.st_mode & S_IFDIR )
	{
		if( path.at( path.size() - 1 ) != '/' )
			path += "/";

		int i;
		s32 fd;
		sysFSDirent entry;
		u64 read;
		//open dir
		i = sysFsOpendir( path.c_str(), &fd );
		if( i )
		{
			printf("sysFsOpendir( %s ): %i\n", path.c_str(), i );
			return ret;
		}
		while( !sysFsReaddir( fd, &entry , &read ) && read > 0 )
		{
			if( !entry.d_namlen || !strcmp( entry.d_name, "." ) || !strcmp( entry.d_name, ".." ) )
			{
				continue;
			}

			std::string subPath = path + entry.d_name;

			if( sysFsStat( subPath.c_str(), &stat ) )
				continue;

			if( stat.st_mode & S_IFDIR )
			{
				if( depth < MAX_RECURSE_DEPTH )
					ret += FileSize( subPath, depth + 1 );
				else
				{
					printf("FileSize( \"%s\" ): max recursion depth reached\n", subPath.c_str() );
				}
			}
			else
			{
				ret += stat.st_size;
			}
		}
		sysFsClosedir( fd );
	}
	else//its a file
	{
		ret = stat.st_size;
	}
	return ret;
}
int exists(const char *path)
{
	sysFSStat info;

	if (sysFsStat(path, &info) >= 0) return 0;
	return -1;
}
double get_filesize(const char *path)
{
	sysFSStat info;

	if (sysFsStat(path, &info) >= 0) return (double)info.st_size;
	else return 0;
}
int is_dev_blind_mounted()
{
	const char* MOUNT_POINT = "/dev_blind"; //our mount point
	sysFSStat dir;

	return sysFsStat(MOUNT_POINT, &dir);
}
Exemplo n.º 5
0
bool IsDir( const char* path )
{
	sysFSStat entry;
	if( sysFsStat( path, &entry ) )
		return false;
	bool ret = ( ( entry.st_mode & S_IFDIR ) != 0 );
	return ret;
}
const string fileCreatedDateTime(const char *path)
{
	time_t tmod;
	char buf[80];
	sysFSStat info;

	if (sysFsStat(path, &info) >= 0)
	{
		tmod=info.st_mtime;
		strftime(buf, sizeof(buf), "%Y-%m-%d %Hh%Mm%Ss", localtime(&tmod));
		return buf;
	}
	else return "";
}
Exemplo n.º 7
0
u8* ReadFile( const char* path, u32 *size )
{
	u8* ret = NULL;
	sysFSStat stat;
	s32 fd;
	u64 read;
	if( size )
		*size = 0;

	int i = sysFsStat( path, &stat );

	if( i < 0 || !stat.st_size || ( stat.st_mode & S_IFDIR ) )
	{
		//printf("sysFsStat( %s ): %i\n", path, i );
		return ret;
	}
	ret = (u8*)malloc( stat.st_size );
	if( !ret )
	{
		printf("failed to allocate %u bytes\n", (unsigned int)stat.st_size );
		return NULL;

	}
	i = sysFsOpen( path, SYS_O_RDONLY, &fd, NULL, 0 );
	if( i )
	{
		printf("sysFsOpen( %s ) %i\n", path, i );
		free( ret );
		return NULL;
	}
	i = sysFsRead( fd, ret, stat.st_size, &read );
	if( i || read != stat.st_size )
	{
		printf("sysFsRead( %u ): %i ( %u )\n", (unsigned int)stat.st_size, i, (unsigned int)read );
		free( ret );
		sysFsClose( fd );
		return NULL;
	}
	sysFsClose( fd );

	if( size )
		*size = stat.st_size;

	return ret;
}
Exemplo n.º 8
0
Buffer ReadFileToBuffer( const std::string &path )
{
	Buffer ret;
	sysFSStat stat;
	s32 fd;
	u64 read;

	int i = sysFsStat( path.c_str(), &stat );

	if( i < 0 || !stat.st_size || ( stat.st_mode & S_IFDIR ) )
	{
		//printf("sysFsStat( %s ): %08x\n", path.c_str(), i );
		return ret;
	}
	ret.Resize( stat.st_size );
	if( ret.IsEmpty() )
	{
		printf("ReadFileToBuffer() failed to resize buffer\n");
		return ret;
	}
	i = sysFsOpen( path.c_str(), SYS_O_RDONLY, &fd, NULL, 0 );
	if( i )
	{
		printf("sysFsOpen( %s ) %i\n", path.c_str(), i );
		ret.Free();
		return ret;
	}
	i = sysFsRead( fd, ret.Data(), stat.st_size, &read );
	if( i || read != stat.st_size )
	{
		printf("sysFsRead( %u ): %i ( %u )\n", (unsigned int)stat.st_size, i, (unsigned int)read );
		ret.Free();
		sysFsClose( fd );
		return ret;
	}
	sysFsClose( fd );
	return ret;
}
Exemplo n.º 9
0
/***************************************************************************
 * Browse subdirectories
 **************************************************************************/
int
ParseDirectory()
{
	int i;
	s32 fd;
	sysFSDirent entry;
	u64 read;

	//DIR_ITER *dir = NULL;
	char fulldir[ MAXPATHLEN ];
	char filename[ MAXPATHLEN ];

	// reset browser
	Reset();

	// open the directory
	snprintf( fulldir, sizeof( fulldir ), "%s%s", rootdir, browser.dir); // add currentDevice to path
	printf("browsing: \"%s\" root: \"%s\"  dir: \"%s\"\n", fulldir, rootdir, browser.dir );

	//open dir
	i = sysFsOpendir( fulldir, &fd );
	if( i )
	{
		printf("sysFsOpendir( %s ): %i\n", fulldir, i );
		browser.dir[ 0 ] = 0;
		i = sysFsOpendir( rootdir, &fd );
		if( i )
		{
			printf("sysFsOpendir( %s ): %i\n", rootdir, i );
			return -1;
		}
	}

	// index files/folders
	int entryNum = 0;

	while( !sysFsReaddir( fd, &entry , &read ) && read > 0 )
	{
		if( !strcmp( entry.d_name,".") )
			continue;

		snprintf( filename, sizeof( filename ), "%s%s/%s", rootdir, browser.dir, entry.d_name );

		sysFSStat filestat;
		if( sysFsStat( filename, &filestat ) )
			continue;

		if( ( !strcmp( entry.d_name, ".." ) && !strlen( browser.dir ) )//dont add dotdot if this is the lower allowed directory
			|| ( ( filestat.st_mode & S_IFDIR ) && !( browser.mode & DIR_DIRS ) )//we dont want to see folders, so skip them
			|| ( !( filestat.st_mode & S_IFDIR ) && !( browser.mode & DIR_FILES ) ))
		{
			continue;
		}

		BROWSERENTRY * newBrowserList = (BROWSERENTRY *)realloc( browserList, ( entryNum + 1 ) * sizeof(BROWSERENTRY));

		if( !newBrowserList ) // failed to allocate required memory
		{
			Reset();
			entryNum = -1;
			break;
		}
		else
		{
			browserList = newBrowserList;
		}
		memset( &( browserList[ entryNum ] ), 0, sizeof(BROWSERENTRY) ); // clear the new entry

		strncpy( browserList[ entryNum ].filename, entry.d_name, MAXJOLIET );

		if( strcmp( entry.d_name,"..") == 0 )
		{
			sprintf( browserList[ entryNum ].displayname, "Up One Level" );
		}
		else
		{
			strncpy(browserList[entryNum].displayname, entry.d_name, MAXDISPLAY);	// crop name for display
		}

		browserList[ entryNum ].length = filestat.st_size;
		browserList[ entryNum ].isdir = (filestat.st_mode & S_IFDIR ) == 0 ? 0 : 1; // flag this as a dir

		entryNum++;
	}

	// close directory
	sysFsClosedir( fd );

	// Sort the file list
	qsort(browserList, entryNum, sizeof(BROWSERENTRY), FileSortCallback);

	browser.numEntries = entryNum;
	return entryNum;
}
Exemplo n.º 10
0
int main(s32 argc, char* argv[])
{
	atexit(_unload);

	// Initialize graphics
	GFX = new NoRSX();
	MsgDialog MSG(GFX);

	// Release message
	MSG.Dialog(MSG_OK, "This build of OpenPS3FTP has not been tested by the author. As such, you use this software at your own risk. Please report any issues found to the OpenPS3FTP GitHub repository or send a tweet to @jjolano. See README.txt for more details.");

	// Initialize required libraries: net, netctl, io
	netInitialize();
	netCtlInit();
	ioPadInit(7);

	// Verify connection state
	s32 state;
	netCtlGetState(&state);

	if(state != NET_CTL_STATE_IPObtained)
	{
		// not connected to network - terminate program
		MSG.Dialog(MSG_OK, "Could not verify connection status. OpenPS3FTP will now exit.");
		exit(EXIT_FAILURE);
	}

	// Set application running state
	GFX->AppStart();

	// Create thread for server
	sys_ppu_thread_t id;
	sysThreadCreate(&id, ftp_main, GFX, 1001, 0x1000, THREAD_JOINABLE, const_cast<char*>("opf_ftp_main"));

	// Set up graphics
	Font F1(LATIN2, GFX);
	Background BG(GFX);
	Bitmap BM(GFX);

	NoRSX_Bitmap PCL;
	BM.GenerateBitmap(&PCL);
	BG.MonoBitmap(COLOR_BLACK, &PCL);

	// Retrieve detailed connection information (ip address)
	net_ctl_info info;
	netCtlGetInfo(NET_CTL_INFO_IP_ADDRESS, &info);

	// Draw bitmap layer
	// Not sure how this will actually look.
	F1.PrintfToBitmap(50, 50, &PCL, COLOR_WHITE, "OpenPS3FTP version %s", OFTP_VERSION);
	F1.PrintfToBitmap(50, 100, &PCL, COLOR_WHITE, "Written by John Olano (twitter: @jjolano)");

	F1.PrintfToBitmap(50, 200, &PCL, COLOR_WHITE, "IP Address: %s (port 21)", info.ip_address);

	F1.PrintfToBitmap(50, 300, &PCL, COLOR_WHITE, "SELECT: Execute dev_blind");
	F1.PrintfToBitmap(50, 350, &PCL, COLOR_WHITE, "START: Exit OpenPS3FTP");

	// Pad IO variables
	padInfo padinfo;
	padData paddata;
	padData paddata_old[MAX_PADS];

	// Main thread loop
	while(GFX->GetAppStatus() != APP_EXIT)
	{
		// Get Pad Status
		ioPadGetInfo(&padinfo);

		for(unsigned int i = 0; i < MAX_PADS; i++)
		{
			if(padinfo.status[i])
			{
				// Get Pad Data
				ioPadGetData(i, &paddata);

				// Parse Pad Data
				if(Pad_onPress(paddata, paddata_old[i], BTN_SELECT))
				{
					// dev_blind stuff
					sysFSStat stat;
					s32 ret = sysFsStat("/dev_blind", &stat);

					if(ret == 0)
					{
						// dev_blind exists - ask to unmount
						MSG.Dialog(MSG_YESNO, "Do you want to unmount dev_blind?");

						if(MSG.GetResponse(MSG_DIALOG_BTN_YES) == 1)
						{
							// syscall unmount
							lv2syscall1(838, (u64)"/dev_blind");

							// display success
							MSG.Dialog(MSG_OK, "dev_blind was successfully unmounted.");
						}
					}
					else
					{
						// dev_blind does not exist - ask to mount
						MSG.Dialog(MSG_YESNO, "Do you want to mount dev_blind?");

						if(MSG.GetResponse(MSG_DIALOG_BTN_YES) == 1)
						{
							// syscall mount
							lv2syscall8(837, (u64)"CELL_FS_IOS:BUILTIN_FLSH1", (u64)"CELL_FS_FAT", (u64)"/dev_blind", 0, 0 /* readonly */, 0, 0, 0);

							// display success with info
							MSG.Dialog(MSG_OK, "dev_blind was successfully mounted. Please note that dev_blind will not automatically unmount upon exiting OpenPS3FTP.");
						}
					}
				}

				if(Pad_onPress(paddata, paddata_old[i], BTN_START))
				{
					// Exit application
					GFX->AppExit();
				}

				paddata_old[i] = paddata;
			}
		}

		// Draw bitmap->screenbuffer
		BM.DrawBitmap(&PCL);
		GFX->Flip();
	}

	BM.ClearBitmap(&PCL);

	// Wait for server thread to complete
	u64 retval;
	sysThreadJoin(id, &retval);

	// Parse thread return value if application is not exiting
	if(GFX->ExitSignalStatus() == NO_SIGNAL && retval != 0)
	{
		// Error - see ftp.cpp
		MSG.ErrorDialog((u32)retval);
		exit(EXIT_FAILURE);
	}

	return 0;
}
Exemplo n.º 11
0
bool RecurseDeletePath( std::string path, u8 depth )
{
	bool ret = true;
	int i;
	sysFSStat stat;
	if( sysFsStat( path.c_str(), &stat ) )
		return false;

	//its a directory
	if( stat.st_mode & S_IFDIR )
	{
		if( path.at( path.size() - 1 ) != '/' )
			path += "/";

		s32 fd;
		sysFSDirent entry;
		u64 read;
		//open dir
		i = sysFsOpendir( path.c_str(), &fd );
		if( i )
		{
			printf("sysFsOpendir( %s ): %i\n", path.c_str(), i );
			return false;
		}
		while( !sysFsReaddir( fd, &entry , &read ) && read > 0 )
		{
			if( !entry.d_namlen || !strcmp( entry.d_name, "." ) || !strcmp( entry.d_name, ".." ) )
			{
				continue;
			}

			std::string subPath = path + entry.d_name;

			if( sysFsStat( subPath.c_str(), &stat ) )
				continue;

			if( stat.st_mode & S_IFDIR )
			{
				if( depth < MAX_RECURSE_DEPTH )
				{
					if( !RecurseDeletePath( subPath, depth ) )
					{
						ret = false;
						break;
					}
				}
				else
				{
					printf("RecurseDeletePath( \"%s\" ): max recursion depth reached\n", subPath.c_str() );
					ret = false;
					break;
				}
			}
			else
			{
				i = sysFsUnlink( subPath.c_str() );
				if( i )
				{
					printf("sysFsUnlink( %s ): %i\n", subPath.c_str(), i );
					ret = false;
					break;
				}
			}
		}
		sysFsClosedir( fd );
		if( ret )
		{
			i = sysFsRmdir( path.c_str() );
			if( i )
			{
				printf("sysFsRmdir( %s ): %08x\n", path.c_str(), i );
				ret = false;
			}
		}
	}
	else//its a file
	{
		i = sysFsUnlink( path.c_str() );
		if( i )
		{
			printf("sysFsUnlink( %s ): %i\n", path.c_str(), i );
			ret = false;
		}
	}
	return ret;
}
Exemplo n.º 12
0
bool Exists( const char* path )
{
	//printf("Exists( %s )\n", path );
	sysFSStat entry;
	return( sysFsStat( path, &entry ) == 0 );
}