diff options
Diffstat (limited to 'testcases/kernel/syscalls/access/access04.c')
-rw-r--r-- | testcases/kernel/syscalls/access/access04.c | 71 |
1 files changed, 44 insertions, 27 deletions
diff --git a/testcases/kernel/syscalls/access/access04.c b/testcases/kernel/syscalls/access/access04.c index 2d6dd70e8..b5764a5dd 100644 --- a/testcases/kernel/syscalls/access/access04.c +++ b/testcases/kernel/syscalls/access/access04.c @@ -2,26 +2,27 @@ /* * Copyright (c) International Business Machines Corp., 2001 * Copyright (c) 2013 Fujitsu Ltd. + * Copyright (c) Linux Test Project, 2003-2023 + * Ported to LTP: Wayne Boyer + * 11/2013 Ported by Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com> + * 11/2016 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com> */ -/* - * Verify that, - * 1) access() fails with -1 return value and sets errno to EINVAL - * if the specified access mode argument is invalid. - * 2) access() fails with -1 return value and sets errno to ENOENT - * if the specified file doesn't exist (or pathname is NULL). - * 3) access() fails with -1 return value and sets errno to ENAMETOOLONG - * if the pathname size is > PATH_MAX characters. - * 4) access() fails with -1 return value and sets errno to ENOTDIR - * if a component used as a directory in pathname is not a directory. - * 5) access() fails with -1 return value and sets errno to ELOOP - * if too many symbolic links were encountered in resolving pathname. - * 6) access() fails with -1 return value and sets errno to EROFS - * if write permission was requested for files on a read-only file system. +/*\ + * [Description] * - * Ported to LTP: Wayne Boyer - * 11/2013 Ported by Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com> - * 11/2016 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com> + * - access() fails with -1 return value and sets errno to EINVAL + * if the specified access mode argument is invalid. + * - access() fails with -1 return value and sets errno to ENOENT + * if the specified file doesn't exist (or pathname is NULL). + * - access() fails with -1 return value and sets errno to ENAMETOOLONG + * if the pathname size is > PATH_MAX characters. + * - access() fails with -1 return value and sets errno to ENOTDIR + * if a component used as a directory in pathname is not a directory. + * - access() fails with -1 return value and sets errno to ELOOP + * if too many symbolic links were encountered in resolving pathname. + * - access() fails with -1 return value and sets errno to EROFS + * if write permission was requested for files on a read-only file system. */ #include <errno.h> @@ -39,26 +40,32 @@ #define SNAME1 "symlink1" #define SNAME2 "symlink2" #define MNT_POINT "mntpoint" +#define LONGPATHSIZE (PATH_MAX + 2) static uid_t uid; -static char longpathname[PATH_MAX + 2]; +static char *longpathname; +static char *fname1; +static char *fname2; +static char *sname1; +static char *empty_fname; +static char *mnt_point; static struct tcase { - const char *pathname; + char **pathname; int mode; int exp_errno; } tcases[] = { - {FNAME1, -1, EINVAL}, - {"", W_OK, ENOENT}, - {longpathname, R_OK, ENAMETOOLONG}, - {FNAME2, R_OK, ENOTDIR}, - {SNAME1, R_OK, ELOOP}, - {MNT_POINT, W_OK, EROFS} + {&fname1, -1, EINVAL}, + {&empty_fname, W_OK, ENOENT}, + {&longpathname, R_OK, ENAMETOOLONG}, + {&fname2, R_OK, ENOTDIR}, + {&sname1, R_OK, ELOOP}, + {&mnt_point, W_OK, EROFS} }; static void access_test(struct tcase *tc, const char *user) { - TST_EXP_FAIL(access(tc->pathname, tc->mode), tc->exp_errno, + TST_EXP_FAIL(access(*tc->pathname, tc->mode), tc->exp_errno, "access as %s", user); } @@ -86,7 +93,8 @@ static void setup(void) uid = pw->pw_uid; - memset(longpathname, 'a', sizeof(longpathname) - 1); + memset(longpathname, 'a', LONGPATHSIZE - 1); + longpathname[LONGPATHSIZE-1] = 0; SAFE_TOUCH(FNAME1, 0333, NULL); SAFE_TOUCH(DNAME, 0644, NULL); @@ -103,4 +111,13 @@ static struct tst_test test = { .mntpoint = MNT_POINT, .setup = setup, .test = verify_access, + .bufs = (struct tst_buffers []) { + {&fname1, .str = FNAME1}, + {&fname2, .str = FNAME2}, + {&sname1, .str = SNAME1}, + {&empty_fname, .str = ""}, + {&longpathname, .size = LONGPATHSIZE}, + {&mnt_point, .str = MNT_POINT}, + {} + } }; |