4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
36 #include <sys/types.h>
47 #include <liblustre.h>
49 #include "test_common.h"
53 /******************************************************************
55 ******************************************************************/
67 #define EXIT_RET(err) \
76 void t_touch(const char *path)
80 fd = open(path, O_RDWR|O_CREAT, 0644);
82 printf("open(%s) error: %s\n", path, strerror(errno));
88 printf("close(%s) error: %s\n", path, strerror(errno));
93 /* XXX Now libsysio don't support mcreate */
94 void t_create(const char *path)
100 rc = mknod(path, S_IFREG | 0644, 0);
102 printf("mknod(%s) error: %s\n", path, strerror(errno));
108 void t_link(const char *src, const char *dst)
114 printf("link(%s -> %s) error: %s\n", src, dst, strerror(errno));
119 void t_unlink(const char *path)
125 printf("unlink(%s) error: %s\n", path, strerror(errno));
130 void t_mkdir(const char *path)
134 rc = mkdir(path, 00755);
136 printf("mkdir(%s) error: %s\n", path, strerror(errno));
141 void t_rmdir(const char *path)
147 printf("rmdir(%s) error: %s\n", path, strerror(errno));
152 void t_symlink(const char *src, const char *new)
156 rc = symlink(src, new);
158 printf("symlink(%s<-%s) error: %s\n", src, new, strerror(errno));
163 #define MKDEV(a,b) (((a) << 8) | (b))
164 void t_mknod(const char *path, mode_t mode, int major, int minor)
168 rc = mknod(path, mode, MKDEV(5, 4));
170 printf("mknod(%s) error: %s\n", path, strerror(errno));
175 void t_chmod_raw(const char *path, mode_t mode)
179 rc = chmod(path, mode);
181 printf("chmod(%s) error: %s\n", path, strerror(errno));
186 void t_chmod(const char *path, const char *format, ...)
190 void t_rename(const char *oldpath, const char *newpath)
194 rc = rename(oldpath, newpath);
196 printf("rename(%s -> %s) error: %s\n",
197 oldpath, newpath, strerror(errno));
202 int t_open_readonly(const char *path)
206 fd = open(path, O_RDONLY);
208 printf("open(%s) error: %s\n", path, strerror(errno));
214 int t_open(const char *path)
218 fd = open(path, O_RDWR | O_LARGEFILE);
220 printf("open(%s) error: %s\n", path, strerror(errno));
226 int t_chdir(const char *path)
228 int rc = chdir(path);
230 printf("chdir(%s) error: %s\n", path, strerror(errno));
236 int t_utime(const char *path, const struct utimbuf *buf)
238 int rc = utime(path, buf);
240 printf("utime(%s, %p) error: %s\n", path, buf,
247 int t_opendir(const char *path)
251 fd = open(path, O_RDONLY);
253 printf("opendir(%s) error: %s\n", path, strerror(errno));
265 printf("close(%d) error: %s\n", fd, strerror(errno));
270 int t_check_stat(const char *name, struct stat *buf)
275 memset(&stat, 0, sizeof(stat));
277 rc = lstat(name, &stat);
279 printf("error %d stat %s\n", rc, name);
283 memcpy(buf, &stat, sizeof(*buf));
284 if (stat.st_blksize == 0) {
285 printf("error: blksize is 0\n");
292 int t_check_stat_fail(const char *name)
297 rc = lstat(name, &stat);
299 printf("%s still exists\n", name);
306 void t_echo_create(const char *path, const char *str)
310 fd = open(path, O_RDWR|O_CREAT, 0644);
312 printf("open(%s) error: %s\n", path, strerror(errno));
316 if (write(fd, str, strlen(str)+1) != strlen(str)+1) {
317 printf("write(%s) error: %s\n", path, strerror(errno));
323 printf("close(%s) error: %s\n", path, strerror(errno));
328 static void _t_grep(const char *path, char *str, int should_contain)
334 fd = t_open_readonly(path);
335 if (lseek(fd, 0, SEEK_SET) == -1) {
336 printf("pread_once: seek to 0 error: %s\n", strerror(errno));
340 rc = read(fd, buf, 1023);
342 printf("grep: read error: %s\n", strerror(errno));
348 if ((strstr(buf, str) != 0) ^ should_contain) {
349 printf("grep: can't find string %s\n", str);
354 void t_grep(const char *path, char *str)
356 _t_grep(path, str, 1);
359 void t_grep_v(const char *path, char *str)
361 _t_grep(path, str, 0);
364 void t_ls(int fd, char *buf, int size)
366 struct dirent64 *ent;
370 printf("dir entries listing...\n");
371 while ((rc = getdirentries64(fd, buf, size, &base)) > 0) {
374 ent = (struct dirent64 *)((char *)buf + pos);
375 printf("%s\n", ent->d_name);
376 pos += ent->d_reclen;
381 printf("getdents error %d\n", rc);
386 int t_fcntl(int fd, int cmd, ...)
399 printf("fcntl GETFL failed: %s\n",
405 arg = va_arg(ap, long);
407 rc = fcntl(fd, cmd, arg);
409 printf("fcntl SETFL %ld failed: %s\n",
410 arg, strerror(errno));
416 #if F_GETLK64 != F_GETLK
422 #if F_SETLK64 != F_SETLK
428 #if F_SETLKW64 != F_SETLKW
432 lock = va_arg(ap, struct flock *);
434 rc = fcntl(fd, cmd, lock);
436 printf("fcntl cmd %d failed: %s\n",
437 cmd, strerror(errno));
442 arg = va_arg(ap, long);
444 rc = fcntl(fd, cmd, arg);
446 printf("fcntl F_DUPFD %d failed: %s\n",
447 (int)arg, strerror(errno));
453 printf("fcntl cmd %d not supported\n", cmd);
459 char *safe_strncpy(char *dst, char *src, int max_size)
462 src_size=strlen(src);
463 if (src_size >= max_size) {
466 memcpy(dst, src, src_size);