[LTP] [PATCH V2 01/10] tst_device: Add tst_ismount() helper

Li Wang liwang@redhat.com
Thu Feb 20 08:06:33 CET 2020


> +int tst_ismount(const char *path)
> +{
> +       char line[256];
> +       FILE *file;
> +       int ret = -1;

+
> +       file = SAFE_FOPEN(NULL, "/proc/mounts", "r");
> +
> +       while (fgets(line, sizeof(line), file)) {
> +               if (strstr(line, path) != NULL) {
> +                       ret = 0;
> +                       break;
> +               }
> +       }
> +
> +       SAFE_FCLOSE(NULL, file);
> +
> +       if (ret) {
> +               errno = ENOENT;
> +               tst_resm(TWARN, "No device is mounted at %s", path);
> +       }
> +
> +       return ret;
>

Sorry, I think the return value should be '1' if it has been mounted
already.

e.g
These codes will make people confused about whether it's
mounted successfully or not.

if (tst_ismount(MNTPOINT))
        tst_brk(TBROK | TERRNO, "device not mounted");


+}
>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200220/98197515/attachment.htm>


More information about the ltp mailing list