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 ******************************************************************/
33 #define EXIT_RET(err) \
42 void t_touch(const char *path)
46 fd = open(path, O_RDWR|O_CREAT, 0644);
48 printf("open(%s) error: %s\n", path, strerror(errno));
54 printf("close(%s) error: %s\n", path, strerror(errno));
59 /* XXX Now libsysio don't support mcreate */
60 void t_create(const char *path)
66 rc = mknod(path, S_IFREG | 0644, 0);
68 printf("mknod(%s) error: %s\n", path, strerror(errno));
74 void t_link(const char *src, const char *dst)
80 printf("link(%s -> %s) error: %s\n", src, dst, strerror(errno));
85 void t_unlink(const char *path)
91 printf("unlink(%s) error: %s\n", path, strerror(errno));
96 void t_mkdir(const char *path)
100 rc = mkdir(path, 00755);
102 printf("mkdir(%s) error: %s\n", path, strerror(errno));
107 void t_rmdir(const char *path)
113 printf("rmdir(%s) error: %s\n", path, strerror(errno));
118 void t_symlink(const char *src, const char *new)
122 rc = symlink(src, new);
124 printf("symlink(%s<-%s) error: %s\n", src, new, strerror(errno));
129 #define MKDEV(a,b) (((a) << 8) | (b))
130 void t_mknod(const char *path, mode_t mode, int major, int minor)
134 rc = mknod(path, mode, MKDEV(5, 4));
136 printf("mknod(%s) error: %s\n", path, strerror(errno));
141 void t_chmod_raw(const char *path, mode_t mode)
145 rc = chmod(path, mode);
147 printf("chmod(%s) error: %s\n", path, strerror(errno));
152 void t_chmod(const char *path, const char *format, ...)
156 void t_rename(const char *oldpath, const char *newpath)
160 rc = rename(oldpath, newpath);
162 printf("rename(%s -> %s) error: %s\n",
163 oldpath, newpath, strerror(errno));
168 int t_open_readonly(const char *path)
172 fd = open(path, O_RDONLY);
174 printf("open(%s) error: %s\n", path, strerror(errno));
180 int t_open(const char *path)
184 fd = open(path, O_RDWR | O_LARGEFILE);
186 printf("open(%s) error: %s\n", path, strerror(errno));
192 int t_chdir(const char *path)
194 int rc = chdir(path);
196 printf("chdir(%s) error: %s\n", path, strerror(errno));
202 int t_utime(const char *path, const struct utimbuf *buf)
204 int rc = utime(path, buf);
206 printf("utime(%s, %p) error: %s\n", path, buf,
213 int t_opendir(const char *path)
217 fd = open(path, O_RDONLY);
219 printf("opendir(%s) error: %s\n", path, strerror(errno));
231 printf("close(%d) error: %s\n", fd, strerror(errno));
236 int t_check_stat(const char *name, struct stat *buf)
241 memset(&stat, 0, sizeof(stat));
243 rc = lstat(name, &stat);
245 printf("error %d stat %s\n", rc, name);
249 memcpy(buf, &stat, sizeof(*buf));
250 if (stat.st_blksize == 0) {
251 printf("error: blksize is 0\n");
258 int t_check_stat_fail(const char *name)
263 rc = lstat(name, &stat);
265 printf("%s still exists\n", name);
272 void t_echo_create(const char *path, const char *str)
276 fd = open(path, O_RDWR|O_CREAT, 0644);
278 printf("open(%s) error: %s\n", path, strerror(errno));
282 if (write(fd, str, strlen(str)+1) != strlen(str)+1) {
283 printf("write(%s) error: %s\n", path, strerror(errno));
289 printf("close(%s) error: %s\n", path, strerror(errno));
294 static void _t_grep(const char *path, char *str, int should_contain)
300 fd = t_open_readonly(path);
301 if (lseek(fd, 0, SEEK_SET) == -1) {
302 printf("pread_once: seek to 0 error: %s\n", strerror(errno));
306 rc = read(fd, buf, 1023);
308 printf("grep: read error: %s\n", strerror(errno));
314 if ((strstr(buf, str) != 0) ^ should_contain) {
315 printf("grep: can't find string %s\n", str);
320 void t_grep(const char *path, char *str)
322 _t_grep(path, str, 1);
325 void t_grep_v(const char *path, char *str)
327 _t_grep(path, str, 0);
330 void t_ls(int fd, char *buf, int size)
336 printf("dir entries listing...\n");
337 while ((rc = getdirentries64(fd, buf, size, &base)) > 0) {
340 ent = (cfs_dirent_t *) ((char*) buf + pos);
341 printf("%s\n", ent->d_name);
342 pos += ent->d_reclen;
347 printf("getdents error %d\n", rc);
352 int t_fcntl(int fd, int cmd, ...)
365 printf("fcntl GETFL failed: %s\n",
371 arg = va_arg(ap, long);
373 rc = fcntl(fd, cmd, arg);
375 printf("fcntl SETFL %ld failed: %s\n",
376 arg, strerror(errno));
382 #if F_GETLK64 != F_GETLK
388 #if F_SETLK64 != F_SETLK
394 #if F_SETLKW64 != F_SETLKW
398 lock = va_arg(ap, struct flock *);
400 rc = fcntl(fd, cmd, lock);
402 printf("fcntl cmd %d failed: %s\n",
403 cmd, strerror(errno));
408 arg = va_arg(ap, long);
410 rc = fcntl(fd, cmd, arg);
412 printf("fcntl F_DUPFD %d failed: %s\n",
413 (int)arg, strerror(errno));
419 printf("fcntl cmd %d not supported\n", cmd);
425 char *safe_strncpy(char *dst, char *src, int max_size)
428 src_size=strlen(src);
429 if (src_size >= max_size) {
432 memcpy(dst, src, src_size);