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