xref: /freebsd/tools/test/stress2/misc/msdos8.sh (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1#!/bin/sh
2
3#
4# Copyright (c) 2017 Dell EMC Isilon
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29# msdosfs rename scenario
30# "Invalid long filename entry" seen from fsck
31
32. ../default.cfg
33[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1
34
35[ -x /sbin/mount_msdosfs ] || exit 0
36dir=/tmp
37odir=`pwd`
38cd $dir
39sed '1,/^EOF/d' < $odir/$0 > $dir/msdos8.c
40cc -o msdos8 -Wall -Wextra -O0 -g msdos8.c || exit 1
41rm -f msdos8.c
42cd $odir
43log=/tmp/msdos8.sh.log
44mount | grep "$mntpoint" | grep -q md$mdstart && umount -f $mntpoint
45mdconfig -l | grep -q $mdstart &&  mdconfig -d -u $mdstart
46
47mdconfig -a -t swap -s 1g -u $mdstart
48bsdlabel -w md$mdstart auto
49newfs_msdos /dev/md${mdstart}$part #> /dev/null
50mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1
51
52(cd $mntpoint; /tmp/msdos8)
53s=$?
54
55while mount | grep "$mntpoint" | grep -q md$mdstart; do
56	umount $mntpoint || sleep 1
57done
58fsck -t msdosfs -y /dev/md${mdstart}$part > $log 2>&1
59if egrep -q "BAD|INCONSISTENCY|MODIFIED" $log; then
60	cat $log
61	s=1
62
63	mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1
64	ls -lR $mntpoint
65	umount $mntpoint
66fi
67mdconfig -d -u $mdstart
68rm /tmp/msdos8 $log
69s=0	# Ignore for now
70exit $s
71EOF
72#include <sys/param.h>
73#include <sys/stat.h>
74#include <sys/wait.h>
75
76#include <err.h>
77#include <fcntl.h>
78#include <stdio.h>
79#include <stdlib.h>
80#include <string.h>
81#include <time.h>
82#include <unistd.h>
83
84# define PARALLEL 10
85
86static unsigned long size;
87
88static void
89test(void)
90{
91	pid_t pid;
92	int fd, i, j;
93	char file1[128], file2[128];
94
95	pid = getpid();
96	for (i = 0; i < (int)size; i++) {
97		sprintf(file1,"p%05d.%05d", pid, i);
98		if ((fd = open(file1, O_RDONLY|O_CREAT, 0660)) == -1)
99			err(1, "openat(%s), %s:%d", file1, __FILE__,
100			    __LINE__);
101		close(fd);
102	}
103	for (j = 0; j < 100; j++) {
104		for (i = 0; i < (int)size; i++) {
105			sprintf(file1,"p%05d.%05d", pid, i);
106			sprintf(file2,"p%05d.%05d.togo", pid, i);
107			if (rename(file1, file2) == -1)
108				err(1, "rename(%s, %s). %s:%d", file1,
109				    file2, __FILE__, __LINE__);
110		}
111		for (i = 0; i < (int)size; i++) {
112			sprintf(file1,"p%05d.%05d", pid, i);
113			sprintf(file2,"p%05d.%05d.togo", pid, i);
114			if (rename(file2, file1) == -1)
115				err(1, "rename(%s, %s). %s:%d", file2,
116				    file1, __FILE__, __LINE__);
117		}
118	}
119
120	for (i = 0; i < (int)size; i++) {
121		sprintf(file1,"p%05d.%05d", pid, i);
122		if (unlink(file1) == -1)
123			err(1, "unlink(%s), %s:%d", file1, __FILE__,
124			    __LINE__);
125	}
126	_exit(0);
127}
128
129int
130main(void)
131{
132	pid_t pids[PARALLEL];
133	time_t start;
134	int e, i, status;
135
136	e = 0;
137	size = 5;
138	start = time(NULL);
139	while ((time(NULL) - start) < 60 && e == 0) {
140		for (i = 0; i < PARALLEL; i++) {
141			if ((pids[i] = fork()) == 0)
142				test();
143			if (pids[i] == -1)
144				err(1, "fork()");
145		}
146		for (i = 0; i < PARALLEL; i++) {
147			if (waitpid(pids[i], &status, 0) == -1)
148				err(1, "waitpid(%d)", pids[i]);
149			if (WIFSIGNALED(status))
150				fprintf(stderr, "pid %d exit signal %d\n",
151				    pids[i], WTERMSIG(status));
152			e += status == 0 ? 0 : 1;
153		}
154	}
155
156	return (e);
157}
158