Exemple #1
0
s32 cellFsSdataOpen(vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, vm::cptr<void> arg, u64 size)
{
	cellFs.notice("cellFsSdataOpen(path=*0x%x, flags=%#o, fd=*0x%x, arg=*0x%x, size=0x%llx)", path, flags, fd, arg, size);

	if (flags != CELL_FS_O_RDONLY)
	{
		return CELL_FS_EINVAL;
	}

	return cellFsOpen(path, CELL_FS_O_RDONLY, fd, vm::make_var<be_t<u32>[2]>({ 0x180, 0x10 }), 8);

	// Don't implement sdata decryption in this function, it should be done in sys_fs_open() syscall or somewhere else

	/*
	std::string suffix = path.substr(path.length() - 5, 5);
	if (suffix != ".sdat" && suffix != ".SDAT")
	return CELL_ENOTSDATA;

	std::string::size_type last_slash = path.rfind('/'); //TODO: use a filesystem library to solve this more robustly
	last_slash = last_slash == std::string::npos ? 0 : last_slash+1;
	std::string unpacked_path = "/dev_hdd1/"+path.substr(last_slash,path.length()-last_slash)+".unpacked";
	s32 ret = sdata_unpack(path, unpacked_path);
	if (ret) return ret;

	fd = idm::GetNewID(Emu.GetVFS().OpenFile(unpacked_path, vfsRead), TYPE_FS_FILE);

	return CELL_OK;
	*/
}
Exemple #2
0
int main(void)
{
	int ret;
	
	ret = cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
	if (ret != CELL_OK) return ret;
	
	ret = cellFsOpen("/dev_hdd0/libntfs_sample_log.txt",
                     CELL_FS_O_RDWR|CELL_FS_O_CREAT, &LOG, NULL, 0);
	if(ret) return ret;

	log_printf("\n\nntfsMountAll");
	mountCount = ntfsMountAll(&mounts, NTFS_DEFAULT | NTFS_RECOVER /* | NTFS_READ_ONLY */ );
	if (mountCount <= 0) 	log_printf("\n\nCan't mount");

	// NTFS operation to write

	log_printf("\n\nWriting to ntfs0");
	ps3ntfs_open("ntfs0:/text.txt", O_CREAT | O_WRONLY | O_TRUNC, 0777);


	log_printf("\n\nUnmounting...");
	for (uint8_t u = 0; u < mountCount; u++) ntfsUnmount(mounts[u].name, 1);
	
	return 0;
}
Exemple #3
0
int cellFsSdataOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size)
{
	const std::string& path = Memory.ReadString(path_addr);
	sys_fs->Warning("cellFsSdataOpen(path=\"%s\", flags=0x%x, fd_addr=0x%x, arg_addr=0x%x, size=0x%llx) -> cellFsOpen()",
		path.c_str(), flags, fd.GetAddr(), arg.GetAddr(), size);

	/*if (!fd.IsGood() || (!arg.IsGood() && size))
		return CELL_EFAULT;

	if (flags != CELL_O_RDONLY)
		return CELL_EINVAL;

	std::string suffix = path.substr(path.length() - 5, 5);
	if (suffix != ".sdat" && suffix != ".SDAT")
		return CELL_ENOTSDATA;

	std::string::size_type last_slash = path.rfind('/'); //TODO: use a filesystem library to solve this more robustly
	last_slash = last_slash == std::string::npos ? 0 : last_slash+1;
	std::string unpacked_path = "/dev_hdd1/"+path.substr(last_slash,path.length()-last_slash)+".unpacked";
	int ret = sdata_unpack(path, unpacked_path);
	if (ret) return ret;

	fd = sys_fs->GetNewId(Emu.GetVFS().OpenFile(unpacked_path, vfsRead), flags);

	return CELL_OK;*/

	return cellFsOpen(path_addr, flags, fd, arg, size);
}
Exemple #4
0
int cellJpgDecOpen(u32 mainHandle, mem32_t subHandle, mem_ptr_t<CellJpgDecSrc> src, mem_ptr_t<CellJpgDecOpnInfo> openInfo)
{
	cellJpgDec.Warning("cellJpgDecOpen(mainHandle=0x%x, subHandle=0x%x, src_addr=0x%x, openInfo=0x%x)",
		mainHandle, subHandle.GetAddr(), src.GetAddr(), openInfo);

	if (!subHandle.IsGood() || !src.IsGood() || !openInfo.IsGood())
		return CELL_JPGDEC_ERROR_ARG;

	CellJpgDecSubHandle *current_subHandle = new CellJpgDecSubHandle;

	// Get file descriptor
	MemoryAllocator<be_t<u32>> fd;
	int ret = cellFsOpen(src->fileName, 0, fd, NULL, 0);
	current_subHandle->fd = fd->ToLE();
	if(ret != CELL_OK) return CELL_JPGDEC_ERROR_OPEN_FILE;

	// Get size of file
	MemoryAllocator<CellFsStat> sb; // Alloc a CellFsStat struct
	ret = cellFsFstat(current_subHandle->fd, sb.GetAddr());
	if(ret != CELL_OK) return ret;
	current_subHandle->fileSize = sb->st_size;	// Get CellFsStat.st_size

	// From now, every u32 subHandle argument is a pointer to a CellPngDecSubHandle struct.
	subHandle = cellJpgDec.GetNewId(current_subHandle);

	return CELL_OK;
}
Exemple #5
0
int cellJpgDecOpen(u32 mainHandle, mem32_t subHandle, u32 src_addr, mem_struct_ptr_t<CellJpgDecOpnInfo> openInfo)
{
	//u32 srcSelect       = Memory.Read32(src_addr);
	u32 fileName		  = Memory.Read32(src_addr+4);
	//u32 fileOffset      = Memory.Read32(src_addr+8);
	//u32 fileSize        = Memory.Read32(src_addr+12);
	//u32 streamPtr       = Memory.Read32(src_addr+16);
	//u32 streamSize      = Memory.Read32(src_addr+20);
	//u32 spuThreadEnable = Memory.Read32(src_addr+24);

	CellJpgDecSubHandle *current_subHandle = new CellJpgDecSubHandle;

	// Get file descriptor
	MemoryAllocator<be_t<u32>> fd;
	int ret = cellFsOpen(fileName, 0, fd, NULL, 0);
	current_subHandle->fd = fd->ToLE();
	if(ret != CELL_OK) return CELL_JPGDEC_ERROR_OPEN_FILE;

	// Get size of file
	MemoryAllocator<CellFsStat> sb; // Alloc a CellFsStat struct
	ret = cellFsFstat(current_subHandle->fd, sb);
	if(ret != CELL_OK) return ret;
	current_subHandle->fileSize = sb->st_size;	// Get CellFsStat.st_size

	// From now, every u32 subHandle argument is a pointer to a CellPngDecSubHandle struct.
	subHandle = cellJpgDec.GetNewId(current_subHandle);

	return CELL_OK;
}
Exemple #6
0
int read_cobra_config(void)
{
	int fd;
	
	if (cellFsOpen(COBRA_CONFIG_FILE, CELL_FS_O_RDONLY, &fd, 0, NULL, 0) == 0)
	{
		uint64_t r;
		
		cellFsRead(fd, &config, sizeof(config), &r);
		cellFsClose(fd);
	}
	
	if (config.size > 4096 || checksum(&config) != config.checksum)
	{
		memset(&config, 0, sizeof(config));		
	}
	else
	{
		check_and_correct(&config);
	}
	
	config.size = sizeof(config);
	
	bd_video_region = config.bd_video_region;
	dvd_video_region = config.dvd_video_region;
	// Removed. Now condition_ps2softemu has another meaning and it is set automatically in storage_ext if no BC console
	//condition_ps2softemu = config.ps2softemu;
	//DPRINTF("Configuration read. bd_video_region=%d,dvd_video_region=%d\nspoof_version = %04X, spoof_revision = %d\n", bd_video_region, dvd_video_region, config.spoof_version, config.spoof_revision);
		
	return 0;
}
Exemple #7
0
int disable_cobra_stage()
{
	cellFsUtilMount_h("CELL_FS_IOS:BUILTIN_FLSH1", "CELL_FS_FAT", "/dev_habib", 0, 0, 0, 0, 0);
	CellFsStat stat;
	cellFsStat(CB_LOCATION, &stat);
	uint64_t len=stat.st_size;
	uint8_t *buf;
	uint64_t size;
	int src;
	int dst;
	
	page_allocate_auto(NULL, 0x40000, 0x2F, (void **)&buf);
	if (cellFsOpen(CB_LOCATION, CELL_FS_O_RDONLY, &src, 0, NULL, 0) == 0)
	{
		cellFsRead(src, buf, len, &size);
		cellFsClose(src);
	}
	else
	{
		page_free(NULL, buf, 0x2F);
		return -1;
	}

	if (cellFsOpen(CB_LOCATION".bak", CELL_FS_O_WRONLY | CELL_FS_O_CREAT | CELL_FS_O_TRUNC, &dst, 0666, NULL, 0) == 0)
	{	
		cellFsWrite(dst, buf, len, &size);
		cellFsClose(dst);
	}
	else
	{
		page_free(NULL, buf, 0x2F);
		return -1;
	}
	
	page_free(NULL, buf, 0x2F);
	cellFsUnlink(CB_LOCATION);
	size=0x5343450000000000;
	cellFsOpen("/dev_hdd0/tmp/loadoptical", CELL_FS_O_WRONLY | CELL_FS_O_CREAT | CELL_FS_O_TRUNC, &dst, 0666, NULL, 0);
	cellFsWrite(dst, &size, 4, &size);
	cellFsClose(dst);
	return 0;
}
Exemple #8
0
int cellGifDecOpen(u32 mainHandle, mem32_t subHandle, const mem_ptr_t<CellGifDecSrc> src, mem_ptr_t<CellGifDecOpnInfo> openInfo)
{
	if (!subHandle.IsGood() || !src.IsGood())
		return CELL_GIFDEC_ERROR_ARG;
	/*
	vfsStream* stream;

	switch(src->srcSelect)
	{
	case CELL_GIFDEC_FILE:
		stream = Emu.GetVFS().Open(src->fileName.GetString(), vfsRead);
		stream->Seek(src->fileOffset);
		src->fileSize;
	break;

	case CELL_GIFDEC_BUFFER:
		if(src->streamSize < 5)
			return CELL_GIFDEC_ERROR_ARG;

		stream = new vfsStreamMemory(src->streamPtr.GetAddr(), src->streamSize);
	break;

	default:
		return CELL_GIFDEC_ERROR_ARG;
	}

	if(!stream->IsOpened())
	{
		return CELL_GIFDEC_ERROR_OPEN_FILE;
	}
	*/

	CellGifDecSubHandle *current_subHandle = new CellGifDecSubHandle;

	// Get file descriptor
	MemoryAllocator<be_t<u32>> fd;
	int ret = cellFsOpen(src->fileName, 0, fd, 0, 0);
	current_subHandle->fd = fd->ToLE();
	if(ret != CELL_OK) return CELL_GIFDEC_ERROR_OPEN_FILE;

	// Get size of file
	MemoryAllocator<CellFsStat> sb; // Alloc a CellFsStat struct
	ret = cellFsFstat(current_subHandle->fd, sb.GetAddr());
	if(ret != CELL_OK) return ret;
	current_subHandle->fileSize = sb->st_size; // Get CellFsStat.st_size

	// From now, every u32 subHandle argument is a pointer to a CellPngDecSubHandle struct.
	subHandle = cellGifDec->GetNewId(current_subHandle);

	return CELL_OK;
}
Exemple #9
0
/*
 * Function:		getFileSize()
 * File:			main.c
 * Project:			ArtemisPS3-PRX
 * Description:		Gets the file size of a file
 * Arguments:
 *	path:			path to file
 * Return:			size of file
 */
int getFileSize(const char * path)
{
	int fd = 0, size = 0;
	
	if(cellFsOpen(path, CELL_FS_O_RDONLY, &fd, NULL, 0) == CELL_FS_SUCCEEDED)
	{
		u64 pos;
		cellFsLseek(fd, 0, CELL_FS_SEEK_END, &pos);
		size = (int)pos;
		
		cellFsClose(fd);
	}
	
	return size;
}
Exemple #10
0
int write_cobra_config(void)
{
	int fd;
	uint64_t w;
	int ret = 0;
	
	if (cellFsOpen(COBRA_CONFIG_FILE, CELL_FS_O_WRONLY|CELL_FS_O_CREAT|CELL_FS_O_TRUNC, &fd, 0666, NULL, 0) != 0)
	{
		return ENODEV;
	}
	
	if (cellFsWrite(fd, &config, sizeof(config), &w) != 0)
		ret = ENODEV;
	
	cellFsClose(fd);	
	return ret;
}
Exemple #11
0
/*
 * Function:		readFile()
 * File:			main.c
 * Project:			ArtemisPS3-PRX
 * Description:		Reads a file
 * Arguments:
 *	path:			path to file to read
 *	buffer:			buffer to store the file contents toascii
 *	size:			number of bytes to read from the file
 * Return:			Returns 0 if failed, 1 if succeeded
 */
int readFile(const char * path, char * buffer, int size)
{
	int fd, ret = 0;
	
	if(cellFsOpen(path, CELL_FS_O_RDONLY, &fd, NULL, 0) == CELL_FS_SUCCEEDED)
	{
		u64 read_e = 0, pos; //, write_e
		cellFsLseek(fd, 0, CELL_FS_SEEK_SET, &pos);
		
		if (cellFsRead(fd, (void *)buffer, size, &read_e)==CELL_FS_SUCCEEDED)
		{
			ret = 1;
		}
		
		cellFsClose(fd);
	}
	
	buffer[size] = '\0';
	return ret;
}
Exemple #12
0
/*
 * Function:		art_process()
 * File:			main.c
 * Project:			ArtemisPS3-PRX
 * Description:		Processes an entire codelist once
 * Arguments:
 *	forceWrite:		whether the user activated Artemis (1) or a constant write (0)
 * Return:			void
 */
static void art_process(int forceWrite)
{
	int fd = 0;
	
	if (attachedPID)
	{
		doForceWrite = forceWrite;
		
		//Force load userCodes on forceWrite
		if (forceWrite && userCodes)
		{
			reset_heap();
			userCodes = NULL;
		}

		if (!userCodes)
		{
			int fileSize = getFileSize("/dev_hdd0/tmp/art.txt");
			userCodes = (char *)mem_alloc(fileSize + 2);
			memset(userCodes, 0, fileSize + 2);
			if(cellFsOpen("/dev_hdd0/tmp/art.txt", CELL_FS_O_RDONLY, &fd, NULL, 0) == CELL_FS_SUCCEEDED)
			{
				u64 read_e = 0, pos;
				cellFsLseek(fd, 0, CELL_FS_SEEK_SET, &pos);
				
				cellFsRead(fd, (void *)userCodes, fileSize, &read_e);
				cellFsClose(fd);
			}
			userCodes[fileSize] = '\n';
		}
		
		if (attachedPID != NULL && attachedPID != 0)
		{
			ConvertCodes(attachedPID, userCodes);
			sys_timer_sleep(0.1);
		}
	}
	
	doForceWrite = 0;
}
Exemple #13
0
int cellPngDecOpen(u32 mainHandle, mem32_t subHandle, mem_ptr_t<CellPngDecSrc> src, u32 openInfo)
{
	cellPngDec.Warning("cellPngDecOpen(mainHandle=0x%x, subHandle=0x%x, src_addr=0x%x, openInfo=0x%x)",
		mainHandle, subHandle.GetAddr(), src.GetAddr(), openInfo);

	if (!subHandle.IsGood() || !src.IsGood())
		return CELL_PNGDEC_ERROR_ARG;

	CellPngDecSubHandle *current_subHandle = new CellPngDecSubHandle;

	current_subHandle->fd = NULL;
	current_subHandle->src = *src;

	switch(src->srcSelect.ToBE())
	{
	case const_se_t<u32, CELL_PNGDEC_BUFFER>::value:
		current_subHandle->fileSize = src->streamSize.ToLE();
		break;

	case const_se_t<u32, CELL_PNGDEC_FILE>::value:
		// Get file descriptor
		MemoryAllocator<be_t<u32>> fd;
		int ret = cellFsOpen(src->fileName_addr, 0, fd.GetAddr(), NULL, 0);
		current_subHandle->fd = fd->ToLE();
		if(ret != CELL_OK) return CELL_PNGDEC_ERROR_OPEN_FILE;

		// Get size of file
		MemoryAllocator<CellFsStat> sb; // Alloc a CellFsStat struct
		ret = cellFsFstat(current_subHandle->fd, sb.GetAddr());
		if(ret != CELL_OK) return ret;
		current_subHandle->fileSize = sb->st_size;	// Get CellFsStat.st_size
		break;
	}

	// From now, every u32 subHandle argument is a pointer to a CellPngDecSubHandle struct.
	subHandle = cellPngDec.GetNewId(current_subHandle);

	return CELL_OK;
}
Exemple #14
0
int sys_load_mamba(char *mamba_file)
{
	if (mamba_loaded == 1) return ECANCELED;
	mamba_file = get_secure_user_ptr(mamba_file); 
	CellFsStat stat;
	int ret = cellFsStat(mamba_file, &stat);
	if (ret == 0)
	{
		int fd;	
		ret = cellFsOpen(mamba_file, CELL_FS_O_RDONLY, &fd, 0, NULL, 0);
		if (ret == 0)
		{
			uint32_t psize = stat.st_size;	
			void *mamba = alloc(psize, 0x27);
			if (mamba)
			{
				uint64_t rs;
				ret = cellFsRead(fd, mamba, psize, &rs);
				cellFsClose(fd);
				if (ret != 0)
				{
					dealloc(mamba, 0x27);
					mamba = NULL;
					return ret;
				}
				mamba_loaded = 1;	
				f_desc_t f;
				f.toc = (void *)MKA(TOC);
				int (* func)(void);	
				f.addr = mamba;			
				func = (void *)&f;	
				func();
				return 0;
			}
			return ENOMEM;
		}       
	}
	return ret;
}
RFILE *filestream_open(const char *path, unsigned mode, ssize_t len)
{
   int            flags = 0;
   int         mode_int = 0;
   const char *mode_str = NULL;
   RFILE        *stream = (RFILE*)calloc(1, sizeof(*stream));

   if (!stream)
      return NULL;

   (void)mode_str;
   (void)mode_int;
   (void)flags;

   stream->hints = mode;

#ifdef HAVE_MMAP
   if (stream->hints & RFILE_HINT_MMAP && (stream->hints & 0xff) == RFILE_MODE_READ)
      stream->hints |= RFILE_HINT_UNBUFFERED;
   else
#endif
      stream->hints &= ~RFILE_HINT_MMAP;

   switch (mode & 0xff)
   {
      case RFILE_MODE_READ:
#if defined(VITA) || defined(PSP)
         mode_int = 0777;
         flags    = PSP_O_RDONLY;
#elif defined(__CELLOS_LV2__)
         mode_int = 0777;
         flags    = CELL_FS_O_RDONLY;
#else
#if defined(HAVE_BUFFERED_IO)
         if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
            mode_str = "rb";
#endif
         /* No "else" here */
         flags    = O_RDONLY;
#endif
         break;
      case RFILE_MODE_WRITE:
#if defined(VITA) || defined(PSP)
         mode_int = 0777;
         flags    = PSP_O_CREAT | PSP_O_WRONLY | PSP_O_TRUNC;
#elif defined(__CELLOS_LV2__)
         mode_int = 0777;
         flags    = CELL_FS_O_CREAT | CELL_FS_O_WRONLY | CELL_FS_O_TRUNC;
#else
#if defined(HAVE_BUFFERED_IO)
         if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
            mode_str = "wb";
#endif
         else
         {
            flags    = O_WRONLY | O_CREAT | O_TRUNC;
#ifndef _WIN32
            flags   |=  S_IRUSR | S_IWUSR;
#endif
         }
#endif
         break;
      case RFILE_MODE_READ_WRITE:
#if defined(VITA) || defined(PSP)
         mode_int = 0777;
         flags    = PSP_O_RDWR;
#elif defined(__CELLOS_LV2__)
         mode_int = 0777;
         flags    = CELL_FS_O_RDWR;
#else
#if defined(HAVE_BUFFERED_IO)
         if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
            mode_str = "w+";
#endif
         else
         {
            flags    = O_RDWR;
#ifdef _WIN32
            flags   |= O_BINARY;
#endif
         }
#endif
         break;
   }

#if defined(VITA) || defined(PSP)
   stream->fd = sceIoOpen(path, flags, mode_int);
#elif defined(__CELLOS_LV2__)
   cellFsOpen(path, flags, &stream->fd, NULL, 0);
#else
#if defined(HAVE_BUFFERED_IO)
   if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0)
   {
      stream->fp = fopen(path, mode_str);
      if (!stream->fp)
         goto error;
   }
   else
#endif
   {
      stream->fd = open(path, flags);
      if (stream->fd == -1)
         goto error;
#ifdef HAVE_MMAP
      if (stream->hints & RFILE_HINT_MMAP)
      {
         stream->mappos  = 0;
         stream->mapped  = NULL;
         stream->mapsize = filestream_seek(stream, 0, SEEK_END);

         if (stream->mapsize == (uint64_t)-1)
            goto error;

         filestream_rewind(stream);

         stream->mapped = (uint8_t*)mmap((void*)0, stream->mapsize, PROT_READ,  MAP_SHARED, stream->fd, 0);

         if (stream->mapped == MAP_FAILED)
            stream->hints &= ~RFILE_HINT_MMAP;
      }
#endif
   }
#endif

#if defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__)
   if (stream->fd == -1)
      goto error;
#endif

   return stream;

error:
   filestream_close(stream);
   return NULL;
}
Exemple #16
0
int main(void)
{
	void *stage2 = NULL;
	
	f_desc_t f;
	int (* func)(void);	
	int ret;
	
#ifdef DEBUG		
	debug_init();
	DPRINTF("Stage 1 hello.\n");	
#endif
	f.addr = flash_mount_clone;
	f.toc = (void *)MKA(TOC);
	func = (void *)&f;
	
	ret = func();
	
	if (ret != 0 && ret != 1)
	{
		DPRINTF("Flash mount failed!\n");		
	}
	else
	{
		CellFsStat stat;
		
		DPRINTF("Flash mounted\n");
				
		if (cellFsStat(STAGE2_FILE, &stat) == 0)
		{
			int fd;
			
			if (cellFsOpen(STAGE2_FILE, CELL_FS_O_RDONLY, &fd, 0, NULL, 0) == 0)
			{
				uint32_t psize = stat.st_size;
				
				DPRINTF("Payload size = %d\n", psize);
				
				stage2 = alloc(psize, 0x27);
				if (stage2)
				{
					uint64_t rs;
					
					if (cellFsRead(fd, stage2, psize, &rs) != 0)
					{
						DPRINTF("Stage 2 read fail.\n");
						dealloc(stage2, 0x27);
						stage2 = NULL;
					}
				}
				else
				{
					DPRINTF("Cannot allocate stage2\n");
				}
				
				cellFsClose(fd);
			}
		}
		else
		{
			DPRINTF("There is no stage 2, booting system.\n");
		}
	}
	
	if (stage2)
	{
		f.addr = stage2;			
		func = (void *)&f;	
		DPRINTF("Calling stage 2...\n");
		func();
	}
	
	return ret;
}
Exemple #17
0
int sys_psp_read_header(int fd, char *buf, uint64_t nbytes, uint64_t *nread)
{
	int ret;
	uint32_t n, unk2;
	uint64_t umd_size;
	sys_prx_id_t *list;
	uint32_t *unk;
	process_t process;
	
	#ifdef DEBUG
	DPRINTF("umd read header: %p %lx\n", buf, nbytes);
	#endif
	
	buf = get_secure_user_ptr(buf);
	nread = get_secure_user_ptr(nread);
		
	if (!umd_file || nbytes != 0x100)
		return EABORT;
	
	pemucorelib_base = 0;
	emulator_api_base = 0;
	list = alloc(SPRX_NUM*sizeof(sys_prx_module_info_t), 0x35);
	unk = alloc(SPRX_NUM*sizeof(uint32_t), 0x35);
	process = get_current_process();	
	
	ret = prx_get_module_list(process, list, unk, SPRX_NUM, &n, &unk2);
	if (ret == 0)
	{
		char *filename = alloc(256, 0x35);
		sys_prx_segment_info_t *segments = alloc(sizeof(sys_prx_segment_info_t), 0x35);
		
		for (int i = 0; i < SPRX_NUM; i++)
		{
			sys_prx_module_info_t modinfo;
			
			memset(&modinfo, 0, sizeof(sys_prx_module_info_t));
			modinfo.filename_size = 256;
			modinfo.segments_num = 1;
			
			if (prx_get_module_info(process, list[i], &modinfo, filename, segments) == 0)
			{
				if (strstr(filename, "/emulator_api.sprx"))
				{
					emulator_api_base = segments[0].base;
					#ifdef DEBUG
					DPRINTF("emulator_api base = %08lx\n", emulator_api_base);
					#endif	
				}
				else if (strstr(filename, "/PEmuCoreLib.sprx"))
				{
					pemucorelib_base = segments[0].base;						
					#ifdef DEBUG
					DPRINTF("PEmuCoreLib base = %08lx\n", pemucorelib_base);
					#endif
				}
			}
		}
		
		if (pemucorelib_base == 0 || emulator_api_base == 0)
			ret = EABORT;
		
		dealloc(filename, 0x35);
		dealloc(segments, 0x35);
	}
	
	dealloc(list, 0x35);
	dealloc(unk, 0x35);
	
	if (ret != 0)
		return ret;
		
	ret = cellFsOpen(umd_file, CELL_FS_O_RDONLY, &umd_fd, 0, NULL, 0);
	if (ret != 0)
		return ret;
	
	cellFsLseek(umd_fd, 0, SEEK_END, &umd_size);
	// Fake header. We will write only values actually used
	memset(buf, 0, 0x100);
	*(uint32_t *)(buf+0x0c) = 0x10;
	*(uint32_t *)(buf+0x64) = (umd_size/0x800)-1; // Last sector of umd	
	strncpy(buf+0x70, psp_id, 10);
						
	#ifdef DEBUG
	DPRINTF("ID: %s\n", psp_id);
	#endif
	
	if (mutex && user_mutex)
	{
		mutex = NULL;
		user_mutex = 0;
	}
	
	*nread = 0x100;
	return 0;
}
RFILE *retro_fopen(const char *path, unsigned mode, ssize_t len)
{
   int            flags = 0;
   int         mode_int = 0;
   const char *mode_str = NULL;
   RFILE        *stream = (RFILE*)calloc(1, sizeof(*stream));

   if (!stream)
      return NULL;

   (void)mode_str;
   (void)mode_int;
   (void)flags;

   switch (mode)
   {
      case RFILE_MODE_READ:
#if defined(VITA) || defined(PSP)
         mode_int = 0777;
         flags    = PSP_O_RDONLY;
#elif defined(__CELLOS_LV2__)
         mode_int = 0777;
         flags    = CELL_FS_O_RDONLY;
#elif defined(HAVE_BUFFERED_IO)
         mode_str = "rb";
#else
         flags    = O_RDONLY;
#endif
         break;
      case RFILE_MODE_WRITE:
#if defined(VITA) || defined(PSP)
         mode_int = 0777;
         flags    = PSP_O_CREAT | PSP_O_WRONLY | PSP_O_TRUNC;
#elif defined(__CELLOS_LV2__)
         mode_int = 0777;
         flags    = CELL_FS_O_CREAT | CELL_FS_O_WRONLY | CELL_FS_O_TRUNC;
#elif defined(HAVE_BUFFERED_IO)
         mode_str = "wb";
#else
         flags    = O_WRONLY | O_CREAT | O_TRUNC | S_IRUSR | S_IWUSR;
#endif
         break;
      case RFILE_MODE_READ_WRITE:
#if defined(VITA) || defined(PSP)
         mode_int = 0777;
         flags    = PSP_O_RDWR;
#elif defined(__CELLOS_LV2__)
         mode_int = 0777;
         flags    = CELL_FS_O_RDWR;
#elif defined(HAVE_BUFFERED_IO)
         mode_str = "w+";
#else
         flags    = O_RDWR;
#ifdef _WIN32
         flags   |= O_BINARY;
#endif
#endif
         break;
   }

#if defined(VITA) || defined(PSP)
   stream->fd = sceIoOpen(path, flags, mode_int);
#elif defined(__CELLOS_LV2__)
   cellFsOpen(path, flags, &stream->fd, NULL, 0);
#elif defined(HAVE_BUFFERED_IO)
   stream->fd = fopen(path, mode_str);
#else
   stream->fd = open(path, flags);
#endif

#if defined(HAVE_BUFFERED_IO)
   if (!stream->fd)
      goto error;
#else
   if (stream->fd == -1)
      goto error;
#endif

   return stream;

error:
   retro_fclose(stream);
   return NULL;
}
Exemple #19
0
int main(void)
{
	int ret;
	int k;
	int fd;
	char temp[128];
	ntfs_md *mounts;
	
	ret = cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
	if (ret != CELL_OK) return ret;
	
	ret = cellFsOpen("/dev_hdd0/libntfs_sample_log.txt",
                     CELL_FS_O_RDWR|CELL_FS_O_CREAT, &LOG, NULL, 0);
	if(ret) return ret;
		
	log_printf("*** LOG ***\n");
	
	log_printf("\n*** PS3_NTFS_IsInserted ***\n\n");
	for(k = 0; k < 8; k++) {
		if(PS3_NTFS_IsInserted(k)) log_printf("- PS3_NTFS_IsInserted(%d) = true\n", k);
		else log_printf("- PS3_NTFS_IsInserted(%d) = false\n", k);
	}
	
	log_printf("\n*** ntfsFindPartitions ***\n");
	sec_t *partitions = NULL;
	int partition_number = ntfsFindPartitions(disc_ntfs[0], &partitions);
	log_printf("- ntfsFindPartitions = %d\n", partition_number);
	
	log_printf("\n*** ntfsMount ***\n");
	
	if(ntfsMount("ntfs0", disc_ntfs[0], partitions[0], CACHE_DEFAULT_PAGE_COUNT, CACHE_DEFAULT_PAGE_SIZE, NTFS_DEFAULT | NTFS_RECOVER))
		log_printf("- ntfsMount = true\n");
	else
		log_printf("- ntfsMount = false\n");
	
	if(partitions) free(partitions);
	
	log_printf("\n*** ntfsUnmount ***\n");
	ntfsUnmount("ntfs0", 1);
	
	log_printf("\n*** ntfsMountDevice ***\n");	
	ret = ntfsMountDevice(disc_ntfs[0], &mounts, NTFS_DEFAULT | NTFS_RECOVER);
	log_printf("- ntfsMountDevice = %d\n", ret);
	log_printf("- mount->name = %s\n", mounts->name);
	
	log_printf("\n*** ntfsUnmount ***\n");
	ntfsUnmount(mounts->name, 1);
	
	log_printf("\n*** ntfsMountAll ***\n");
	int mountCount = ntfsMountAll(&mounts, NTFS_DEFAULT | NTFS_RECOVER );
	log_printf("- ntfsMountAll = %d\n", mountCount);
	log_printf("- mount[0].name = %s\n", mounts[0].name);
	
	log_printf("\n*** ntfsGetVolumeName ***\n");
	const char *OldName = ntfsGetVolumeName(mounts[0].name);
	if(OldName) log_printf("- Old name : '%s'\n", OldName);
	else log_printf("- Error %d\n", ps3ntfs_errno());
	
	/* need to re-mount the device after SetVolumeName to 'update' the value of GetVolumeName
	log_printf("\n*** ntfsSetVolumeName ***\n");
	if(ntfsSetVolumeName(mounts[0].name, "NTFS_VOLUME"))
		log_printf("- ntfsSetVolumeName = true\n");
	else
		log_printf("- ntfsSetVolumeName = false - %d \n", ps3ntfs_errno());
	
	const char *NewName = ntfsGetVolumeName(mounts[0].name);
	if(NewName) log_printf("- New name : '%s'\n", NewName);
	else log_printf("- Error %d\n", ps3ntfs_errno());
	*/
	
	log_printf("\n*** ps3ntfs_mkdir ***\n");
	
	sprintf(temp, "%s:/viper6", mounts[0].name);
	if(ps3ntfs_mkdir(temp, 0777) == 0)
		log_printf("- ps3ntfs_mkdir = true\n");
	else 
		log_printf("- ps3ntfs_mkdir = false\n");
		
	log_printf("\n*** ps3ntfs_open ***\n");
	strcat(temp, (char*) "/ntfs.txt");
	
	for(k=0; k<5000; k++) { // force
		fd = ps3ntfs_open(temp, O_CREAT | O_WRONLY | O_TRUNC, 0777);
		if(fd>0) break;
	}
	
	if(fd > 0) {
		log_printf("- ps3ntfs_open = success\n");
		
		log_printf("\n*** ps3ntfs_write ***\n");
		ret = ps3ntfs_write(fd, message, strlen(message));
		log_printf("- ps3ntfs_write = %d\n", ret);
		if(ret != (int) strlen(message)) log_printf("- Error writing the file!\n");
		
		log_printf("\n*** ps3ntfs_close ***\n");
		ret = ps3ntfs_close(fd);
		log_printf("- ps3ntfs_close = %d\n", ret);
	} else log_printf("- ps3ntfs_open = failed - %s\n", temp);
	
	struct stat st;
	
	log_printf("\n*** ps3ntfs_stat ***\n");
	
	ret = ps3ntfs_stat(temp, &st);
	log_printf("- ps3ntfs_stat = %d\n", ret);
	log_printf("- SIZE = %d\n", st.st_size);
	log_printf("- last_access_time = %d\n", st.st_atime);
	log_printf("- last_mft_change_time = %d\n", st.st_ctime);
	log_printf("- last_data_change_time = %d\n", st.st_mtime);
	log_printf("- st_dev (id) = %d\n", st.st_dev);
	log_printf("- st uid = %d\n", st.st_uid);
	log_printf("- st gid = %d\n", st.st_gid);
	log_printf("- st ino = %d\n", st.st_ino);

	log_printf("\n*** ps3ntfs_open ***\n");
	for(k=0; k<5000; k++) { // force
		fd = ps3ntfs_open(temp, O_RDONLY, 0);
		if(fd > 0) break;
	}
	log_printf("- ps3ntfs_open = %d\n", fd);
	if(fd > 0) {
	
		log_printf("- ps3ntfs_open = success\n");
		
		log_printf("\n*** ps3ntfs_fstat ***\n");
	
		ret = ps3ntfs_fstat(fd, &st);
		log_printf("- ps3ntfs_fstat = %d\n", ret);
		log_printf("- SIZE = %d\n", st.st_size);
		log_printf("- last_access_time = %d\n", st.st_atime);
		log_printf("- last_mft_change_time = %d\n", st.st_ctime);
		log_printf("- last_data_change_time = %d\n", st.st_mtime);
		log_printf("- st_dev (id) = %d\n", st.st_dev);
		log_printf("- st uid = %d\n", st.st_uid);
		log_printf("- st gid = %d\n", st.st_gid);
		log_printf("- st ino = %d\n", st.st_ino);
		
		log_printf("\n*** ps3ntfs_seek ***\n");
		
		int size = ps3ntfs_seek(fd, 0, SEEK_END);

		log_printf("- ps3ntfs_seek - size = %d\n", size);

		ps3ntfs_seek(fd, 0, SEEK_SET);
		
		log_printf("\n*** ps3ntfs_read ***\n");
		ret = ps3ntfs_read(fd, buffer, size);
		log_printf("- ps3ntfs_read : '%s'\n", buffer);
		if(ret != size) log_printf("Error reading the file!\n"); 
		
		log_printf("\n*** ps3ntfs_close ***\n");
		ret = ps3ntfs_close(fd);
		log_printf("- ps3ntfs_close = %d\n", ret);

	} else log_printf("- ps3ntfs_open = failed - %s\n", temp);
		
	sprintf(buffer, "%s:/viper6/ntfs_newname.txt", mounts[0].name);
	log_printf("\n*** ps3ntfs_rename ***\n");
	for(k=0; k<5000; k++) { // force
		ret = ps3ntfs_rename(temp, buffer);
		if(ret==0) break;
	}
	if(ret==0) log_printf("- ps3ntfs_rename = %d\n", ret);
	else log_printf("- ps3ntfs_rename = %d - %s > %s\n", ret, temp, buffer);
	
	DIR_ITER *pdir;
	char filename[255];
	
	log_printf("\n*** ps3ntfs_diropen ***\n");
	sprintf(temp, "%s:/viper6", mounts[0].name);
	
	for(k=0; k<5000; k++) { // force
		pdir = ps3ntfs_diropen(temp);
		if (pdir) break;
	}
	if (pdir) {
		log_printf("- ps3ntfs_diropen = success\n");
		
		log_printf("\n*** ps3ntfs_dirnext ***\n");
		
		while (ps3ntfs_dirnext(pdir, filename, &st) == 0) {
		  
			if ((strcmp(filename, ".") == 0) || (strcmp(filename, "..") == 0)) continue;
			
			log_printf("- ps3ntfs_dirnext = File : %s/\n", filename);
			log_printf("- last_access_time = %d\n", st.st_atime);
			log_printf("- last_mft_change_time = %d\n", st.st_ctime);
			log_printf("- last_data_change_time = %d\n", st.st_mtime);

		}
		
		log_printf("\n*** ps3ntfs_dirreset ***\n");
		ret = ps3ntfs_dirreset(pdir);
		log_printf("- ps3ntfs_dirreset = %d\n", ret);
		
		log_printf("\n*** ps3ntfs_dirclose ***\n");
		ret = ps3ntfs_dirclose(pdir);
		log_printf("- ps3ntfs_dirclose = %d\n", ret);

	} else log_printf("- ps3ntfs_diropen = failed\n");
	
	log_printf("\n*** ps3ntfs_open ***\n");
	strcat(temp, (char*)"/unlink.txt");
	for(k=0; k<5000; k++) { // force
		fd = ps3ntfs_open(temp, O_CREAT | O_WRONLY | O_TRUNC, 0777);
		if(fd > 0) break;
	}
	if(fd > 0) {
		log_printf("- ps3ntfs_open = success\n");
		
		log_printf("\n*** ps3ntfs_close ***\n");
		ret = ps3ntfs_close(fd);
		log_printf("- ps3ntfs_close = %d\n", ret);
		
	} else log_printf("- ps3ntfs_open = failed\n");
	
	log_printf("\n*** ps3ntfs_unlink ***\n");
	for(k=0; k<5000; k++) { // force
		ret = ps3ntfs_unlink(temp);
		if(ret==0) break;
	}
	log_printf("- ps3ntfs_unlink = %d\n", ret);
	
	log_printf("\n*** ntfsUnmount ***\n");
	for (k = 0; k < mountCount; k++) ntfsUnmount(mounts[k].name, 1);
	
	log_printf("\n*** PS3_NTFS_Shutdown ***\n\n");
	for(k = 0; k < 8; k++) {
		if(PS3_NTFS_Shutdown(k)) log_printf("- PS3_NTFS_Shutdown(%d) = true\n", k);
		else log_printf("- PS3_NTFS_Shutdown(%d) = false\n", k);
	}
	
	/* // Debugging for time related functions in ntfstime.h
	struct timespec {
		time_t tv_sec;
		long tv_nsec;
	} ;

	struct timespec now;
	typedef uint64_t u64;
	typedef u64 sle64;
	typedef sle64 ntfs_time;
	
	//sys_time_sec_t  time_s;
	//sys_time_nsec_t time_n_s;
	//sys_time_get_current_time(&time_s, &time_n_s);
	//now.tv_sec = time_s;
	//now.tv_nsec = time_n_s;
	
	now.tv_sec = time((time_t*)NULL);
	now.tv_nsec = 0;
	
	log_printf("- test now.tv_sec = %d\n", now.tv_sec);
	log_printf("- test now.tv_nsec = %d\n", now.tv_nsec);

	ntfs_time ntfstime;
	struct timespec unixtime;

	#define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000)

	s64 units;

	units = (s64)now.tv_sec * 10000000 + NTFS_TIME_OFFSET + now.tv_nsec/100;
	
	ntfstime = (cpu_to_sle64(units));
	
	log_printf("- timespec2ntfs = %d\n", ntfstime);
	
	struct timespec spec;
	s64 cputime;

	cputime = sle64_to_cpu(ntfstime);
	spec.tv_sec = (cputime - (NTFS_TIME_OFFSET)) / 10000000;
	spec.tv_nsec = (cputime - (NTFS_TIME_OFFSET)
			- (s64)spec.tv_sec*10000000)*100;
		//force zero nsec for overflowing dates
	if ((spec.tv_nsec < 0) || (spec.tv_nsec > 999999999))
		spec.tv_nsec = 0;
		
	unixtime = spec;
	
	log_printf("- ntfs2timespec = %d\n", unixtime);
	*/	// End debugging

	/*
	TODO
	int ps3ntfs_file_to_sectors(const char *path, uint32_t *sec_out, uint32_t *size_out, int max, int phys);
	int ps3ntfs_get_fd_from_FILE(FILE *fp);
	s64 ps3ntfs_seek64(int fd, s64 pos, int dir);
	int ps3ntfs_link(const char *existing, const char  *newLink);
	
	int ps3ntfs_statvfs(const char *path, struct statvfs *buf);
	int ps3ntfs_ftruncate(int fd, off_t len);
	int ps3ntfs_fsync(int fd);
	
	void NTFS_init_system_io(void);
	void NTFS_deinit_system_io(void);
	
	Standard functions supported:
	
	open_r -> for stdio.h fopen()...
	close_r -> for stdio.h fclose()...
	read_r -> for stdio.h fread()...
	write_r -> for stdio.h fwrite()...
	lseek_r -> for stdio.h fseek()...
	lseek64_r -> for using with large files (see ps3_example_stdio for this)
	fstat_r -> for stat.h fstat()
	stat_r -> for stat.h stat()

	ftruncate_r -> for unistd.h ftruncate()
	truncate_r -> for unistd.h truncate()
	fsync_r -> for stdio.h fflush()
	link_r -> for unistd.h link()
	unlink_r -> for unistd.h unlink()
	rename_r -> for stdio.h rename()
	mkdir_r -> for stat.h mkdir()
	rmdir_r -> for unistd.h rmdir()
	*/
	
	cellFsClose(LOG);
	
	return 0;
}