summaryrefslogtreecommitdiff
path: root/tests/generic/556
blob: cb6249ca584165e5b6b7384922f8d7cde66ca5d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# SPDX-License-Identifier: GPL-2.0+
#!/bin/bash
# FS QA Test No. 556
#
# Test the basic functionality of filesystems with case-insensitive
# support.

. ./common/preamble
_begin_fstest auto quick casefold

. ./common/filter
. ./common/casefold
. ./common/attr

_supported_fs generic
_require_scratch_nocheck
_require_scratch_casefold
_require_symlinks
_require_check_dmesg
_require_attrs

sdev=$(_short_dev ${SCRATCH_DEV})

filename1="file.txt"
filename2="FILE.TXT"

pt_file1=$(echo -e "coração")
pt_file2=$(echo -e "corac\xcc\xa7\xc3\xa3o" | tr a-z A-Z)

fr_file2=$(echo -e "french_caf\xc3\xa9.txt")
fr_file1=$(echo -e "french_cafe\xcc\x81.txt")

ar_file1=$(echo -e "arabic_\xdb\x92\xd9\x94.txt")
ar_file2=$(echo -e "arabic_\xdb\x93.txt" | tr a-z A-Z)

jp_file1=$(echo -e "japanese_\xe3\x82\xb2.txt")
jp_file2=$(echo -e "japanese_\xe3\x82\xb1\xe3\x82\x99.txt")

# '\xc3\x00' is an invalid sequence. Despite that, the sequences
# below could match, if we ignored the error.  But we don't want
# to be greedy at normalization, so at the first error we treat
# the entire sequence as an opaque blob.  Therefore, these two
# must NOT match.
blob_file1=$(echo -e "corac\xcc\xa7\xc3")
blob_file2=$(echo -e "coraç\xc3")

filter_touch()
{
    _filter_touch | _filter_scratch
}

# Test helpers
basic_create_lookup()
{
	local basedir=${1}
	local exact=${2}
	local lookup=${3}

	touch "${basedir}/${exact}"
	[ -f "${basedir}/${lookup}" ] || \
		echo "lookup of ${exact} using ${lookup} failed"
	_casefold_check_exact_name "${basedir}" "${exact}" || \
		echo "Created file ${exact} with wrong name."
}

# CI search should fail.
bad_basic_create_lookup()
{
	local basedir=${1}
	local exact=${2}
	local lookup=${3}

	touch "${basedir}/${exact}"
	[ -f "${basedir}/${lookup}" ] && \
		echo "Lookup of ${exact} using ${lookup} should fail"
}

# Testcases
test_casefold_lookup()
{
	local basedir=${SCRATCH_MNT}/casefold_lookup

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	basic_create_lookup "${basedir}" "${filename1}" "${filename2}"
	basic_create_lookup "${basedir}" "${pt_file1}" "${pt_file2}"
	basic_create_lookup "${basedir}" "${fr_file1}" "${fr_file2}"
	basic_create_lookup "${basedir}" "${ar_file1}" "${ar_file2}"
	basic_create_lookup "${basedir}" "${jp_file1}" "${jp_file2}"
}

test_bad_casefold_lookup()
{
	local basedir=${SCRATCH_MNT}/casefold_lookup

	mkdir -p ${basedir}

	bad_basic_create_lookup ${basedir} ${blob_file1} ${blob_file2}
}

do_create_and_remove()
{
	local basedir=${1}
	local exact=${2}
	local casefold=${3}

	basic_create_lookup ${basedir} ${exact} ${casefold}
	rm -f ${basedir}/${exact}
	[ -f ${basedir}/${exact} ] && \
		echo "File ${exact} was not removed using exact name"

	basic_create_lookup ${basedir} ${exact} ${casefold}
	rm -f ${basedir}/${casefold}
	[ -f ${basedir}/${exact} ] && \
		echo "File ${exact} was not removed using inexact name"
}

# remove and recreate
test_create_and_remove()
{
	local basedir=${SCRATCH_MNT}/create_and_remove
	mkdir -p ${basedir}

	_casefold_set_attr ${basedir}
	do_create_and_remove "${basedir}" "${pt_file1}" "${pt_file2}"
	do_create_and_remove "${basedir}" "${jp_file1}" "${jp_file2}"
	do_create_and_remove "${basedir}" "${ar_file1}" "${ar_file2}"
	do_create_and_remove "${basedir}" "${fr_file1}" "${fr_file2}"
}

test_casefold_flag_basic()
{
	local basedir=${SCRATCH_MNT}/basic

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}
	_casefold_lsattr_dir ${basedir} | _filter_scratch

	_casefold_unset_attr ${basedir}
	_casefold_lsattr_dir ${basedir} | _filter_scratch
}

test_casefold_flag_removal()
{
	local basedir=${SCRATCH_MNT}/casefold_flag_removal

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}
	_casefold_lsattr_dir ${basedir} | _filter_scratch

	# Try to remove +F attribute on non empty directory
	touch ${basedir}/${filename1}
	_casefold_unset_attr ${basedir} &>/dev/null
	_casefold_lsattr_dir ${basedir} | _filter_scratch
}

# Test Inheritance of casefold flag
test_casefold_flag_inheritance()
{
	local basedir=${SCRATCH_MNT}/flag_inheritance
	local dirpath1="d1/d2/d3"
	local dirpath2="D1/D2/D3"

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	mkdir -p ${basedir}/${dirpath1}
	_casefold_lsattr_dir ${basedir}/${dirpath1} | _filter_scratch

	[ -d ${basedir}/${dirpath2} ] || \
		echo "Directory CI Lookup failed."
	_casefold_check_exact_name "${basedir}" "${dirpath1}" || \
		echo "Created directory with wrong name."

	touch ${basedir}/${dirpath2}/${filename1}
	[ -f ${basedir}/${dirpath1}/${filename2} ] || \
		echo "Couldn't create file on casefolded parent."
}

# Test nesting of sensitive directory inside insensitive directory.
test_nesting_sensitive_insensitive_tree_simple()
{
	local basedir=${SCRATCH_MNT}/sd1

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	mkdir -p ${basedir}/sd1
	_casefold_set_attr ${basedir}/sd1

	mkdir ${basedir}/sd1/sd2
	_casefold_unset_attr ${basedir}/sd1/sd2

	touch ${basedir}/sd1/sd2/${filename1}
	[ -f ${basedir}/sd1/sd2/${filename1} ] || \
		echo "Exact nested file lookup failed."
	[ -f ${basedir}/sd1/SD2/${filename1} ] || \
		echo "Nested file lookup failed."
	[ -f ${basedir}/sd1/SD2/${filename2} ] && \
		echo "Wrong file lookup passed, should have fail."
}

test_nesting_sensitive_insensitive_tree_complex()
{
	# Test nested-directories
	local basedir=${SCRATCH_MNT}/nesting

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	mkdir ${basedir}/nd1
	_casefold_set_attr ${basedir}/nd1
	mkdir ${basedir}/nd1/nd2
	_casefold_unset_attr ${basedir}/nd1/nd2
	mkdir ${basedir}/nd1/nd2/nd3
	_casefold_set_attr ${basedir}/nd1/nd2/nd3
	mkdir ${basedir}/nd1/nd2/nd3/nd4
	_casefold_unset_attr ${basedir}/nd1/nd2/nd3/nd4
	mkdir ${basedir}/nd1/nd2/nd3/nd4/nd5
	_casefold_set_attr ${basedir}/nd1/nd2/nd3/nd4/nd5

	[ -d ${basedir}/ND1/ND2/nd3/ND4/nd5 ] || \
		echo "Nest-dir Lookup failed."
	[ -d ${basedir}/nd1/nd2/nd3/nd4/ND5 ] && \
		echo "ND5: Nest-dir Lookup passed, it should fail."
	[ -d ${basedir}/nd1/nd2/nd3/ND4/nd5 ] || \
		echo "Nest-dir Lookup failed."
	[ -d ${basedir}/nd1/nd2/ND3/nd4/ND5 ] && \
		echo "ND3: Nest-dir Lookup passed, it should fail."
}

test_symlink_with_inexact_name()
{
	local basedir=${SCRATCH_MNT}/symlink

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	mkdir ${basedir}/ind1
	mkdir ${basedir}/ind2
	_casefold_set_attr ${basedir}/ind1
	touch ${basedir}/ind1/target

	ln -s ${basedir}/ind1/TARGET ${basedir}/ind2/link
	[ -L ${basedir}/ind2/link ] || echo "Not a symlink."
	readlink -e ${basedir}/ind2/link | _filter_scratch
}

do_test_name_preserve()
{
	local basedir=${1}
	local exact=${2}
	local casefold=${3}

	touch ${basedir}/${exact}
	rm ${basedir}/${exact}

	touch ${basedir}/${casefold}
	_casefold_check_exact_name ${basedir} ${casefold} ||
		echo "${casefold} was not created with exact name"
}

# Name-preserving tests
# We create a file with a name, delete it and create again with an
# equivalent name.  If the negative dentry wasn't invalidated, the
# file might be created using $1 instead of $2.
test_name_preserve()
{
	local basedir=${SCRATCH_MNT}/test_name_preserve

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	do_test_name_preserve "${basedir}" "${pt_file1}" "${pt_file2}"
	do_test_name_preserve "${basedir}" "${jp_file1}" "${jp_file2}"
	do_test_name_preserve "${basedir}" "${ar_file1}" "${ar_file2}"
	do_test_name_preserve "${basedir}" "${fr_file1}" "${fr_file2}"
}

do_test_dir_name_preserve()
{
	local basedir=${1}
	local exact=${2}
	local casefold=${3}

	mkdir ${basedir}/${exact}
	rmdir ${basedir}/${exact}

	mkdir ${basedir}/${casefold}
	_casefold_check_exact_name ${basedir} ${casefold} ||
		echo "${casefold} was not created with exact name"
}

test_dir_name_preserve()
{
	local basedir=${SCRATCH_MNT}/"dir-test_name_preserve"

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	do_test_dir_name_preserve "${basedir}" "${pt_file1}" "${pt_file2}"
	do_test_dir_name_preserve "${basedir}" "${jp_file1}" "${jp_file2}"
	do_test_dir_name_preserve "${basedir}" "${ar_file1}" "${ar_file2}"
	do_test_dir_name_preserve "${basedir}" "${fr_file1}" "${fr_file2}"
}

test_name_reuse()
{
	local basedir=${SCRATCH_MNT}/reuse
	local reuse1=fileX
	local reuse2=FILEX

	mkdir ${basedir}
	_casefold_set_attr ${basedir}

	touch ${basedir}/${reuse1}
	rm -f ${basedir}/${reuse1} || echo "File lookup failed."
	touch ${basedir}/${reuse2}
	_casefold_check_exact_name "${basedir}" "${reuse2}" || \
		echo "File created with wrong name"
	_casefold_check_exact_name "${basedir}" "${reuse1}" && \
		echo "File created with the old name"
}

test_create_with_same_name()
{
	local basedir=${SCRATCH_MNT}/same_name

	mkdir ${basedir}
	_casefold_set_attr ${basedir}

	mkdir -p ${basedir}/same1/same1
	touch ${basedir}/SAME1/sAME1/sAMe1
	touch -c ${basedir}/SAME1/sAME1/same1 ||
		echo "Would create a new file instead of using old one"
}

test_file_rename()
{
	local basedir=${SCRATCH_MNT}/rename

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	touch ${basedir}/rename

	# Move to an equivalent name should not work
	mv ${basedir}/rename ${basedir}/RENAME 2>&1 | \
		_filter_scratch

	_casefold_check_exact_name ${basedir} "rename" || \
		echo "Name shouldn't change."
}

test_toplevel_dir_rename()
{
	local dir=${SCRATCH_MNT}/dir_rename

	# With the cache cold, rename a casefolded directory located in the
	# top-level directory.  If $MOUNT_OPTIONS contains
	# test_dummy_encryption, this detects the bug that was fixed by
	# 'f2fs: don't use casefolded comparison for "." and ".."'.
	mkdir ${dir}
	_casefold_set_attr ${dir}
	sync
	echo 2 > /proc/sys/vm/drop_caches
	mv ${dir} ${dir}.new
}

# Test openfd with casefold.
# 1. Delete a file after gettings its fd.
# 2. Then create new dir with same name
test_casefold_openfd()
{
	local basedir=${SCRATCH_MNT}/openfd
	local ofd1="openfd"
	local ofd2="OPENFD"

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	exec 3<> ${basedir}/${ofd1}
	rm -rf ${basedir}/${ofd1}
	mkdir ${basedir}/${ofd2}
	[ -d ${basedir}/${ofd2} ] || echo "Not a directory"
	_casefold_check_exact_name ${basedir} "${ofd2}" ||
		echo "openfd file was created using old name"
	rm -rf ${basedir}/${ofd2}
	exec 3>&-
}

# Test openfd with casefold.
# 1. Delete a file after gettings its fd.
# 2. Then create new file with same name
# 3. Read from open-fd and write into new file.
test_casefold_openfd2()
{
	local basedir=${SCRATCH_MNT}/openfd2
	local ofd1="openfd"
	local ofd2="OPENFD"

	mkdir ${basedir}
	_casefold_set_attr ${basedir}

	date > ${basedir}/${ofd1}
	exec 3<> ${basedir}/${ofd1}
	rm -rf ${basedir}/${ofd1}
	touch ${basedir}/${ofd1}
	[ -f ${basedir}/${ofd2} ] || echo "Not a file"
	read data <&3
	echo $data >> ${basedir}/${ofd1}
	exec 3>&-
}

test_hard_link_lookups()
{
	local basedir=${SCRATCH_MNT}/hard_link

	mkdir ${basedir}
	_casefold_set_attr ${basedir}

	touch ${basedir}/h1
	ln ${basedir}/H1 ${SCRATCH_MNT}/h1
	cnt=`stat -c %h ${basedir}/h1`
	[ $cnt -eq 1 ] && echo "Unable to create hardlink"

	# Create hardlink for casefold dir file and inside regular dir.
	touch ${SCRATCH_MNT}/h2
	ln ${SCRATCH_MNT}/h2 ${basedir}/H2
	cnt=`stat -c %h ${basedir}/h2`
	[ $cnt -eq 1 ] && echo "Unable to create hardlink"
}

test_xattrs_lookups()
{
	local basedir=${SCRATCH_MNT}/xattrs

	mkdir ${basedir}
	_casefold_set_attr ${basedir}

	mkdir -p ${basedir}/x

	${SETFATTR_PROG} -n user.foo -v bar ${basedir}/x
	${GETFATTR_PROG} --absolute-names -n user.foo \
		${basedir}/x | _filter_scratch

	touch ${basedir}/x/f1
	${SETFATTR_PROG} -n user.foo -v bar ${basedir}/x/f1
	${GETFATTR_PROG} --absolute-names -n user.foo \
		${basedir}/x/f1 | _filter_scratch
}

test_lookup_large_directory()
{
	local basedir=${SCRATCH_MNT}/large

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	touch $(seq -f "${basedir}/file%g" 0 2000)

	# We really want to spawn a single process here, to speed up the
	# test, but we don't want the output of 2k files, except for
	# errors.
	cat $(seq -f "${basedir}/FILE%g" 0 2000) || \
		echo "Case on large dir failed"
}

test_strict_mode_invalid_filename()
{
	local basedir=${SCRATCH_MNT}/strict

	mkdir -p ${basedir}
	_casefold_set_attr ${basedir}

	# These creation commands should fail, since we are on strict
	# mode.
	touch "${basedir}/${blob_file1}" 2>&1 | filter_touch
	touch "${basedir}/${blob_file2}" 2>&1 | filter_touch
}

#############
# Run tests #
#############

_scratch_mkfs_casefold >>$seqres.full 2>&1

_scratch_mount

_check_dmesg_for \
	"\(${sdev}\): Using encoding defined by superblock: utf8" || \
	_fail "Could not mount with encoding: utf8"

test_casefold_flag_basic
test_casefold_lookup
# bcachefs only supports strict mode - this may be subject to change:
[[ $FSTYP != bcachefs ]] && test_bad_casefold_lookup
test_create_and_remove
test_casefold_flag_removal
test_casefold_flag_inheritance
test_nesting_sensitive_insensitive_tree_simple
test_nesting_sensitive_insensitive_tree_complex
test_symlink_with_inexact_name
test_name_preserve
test_dir_name_preserve
test_name_reuse
test_create_with_same_name
test_file_rename
test_toplevel_dir_rename
test_casefold_openfd
test_casefold_openfd2
test_hard_link_lookups
test_xattrs_lookups
test_lookup_large_directory

_scratch_unmount
_check_scratch_fs

# Test Strict Mode
_scratch_mkfs_casefold_strict >>$seqres.full 2>&1
_scratch_mount

test_strict_mode_invalid_filename

_scratch_unmount
_check_scratch_fs

status=0
exit