1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
17 #include <liblustre.h>
19 #include "test_common.h"
23 /******************************************************************
25 ******************************************************************/
37 #define EXIT_RET(err) \
46 void t_touch(const char *path)
50 fd = open(path, O_RDWR|O_CREAT, 0644);
52 printf("open(%s) error: %s\n", path, strerror(errno));
58 printf("close(%s) error: %s\n", path, strerror(errno));
63 /* XXX Now libsysio don't support mcreate */
64 void t_create(const char *path)
70 rc = mknod(path, S_IFREG | 0644, 0);
72 printf("mknod(%s) error: %s\n", path, strerror(errno));
78 void t_link(const char *src, const char *dst)
84 printf("link(%s -> %s) error: %s\n", src, dst, strerror(errno));
89 void t_unlink(const char *path)
95 printf("unlink(%s) error: %s\n", path, strerror(errno));
100 void t_mkdir(const char *path)
104 rc = mkdir(path, 00755);
106 printf("mkdir(%s) error: %s\n", path, strerror(errno));
111 void t_rmdir(const char *path)
117 printf("rmdir(%s) error: %s\n", path, strerror(errno));
122 void t_symlink(const char *src, const char *new)
126 rc = symlink(src, new);
128 printf("symlink(%s<-%s) error: %s\n", src, new, strerror(errno));
133 #define MKDEV(a,b) (((a) << 8) | (b))
134 void t_mknod(const char *path, mode_t mode, int major, int minor)
138 rc = mknod(path, mode, MKDEV(5, 4));
140 printf("mknod(%s) error: %s\n", path, strerror(errno));
145 void t_chmod_raw(const char *path, mode_t mode)
149 rc = chmod(path, mode);
151 printf("chmod(%s) error: %s\n", path, strerror(errno));
156 void t_chmod(const char *path, const char *format, ...)
160 void t_rename(const char *oldpath, const char *newpath)
164 rc = rename(oldpath, newpath);
166 printf("rename(%s -> %s) error: %s\n",
167 oldpath, newpath, strerror(errno));
172 int t_open_readonly(const char *path)
176 fd = open(path, O_RDONLY);
178 printf("open(%s) error: %s\n", path, strerror(errno));
184 int t_open(const char *path)
188 fd = open(path, O_RDWR | O_LARGEFILE);
190 printf("open(%s) error: %s\n", path, strerror(errno));
196 int t_chdir(const char *path)
198 int rc = chdir(path);
200 printf("chdir(%s) error: %s\n", path, strerror(errno));
206 int t_utime(const char *path, const struct utimbuf *buf)
208 int rc = utime(path, buf);
210 printf("utime(%s, %p) error: %s\n", path, buf,
217 int t_opendir(const char *path)
221 fd = open(path, O_RDONLY);
223 printf("opendir(%s) error: %s\n", path, strerror(errno));
235 printf("close(%d) error: %s\n", fd, strerror(errno));
240 int t_check_stat(const char *name, struct stat *buf)
245 memset(&stat, 0, sizeof(stat));
247 rc = lstat(name, &stat);
249 printf("error %d stat %s\n", rc, name);
253 memcpy(buf, &stat, sizeof(*buf));
254 if (stat.st_blksize == 0) {
255 printf("error: blksize is 0\n");
262 int t_check_stat_fail(const char *name)
267 rc = lstat(name, &stat);
269 printf("%s still exists\n", name);
276 void t_echo_create(const char *path, const char *str)
280 fd = open(path, O_RDWR|O_CREAT, 0644);
282 printf("open(%s) error: %s\n", path, strerror(errno));
286 if (write(fd, str, strlen(str)+1) != strlen(str)+1) {
287 printf("write(%s) error: %s\n", path, strerror(errno));
293 printf("close(%s) error: %s\n", path, strerror(errno));
298 static void _t_grep(const char *path, char *str, int should_contain)
304 fd = t_open_readonly(path);
305 if (lseek(fd, 0, SEEK_SET) == -1) {
306 printf("pread_once: seek to 0 error: %s\n", strerror(errno));
310 rc = read(fd, buf, 1023);
312 printf("grep: read error: %s\n", strerror(errno));
318 if ((strstr(buf, str) != 0) ^ should_contain) {
319 printf("grep: can't find string %s\n", str);
324 void t_grep(const char *path, char *str)
326 _t_grep(path, str, 1);
329 void t_grep_v(const char *path, char *str)
331 _t_grep(path, str, 0);
334 void t_ls(int fd, char *buf, int size)
340 printf("dir entries listing...\n");
341 while ((rc = getdirentries64(fd, buf, size, &base)) > 0) {
344 ent = (cfs_dirent_t *) ((char*) buf + pos);
345 printf("%s\n", ent->d_name);
346 pos += ent->d_reclen;
351 printf("getdents error %d\n", rc);
356 int t_fcntl(int fd, int cmd, ...)
369 printf("fcntl GETFL failed: %s\n",
375 arg = va_arg(ap, long);
377 rc = fcntl(fd, cmd, arg);
379 printf("fcntl SETFL %ld failed: %s\n",
380 arg, strerror(errno));
386 #if F_GETLK64 != F_GETLK
392 #if F_SETLK64 != F_SETLK
398 #if F_SETLKW64 != F_SETLKW
402 lock = va_arg(ap, struct flock *);
404 rc = fcntl(fd, cmd, lock);
406 printf("fcntl cmd %d failed: %s\n",
407 cmd, strerror(errno));
412 arg = va_arg(ap, long);
414 rc = fcntl(fd, cmd, arg);
416 printf("fcntl F_DUPFD %d failed: %s\n",
417 (int)arg, strerror(errno));
423 printf("fcntl cmd %d not supported\n", cmd);
429 char *safe_strncpy(char *dst, char *src, int max_size)
432 src_size=strlen(src);
433 if (src_size >= max_size) {
436 memcpy(dst, src, src_size);