In terms of code, the ioctl() method's code within the sed2 driver for the encrypt operation is as follows (for clarity, we won't show all the error checking code here; we will show only the most relevant parts). You can find the full code at ch5/sed2/:
// ch5/sed2/sed2_driver/sed2_drv.c
[ ... ]
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
static long ioctl_miscdrv(struct file *filp, unsigned int cmd, unsigned long arg)
#else
static int ioctl_miscdrv(struct inode *ino, struct file *filp, unsigned int cmd, unsigned long arg)
#endif
{
struct stMyCtx *priv = gpriv;
[ ... ]
switch (cmd) {
case IOCTL_LLKD_SED_IOC_ENCRYPT_MSG: /* kthread: encrypts the msg passed in */
[ ... ]
if (atomic_read(&priv->msg_state) == XF_ENCRYPT) { // already encrypted?
pr_notice("encrypt op: message is currently encrypted; aborting op...\n");
return -EBADRQC; /* 'Invalid request code...