Add EROFS error number test for fchown(2)

Signed-off-by: Zeng Linggang <[email protected]>
---
 runtest/ltplite                             |  2 +-
 runtest/stress.part3                        |  2 +-
 runtest/syscalls                            |  4 +-
 testcases/kernel/syscalls/fchown/fchown04.c | 59 +++++++++++++++++++++++++++--
 4 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/runtest/ltplite b/runtest/ltplite
index 0c51213..859a719 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -190,7 +190,7 @@ fchmod07 fchmod07
 fchown01 fchown01
 fchown02 fchown02
 fchown03 fchown03
-fchown04 fchown04
+fchown04 fchown04 -D $LTP_DEV -T $LTP_DEV_FS_TYPE
 fchown05 fchown05
 
 fcntl01 fcntl01
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 2471193..e36bd63 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -131,7 +131,7 @@ fchmod07 fchmod07
 fchown01 fchown01
 fchown02 fchown02
 fchown03 fchown03
-fchown04 fchown04
+fchown04 fchown04 -D $LTP_DEV -T $LTP_DEV_FS_TYPE
 fchown05 fchown05
 
 fcntl01 fcntl01
diff --git a/runtest/syscalls b/runtest/syscalls
index b9c1927..b9317a0 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -186,8 +186,8 @@ fchown02 fchown02
 fchown02_16 fchown02_16
 fchown03 fchown03
 fchown03_16 fchown03_16
-fchown04 fchown04
-fchown04_16 fchown04_16
+fchown04 fchown04 -D $LTP_DEV -T $LTP_DEV_FS_TYPE
+fchown04_16 fchown04_16 -D $LTP_DEV -T $LTP_DEV_FS_TYPE
 fchown05 fchown05
 fchown05_16 fchown05_16
 
diff --git a/testcases/kernel/syscalls/fchown/fchown04.c 
b/testcases/kernel/syscalls/fchown/fchown04.c
index 42c94f8..f57d81d 100644
--- a/testcases/kernel/syscalls/fchown/fchown04.c
+++ b/testcases/kernel/syscalls/fchown/fchown04.c
@@ -25,6 +25,8 @@
  *     not super user.
  *   2) fchown(2) returns -1 and sets errno to EBADF if the file descriptor
  *     of the specified file is not valid.
+ *   3) fchown(2) returns -1 and sets errno to EROFS if the named file resides
+ *     on a read-only file system.
  */
 
 #include <stdio.h>
@@ -38,14 +40,27 @@
 #include <pwd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/mount.h>
 
 #include "test.h"
 #include "usctest.h"
 #include "safe_macros.h"
 
+#define DIR_MODE       (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
+                        S_IXGRP|S_IROTH|S_IXOTH)
 
 static int fd1;
 static int fd2 = -1;
+static int fd3;
+static char *fstype = "ext2";
+static char *device;
+static int mount_flag;
+
+static option_t options[] = {
+       {"T:", NULL, &fstype},
+       {"D:", NULL, &device},
+       {NULL, NULL, NULL}
+};
 
 static struct test_case_t {
        int *fd;
@@ -53,15 +68,17 @@ static struct test_case_t {
 } test_cases[] = {
        {&fd1, EPERM},
        {&fd2, EBADF},
+       {&fd3, EROFS},
 };
 
 char *TCID = "fchown04";
 int TST_TOTAL = ARRAY_SIZE(test_cases);
-static int exp_enos[] = { EPERM, EBADF, 0 };
+static int exp_enos[] = { EPERM, EBADF, EROFS, 0 };
 
 static void setup(void);
 static void fchown_verify(int);
 static void cleanup(void);
+static void help(void);
 
 int main(int ac, char **av)
 {
@@ -69,10 +86,16 @@ int main(int ac, char **av)
        char *msg;
        int i;
 
-       msg = parse_opts(ac, av, NULL, NULL);
+       msg = parse_opts(ac, av, options, help);
        if (msg != NULL)
                tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
+       if (!device) {
+               tst_brkm(TBROK, NULL,
+                        "you must specify the device used for mounting with "
+                        "-D option");
+       }
+
        setup();
 
        TEST_EXP_ENOS(exp_enos);
@@ -103,6 +126,21 @@ static void setup(void)
 
        fd1 = SAFE_OPEN(cleanup, "tfile_1", O_RDWR | O_CREAT, 0666);
 
+       tst_mkfs(NULL, device, fstype, NULL);
+       SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);
+       if (mount(device, "mntpoint", fstype, 0, NULL) < 0) {
+               tst_brkm(TBROK | TERRNO, cleanup,
+                        "mount device:%s failed", device);
+       }
+       mount_flag = 1;
+       SAFE_TOUCH(cleanup, "mntpoint/tfile_3", 0644, NULL);
+       if (mount(device, "mntpoint", fstype,
+                 MS_REMOUNT | MS_RDONLY, NULL) < 0) {
+               tst_brkm(TBROK | TERRNO, cleanup,
+                        "mount device:%s failed", device);
+       }
+       fd3 = SAFE_OPEN(cleanup, "mntpoint/tfile_3", O_RDONLY);
+
        ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
        SAFE_SETEUID(cleanup, ltpuser->pw_uid);
 }
@@ -128,12 +166,25 @@ static void fchown_verify(int i)
 static void cleanup(void)
 {
        if (seteuid(0))
-                tst_resm(TINFO | TERRNO, "Failet to seteuid(0) before 
cleanup");
+               tst_resm(TINFO | TERRNO, "Failet to seteuid(0) before cleanup");
 
        TEST_CLEANUP;
 
        if (fd1 > 0)
-                close(fd1);
+               close(fd1);
+
+       if (fd3 > 0)
+               close(fd3);
+
+       if (mount_flag && umount("mntpoint") < 0)
+               tst_resm(TWARN | TERRNO, "umount device:%s failed", device);
 
        tst_rmdir();
 }
+
+static void help(void)
+{
+       printf("-T type   : specifies the type of filesystem to be mounted. "
+              "Default ext2.\n");
+       printf("-D device : device used for mounting.\n");
+}
-- 
1.8.4.2




------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to