xref: /freebsd/contrib/netbsd-tests/fs/hfs/t_pathconvert.c (revision 63a938566d524836885917d95bd491aa4400b181)
1 /*	$NetBSD: t_pathconvert.c,v 1.6 2017/01/13 21:30:40 christos Exp $	*/
2 
3 #include <sys/types.h>
4 #include <sys/mount.h>
5 
6 #include <atf-c.h>
7 #include <dirent.h>
8 #include <errno.h>
9 #include <fcntl.h>
10 #include <limits.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <string.h>
15 
16 #include <rump/rump.h>
17 #include <rump/rump_syscalls.h>
18 
19 #include <fs/hfs/hfs.h>
20 
21 #include "h_macros.h"
22 
23 ATF_TC(colonslash);
24 ATF_TC_HEAD(colonslash, tc)
25 {
26 	atf_tc_set_md_var(tc, "descr", "HFS+ colons/slashes (PR kern/44523)");
27 	atf_tc_set_md_var(tc, "timeout", "20");
28 }
29 
30 #define IMGNAME "colon.hfs"
31 #define FAKEBLK "/dev/blk"
32 #define FUNNY_FILENAME "foo:bar"
33 ATF_TC_BODY(colonslash, tc)
34 {
35 	struct hfs_args args;
36 	int dirfd, fd;
37 	char thecmd[1024];
38 	char buf[DIRBLKSIZ];
39 	struct dirent *dirent;
40 	int offset, nbytes;
41 	bool ok = false;
42 
43 	snprintf(thecmd, sizeof(thecmd), "uudecode %s/colon.hfs.bz2.uue",
44 	    atf_tc_get_config_var(tc, "srcdir"));
45 	RZ(system(thecmd));
46 
47 	snprintf(thecmd, sizeof(thecmd), "bunzip2 " IMGNAME ".bz2");
48 	RZ(system(thecmd));
49 
50 	memset(&args, 0, sizeof args);
51 	args.fspec = __UNCONST(FAKEBLK);
52 	RZ(rump_init());
53 
54 	RL(rump_sys_mkdir("/mp", 0777));
55 	RZ(rump_pub_etfs_register(FAKEBLK, IMGNAME, RUMP_ETFS_BLK));
56 	RL(rump_sys_mount(MOUNT_HFS, "/mp", 0, &args, sizeof args));
57 
58 	RL(dirfd = rump_sys_open("/mp", O_RDONLY));
59 
60 	RL(nbytes = rump_sys_getdents(dirfd, buf, sizeof buf));
61 
62 	for (offset = 0; offset < nbytes; offset += dirent->d_reclen) {
63 		dirent = (struct dirent *)(buf + offset);
64 		if (strchr(dirent->d_name, '/'))
65 			atf_tc_fail("dirent with slash: %s", dirent->d_name);
66 		if (0 == strcmp(FUNNY_FILENAME, dirent->d_name))
67 			ok = true;
68 	}
69 
70 	if (!ok)
71 		atf_tc_fail("no dirent for file: %s", FUNNY_FILENAME);
72 
73 	RL(rump_sys_close(dirfd));
74 	RL(fd = rump_sys_open("/mp/" FUNNY_FILENAME, O_RDONLY));
75 	RL(rump_sys_close(fd));
76 	RL(rump_sys_unmount("/mp", 0));
77 }
78 
79 ATF_TP_ADD_TCS(tp)
80 {
81 	ATF_TP_ADD_TC(tp, colonslash);
82 	return 0;
83 }
84