optimize ioctl logic