Debian Codegraph @

tests/ts/blkid/cache

raw
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2009 Karel Zak <[email protected]>
5 #
6 # This file is part of util-linux.
7 #
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This file is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18
19 TS_TOPDIR="${0%/*}/../.."
20 TS_DESC="caching"
21
22 . "$TS_TOPDIR"/functions.sh
23
24 ts_init "$*"
25
26 ts_skip_nonroot
27 ts_check_test_command "$TS_CMD_BLKID"
28 ts_check_test_command "$TS_CMD_MKSWAP"
29 ts_check_losetup
30
31 ts_device_init
32
33 "$TS_CMD_MKSWAP" --quiet --pagesize 4096 --endianness little \
34 --uuid 11111111-1111-1111-1111-111111111111 \
35 "$TS_LODEV" \
36 >> "$TS_OUTPUT" 2>> "$TS_ERRLOG"
37
38 "$TS_CMD_BLKID" "$TS_LODEV" \
39 | sed -e "s|$TS_LODEV|DEVICE|" \
40 >> "$TS_OUTPUT" 2>> "$TS_ERRLOG"
41
42 cat "$BLKID_FILE" | grep "$TS_LODEV" \
43 | sed -e 's/DEVNO="[^"]*"/DEVNO=""/' \
44 -e 's/TIME="[^"]*"/TIME=""/' \
45 -e "s|$TS_LODEV|DEVICE|" \
46 >> "$TS_OUTPUT"
47
48 # Test the cache garbage collection by detaching a newly registered
49 # loop device before garbage collection.
50 # We expect $TS_LODEV (/dev/loopX) to not be present in $BLKID_FILE
51 # anymore after the operation.
52
53 # Initialize another loop device to keep at least the previously
54 # attached one in the cache. We do this because otherwise the list of
55 # block devices (blkid_cache->bic_devs) will be empty and that will
56 # prevent an update of the cache.
57 # See libblkid/src/save.c::blkid_flush_cache()
58 ts_device_init
59
60 "$TS_CMD_MKSWAP" --quiet --pagesize 4096 --endianness little \
61 --uuid 221ffb62-649b-4f86-87ae-0ebd15daf169 \
62 "$TS_LODEV" &>/dev/null
63
64 # Update the cache with new loop device
65 "$TS_CMD_BLKID" &>/dev/null
66
67 ts_device_deinit "$TS_LODEV"
68
69 "$TS_CMD_BLKID" --garbage-collect &>/dev/null
70
71 if grep "$TS_LODEV" "$BLKID_FILE" &>/dev/null ; then
72 ts_failed "cache garbage collection failed"
73 fi
74
75
76 ts_finalize