Exemplo n.º 1
0
int file_main(char* ntfs_file, dis_context_t* dis_ctx)
{
	// Check parameter
	if(!ntfs_file)
	{
		xprintf(L_ERROR, "Error, empty string file. Abort.\n");
		return EXIT_FAILURE;
	}
	
	if(!dis_ctx)
	{
		xprintf(L_ERROR, "Error, no context given. Abort.\n");
		return EXIT_FAILURE;
	}
	
	dis_iodata_t io_data = dis_ctx->io_data;
	size_t buf_size = (size_t)(NB_READ_SECTOR * io_data.sector_size);
	uint8_t* buffer = xmalloc(buf_size);
	
	mode_t mode = S_IRUSR|S_IWUSR;
	if(dis_ctx->cfg.is_ro & READ_ONLY)
		mode = S_IRUSR;
	
	int fd_ntfs = xopen2(ntfs_file, O_CREAT|O_RDWR|O_LARGEFILE, mode);
	
	
	off_t offset          = 0;
	long long int percent = 0;
	
	xprintf(L_INFO, "File size: %llu bytes\n", io_data.volume_size);
	
	/* Read all sectors and decrypt them if necessary */
	xprintf(L_INFO, "\rDecrypting... 0%%");
	fflush(stdout);
	
	off_t decrypting_size = (off_t)io_data.volume_size;
	
	while(offset < decrypting_size)
	{
		/* Read and decrypt an entire region of the disk */
		dislock(dis_ctx, buffer, offset, buf_size);
		
		offset += (off_t) buf_size;
		
		
		/* Now copy the required amount of data to the user file */
		xwrite(fd_ntfs, buffer, buf_size);
		
		/* Screen update */
		if(percent != (offset*100)/decrypting_size)
		{
			percent = (offset*100)/decrypting_size;
			xprintf(L_INFO, "\rDecrypting... %lld%%", percent);
			fflush(stdout);
		}
	}
	
	xprintf(L_INFO, "\rDecrypting... Done.\n");
	
	xfree(buffer);
	xclose(fd_ntfs);
	
	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
/**
 * Waits for a FIFO to open on "the other side"
 * Takes the pathname of the fifo and the flag with which open should open the fifo
 * TODO review this
 */
void waitFifo(const char *pathname, int flags) {
    // opens the fifo and closes it right after
    xclose(xopen2(pathname, flags));
}