1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 #include <sys/types.h>
49 #include <liblustre.h>
51 #include "test_common.h"
55 /******************************************************************
57 ******************************************************************/
69 #define EXIT_RET(err) \
78 void t_touch(const char *path)
82 fd = open(path, O_RDWR|O_CREAT, 0644);
84 printf("open(%s) error: %s\n", path, strerror(errno));
90 printf("close(%s) error: %s\n", path, strerror(errno));
95 /* XXX Now libsysio don't support mcreate */
96 void t_create(const char *path)
102 rc = mknod(path, S_IFREG | 0644, 0);
104 printf("mknod(%s) error: %s\n", path, strerror(errno));
110 void t_link(const char *src, const char *dst)
116 printf("link(%s -> %s) error: %s\n", src, dst, strerror(errno));
121 void t_unlink(const char *path)
127 printf("unlink(%s) error: %s\n", path, strerror(errno));
132 void t_mkdir(const char *path)
136 rc = mkdir(path, 00755);
138 printf("mkdir(%s) error: %s\n", path, strerror(errno));
143 void t_rmdir(const char *path)
149 printf("rmdir(%s) error: %s\n", path, strerror(errno));
154 void t_symlink(const char *src, const char *new)
158 rc = symlink(src, new);
160 printf("symlink(%s<-%s) error: %s\n", src, new, strerror(errno));
165 #define MKDEV(a,b) (((a) << 8) | (b))
166 void t_mknod(const char *path, mode_t mode, int major, int minor)
170 rc = mknod(path, mode, MKDEV(5, 4));
172 printf("mknod(%s) error: %s\n", path, strerror(errno));
177 void t_chmod_raw(const char *path, mode_t mode)
181 rc = chmod(path, mode);
183 printf("chmod(%s) error: %s\n", path, strerror(errno));
188 void t_chmod(const char *path, const char *format, ...)
192 void t_rename(const char *oldpath, const char *newpath)
196 rc = rename(oldpath, newpath);
198 printf("rename(%s -> %s) error: %s\n",
199 oldpath, newpath, strerror(errno));
204 int t_open_readonly(const char *path)
208 fd = open(path, O_RDONLY);
210 printf("open(%s) error: %s\n", path, strerror(errno));
216 int t_open(const char *path)
220 fd = open(path, O_RDWR | O_LARGEFILE);
222 printf("open(%s) error: %s\n", path, strerror(errno));
228 int t_chdir(const char *path)
230 int rc = chdir(path);
232 printf("chdir(%s) error: %s\n", path, strerror(errno));
238 int t_utime(const char *path, const struct utimbuf *buf)
240 int rc = utime(path, buf);
242 printf("utime(%s, %p) error: %s\n", path, buf,
249 int t_opendir(const char *path)
253 fd = open(path, O_RDONLY);
255 printf("opendir(%s) error: %s\n", path, strerror(errno));
267 printf("close(%d) error: %s\n", fd, strerror(errno));
272 int t_check_stat(const char *name, struct stat *buf)
277 memset(&stat, 0, sizeof(stat));
279 rc = lstat(name, &stat);
281 printf("error %d stat %s\n", rc, name);
285 memcpy(buf, &stat, sizeof(*buf));
286 if (stat.st_blksize == 0) {
287 printf("error: blksize is 0\n");
294 int t_check_stat_fail(const char *name)
299 rc = lstat(name, &stat);
301 printf("%s still exists\n", name);
308 void t_echo_create(const char *path, const char *str)
312 fd = open(path, O_RDWR|O_CREAT, 0644);
314 printf("open(%s) error: %s\n", path, strerror(errno));
318 if (write(fd, str, strlen(str)+1) != strlen(str)+1) {
319 printf("write(%s) error: %s\n", path, strerror(errno));
325 printf("close(%s) error: %s\n", path, strerror(errno));
330 static void _t_grep(const char *path, char *str, int should_contain)
336 fd = t_open_readonly(path);
337 if (lseek(fd, 0, SEEK_SET) == -1) {
338 printf("pread_once: seek to 0 error: %s\n", strerror(errno));
342 rc = read(fd, buf, 1023);
344 printf("grep: read error: %s\n", strerror(errno));
350 if ((strstr(buf, str) != 0) ^ should_contain) {
351 printf("grep: can't find string %s\n", str);
356 void t_grep(const char *path, char *str)
358 _t_grep(path, str, 1);
361 void t_grep_v(const char *path, char *str)
363 _t_grep(path, str, 0);
366 void t_ls(int fd, char *buf, int size)
372 printf("dir entries listing...\n");
373 while ((rc = getdirentries64(fd, buf, size, &base)) > 0) {
376 ent = (cfs_dirent_t *) ((char*) buf + pos);
377 printf("%s\n", ent->d_name);
378 pos += ent->d_reclen;
383 printf("getdents error %d\n", rc);
388 int t_fcntl(int fd, int cmd, ...)
401 printf("fcntl GETFL failed: %s\n",
407 arg = va_arg(ap, long);
409 rc = fcntl(fd, cmd, arg);
411 printf("fcntl SETFL %ld failed: %s\n",
412 arg, strerror(errno));
418 #if F_GETLK64 != F_GETLK
424 #if F_SETLK64 != F_SETLK
430 #if F_SETLKW64 != F_SETLKW
434 lock = va_arg(ap, struct flock *);
436 rc = fcntl(fd, cmd, lock);
438 printf("fcntl cmd %d failed: %s\n",
439 cmd, strerror(errno));
444 arg = va_arg(ap, long);
446 rc = fcntl(fd, cmd, arg);
448 printf("fcntl F_DUPFD %d failed: %s\n",
449 (int)arg, strerror(errno));
455 printf("fcntl cmd %d not supported\n", cmd);
461 char *safe_strncpy(char *dst, char *src, int max_size)
464 src_size=strlen(src);
465 if (src_size >= max_size) {
468 memcpy(dst, src, src_size);