Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F162774535
D51207.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D51207.id.diff
View Options
diff --git a/usr.bin/truncate/tests/truncate_test.sh b/usr.bin/truncate/tests/truncate_test.sh
--- a/usr.bin/truncate/tests/truncate_test.sh
+++ b/usr.bin/truncate/tests/truncate_test.sh
@@ -438,6 +438,53 @@
[ ${st_size} -eq 0 ] || atf_fail "new file should now be 0 bytes"
}
+atf_test_case deallocate
+deallocate_head()
+{
+ atf_set "descr" "Verifies that -d punches a hole in the file"
+ atf_set "require.user" "root"
+}
+deallocate_body()
+{
+ blocksz=$(stat -h . | cut -f1 -d' ')
+ atf_check test -n "$blocksz"
+
+ # We use /dev/random here to defeat ZFS compression, which would
+ # collapse ranges of zeroes into holes without us deallocating it. This
+ # isn't a concern below because those are specificially for creating our
+ # reference files -- we expect the deallocate operation to result in
+ # ranges of zeroes, whether they end up creating a hole or not.
+ filesz=$((blocksz * 3))
+ atf_check -e not-empty dd if=/dev/random of=sparse \
+ bs=${filesz} count=1 conv=notrunc
+
+ atf_check cp sparse sparse.orig
+ atf_check cp sparse sparse.orig.orig
+
+ # Punch a hole in the middle, ensure that bit is zeroed out.
+ atf_check -e not-empty dd if=/dev/zero of=sparse.orig \
+ bs=${blocksz} oseek=1 count=1 conv=notrunc
+ atf_check truncate -d -o ${blocksz} -l ${blocksz} sparse
+ atf_check cmp -s sparse sparse.orig
+
+ # Clobber the end part of the original file and punch a hole in
+ # the same spot on the new file, ensure that it has zeroed out that
+ # portion.
+ atf_check -e not-empty dd if=/dev/zero of=sparse.orig \
+ bs=${blocksz} oseek=2 count=1 conv=notrunc
+ atf_check truncate -d -o $((blocksz * 2)) -l ${blocksz} sparse
+ atf_check cmp -s sparse sparse.orig
+
+ # Now bring the original file back and make sure that punching a hole
+ # in data at the beginning doesn't disturb the data at the end.
+ atf_check cp sparse.orig.orig sparse.orig
+ atf_check cp sparse.orig.orig sparse
+ atf_check -e not-empty dd if=/dev/zero of=sparse.orig \
+ bs=${blocksz} oseek=0 count=1 conv=notrunc
+ atf_check truncate -d -l ${blocksz} sparse
+ atf_check cmp -s sparse sparse.orig
+}
+
atf_init_test_cases()
{
atf_add_test_case illegal_option
@@ -459,4 +506,5 @@
atf_add_test_case roundup
atf_add_test_case rounddown
atf_add_test_case rounddown_zero
+ atf_add_test_case deallocate
}
diff --git a/usr.bin/truncate/truncate.c b/usr.bin/truncate/truncate.c
--- a/usr.bin/truncate/truncate.c
+++ b/usr.bin/truncate/truncate.c
@@ -62,7 +62,6 @@
int do_refer;
int got_size;
char *fname, *rname;
- struct spacectl_range sr;
fd = -1;
rsize = tsize = sz = off = 0;
@@ -198,6 +197,8 @@
tsize = 0;
if (do_dealloc == 1) {
+ struct spacectl_range sr;
+
sr.r_offset = off;
sr.r_len = len;
r = fspacectl(fd, SPACECTL_DEALLOC, &sr, 0, &sr);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jul 17, 6:21 PM (11 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35173689
Default Alt Text
D51207.id.diff (2 KB)
Attached To
Mode
D51207: truncate: fix a minor nit + add a hole-punching test
Attached
Detach File
Event Timeline
Log In to Comment