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

Viresh Kumar viresh.kumar@linaro.org
Thu Feb 20 08:19:23 CET 2020


On 20-02-20, 15:06, Li Wang wrote:
> > +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");

I kept the return 0 on success thing here as well, but maybe yeah, it
should return 1 on success here.

-- 
viresh


More information about the ltp mailing list