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 | 57 ++++++++++++++++++++++++++++-
 4 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/runtest/ltplite b/runtest/ltplite
index c90bc48..c553746 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -189,7 +189,7 @@ fchmod07 fchmod07
 fchown01 fchown01
 fchown02 fchown02
 fchown03 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;fchown03
-fchown04 export change_owner=$LTPROOT/testcases/bin/change_owner;fchown04
+fchown04 fchown04 -D DEVICE -T DEVICE_FS_TYPE
 fchown05 fchown05
 
 fcntl01 fcntl01
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index eac28d0..90cd030 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -130,7 +130,7 @@ fchmod07 fchmod07
 fchown01 fchown01
 fchown02 fchown02
 fchown03 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;fchown03
-fchown04 export change_owner=$LTPROOT/testcases/bin/change_owner;fchown04
+fchown04 fchown04 -D DEVICE -T DEVICE_FS_TYPE
 fchown05 fchown05
 
 fcntl01 fcntl01
diff --git a/runtest/syscalls b/runtest/syscalls
index c5bbe8f..d7b93f2 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -185,8 +185,8 @@ fchown02 fchown02
 fchown02_16 fchown02_16
 fchown03 fchown03
 fchown03_16 fchown03_16
-fchown04 fchown04
-fchown04_16 fchown04_16
+fchown04 fchown04 -D DEVICE -T DEVICE_FS_TYPE
+fchown04_16 fchown04_16 -D DEVICE -T DEVICE_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 75a7ca0..0a79624 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,28 @@
 #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;
+static int fd3;
+static char *fstype = "ext2";
+static char *device;
+static int dflag;
+static int mount_flag;
+
+static option_t options[] = {
+       {"T:", NULL, &fstype},
+       {"D:", &dflag, &device},
+       {NULL, NULL, NULL}
+};
 
 static struct test_case_t {
        int *fd;
@@ -53,15 +69,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 +87,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 (!dflag) {
+               tst_brkm(TBROK, NULL,
+                        "you must specify the device used for mounting with "
+                        "-D option");
+       }
+
        setup();
 
        TEST_EXP_ENOS(exp_enos);
@@ -107,6 +131,21 @@ static void setup(void)
 
        fd2 = -1;
 
+       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);
 }
@@ -137,5 +176,19 @@ static void cleanup(void)
 
        SAFE_CLOSE(NULL, fd1);
 
+       SAFE_CLOSE(NULL, fd3);
+
+       if (mount_flag && umount("mntpoint") < 0) {
+               tst_brkm(TBROK | TERRNO, NULL,
+                        "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




------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to