SceMemDisk

From Vita Development Wiki
Jump to navigation Jump to search

Module

Version World Privilege
0.931-0.996 Non-secure Kernel

Example code

void md_access_test(void){

	int md_res;
	SceUID memid, fd;

	memid = sceKernelAllocMemBlock("md_buffer", 0x0C20D060, 0x10000, NULL);

	md_res = 0xDEADBEEF;
	res = sceIoDevctl("md0:", 1, &memid, sizeof(memid), &md_res, sizeof(md_res));
	sceClibPrintf("sceIoDevctl: 0x%X md_res: 0x%X\n", res, md_res);

	res = sceIoRemove("md0:0");
	sceClibPrintf("sceIoRemove: 0x%X\n", res);

	fd = sceIoOpen("md0:0", SCE_O_WRONLY, 0);
	sceClibPrintf("sceIoOpen: 0x%X\n", fd);
	if(fd >= 0){
		char buf[0x200];

		sceClibStrncpy(buf, "Hello", 0x200);

		res = sceIoWrite(fd, buf, sizeof(buf));
		sceIoClose(fd);
		sceClibPrintf("sceIoWrite: 0x%X\n", res);
	}

	fd = sceIoOpen("md0:0", SCE_O_RDONLY, 0);
	sceClibPrintf("sceIoOpen: 0x%X\n", fd);
	if(fd >= 0){
		char buf[0x200];
		sceClibMemset(buf, 0, sizeof(buf));

		res = sceIoRead(fd, buf, 0x200);
		sceIoClose(fd);
		sceClibPrintf("sceIoRead: 0x%X\n", res);
		sceClibPrintf("Msg: %s\n", buf);
	}

	res = sceIoRemove("md0:0");
	sceClibPrintf("sceIoRemove: 0x%X\n", res);
	res = sceIoRemove("md0:");
	sceClibPrintf("sceIoRemove: 0x%X\n", res);

	sceKernelFreeMemBlock(memid);
}