1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
17 #include "test_common.h"
21 /******************************************************************
23 ******************************************************************/
31 #define EXIT_RET(err) \
40 void t_touch(const char *path)
44 fd = open(path, O_RDWR|O_CREAT, 0644);
46 printf("open(%s) error: %s\n", path, strerror(errno));
52 printf("close(%s) error: %s\n", path, strerror(errno));
57 /* XXX Now libsysio don't support mcreate */
58 void t_create(const char *path)
64 rc = mknod(path, S_IFREG | 0644, 0);
66 printf("mknod(%s) error: %s\n", path, strerror(errno));
72 void t_link(const char *src, const char *dst)
78 printf("link(%s -> %s) error: %s\n", src, dst, strerror(errno));
83 void t_unlink(const char *path)
89 printf("unlink(%s) error: %s\n", path, strerror(errno));
94 void t_mkdir(const char *path)
98 rc = mkdir(path, 00755);
100 printf("mkdir(%s) error: %s\n", path, strerror(errno));
105 void t_rmdir(const char *path)
111 printf("rmdir(%s) error: %s\n", path, strerror(errno));
116 void t_symlink(const char *src, const char *new)
120 rc = symlink(src, new);
122 printf("symlink(%s<-%s) error: %s\n", src, new, strerror(errno));
127 #define MKDEV(a,b) (((a) << 8) | (b))
128 void t_mknod(const char *path, mode_t mode, int major, int minor)
132 rc = mknod(path, mode, MKDEV(5, 4));
134 printf("mknod(%s) error: %s\n", path, strerror(errno));
139 void t_chmod_raw(const char *path, mode_t mode)
143 rc = chmod(path, mode);
145 printf("chmod(%s) error: %s\n", path, strerror(errno));
150 void t_chmod(const char *path, const char *format, ...)
154 void t_rename(const char *oldpath, const char *newpath)
158 rc = rename(oldpath, newpath);
160 printf("rename(%s -> %s) error: %s\n",
161 oldpath, newpath, strerror(errno));
166 int t_open_readonly(const char *path)
170 fd = open(path, O_RDONLY);
172 printf("open(%s) error: %s\n", path, strerror(errno));
178 int t_open(const char *path)
182 fd = open(path, O_RDWR | O_LARGEFILE);
184 printf("open(%s) error: %s\n", path, strerror(errno));
190 int t_chdir(const char *path)
192 int rc = chdir(path);
194 printf("chdir(%s) error: %s\n", path, strerror(errno));
200 int t_utime(const char *path, const struct utimbuf *buf)
202 int rc = utime(path, buf);
204 printf("utime(%s, %p) error: %s\n", path, buf,
211 int t_opendir(const char *path)
215 fd = open(path, O_RDONLY);
217 printf("opendir(%s) error: %s\n", path, strerror(errno));
229 printf("close(%d) error: %s\n", fd, strerror(errno));
234 int t_check_stat(const char *name, struct stat *buf)
239 memset(&stat, 0, sizeof(stat));
241 rc = lstat(name, &stat);
243 printf("error %d stat %s\n", rc, name);
247 memcpy(buf, &stat, sizeof(*buf));
248 if (stat.st_blksize == 0) {
249 printf("error: blksize is 0\n");
256 int t_check_stat_fail(const char *name)
261 rc = lstat(name, &stat);
263 printf("%s still exists\n", name);
270 void t_echo_create(const char *path, const char *str)
274 fd = open(path, O_RDWR|O_CREAT, 0644);
276 printf("open(%s) error: %s\n", path, strerror(errno));
280 if (write(fd, str, strlen(str)+1) != strlen(str)+1) {
281 printf("write(%s) error: %s\n", path, strerror(errno));
287 printf("close(%s) error: %s\n", path, strerror(errno));
292 static void _t_grep(const char *path, char *str, int should_contain)
298 fd = t_open_readonly(path);
299 if (lseek(fd, 0, SEEK_SET) == -1) {
300 printf("pread_once: seek to 0 error: %s\n", strerror(errno));
304 rc = read(fd, buf, 1023);
306 printf("grep: read error: %s\n", strerror(errno));
312 if ((strstr(buf, str) != 0) ^ should_contain) {
313 printf("grep: can't find string %s\n", str);
318 void t_grep(const char *path, char *str)
320 _t_grep(path, str, 1);
323 void t_grep_v(const char *path, char *str)
325 _t_grep(path, str, 0);
328 void t_ls(int fd, char *buf, int size)
330 struct dirent64 *ent;
334 printf("dir entries listing...\n");
335 while ((rc = getdirentries64(fd, buf, size, &base)) > 0) {
338 ent = (struct dirent64 *) ((char*) buf + pos);
339 printf("%s\n", ent->d_name);
340 pos += ent->d_reclen;
345 printf("getdents error %d\n", rc);
350 int t_fcntl(int fd, int cmd, ...)
363 printf("fcntl GETFL failed: %s\n",
369 arg = va_arg(ap, long);
371 rc = fcntl(fd, cmd, arg);
373 printf("fcntl SETFL %ld failed: %s\n",
374 arg, strerror(errno));
380 #if F_GETLK64 != F_GETLK
386 #if F_SETLK64 != F_SETLK
392 #if F_SETLKW64 != F_SETLKW
396 lock = va_arg(ap, struct flock *);
398 rc = fcntl(fd, cmd, lock);
400 printf("fcntl cmd %d failed: %s\n",
401 cmd, strerror(errno));
406 arg = va_arg(ap, long);
408 rc = fcntl(fd, cmd, arg);
410 printf("fcntl F_DUPFD %d failed: %s\n",
411 (int)arg, strerror(errno));
417 printf("fcntl cmd %d not supported\n", cmd);
423 char *safe_strncpy(char *dst, char *src, int max_size)
426 src_size=strlen(src);
427 if (src_size >= max_size) {
430 memcpy(dst, src, src_size);