Clean up code and remove debug. Call fd_drop_written() on write case like
the kernel does.