fd: split kern_dup flags argument into actual flags and a mode
Tidy up the code inside to switch on the mode.