On Fri, Aug 31, 2018 at 01:06:00AM +1200, Stuart Richards wrote: > > Attempting to defrag a file with e4defrag -v filetobedefragged on a Raspberry > Pi gives the error "-v: No such file or directory while trying to open file > system: /dev/root". The same command works as expected on an AMD64 system.
Thanks for reporting this bug! When e4defrag is run as root, it tries to open the file system to get some file system parameters; this isn't strictly needed; it uses the information to improve the decision about whether or not the file is already optimally defragged or not. The problem is that it does this by trying to parse /etc/mtab (which is often a symlink to /proc/self/mounts). If on that particular system, the kernel reports the root file system as "/dev/root", then e4defrag will try to use it. If /dev/root does not exist (which ia likely) then e4defrag will print the above mentioned error message and bail out. There are a couple of bugs hiding here. (a) The error message which is printed uses argv[1] instead of argv[0], which is where "-v: No such file or directory...." is coming from. (b) E4defrag should not bail out; since it's not fatal if the file system parameters can't be fetched (in fact e4defrag will never try if not running as root). (c) The way e4defrag is trying to find the file system is not really the most intelligent; for one thing it will get misled with bind mounts, and it can try to use the blkid library to find the device name. (d) If a large number of files are specified on the comamnd line, e4defrag not cache the result of the file parameters, but instead fetch them over and over again. I'll fix (a) and (b) for now, but e4defrag really needs to be cleaned up eventually. Regards, - Ted