1 /* 2 * Copyright (c) 2016 Fujitsu Ltd. 3 * Author: Xiao Yang <yangx.jy (at) cn.fujitsu.com> 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it would be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 * 13 * You should have received a copy of the GNU General Public License 14 * alone with this program. 15 */ 16 17 /* 18 * Test Name: removexattr02 19 * 20 * Description: 21 * 1) removexattr(2) fails if the named attribute does not exist. 22 * 2) removexattr(2) fails if path is an empty string. 23 * 3) removexattr(2) fails when attempted to read from a invalid address. 24 * 25 * Expected Result: 26 * 1) removexattr(2) should return -1 and set errno to ENOATTR. 27 * 2) removcxattr(2) should return -1 and set errno to ENOENT. 28 * 3) removexattr(2) should return -1 and set errno to EFAULT. 29 */ 30 31 #include "config.h" 32 #include <errno.h> 33 #include <sys/types.h> 34 35 #ifdef HAVE_ATTR_XATTR_H 36 #include <attr/xattr.h> 37 #endif 38 39 #include "test.h" 40 #include "safe_macros.h" 41 42 char *TCID = "removexattr02"; 43 44 #ifdef HAVE_ATTR_XATTR_H 45 46 static struct test_case { 47 const char *path; 48 char *name; 49 int exp_err; 50 } tc[] = { 51 /* test1 */ 52 {"testfile", "user.test", ENOATTR}, 53 /* test2 */ 54 {"", "user.test", ENOENT}, 55 /* test3 */ 56 {(char *)-1, "user.test", EFAULT} 57 }; 58 59 static void verify_removexattr(struct test_case *tc); 60 static void setup(void); 61 static void cleanup(void); 62 63 int TST_TOTAL = ARRAY_SIZE(tc); 64 65 int main(int ac, char **av) 66 { 67 int lc; 68 int i; 69 70 tst_parse_opts(ac, av, NULL, NULL); 71 72 setup(); 73 74 for (lc = 0; TEST_LOOPING(lc); lc++) { 75 tst_count = 0; 76 for (i = 0; i < TST_TOTAL; i++) 77 verify_removexattr(&tc[i]); 78 } 79 80 cleanup(); 81 tst_exit(); 82 } 83 84 static void verify_removexattr(struct test_case *tc) 85 { 86 87 TEST(removexattr(tc->path, tc->name)); 88 if (TEST_RETURN == -1 && TEST_ERRNO == ENOTSUP) { 89 tst_brkm(TCONF, cleanup, "No xattr support in fs or " 90 "mount without user_xattr option"); 91 } 92 93 if (TEST_RETURN != -1) { 94 tst_resm(TFAIL, "removexattr() succeeded unexpectedly"); 95 return; 96 } 97 98 if (TEST_ERRNO != tc->exp_err) { 99 tst_resm(TFAIL | TTERRNO, "removexattr() failed unexpectedly," 100 " expected %s", tst_strerrno(tc->exp_err)); 101 } else { 102 tst_resm(TPASS | TTERRNO, 103 "removexattr() failed as expected"); 104 } 105 } 106 107 static void setup(void) 108 { 109 tst_sig(NOFORK, DEF_HANDLER, cleanup); 110 111 TEST_PAUSE; 112 113 tst_tmpdir(); 114 115 SAFE_TOUCH(cleanup, "testfile", 0644, NULL); 116 } 117 118 static void cleanup(void) 119 { 120 tst_rmdir(); 121 } 122 123 #else /* HAVE_ATTR_XATTR_H */ 124 int main(int ac, char **av) 125 { 126 tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist."); 127 } 128 #endif 129