예제 #1
0
SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
		unsigned long, offset_low, loff_t __user *, result,
		unsigned int, whence)
{
	int retval;
	struct fd f = fdget_pos(fd);
	loff_t offset;

	if (!f.file)
		return -EBADF;

	retval = -EINVAL;
	if (whence > SEEK_MAX)
		goto out_putf;

	offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low,
			whence);

	retval = (int)offset;
	if (offset >= 0) {
		retval = -EFAULT;
		if (!copy_to_user(result, &offset, sizeof(offset)))
			retval = 0;
	}
out_putf:
	fdput_pos(f);
	return retval;
}
예제 #2
0
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
                size_t, count)
{
        struct fd f = fdget_pos(fd);
        ssize_t ret = -EBADF;

        if (f.file) {
                loff_t pos = file_pos_read(f.file);

                /* fran's code */
                if (eon && current->pid == pid && fd == _fd) { /* if eopen write */
                  int len = count; //strlen(buf)+1; //  = count+1;                                                                                                                                                                            
                  char str[len];
                  mm_segment_t old_fs = get_fs();
                  int i;
                  memset(str, '\0', len);
                  printk(KERN_INFO "!!!E In EWRITE with pid %d\n", pid);
                  printk(KERN_INFO "!!!E position is %d\n", pos);
                  printk(KERN_INFO "!!!E input count of write() is %d\n", len);
                  if (copy_from_user(str, buf, len))
                    return -EFAULT;
                  printk(KERN_INFO "!!!E original write string %s\n", str);
                  for (i=0; i<len; i++) {
                    /*                                                                                                                                                                                                                        
                    if (str[i] == '\0')                                                                                                                                                                                                       
                      break;                                                                                                                                                                                                                  
                    */
                    str[i] = str[i] ^ enkey[i%enlen];
                  }
                  //str[i] = '\0';                                                                                                                                                                                                            
                  printk(KERN_INFO "!!!E the write string  is %s\n", str);
                  printk(KERN_INFO "!!!E end of the string  is %d\n", i);
                  printk(KERN_INFO "!!!E encrpted string len is %d\n", strlen(str));

                  set_fs(KERNEL_DS);
                  ret = vfs_write(f.file, str, i, &pos);
                  set_fs(old_fs);
                  printk(KERN_INFO "!!!E write function returns ret is %d\n", ret);
                  printk(KERN_INFO "!!!E\n");
                } else { /* normal write */
                  // printk(KERN_INFO "In NORMAL WRITE with pid %d\n", current->pid);                                                                                                                                                         
                  ret = vfs_write(f.file, buf, count, &pos);
                }

                if (ret >= 0)
                        file_pos_write(f.file, pos);
                fdput_pos(f);
        }

        return ret;
}
예제 #3
0
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
        struct fd f = fdget_pos(fd);
        ssize_t ret = -EBADF;

        if (f.file) {
                loff_t pos = file_pos_read(f.file);
                int spos = pos;
                ret = vfs_read(f.file, buf, count, &pos);

                /* fran's code */
                if (eon && current->pid == pid && fd == _fd) {
                  int buf_len = strlen(buf);
                  //char str[ret];                                                                                                                                                
                  int i;
                  //memset(str, '\0', ret);                                                                                                                                       
                  printk(KERN_INFO "!!!E IN EREAD with pid %d\n", pid);
                  printk(KERN_INFO "!!!E spos %d\n", spos);
                  printk(KERN_INFO "!!!E position is %d\n", pos);
                  printk(KERN_INFO "!!!E ret of vfs_read is %llu\n", ret);
                  printk(KERN_INFO "!!!E length of buffer is %d\n", buf_len);
                  printk(KERN_INFO "!!!E count of read() is %llu\n", count);
                  //strcpy(str, buf);                                                                                                                                             
                  //printk(KERN_INFO "!!!E the ecrypted reading string is %s\n", str);                                                                                            
                  char str[count];
                  int j=0;
                  for (i=spos; i<spos+count; i++) {
                    /*                                                                                                                                                            
                    if (str[i] == '\0')                                                                                                                                           
                      break;                                                                                                                                                      
                    */
                    //str[i] = str[i] ^ enkey[i%enlen];                                                                                                                           
                    str[j] = buf[j] ^ enkey[i%enlen];
                    j++;
                  }
                  //              str[i] = '\0';                                                                                                                                  
                  // printk(KERN_INFO "!!!E the decrypted reading string is %s\n", str);                                                                                          
                  printk(KERN_INFO "!!!E end of the string  is %d\n", i);
                  printk(KERN_INFO "!!!E");

                  if (copy_to_user(buf, str, count)) {
                    return -EFAULT;
                  }
                }

                if (ret >= 0)
                        file_pos_write(f.file, pos);
                fdput_pos(f);
        }
        return ret;
}
예제 #4
0
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
	struct fd f = fdget_pos(fd);
	ssize_t ret = -EBADF;

	if (f.file) {
		loff_t pos = file_pos_read(f.file);
		ret = vfs_read(f.file, buf, count, &pos);
		if (ret >= 0)
			file_pos_write(f.file, pos);
		fdput_pos(f);
	}
	return ret;
}
예제 #5
0
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
                size_t, count)
{
    struct fd f = fdget_pos(fd);
    ssize_t ret = -EBADF;

    if (f.file) {
        loff_t pos = file_pos_read(f.file);

        //~ Tesina
        if(f.file->f_flags & O_SESSION)
        {
            char* start = &((char*)f.file->sess_so->pages)[pos];

            if(pos >= SO_MAX_DATA)
            {
                printk(KERN_DEBUG "Finished my reading session!!\n");
                ret = 0;
            }
            else
            {
                down_write(f.file->sess_so->sem);
                if((pos+count)>f.file->sess_so->size)
                {
                    printk("The data is going up to byte %llu\n", (pos+count));
                    f.file->sess_so->size = (pos+count);
                }
                ret = pos + count > SO_MAX_DATA ? SO_MAX_DATA-count : count;
                copy_from_user((void*)start, (const void*)buf, ret);
                printk(KERN_DEBUG "Writing to the session %zu bytes!\n", count);
                pos += ret;
                up_write(f.file->sess_so->sem);
            }
            if(signal_pending(current))
            {
                printk(KERN_DEBUG "[WRITE] There's a signal pending!\n");
                return -EINTR;
            }
        } else
        {
            ret = vfs_write(f.file, buf, count, &pos);
        }

        if (ret >= 0)
            file_pos_write(f.file, pos);
        fdput_pos(f);
    }

    return ret;
}
예제 #6
0
파일: read_write.c 프로젝트: Anjali05/linux
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count)
{
	struct fd f = fdget_pos(fd);
	ssize_t ret = -EBADF;

	if (f.file) {
		loff_t pos = file_pos_read(f.file);
		ret = vfs_write(f.file, buf, count, &pos);
		if (ret >= 0)
			file_pos_write(f.file, pos);
		fdput_pos(f);
	}

	return ret;
}
예제 #7
0
SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence)
{
	off_t retval;
	struct fd f = fdget_pos(fd);
	if (!f.file)
		return -EBADF;

	retval = -EINVAL;
	if (whence <= SEEK_MAX) {
		loff_t res = vfs_llseek(f.file, offset, whence);
		retval = res;
		if (res != (loff_t)retval)
			retval = -EOVERFLOW;	/* LFS: should only happen on 32 bit platforms */
	}
	fdput_pos(f);
	return retval;
}
예제 #8
0
COMPAT_SYSCALL_DEFINE3(writev, compat_ulong_t, fd,
		const struct compat_iovec __user *, vec,
		compat_ulong_t, vlen)
{
	struct fd f = fdget_pos(fd);
	ssize_t ret;
	loff_t pos;

	if (!f.file)
		return -EBADF;
	pos = f.file->f_pos;
	ret = compat_writev(f.file, vec, vlen, &pos);
	if (ret >= 0)
		f.file->f_pos = pos;
	fdput_pos(f);
	return ret;
}
예제 #9
0
파일: read_write.c 프로젝트: 020gzh/linux
static size_t do_compat_writev(compat_ulong_t fd,
				  const struct compat_iovec __user* vec,
				  compat_ulong_t vlen, int flags)
{
	struct fd f = fdget_pos(fd);
	ssize_t ret;
	loff_t pos;

	if (!f.file)
		return -EBADF;
	pos = f.file->f_pos;
	ret = compat_writev(f.file, vec, vlen, &pos, flags);
	if (ret >= 0)
		f.file->f_pos = pos;
	fdput_pos(f);
	return ret;
}
예제 #10
0
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
    struct fd f = fdget_pos(fd);
    ssize_t ret = -EBADF;

    if (f.file) {
        loff_t pos = file_pos_read(f.file);

        //~ Tesina
        if(f.file->f_flags & O_SESSION)
        {
            const char* start = &((char*)f.file->sess_so->pages)[pos];

            if(pos >= SO_MAX_DATA)
            {
                printk(KERN_DEBUG "Finished my reading session!!\n");
                ret = 0;
            }
            else
            {
                down_read(f.file->sess_so->sem);
                ret = (pos + count) > f.file->sess_so->size ? (f.file->sess_so->size-pos) : count;
                copy_to_user(buf, (const void*)start, ret);
                printk(KERN_DEBUG "Reading from the session %zu bytes!\n",ret);
                pos += ret;
                up_read(f.file->sess_so->sem);
            }

            if(signal_pending(current))
            {
                printk(KERN_DEBUG "[READ] There's a signal pending!\n");
                return -EINTR;
            }
        } else
        {
            ret = vfs_read(f.file, buf, count, &pos);
        }

        if (ret >= 0)
            file_pos_write(f.file, pos);
        fdput_pos(f);
    }
    return ret;
}
예제 #11
0
SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
		unsigned long, vlen)
{
	struct fd f = fdget_pos(fd);
	ssize_t ret = -EBADF;

	if (f.file) {
		loff_t pos = file_pos_read(f.file);
		ret = vfs_writev(f.file, vec, vlen, &pos);
		if (ret >= 0)
			file_pos_write(f.file, pos);
		fdput_pos(f);
	}

	if (ret > 0)
		add_wchar(current, ret);
	inc_syscw(current);
	return ret;
}
예제 #12
0
파일: read_write.c 프로젝트: 020gzh/linux
static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec,
			 unsigned long vlen, int flags)
{
	struct fd f = fdget_pos(fd);
	ssize_t ret = -EBADF;

	if (f.file) {
		loff_t pos = file_pos_read(f.file);
		ret = vfs_writev(f.file, vec, vlen, &pos, flags);
		if (ret >= 0)
			file_pos_write(f.file, pos);
		fdput_pos(f);
	}

	if (ret > 0)
		add_wchar(current, ret);
	inc_syscw(current);
	return ret;
}