-------- Message original --------
Sujet: Re: fstrim: patch
Date : Sun, 10 Nov 2013 16:52:04 +0100
De : souf <[email protected]>
Pour : Tito <[email protected]>

Le 10/11/2013 14:56, Tito a écrit :
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
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

from man fstrim:

"The mountpoint argument is the pathname of the directory where the
filesystem is mounted."

from fstrim (util-linux-2.24):

path = argv[optind++];

if (optind != argc) {
        warnx(_("unexpected number of arguments"));
        usage(stderr);
}

if (stat(path, &sb) == -1)
        err(EXIT_FAILURE, _("stat failed %s"), path);
if (!S_ISDIR(sb.st_mode))
        errx(EXIT_FAILURE, _("%s: not a directory"), path);

fd = open(path, O_RDONLY);
if (fd < 0)
        err(EXIT_FAILURE, _("cannot open %s"), path);

if (ioctl(fd, FITRIM, &range))
        err(EXIT_FAILURE, _("%s: FITRIM ioctl failed"), path);



_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to