merge local state and flags; move ioctl stuff to other files