/*-
* Copyright (c) 2006-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/tools/regression/fstest/fstest.c,v 1.1 2007/01/17 01:42:07 pjd Exp $
*/
#ifdef linux
#define _GNU_SOURCE
#endif
#include <sys/param.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <grp.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#ifndef HAS_TRUNCATE64
#define truncate64 truncate
#endif
#ifndef HAS_STAT64
#define stat64 stat
#define lstat64 lstat
#endif
#ifndef ALLPERMS
#define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
#endif
enum action {
ACTION_OPEN,
ACTION_CREATE,
ACTION_UNLINK,
ACTION_MKDIR,
ACTION_RMDIR,
ACTION_LINK,
ACTION_SYMLINK,
ACTION_RENAME,
ACTION_MKFIFO,
ACTION_CHMOD,
#ifdef HAS_LCHMOD
ACTION_LCHMOD,
#endif
ACTION_CHOWN,
ACTION_LCHOWN,
#ifdef HAS_CHFLAGS
ACTION_CHFLAGS,
#endif
#ifdef HAS_LCHFLAGS
ACTION_LCHFLAGS,
#endif
ACTION_TRUNCATE,
ACTION_STAT,
ACTION_LSTAT,
};
#define TYPE_NONE 0x0000
#define TYPE_STRING 0x0001
#define TYPE_NUMBER 0x0002
#define TYPE_OPTIONAL 0x0100
#define MAX_ARGS 8
struct syscall_desc {
char *sd_name;
enum action sd_action;
int sd_args[MAX_ARGS];
};
static struct syscall_desc syscalls[] = {
{ "open", ACTION_OPEN, { TYPE_STRING, TYPE_STRING, TYPE_NUMBER | TYPE_OPTIONAL, TYPE_NONE } },
{ "create", ACTION_CREATE, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
{ "unlink", ACTION_UNLINK, { TYPE_STRING, TYPE_NONE } },
{ "mkdir", ACTION_MKDIR, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
{ "rmdir", ACTION_RMDIR, { TYPE_STRING, TYPE_NONE } },
{ "link", ACTION_LINK, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
{ "symlink", ACTION_SYMLINK, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
{ "rename", ACTION_RENAME, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
{ "mkfifo", ACTION_MKFIFO, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
{ "chmod", ACTION_CHMOD, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
#ifdef HAS_LCHMOD
{ "lchmod", ACTION_LCHMOD, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
#endif
{ "chown", ACTION_CHOWN, { TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE } },
{ "lchown", ACTION_LCHOWN, { TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE } },
#ifdef HAS_CHFLAGS
{ "chflags", ACTION_CHFLAGS, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
#endif
#ifdef HAS_LCHFLAGS
{ "lchflags", ACTION_LCHFLAGS, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
#endif
{ "truncate", ACTION_TRUNCATE, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
{ "stat", ACTION_STAT, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
{ "lstat", ACTION_LSTAT, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
{ NULL, -1, { TYPE_NONE } }
};
struct flag {
long long f_flag;
char *f_str;
};
static struct flag open_flags[] = {
#ifdef O_RDONLY
{ O_RDONLY, "O_RDONLY" },
#endif
#ifdef O_WRONLY
{ O_WRONLY, "O_WRONLY" },
#endif
#ifdef O_RDWR
{ O_RDWR, "O_RDWR" },
#endif
#ifdef O_NONBLOCK
{ O_NONBLOCK, "O_NONBLOCK" },
#endif
#ifdef O_APPEND
{ O_APPEND, "O_APPEND" },
#endif
#ifdef O_CREAT
{ O_CREAT, "O_CREAT" },
#endif
#ifdef O_TRUNC
{ O_TRUNC, "O_TRUNC" },
#endif
#ifdef O_EXCL
{ O_EXCL, "O_EXCL" },
#endif
#ifdef O_SHLOCK
{ O_SHLOCK, "O_SHLOCK" },
#endif
#ifdef O_EXLOCK
{ O_EXLOCK, "O_EXLOCK" },
#endif
#ifdef O_DIRECT
{ O_DIRECT, "O_DIRECT" },
#endif
#ifdef O_FSYNC
{ O_FSYNC, "O_FSYNC" },
#endif
#ifdef O_SYNC
{ O_SYNC, "O_SYNC" },
#endif
#ifdef O_NOFOLLOW
{ O_NOFOLLOW, "O_NOFOLLOW" },
#endif
#ifdef O_NOCTTY
{ O_NOCTTY, "O_NOCTTY" },
#endif
{ 0, NULL }
};
#ifdef HAS_CHFLAGS
static struct flag chflags_flags[] = {
#ifdef UF_NODUMP
{ UF_NODUMP, "UF_NODUMP" },
#endif
#ifdef UF_IMMUTABLE
{ UF_IMMUTABLE, "UF_IMMUTABLE" },
#endif
#ifdef UF_APPEND
{ UF_APPEND, "UF_APPEND" },
#endif
#ifdef UF_NOUNLINK
{ UF_NOUNLINK, "UF_NOUNLINK" },
#endif
#ifdef UF_OPAQUE
{ UF_OPAQUE, "UF_OPAQUE" },
#endif
#ifdef SF_ARCHIVED
{ SF_ARCHIVED, "SF_ARCHIVED" },
#endif
#ifdef SF_IMMUTABLE
{ SF_IMMUTABLE, "SF_IMMUTABLE" },
#endif
#ifdef SF_APPEND
{ SF_APPEND, "SF_APPEND" },
#endif
#ifdef SF_NOUNLINK
{ SF_NOUNLINK, "SF_NOUNLINK" },
#endif
#ifdef SF_SNAPSHOT
{ SF_SNAPSHOT, "SF_SNAPSHOT" },
#endif
{ 0, NULL }
};
#endif
static const char *err2str(int error);
static void
usage(void)
{
fprintf(stderr, "usage: fstest [-u uid] [-g gid1[,gid2[...]]] syscall args ...\n");
exit(1);
}
static long long
str2flags(struct flag *tflags, char *sflags)
{
long long flags = 0;
unsigned int i;
char *f;
for (f = strtok(sflags, ","); f != NULL; f = strtok(NULL, ",")) {
/* Support magic 'none' flag which just reset all flags. */
if (strcmp(f, "none") == 0)
return (0);
for (i = 0; tflags[i].f_str != NULL; i++) {
if (strcmp(tflags[i].f_str, f) == 0)
break;
}
if (tflags[i].f_str == NULL) {
fprintf(stderr, "unknown flag '%s'\n", f);
exit(1);
}
flags |= tflags[i].f_flag;
}
return (flags);
}
#ifdef HAS_CHFLAGS
static char *
flags2str(struct flag *tflags, long long flags)
{
static char sflags[1024];
unsigned int i;
sflags[0] = '\0';
for (i = 0; tflags[i].f_str != NULL; i++) {
if (flags & tflags[i].f_flag) {
if (sflags[0] != '\0')
strlcat(sflags, ",", sizeof(sflags));
strlcat(sflags, tflags[i].f_str, sizeof(sflags));
}
}
if (sflags[0] == '\0')
strlcpy(sflags, "none", sizeof(sflags));
return (sflags);
}
#endif
static struct syscall_desc *
find_syscall(const char *name)
{
int i;
for (i = 0; syscalls[i].sd_name != NULL; i++) {
if (strcmp(syscalls[i].sd_name, name) == 0)
return (&syscalls[i]);
}
return (NULL);
}
static void
show_stat(struct stat64 *sp, const char *what)
{
if (strcmp(what, "mode") == 0)
printf("0%o", (unsigned int)(sp->st_mode & ALLPERMS));
else if (strcmp(what, "inode") == 0)
printf("%lld", (long long)sp->st_ino);
else if (strcmp(what, "nlink") == 0)
printf("%lld", (long long)sp->st_nlink);
else if (strcmp(what, "uid") == 0)
printf("%d", (int)sp->st_uid);
else if (strcmp(what, "gid") == 0)
printf("%d", (int)sp->st_gid);
else if (strcmp(what, "size") == 0)
printf("%lld", (long long)sp->st_size);
else if (strcmp(what, "blocks") == 0)
printf("%lld", (long long)sp->st_blocks);
else if (strcmp(what, "atime") == 0)
printf("%lld", (long long)sp->st_atime);
else if (strcmp(what, "mtime") == 0)
printf("%lld", (long long)sp->st_mtime);
else if (strcmp(what, "ctime") == 0)
printf("%lld", (long long)sp->st_ctime);
#ifdef HAS_CHFLAGS
else if (strcmp(what, "flags") == 0)
printf("%s", flags2str(chflags_flags, sp->st_flags));
#endif
else if (strcmp(what, "type") == 0) {
switch (sp->st_mode & S_IFMT) {
case S_IFIFO:
printf("fifo");
break;
case S_IFCHR:
printf("char");
break
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共190个文件
t:184个
license:1个
makefile:1个
fstest是一套简化版的文件系统POSIX兼容性测试套件,它可以工作在FreeBSD, Solaris, Linux上用于测试UFS, ZFS, ext3, XFS and the NTFS-3G等文件系统。测试的系统调用覆盖chmod, chown, link, mkdir, mkfifo, open, rename, rmdir, symlink, truncate, unlink。
资源推荐
资源详情
资源评论
收起资源包目录
pjd-fstest-20080816.tgz (190个子文件)
fstest.c 19KB
conf 238B
LICENSE 1KB
Makefile 296B
README 855B
misc.sh 2KB
10.t 10KB
00.t 9KB
00.t 6KB
00.t 4KB
00.t 4KB
06.t 4KB
00.t 4KB
09.t 3KB
00.t 3KB
11.t 3KB
00.t 3KB
07.t 2KB
09.t 2KB
08.t 2KB
00.t 2KB
00.t 2KB
08.t 2KB
11.t 2KB
10.t 2KB
07.t 1KB
08.t 1KB
07.t 1KB
06.t 1KB
08.t 1KB
09.t 1KB
13.t 1KB
11.t 1KB
08.t 1KB
09.t 1KB
10.t 1KB
10.t 1KB
08.t 1KB
11.t 1KB
10.t 1KB
12.t 1KB
00.t 1KB
11.t 1KB
10.t 1KB
09.t 1KB
09.t 1KB
12.t 1KB
05.t 1KB
04.t 1023B
06.t 999B
05.t 992B
05.t 980B
07.t 970B
15.t 961B
05.t 923B
14.t 890B
03.t 889B
09.t 878B
06.t 876B
05.t 859B
07.t 845B
07.t 842B
10.t 840B
15.t 839B
16.t 830B
09.t 828B
20.t 815B
03.t 814B
02.t 807B
16.t 777B
18.t 772B
16.t 771B
05.t 770B
06.t 769B
06.t 767B
05.t 764B
05.t 762B
19.t 762B
13.t 762B
14.t 758B
05.t 755B
06.t 753B
00.t 752B
10.t 748B
05.t 748B
03.t 746B
11.t 744B
08.t 722B
15.t 717B
03.t 717B
14.t 717B
03.t 716B
11.t 715B
09.t 715B
03.t 713B
03.t 703B
03.t 702B
11.t 700B
11.t 699B
03.t 696B
共 190 条
- 1
- 2
资源评论
watermelon_fan
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功