11 #include "test_common.h"
15 /******************************************************************
17 ******************************************************************/
25 #define EXIT_RET(err) \
34 void t_touch(const char *path)
38 fd = open(path, O_RDWR|O_CREAT, 0644);
40 printf("open(%s) error: %s\n", path, strerror(errno));
46 printf("close(%s) error: %s\n", path, strerror(errno));
51 /* XXX Now libsysio don't support mcreate */
52 void t_create(const char *path)
58 rc = mknod(path, S_IFREG | 0644, 0);
60 printf("mknod(%s) error: %s\n", path, strerror(errno));
66 void t_link(const char *src, const char *dst)
72 printf("link(%s -> %s) error: %s\n", src, dst, strerror(errno));
77 void t_unlink(const char *path)
83 printf("unlink(%s) error: %s\n", path, strerror(errno));
88 void t_mkdir(const char *path)
92 rc = mkdir(path, 00644);
94 printf("mkdir(%s) error: %s\n", path, strerror(errno));
99 void t_rmdir(const char *path)
105 printf("rmdir(%s) error: %s\n", path, strerror(errno));
110 void t_symlink(const char *src, const char *new)
114 rc = symlink(src, new);
116 printf("symlink(%s<-%s) error: %s\n", src, new, strerror(errno));
121 #define MKDEV(a,b) (((a) << 8) | (b))
122 void t_mknod(const char *path, mode_t mode, int major, int minor)
126 rc = mknod(path, mode, MKDEV(5, 4));
128 printf("mknod(%s) error: %s\n", path, strerror(errno));
133 void t_chmod_raw(const char *path, mode_t mode)
137 rc = chmod(path, mode);
139 printf("chmod(%s) error: %s\n", path, strerror(errno));
144 void t_chmod(const char *path, const char *format, ...)
148 void t_rename(const char *oldpath, const char *newpath)
152 rc = rename(oldpath, newpath);
154 printf("rename(%s -> %s) error: %s\n",
155 oldpath, newpath, strerror(errno));
160 int t_open_readonly(const char *path)
164 fd = open(path, O_RDONLY);
166 printf("open(%s) error: %s\n", path, strerror(errno));
172 int t_open(const char *path)
176 fd = open(path, O_RDWR);
178 printf("open(%s) error: %s\n", path, strerror(errno));
184 int t_opendir(const char *path)
188 fd = open(path, O_RDONLY);
190 printf("opendir(%s) error: %s\n", path, strerror(errno));
202 printf("close(%d) error: %s\n", fd, strerror(errno));
207 int t_check_stat(const char *name, struct stat *buf)
212 rc = lstat(name, &stat);
214 printf("error %d stat %s\n", rc, name);
218 memcpy(buf, &stat, sizeof(*buf));
223 int t_check_stat_fail(const char *name)
228 rc = lstat(name, &stat);
230 printf("%s still exists\n", name);
237 void t_echo_create(const char *path, const char *str)
241 fd = open(path, O_RDWR|O_CREAT, 0644);
243 printf("open(%s) error: %s\n", path, strerror(errno));
247 if (write(fd, str, strlen(str)+1) != strlen(str)+1) {
248 printf("write(%s) error: %s\n", path, strerror(errno));
254 printf("close(%s) error: %s\n", path, strerror(errno));
259 static void _t_grep(const char *path, char *str, int should_contain)
265 fd = t_open_readonly(path);
266 if (lseek(fd, 0, SEEK_SET) == -1) {
267 printf("pread_once: seek to 0 error: %s\n", strerror(errno));
271 rc = read(fd, buf, 1023);
273 printf("grep: read error: %s\n", strerror(errno));
279 if ((strstr(buf, str) != 0) ^ should_contain) {
280 printf("grep: can't find string %s\n", str);
285 void t_grep(const char *path, char *str)
287 _t_grep(path, str, 1);
290 void t_grep_v(const char *path, char *str)
292 _t_grep(path, str, 0);
295 void t_ls(int fd, char *buf, int size)
297 struct dirent64 *ent;
301 printf("dir entries listing...\n");
302 while ((rc = getdirentries64(fd, buf, size, &base)) > 0) {
305 ent = (struct dirent64 *) ((char*) buf + pos);
306 printf("%s\n", ent->d_name);
307 pos += ent->d_reclen;
312 printf("getdents error %d\n", rc);
317 char *safe_strncpy(char *dst, char *src, int max_size)
320 src_size=strlen(src);
321 if (src_size >= max_size) {
324 memcpy(dst, src, src_size);