fstrim: patch

Tito farmatito at tiscali.it
Sun Nov 10 13:56:27 UTC 2013


On Sunday 10 November 2013 12:57:41 souf wrote:
> Hi,
> Please apply this patch to fstrim applet
> 
> Thanks.
> 
> 

Hi,
this patch looks wrong to me:

--- busybox/util-linux/fstrim.c.orig    2013-11-10 11:33:33.966789413 +0100
+++ busybox/util-linux/fstrim.c 2013-11-10 12:46:23.045660354 +0100
@@ -60,7 +60,7 @@
 int fstrim_main(int argc UNUSED_PARAM, char **argv)
 {
        struct fstrim_range range;
-       char *arg_o, *arg_l, *arg_m, *bd;
+       char *arg_o, *arg_l, *arg_m;
        unsigned opts;
        int fd;

@@ -83,6 +83,7 @@

        opt_complementary = "=1"; /* exactly one non-option arg: the mountpoint */
        opts = getopt32(argv, "o:l:m:v", &arg_o, &arg_l, &arg_m);
+       argv += optind;

        memset(&range, 0, sizeof(range));
        range.len = ULLONG_MAX;
@@ -94,15 +95,17 @@
        if (opts & OPT_m)
                range.minlen = xatoull_sfx(arg_m, fstrim_sfx);

-       bd = find_block_device(*(argv += optind));
-       if (bd) {
-               fd = xopen_nonblocking(bd);
+       /* here find_block_device() is only used to check
+        * if *argv is a valid mount point.
+        */
+       if (find_block_device(*argv)) {

Now you know that *argv is a mountpoint in other words a directory (as checked by find_block_device).


+               fd = xopen_nonblocking(*argv);

and here you open the directory to get an fd to send IOCTLs.

                xioctl(fd, FITRIM, &range);

I suspect you would rather send the ioctl to the block device mounted on the mount point
so the previous code makes sense.

                if (ENABLE_FEATURE_CLEAN_UP)
                        close(fd);

                if (opts & OPT_v)
-                       printf("%s: %llu bytes were trimmed\n", bd, range.len);
+                       printf("%s: %llu bytes were trimmed\n", *argv, range.len);
                return EXIT_SUCCESS;
        }
        return EXIT_FAILURE;

Ciao,
Tito


More information about the busybox mailing list