[LTP] [PATCH] rfim: add new test for verifying RFIM sysfs interface
Cyril Hrubis
chrubis@suse.cz
Wed Jun 17 10:52:18 CEST 2026
Hi!
> > +static void check_read_only(const char *path)
> > +{
> > + tst_res(TDEBUG, "Checking whether %s is read-only", path);
> > +
> > + if (access(path, F_OK)) {
> > + tst_res(TFAIL | TERRNO, "%s does not exist", path);
> > + return;
> > + }
> > +
> > + int fd = open(path, O_RDONLY);
> > +
> > + if (fd == -1) {
> > + tst_res(TFAIL | TERRNO, "%s can't be read", path);
> > + return;
> > + }
> > + close(fd);
> > +
> > + fd = open(path, O_WRONLY);
> > + if (fd != -1) {
> > + close(fd);
> > + tst_res(TFAIL, "%s is writable", path);
> > + return;
> > + }
> > +
> > + tst_res(TPASS, "%s is read-only", path);
> > +}
>
> This function can be easily replaced by access().
>
> TST_EXP_PASS(access(path, R_OK));
> TST_EXP_FAIL(access(path, W_OK), ..);
This depends on where the error from kernel is supposed to be returned
from. For files that are generated by kernel such as /sys/ and /proc/
the permission bits can be all enabled but you may still get EPERM when
you actually open the file and kernel decides that this file shouldn't
be readable in the open() syscall handler for the particular file.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list