Now, if i issue the following command:
$ sudo kpartx -dv asfd1asdf2asdf3asdf4asdf5asdf6asfd7asdf8asdf9asf10asdf11asdf12asdf14/disk.img
With the fix, if you only match the first 63 characters on dismount you likely end up dismounting the wrong one (probably loop0 as it's the first hit as the loops are iterated), as only the part of the path exceeding 63 chars is significant.
Probably something more elegant is required to fix this problem.
If i understand correctly, the fix is to compare only the first 63 chars of the path.
With kpartx the precise file path matters in resolving the correct loop device, the suggested solution has the following consequence:
Assuming all loop devices are available, these commands succeed and mount their respective images to /dev/loop0 and /dev/loop1
$ sudo kpartx -av asfd1asdf2asdf3 asdf4asdf5asdf6 asfd7asdf8asdf9 asf10asdf11asdf 12asdf13/ disk.img asdf4asdf5asdf6 asfd7asdf8asdf9 asf10asdf11asdf 12asdf14/ disk.img
$ sudo kpartx -av asfd1asdf2asdf3
Now, if i issue the following command: asdf4asdf5asdf6 asfd7asdf8asdf9 asf10asdf11asdf 12asdf14/ disk.img
$ sudo kpartx -dv asfd1asdf2asdf3
With the fix, if you only match the first 63 characters on dismount you likely end up dismounting the wrong one (probably loop0 as it's the first hit as the loops are iterated), as only the part of the path exceeding 63 chars is significant.
Probably something more elegant is required to fix this problem.