Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
# $NetBSD: t_mtree.sh,v 1.7 2017/01/14 20:45:16 christos Exp $
#
# Copyright (c) 2009, 2012 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

# Postprocess mtree output, canonicalising portions that
# are expected to differ from one run to another.
#

h_postprocess()
{
	sed -e '
		/^#	   user: /s/:.*/: x/
		/^#	machine: /s/:.*/: x/
		/^#	   tree: /s/:.*/: x/
		/^#	   date: /s/:.*/: x/
		' \
	    -e '/type=dir/s/ size=[0-9]*//'
}

h_check()
{
        diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
}


atf_test_case mtree_create
atf_test_case netbsd6_create
create_head()
{
	atf_set "descr" "Create a specfile describing a directory tree"
}

create_setup()
{
	# create some directories
	rm -fr create
	mkdir -p create/a/1 create/a/2 create/b
	# create some files
	for file in create/top.file.1 \
		    create/a/a.file.1 \
		    create/a/a.file.2 \
		    create/a/1/a1.file.1 \
		    create/b/b.file.1 \
		    create/b/b.file.2
	do
		echo "$file" >$file
	done
	# hard link to file in same dir
	ln create/b/b.file.1 create/b/b.hardlink.1
	# hard link to file in another dir
	ln create/b/b.file.2 create/a/a.hardlink.b2
	# symlink to file
	ln -s a.file.1 create/a.symlink.1
	# symlink to dir
	ln -s b create/top.symlink.b
	# dangling symlink
	ln -s nonexistent create/top.dangling
}

create_body()
{
	create_setup

	# run mtree and check output
	( cd create && mtree -F ${FLAVOR} -c -k type,nlink,link,size,sha256 ) >output.raw \
	|| atf_fail "mtree exit status $?"
	h_postprocess <output.raw >output
	h_check "$(atf_get_srcdir)/${FLAVOR}_d_create.out" output
}

mtree_create_head() 
{
	FLAVOR=mtree create_head
}
netbsd6_create_head() 
{
	FLAVOR=netbsd6 create_head
}

mtree_create_body() 
{
	FLAVOR=mtree create_body
}
netbsd6_create_body() 
{
	FLAVOR=netbsd6 create_body
}


atf_test_case mtree_check
atf_test_case netbsd6_check
check_head()
{
	atf_set "descr" "Check a directory tree against a specfile"
}

check_body()
{
	# we use the same directory tree and specfile as in the "create" test
	create_setup

	# run mtree and check output
	( cd create && mtree -F ${FLAVOR}  ) <"$(atf_get_srcdir)/${FLAVOR}_d_create.out" >output \
	|| atf_fail "mtree exit status $?"
	h_check /dev/null output
}

mtree_check_head() 
{
	FLAVOR=mtree check_head
}
netbsd6_check_head() 
{
	FLAVOR=netbsd6 check_head
}

mtree_check_body() 
{
	FLAVOR=mtree check_body
}
netbsd6_check_body() 
{
	FLAVOR=netbsd6 check_body
}


atf_test_case mtree_convert_C
atf_test_case netbsd6_convert_C
convert_C_head()
{
	atf_set "descr" "Convert a specfile to mtree -C format, unsorted"
}

convert_C_body()
{
	mtree -F ${FLAVOR} -C -K all <"$(atf_get_srcdir)/d_convert.in" >output
	h_check "$(atf_get_srcdir)/d_convert_C.out" output
}

mtree_convert_C_head() 
{
	FLAVOR=mtree convert_C_head
}
netbsd6_convert_C_head() 
{
	FLAVOR=netbsd6 convert_C_head
}

mtree_convert_C_body() 
{
	FLAVOR=mtree convert_C_body
}
netbsd6_convert_C_body() 
{
	FLAVOR=netbsd6 convert_C_body
}


atf_test_case mtree_convert_C_S
atf_test_case netbsd6_convert_C_S
convert_C_S_head()
{
	atf_set "descr" "Convert a specfile to mtree -C format, sorted"
}

convert_C_S_body()
{
	mtree -F ${FLAVOR} -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
	h_check "$(atf_get_srcdir)/d_convert_C_S.out" output
}

mtree_convert_C_S_head() 
{
	FLAVOR=mtree convert_C_S_head
}
netbsd6_convert_C_S_head() 
{
	FLAVOR=netbsd6 convert_C_S_head
}

mtree_convert_C_S_body() 
{
	FLAVOR=mtree convert_C_S_body
}
netbsd6_convert_C_S_body() 
{
	FLAVOR=netbsd6 convert_C_S_body
}


atf_test_case mtree_convert_D
atf_test_case netbsd6_convert_D
convert_D_head()
{
	atf_set "descr" "Convert a specfile to mtree -D format, unsorted"
}

convert_D_body()
{
	mtree -F ${FLAVOR} -D -K all <"$(atf_get_srcdir)/d_convert.in" >output
	h_check "$(atf_get_srcdir)/d_convert_D.out" output
}

mtree_convert_D_head() 
{
	FLAVOR=mtree convert_D_head
}
netbsd6_convert_D_head() 
{
	FLAVOR=netbsd6 convert_D_head
}

mtree_convert_D_body() 
{
	FLAVOR=mtree convert_D_body
}
netbsd6_convert_D_body() 
{
	FLAVOR=netbsd6 convert_D_body
}


atf_test_case mtree_convert_D_S
atf_test_case netbsd6_convert_D_S
convert_D_S_head()
{
	atf_set "descr" "Convert a specfile to mtree -D format, sorted"
}

convert_D_S_body()
{
	mtree -F ${FLAVOR} -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
	h_check "$(atf_get_srcdir)/d_convert_D_S.out" output
}

mtree_convert_D_S_head() 
{
	FLAVOR=mtree convert_D_S_head
}
netbsd6_convert_D_S_head() 
{
	FLAVOR=netbsd6 convert_D_S_head
}

mtree_convert_D_S_body() 
{
	FLAVOR=mtree convert_D_S_body
}
netbsd6_convert_D_S_body() 
{
	FLAVOR=netbsd6 convert_D_S_body
}


atf_test_case mtree_ignore
atf_test_case netbs6_ignore
ignore_head()
{
	atf_set "descr" "Test that -d ignores symlinks (PR bin/41061)"
}

ignore_body()
{
	# Kyua 0.11 and above point TMPDIR to our work directory and atf-check
	# generates a temporary file, which confuses mtree.  Put the mtree files
	# into a subdirectory.
	#
	# See https://github.com/jmmv/kyua/issues/133 for details.
	mkdir root && cd root

	mkdir newdir
	mtree -F ${FLAVOR} -c | mtree -F ${FLAVOR} -Ck uid,gid,mode > mtree.spec
	ln -s newdir otherdir

	# This yields "extra: otherdir" even with -d.
	# (PR bin/41061)
	atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"

	# Delete the symlink and re-verify.
	#
	rm otherdir
	atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
}

mtree_ignore_head() 
{
	FLAVOR=mtree ignore_head
}
netbsd6_ignore_head() 
{
	FLAVOR=netbsd6 ignore_head
}

mtree_ignore_body() 
{
	FLAVOR=mtree ignore_body
}
netbsd6_ignore_body() 
{
	# Kyua 0.11 and above point TMPDIR to our work directory and atf-check
	# generates a temporary file, which confuses mtree.  Put the mtree files
	# into a subdirectory.
	#
	# See https://github.com/jmmv/kyua/issues/133 for details.
	mkdir root && cd root

	FLAVOR=netbsd6 ignore_body
}


atf_test_case mtree_merge
atf_test_case netbsd6_merge
merge_head()
{
	atf_set "descr" "Merge records of different type"
}

merge_body()
{
	mtree -F ${FLAVOR} -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
	h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
	# same again, with sorting
	mtree -F ${FLAVOR} -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
	h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
}

mtree_merge_head() 
{
	FLAVOR=mtree merge_head
}
netbsd6_merge_head() 
{
	FLAVOR=netbsd6 merge_head
}

mtree_merge_body() 
{
	FLAVOR=mtree merge_body
}
netbsd6_merge_body() 
{
	FLAVOR=netbsd6 merge_body
}


atf_test_case mtree_nonemptydir
atf_test_case netbsd6_nonemptydir
nonemptydir_head()
{
	atf_set "descr" "Test that new non-empty " \
			"directories are recorded (PR bin/25693)"
}

nonemptydir_body()
{
	mkdir testdir
	cd testdir

	mtree -F ${FLAVOR} -c > mtree.spec

	if [ ! -f mtree.spec ]; then
		atf_fail "mtree failed"
	fi

	touch bar
	atf_check -s ignore -o save:output -x "mtree -F ${FLAVOR} -f mtree.spec"

	if [ ! -n "$(egrep "extra: bar" output)" ]; then
		atf_fail "mtree did not record changes (PR bin/25693)"
	fi
}

mtree_nonemptydir_head() 
{
	FLAVOR=mtree nonemptydir_head
}
netbsd6_nonemptydir_head() 
{
	FLAVOR=netbsd6 nonemptydir_head
}

mtree_nonemptydir_body() 
{
	FLAVOR=mtree nonemptydir_body
}
netbsd6_nonemptydir_body() 
{
	FLAVOR=netbsd6 nonemptydir_body
}


atf_init_test_cases()
{
	atf_add_test_case mtree_create
	atf_add_test_case mtree_check
	atf_add_test_case mtree_convert_C
	atf_add_test_case mtree_convert_C_S
	atf_add_test_case mtree_convert_D
	atf_add_test_case mtree_convert_D_S
	atf_add_test_case mtree_ignore
	atf_add_test_case mtree_merge
	atf_add_test_case mtree_nonemptydir

	atf_add_test_case netbsd6_create
	atf_add_test_case netbsd6_check
	atf_add_test_case netbsd6_convert_C
	atf_add_test_case netbsd6_convert_C_S
	atf_add_test_case netbsd6_convert_D
	atf_add_test_case netbsd6_convert_D_S
	atf_add_test_case netbsd6_ignore
	atf_add_test_case netbsd6_merge
	atf_add_test_case netbsd6_nonemptydir
}