void perform_opn(int choice) { switch(choice) { case 1: disp_free_all(); break; case 2: read_write_stdin(); break; case 3: read_write_file(); break; case 4: disp_content(); break; case 5: free_single_pool(); break; case 6: destroy_mem(); printf("\n\nProgram Exited Successfully!!\n\n"); exit(0); default: printf("\nInvalid Operation Selected!!\n"); } }
asmlinkage long xcrypt(void *arg) { /* dummy syscall: returns 0 for non null, -EINVAL for NULL */ struct inputs *mptr= NULL; struct filename *infile= NULL; struct filename *outfile= NULL; char *key= NULL; int rc; printk("xcrypt received arg %p\n", arg); if (arg == NULL) return -EINVAL; mptr = kmalloc(sizeof(struct inputs),GFP_KERNEL); if(IS_ERR(mptr)){ printk("Error in allocating memory to input structure\n "); rc = -PTR_ERR(mptr); goto out; } rc= copy_from_user(mptr,arg,sizeof(struct inputs)); if(rc){ printk("Error in copying inputs from user \n"); rc= -EFAULT; goto out; } infile= getname(mptr->in); if(IS_ERR(infile)){ printk("getname() failed for filename of input file\n"); rc= -PTR_ERR(infile); goto out; } outfile= getname(mptr->out); if(IS_ERR(outfile)){ printk("getname() failed for filename of output file\n"); rc= -PTR_ERR(outfile); goto out; } key= kmalloc(mptr->keylen,GFP_KERNEL); if(IS_ERR(key)){ printk("Error allocating memory to key \n"); rc = -PTR_ERR(key); goto out; } rc= copy_from_user(key,(char*)mptr->keybuf,mptr->keylen); if(rc){ printk("Error copying key to kernel space \n"); rc=-EFAULT; goto out; } rc= read_write_file(infile,outfile,(void*)key,mptr->flag); if(rc < 0){ printk("Syscall xcrypt failed with error= %d \n",rc); } else{ printk("Successfully returned from syscall xcrypt\n"); } out: if(key) kfree(key); if(IS_ERR(outfile)) putname(outfile); if(IS_ERR(infile)) putname(infile); if(mptr) kfree(mptr); return rc; }