Refactor attach loop device in pure Go

/cc @alexlarsson, could you take a look and validate?