static void print_io_dump(int rw, size_t bytes)
{
	unsigned long last_jiffies;
	int reset = 0;

	if (get_tamper_sf() == 1)
		return;

	if (!strcmp(current->comm, "sdcard"))
		return;

	last_jiffies = current->ioac.last_jiffies;
	
	if ((current->ioac.last_jiffies == 0) ||
		time_after(jiffies, last_jiffies + 5 * HZ)) {
		current->ioac.last_jiffies = jiffies;
		current->ioac.acc_write_bytes = (rw == WRITE) ? bytes : 0;
		current->ioac.acc_read_bytes = (rw == READ) ? bytes : 0;
		return;
	}
	if (rw == WRITE)
		current->ioac.acc_write_bytes += bytes;
	else
		current->ioac.acc_read_bytes += bytes;
	if (time_after(jiffies, last_jiffies + HZ)) {
		if (current->ioac.acc_write_bytes > WRITE_THRESHOLD) {
			pr_info("FS Statistics: %s(pid %d) write %llu bytes in %u ms\n",
				current->comm, current->pid,
				current->ioac.acc_write_bytes,
				jiffies_to_msecs(jiffies - last_jiffies));
			reset = 1;
		}
		if (current->ioac.acc_read_bytes > READ_THRESHOLD) {
			pr_info("FS Statistics: %s(pid %d) read %llu bytes in %u ms\n",
				current->comm, current->pid,
				current->ioac.acc_read_bytes,
				jiffies_to_msecs(jiffies - last_jiffies));
			reset = 1;
		}
		if (reset) {
			current->ioac.last_jiffies = 0;
			current->ioac.acc_write_bytes = 0;
			current->ioac.acc_read_bytes = 0;
		}
	}

	return;
}
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
		size_t, count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;
#ifdef CONFIG_DIRTY_SYSTEM_DETECTOR
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
	struct mount *mnt;
#else
	struct vfsmount *mnt;
#endif
#endif

	file = fget_light(fd, &fput_needed);

#ifdef CONFIG_DIRTY_SYSTEM_DETECTOR
	
	
	if (!get_tamper_sf() && file != NULL) {
		
		if (board_mfg_mode() != 2
				&& strcmp("htcunzip", current->comm)) {
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
			mnt = real_mount(file->f_path.mnt);
#else
			mnt = file->f_path.mnt;
#endif
			if (!strcmp("system",  mnt->mnt_mountpoint->d_name.name)) {
				printk("%s to /system partition: file(%s)\n", __func__, file->f_path.dentry->d_name.name);
				mark_system_dirty(file->f_path.dentry->d_name.name);
			}
		}
	}
#endif

	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_write(file, buf, count, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	return ret;
}
Beispiel #3
0
static ssize_t ram_console_read_old(struct file *file, char __user *buf,
				    size_t len, loff_t *offset)
{
	loff_t pos = *offset;
	ssize_t count;

#if defined(CONFIG_DEBUG_LAST_BLDR_LOG) && defined(CONFIG_DEBUG_BLDR_LOG)
	loff_t bootloader_pos;
	loff_t ram_console_pos;
	static char *last_bldr_ptr;
	static unsigned long last_bldr_size;
	static char *bldr_ptr;
	static unsigned long bldr_size;

	if(!get_tamper_sf())
	{
		last_bldr_ptr=last_bldr_log;
		last_bldr_size=last_bldr_log_size;
		bldr_ptr=bldr_log;
		bldr_size=bldr_log_size;
	}
	else
	{
		last_bldr_ptr=last_bldr_log_buf;
		last_bldr_size=last_bldr_log_buf_size;
		bldr_ptr=bldr_log_buf;
		bldr_size=bldr_log_buf_size;
	}

	if (pos >= last_bldr_size + ram_console_old_log_size + bldr_size)
		return 0;

	if (pos >= last_bldr_size + ram_console_old_log_size) {

		bootloader_pos = pos - (last_bldr_size + ram_console_old_log_size);
		count = min(len, (size_t)(bldr_size - bootloader_pos));
		if (copy_to_user(buf, bldr_ptr + bootloader_pos, count))
			return -EFAULT;

		*offset += count;
		return count;
	}

	if (pos >= last_bldr_size) {
		ram_console_pos = pos - last_bldr_size;
		count = min(len, (size_t)(ram_console_old_log_size - ram_console_pos));
		if (copy_to_user(buf, ram_console_old_log + ram_console_pos, count))
			return -EFAULT;

		*offset += count;
		return count;
	}

	count = min(len, (size_t)(last_bldr_size - pos));
	if (copy_to_user(buf, last_bldr_ptr + pos, count))
		return -EFAULT;

	*offset += count;
	return count;
#elif defined(CONFIG_DEBUG_LAST_BLDR_LOG)
	loff_t ram_console_pos;
	static char *last_bldr_ptr;
	static unsigned long last_bldr_size;

	if(!get_tamper_sf())
	{
		last_bldr_ptr=last_bldr_log;
		last_bldr_size=last_bldr_log_size;
	}
	else
	{
		last_bldr_ptr=last_bldr_log_buf;
		last_bldr_size=last_bldr_log_buf_size;
	}

	if (pos >= last_bldr_size + ram_console_old_log_size)
		return 0;

	if (pos >= last_bldr_size) {
		ram_console_pos = pos - last_bldr_size;
		count = min(len, (size_t)(ram_console_old_log_size - ram_console_pos));
		if (copy_to_user(buf, ram_console_old_log + ram_console_pos, count))
			return -EFAULT;

		*offset += count;
		return count;
	}

	count = min(len, (size_t)(last_bldr_size - pos));
	if (copy_to_user(buf, last_bldr_ptr + pos, count))
		return -EFAULT;

	*offset += count;
	return count;
#elif defined(CONFIG_DEBUG_BLDR_LOG)
	loff_t bootloader_pos;
	static char *bldr_ptr;
	static unsigned long bldr_size;

	if(!get_tamper_sf())
	{
		bldr_ptr=bldr_log;
		bldr_size=bldr_log_size;
	}
	else
	{
		bldr_ptr=bldr_log_buf;
		bldr_size=bldr_log_buf_size;
	}

	if (pos >= ram_console_old_log_size + bldr_size)
		return 0;

	if (pos >= ram_console_old_log_size) {

		bootloader_pos = pos - ram_console_old_log_size;
		count = min(len, (size_t)(bldr_size - bootloader_pos));
		if (copy_to_user(buf, bldr_ptr + bootloader_pos, count))
			return -EFAULT;

		*offset += count;
		return count;
	}

	count = min(len, (size_t)(ram_console_old_log_size - pos));
	if (copy_to_user(buf, ram_console_old_log + pos, count))
		return -EFAULT;

	*offset += count;
	return count;
#else
	if (pos >= ram_console_old_log_size)
		return 0;

	count = min(len, (size_t)(ram_console_old_log_size - pos));
	if (copy_to_user(buf, ram_console_old_log + pos, count))
		return -EFAULT;

	*offset += count;
	return count;
#endif
}
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
		size_t, count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;
#ifdef CONFIG_DIRTY_SYSTEM_DETECTOR
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
	struct mount *mnt;
#else
	struct vfsmount *mnt;
#endif
#endif

	file = fget_light(fd, &fput_needed);

#ifdef CONFIG_DIRTY_SYSTEM_DETECTOR
	
	
	if (!get_tamper_sf() && file != NULL) {
		
		if (board_mfg_mode() != 2
				&& strcmp("htcunzip", current->comm)) {
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
			mnt = real_mount(file->f_path.mnt);
#else
			mnt = file->f_path.mnt;
#endif
			if (!strcmp("system",  mnt->mnt_mountpoint->d_name.name)) {
				printk("%s to /system partition: file(%s)\n", __func__, file->f_path.dentry->d_name.name);
				mark_system_dirty(file->f_path.dentry->d_name.name);
			}
		}
	}
#endif
	if (file) {
#if defined(CONFIG_HTC_DEBUG_BINDER_WRITE)
		struct timer_list timer;
		int debug_write;
#endif
		loff_t pos = file_pos_read(file);

#if defined(CONFIG_HTC_DEBUG_BINDER_WRITE)
		debug_write = current_task_is_system_server_binder();
		if (debug_write) {
			init_timer_on_stack(&timer);
			timer.function = vfs_write_timeout;
			timer.expires = jiffies + HZ * WRITE_TIMEOUT_VALUE;
			timer.data = (unsigned long) current;
			add_timer(&timer);
		}
#endif

		ret = vfs_write(file, buf, count, &pos);

#if defined(CONFIG_HTC_DEBUG_BINDER_WRITE)
		if (debug_write) {
			del_timer_sync(&timer);
			destroy_timer_on_stack(&timer);
			if (ret < 0 && file && file->f_op) {
				pr_info("%s: %s (%d:%d) ret: %d, write: %pf, aio_write: %pf\n",
						__func__, current->comm, current->tgid, current->pid, ret,
						file->f_op->write, file->f_op->aio_write);
			}
		}
#endif

		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	return ret;
}
Beispiel #5
0
void bldr_log_parser(const char *bldr_log, char *bldr_log_buf, unsigned long bldr_log_size, unsigned long *bldr_log_buf_size)
{
	int i,j,k;
	int last_index=0;
	int line_length=0;
	const char *bldr_log_ptr=bldr_log;
	char *bldr_log_buf_ptr=bldr_log_buf;
	const char *terminal_pattern="\r\n";
	const char *specific_pattern="[HBOOT]";
	int terminal_pattern_len=strlen(terminal_pattern);
	int specific_pattern_len=strlen(specific_pattern);

	if (!get_tamper_sf()) {
		memcpy(bldr_log_buf, bldr_log, bldr_log_size);
		*bldr_log_buf_size = bldr_log_size;
		printk(KERN_INFO "[K] bldr_log_parser: size %ld\n", *bldr_log_buf_size);
		return;
	}

	for(i=0; i<bldr_log_size; i++) 
	{
		bool terminal_match = true;

		if((i+terminal_pattern_len) > bldr_log_size)
			break;

		for(j=0; j < terminal_pattern_len; j++) 
		{
			if(bldr_log[i+j] != terminal_pattern[j])
			{
				terminal_match = false;
				break;
			}
		}

		if(terminal_match) 
		{
			bool specific_match = true;
			int specific_pattern_start = i-specific_pattern_len;
			line_length = i+terminal_pattern_len-last_index;

			for(k=0; k < specific_pattern_len; k++) 
			{
				if(bldr_log[specific_pattern_start+k] != specific_pattern[k])
				{
					specific_match = false;
					break;
				}
			}

			if(specific_match) 
			{
				
				memcpy(bldr_log_buf_ptr, bldr_log_ptr, line_length-terminal_pattern_len-specific_pattern_len);
				bldr_log_buf_ptr +=(line_length-terminal_pattern_len-specific_pattern_len);
				memcpy(bldr_log_buf_ptr, terminal_pattern, terminal_pattern_len);
				bldr_log_buf_ptr +=terminal_pattern_len;
			}

			bldr_log_ptr+=line_length;
			last_index=i+terminal_pattern_len;
		}
	}

	*bldr_log_buf_size = bldr_log_buf_ptr - bldr_log_buf;
	printk(KERN_INFO "[K] bldr_log_parser: size %ld\n", *bldr_log_buf_size);
}