1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| SYSCALL_DEFINE3(fread_advance,char __user *,res,int,pathcount,char __user *,path) { printk("fread_advance executing"); struct file *filp; struct inode *inode;
off_t fsize; char *buf; unsigned long magic;
char* pathbuf; pathbuf = (char *)kmalloc(sizeof(char) * pathcount, GFP_KERNEL); if(!copy_from_user(pathbuf, path, pathcount)) { printk("input path is %s \n", pathbuf); }
printk("start....\n"); filp=filp_open(pathbuf,O_RDONLY,0); inode=file_inode(filp);
magic=inode->i_sb->s_magic;
printk("file system magic:%li \n",magic); printk("super blocksize:%li \n",inode->i_sb->s_blocksize); printk("inode %li \n",inode->i_ino);
fsize=inode->i_size; printk("file size:%i \n",(int)fsize); buf=(char *) kmalloc(fsize+1,GFP_ATOMIC); printk("buf correct\n");
kernel_read(filp,buf,fsize,&(filp->f_pos)); buf[fsize]='\0'; printk("The File Content is:\n"); printk("%s\n",buf);
if(!copy_to_user(res, buf, fsize+1)) { printk("output success"); } filp_close(filp,NULL); printk("fread_advance end\n"); return 0; }
|