xref: /freebsd/tools/test/stress2/misc/msdos8.sh (revision 38a52bd3b5cac3da6f7f6eef3dd050e6aa08ebb3)
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
48gpart create -s bsd md$mdstart > /dev/null
49gpart add -t freebsd-ufs md$mdstart > /dev/null
50part=a
51newfs_msdos /dev/md${mdstart}$part #> /dev/null
52mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1
53
54(cd $mntpoint; /tmp/msdos8)
55s=$?
56
57while mount | grep "$mntpoint" | grep -q md$mdstart; do
58	umount $mntpoint || sleep 1
59done
60fsck -t msdosfs -y /dev/md${mdstart}$part > $log 2>&1
61if egrep -q "BAD|INCONSISTENCY|MODIFIED" $log; then
62	cat $log
63	s=1
64
65	mount -t msdosfs /dev/md${mdstart}$part $mntpoint || exit 1
66	ls -lR $mntpoint
67	umount $mntpoint
68fi
69mdconfig -d -u $mdstart
70rm /tmp/msdos8 $log
71s=0	# Ignore for now
72exit $s
73EOF
74#include <sys/param.h>
75#include <sys/stat.h>
76#include <sys/wait.h>
77
78#include <err.h>
79#include <fcntl.h>
80#include <stdio.h>
81#include <stdlib.h>
82#include <string.h>
83#include <time.h>
84#include <unistd.h>
85
86# define PARALLEL 10
87
88static unsigned long size;
89
90static void
91test(void)
92{
93	pid_t pid;
94	int fd, i, j;
95	char file1[128], file2[128];
96
97	pid = getpid();
98	for (i = 0; i < (int)size; i++) {
99		sprintf(file1,"p%05d.%05d", pid, i);
100		if ((fd = open(file1, O_RDONLY|O_CREAT, 0660)) == -1)
101			err(1, "openat(%s), %s:%d", file1, __FILE__,
102			    __LINE__);
103		close(fd);
104	}
105	for (j = 0; j < 100; j++) {
106		for (i = 0; i < (int)size; i++) {
107			sprintf(file1,"p%05d.%05d", pid, i);
108			sprintf(file2,"p%05d.%05d.togo", pid, i);
109			if (rename(file1, file2) == -1)
110				err(1, "rename(%s, %s). %s:%d", file1,
111				    file2, __FILE__, __LINE__);
112		}
113		for (i = 0; i < (int)size; i++) {
114			sprintf(file1,"p%05d.%05d", pid, i);
115			sprintf(file2,"p%05d.%05d.togo", pid, i);
116			if (rename(file2, file1) == -1)
117				err(1, "rename(%s, %s). %s:%d", file2,
118				    file1, __FILE__, __LINE__);
119		}
120	}
121
122	for (i = 0; i < (int)size; i++) {
123		sprintf(file1,"p%05d.%05d", pid, i);
124		if (unlink(file1) == -1)
125			err(1, "unlink(%s), %s:%d", file1, __FILE__,
126			    __LINE__);
127	}
128	_exit(0);
129}
130
131int
132main(void)
133{
134	pid_t pids[PARALLEL];
135	time_t start;
136	int e, i, status;
137
138	e = 0;
139	size = 5;
140	start = time(NULL);
141	while ((time(NULL) - start) < 60 && e == 0) {
142		for (i = 0; i < PARALLEL; i++) {
143			if ((pids[i] = fork()) == 0)
144				test();
145			if (pids[i] == -1)
146				err(1, "fork()");
147		}
148		for (i = 0; i < PARALLEL; i++) {
149			if (waitpid(pids[i], &status, 0) == -1)
150				err(1, "waitpid(%d)", pids[i]);
151			if (WIFSIGNALED(status))
152				fprintf(stderr, "pid %d exit signal %d\n",
153				    pids[i], WTERMSIG(status));
154			e += status == 0 ? 0 : 1;
155		}
156	}
157
158	return (e);
159}
160