nand: add llseek for fw_env tools
authorLiang Yang <liang.yang@amlogic.com>
Fri, 12 Jan 2018 06:18:52 +0000 (14:18 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Tue, 16 Jan 2018 06:18:17 +0000 (23:18 -0700)
PD#158552: Implememt llseek for fw_printenv/fw_setenv tools

Change-Id: Ie6176903c7155cdb7daf17049a7356ed8f61e463
Signed-off-by: Liang Yang <liang.yang@amlogic.com>
drivers/amlogic/mtd/aml_env.c

index 8b993fb..32f0a02 100644 (file)
@@ -185,6 +185,41 @@ int uboot_env_open(struct inode *node, struct file *file)
        return 0;
 }
 
+static loff_t uboot_env_llseek(struct file *file, loff_t off, int whence)
+{
+       loff_t newpos;
+
+       mutex_lock(&env_mutex);
+       switch (whence) {
+       case 0: /* SEEK_SET (start postion)*/
+               newpos = off;
+               break;
+
+       case 1: /* SEEK_CUR */
+               newpos = file->f_pos + off;
+               break;
+
+       case 2: /* SEEK_END */
+               newpos = (loff_t)(CONFIG_ENV_SIZE) - 1;
+               newpos = newpos - off;
+               break;
+
+       default: /* can't happen */
+               mutex_unlock(&env_mutex);
+               return -EINVAL;
+       }
+
+       if ((newpos < 0) || (newpos >= (loff_t)CONFIG_ENV_SIZE)) {
+               mutex_unlock(&env_mutex);
+               return -EINVAL;
+       }
+
+       file->f_pos = newpos;
+       mutex_unlock(&env_mutex);
+
+       return newpos;
+}
+
 ssize_t uboot_env_read(struct file *file,
                char __user *buf,
                size_t count,
@@ -291,6 +326,7 @@ static const struct file_operations uboot_env_ops = {
        .open = uboot_env_open,
        .read = uboot_env_read,
        .write = uboot_env_write,
+       .llseek = uboot_env_llseek,
        .unlocked_ioctl = uboot_env_ioctl,
 };
 #endif /* AML_NAND_UBOOT */