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