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 "test_common.h"
53 /******************************************************************
55 ******************************************************************/
63 #define EXIT_RET(err) \
72 void t_touch(const char *path)
76 fd = open(path, O_RDWR|O_CREAT, 0644);
78 printf("open(%s) error: %s\n", path, strerror(errno));
84 printf("close(%s) error: %s\n", path, strerror(errno));
89 /* XXX Now libsysio don't support mcreate */
90 void t_create(const char *path)
96 rc = mknod(path, S_IFREG | 0644, 0);
98 printf("mknod(%s) error: %s\n", path, strerror(errno));
104 void t_link(const char *src, const char *dst)
110 printf("link(%s -> %s) error: %s\n", src, dst, strerror(errno));
115 void t_unlink(const char *path)
121 printf("unlink(%s) error: %s\n", path, strerror(errno));
126 void t_mkdir(const char *path)
130 rc = mkdir(path, 00755);
132 printf("mkdir(%s) error: %s\n", path, strerror(errno));
137 void t_rmdir(const char *path)
143 printf("rmdir(%s) error: %s\n", path, strerror(errno));
148 void t_symlink(const char *src, const char *new)
152 rc = symlink(src, new);
154 printf("symlink(%s<-%s) error: %s\n", src, new, strerror(errno));
159 #define MKDEV(a,b) (((a) << 8) | (b))
160 void t_mknod(const char *path, mode_t mode, int major, int minor)
164 rc = mknod(path, mode, MKDEV(5, 4));
166 printf("mknod(%s) error: %s\n", path, strerror(errno));
171 void t_chmod_raw(const char *path, mode_t mode)
175 rc = chmod(path, mode);
177 printf("chmod(%s) error: %s\n", path, strerror(errno));
182 void t_chmod(const char *path, const char *format, ...)
186 void t_rename(const char *oldpath, const char *newpath)
190 rc = rename(oldpath, newpath);
192 printf("rename(%s -> %s) error: %s\n",
193 oldpath, newpath, strerror(errno));
198 int t_open_readonly(const char *path)
202 fd = open(path, O_RDONLY);
204 printf("open(%s) error: %s\n", path, strerror(errno));
210 int t_open(const char *path)
214 fd = open(path, O_RDWR | O_LARGEFILE);
216 printf("open(%s) error: %s\n", path, strerror(errno));
222 int t_chdir(const char *path)
224 int rc = chdir(path);
226 printf("chdir(%s) error: %s\n", path, strerror(errno));
232 int t_utime(const char *path, const struct utimbuf *buf)
234 int rc = utime(path, buf);
236 printf("utime(%s, %p) error: %s\n", path, buf,
243 int t_opendir(const char *path)
247 fd = open(path, O_RDONLY);
249 printf("opendir(%s) error: %s\n", path, strerror(errno));
261 printf("close(%d) error: %s\n", fd, strerror(errno));
266 int t_check_stat(const char *name, struct stat *buf)
271 memset(&stat, 0, sizeof(stat));
273 rc = lstat(name, &stat);
275 printf("error %d stat %s\n", rc, name);
279 memcpy(buf, &stat, sizeof(*buf));
280 if (stat.st_blksize == 0) {
281 printf("error: blksize is 0\n");
288 int t_check_stat_fail(const char *name)
293 rc = lstat(name, &stat);
295 printf("%s still exists\n", name);
302 void t_echo_create(const char *path, const char *str)
306 fd = open(path, O_RDWR|O_CREAT, 0644);
308 printf("open(%s) error: %s\n", path, strerror(errno));
312 if (write(fd, str, strlen(str)+1) != strlen(str)+1) {
313 printf("write(%s) error: %s\n", path, strerror(errno));
319 printf("close(%s) error: %s\n", path, strerror(errno));
324 static void _t_grep(const char *path, char *str, int should_contain)
330 fd = t_open_readonly(path);
331 if (lseek(fd, 0, SEEK_SET) == -1) {
332 printf("pread_once: seek to 0 error: %s\n", strerror(errno));
336 rc = read(fd, buf, 1023);
338 printf("grep: read error: %s\n", strerror(errno));
344 if ((strstr(buf, str) != 0) ^ should_contain) {
345 printf("grep: can't find string %s\n", str);
350 void t_grep(const char *path, char *str)
352 _t_grep(path, str, 1);
355 void t_grep_v(const char *path, char *str)
357 _t_grep(path, str, 0);
360 void t_ls(int fd, char *buf, int size)
362 struct dirent64 *ent;
366 printf("dir entries listing...\n");
367 while ((rc = getdirentries64(fd, buf, size, &base)) > 0) {
370 ent = (struct dirent64 *) ((char*) buf + pos);
371 printf("%s\n", ent->d_name);
372 pos += ent->d_reclen;
377 printf("getdents error %d\n", rc);
382 int t_fcntl(int fd, int cmd, ...)
395 printf("fcntl GETFL failed: %s\n",
401 arg = va_arg(ap, long);
403 rc = fcntl(fd, cmd, arg);
405 printf("fcntl SETFL %ld failed: %s\n",
406 arg, strerror(errno));
412 #if F_GETLK64 != F_GETLK
418 #if F_SETLK64 != F_SETLK
424 #if F_SETLKW64 != F_SETLKW
428 lock = va_arg(ap, struct flock *);
430 rc = fcntl(fd, cmd, lock);
432 printf("fcntl cmd %d failed: %s\n",
433 cmd, strerror(errno));
438 arg = va_arg(ap, long);
440 rc = fcntl(fd, cmd, arg);
442 printf("fcntl F_DUPFD %d failed: %s\n",
443 (int)arg, strerror(errno));
449 printf("fcntl cmd %d not supported\n", cmd);
455 char *safe_strncpy(char *dst, char *src, int max_size)
458 src_size=strlen(src);
459 if (src_size >= max_size) {
462 memcpy(dst, src, src_size);