summaryrefslogtreecommitdiff
path: root/regress/sys/ffs/tests/truncate
diff options
context:
space:
mode:
Diffstat (limited to 'regress/sys/ffs/tests/truncate')
-rw-r--r--regress/sys/ffs/tests/truncate/00.t46
-rw-r--r--regress/sys/ffs/tests/truncate/01.t13
-rw-r--r--regress/sys/ffs/tests/truncate/02.t10
-rw-r--r--regress/sys/ffs/tests/truncate/03.t17
-rw-r--r--regress/sys/ffs/tests/truncate/04.t12
-rw-r--r--regress/sys/ffs/tests/truncate/05.t27
-rw-r--r--regress/sys/ffs/tests/truncate/06.t19
-rw-r--r--regress/sys/ffs/tests/truncate/07.t14
-rw-r--r--regress/sys/ffs/tests/truncate/08.t52
-rw-r--r--regress/sys/ffs/tests/truncate/09.t10
-rw-r--r--regress/sys/ffs/tests/truncate/10.t27
-rw-r--r--regress/sys/ffs/tests/truncate/11.t11
-rw-r--r--regress/sys/ffs/tests/truncate/12.t22
-rw-r--r--regress/sys/ffs/tests/truncate/13.t11
-rw-r--r--regress/sys/ffs/tests/truncate/14.t7
15 files changed, 298 insertions, 0 deletions
diff --git a/regress/sys/ffs/tests/truncate/00.t b/regress/sys/ffs/tests/truncate/00.t
new file mode 100644
index 00000000000..295ec7b9158
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/00.t
@@ -0,0 +1,46 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/00.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate descrease/increase file size"
+
+n0=`namegen`
+n1=`namegen`
+
+expect 0 mkdir ${n1} 0755
+cdir=`pwd`
+cd ${n1}
+
+expect 0 create ${n0} 0644
+expect 0 truncate ${n0} 1234567
+expect 1234567 lstat ${n0} size
+expect 0 truncate ${n0} 567
+expect 567 lstat ${n0} size
+expect 0 unlink ${n0}
+
+dd if=/dev/random of=${n0} bs=12345 count=1 >/dev/null 2>&1
+expect 0 truncate ${n0} 23456
+expect 23456 lstat ${n0} size
+expect 0 truncate ${n0} 1
+expect 1 lstat ${n0} size
+expect 0 unlink ${n0}
+
+# successful truncate(2) updates ctime.
+expect 0 create ${n0} 0644
+ctime1=`${FSTEST} stat ${n0} ctime`
+sleep 1
+expect 0 truncate ${n0} 123
+ctime2=`${FSTEST} stat ${n0} ctime`
+test_check $ctime1 -lt $ctime2
+expect 0 unlink ${n0}
+
+# unsuccessful truncate(2) does not update ctime.
+expect 0 create ${n0} 0644
+ctime1=`${FSTEST} stat ${n0} ctime`
+sleep 1
+expect EACCES -u 65534 truncate ${n0} 123
+ctime2=`${FSTEST} stat ${n0} ctime`
+test_check $ctime1 -eq $ctime2
+expect 0 unlink ${n0}
+
+cd ${cdir}
+expect 0 rmdir ${n1}
diff --git a/regress/sys/ffs/tests/truncate/01.t b/regress/sys/ffs/tests/truncate/01.t
new file mode 100644
index 00000000000..d70cd3fd931
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/01.t
@@ -0,0 +1,13 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/01.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns ENOTDIR if a component of the path prefix is not a directory"
+
+n0=`namegen`
+n1=`namegen`
+
+expect 0 mkdir ${n0} 0755
+expect 0 create ${n0}/${n1} 0644
+expect ENOTDIR truncate ${n0}/${n1}/test 123
+expect 0 unlink ${n0}/${n1}
+expect 0 rmdir ${n0}
diff --git a/regress/sys/ffs/tests/truncate/02.t b/regress/sys/ffs/tests/truncate/02.t
new file mode 100644
index 00000000000..65adbb546fa
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/02.t
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/02.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns ENAMETOOLONG if a component of a pathname exceeded 255 characters"
+
+expect 0 create ${name255} 0644
+expect 0 truncate ${name255} 123
+expect 123 stat ${name255} size
+expect 0 unlink ${name255}
+expect ENAMETOOLONG truncate ${name256} 123
diff --git a/regress/sys/ffs/tests/truncate/03.t b/regress/sys/ffs/tests/truncate/03.t
new file mode 100644
index 00000000000..c61ca57a34a
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/03.t
@@ -0,0 +1,17 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/03.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns ENAMETOOLONG if an entire path name exceeded 1023 characters"
+
+expect 0 mkdir ${name255} 0755
+expect 0 mkdir ${name255}/${name255} 0755
+expect 0 mkdir ${name255}/${name255}/${name255} 0755
+expect 0 mkdir ${path1021} 0755
+expect 0 create ${path1023} 0644
+expect 0 truncate ${path1023} 123
+expect 0 unlink ${path1023}
+expect ENAMETOOLONG truncate ${path1024} 123
+expect 0 rmdir ${path1021}
+expect 0 rmdir ${name255}/${name255}/${name255}
+expect 0 rmdir ${name255}/${name255}
+expect 0 rmdir ${name255}
diff --git a/regress/sys/ffs/tests/truncate/04.t b/regress/sys/ffs/tests/truncate/04.t
new file mode 100644
index 00000000000..5ab0a1e664d
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/04.t
@@ -0,0 +1,12 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/04.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns ENOENT if the named file does not exist"
+
+n0=`namegen`
+n1=`namegen`
+
+expect 0 mkdir ${n0} 0755
+expect ENOENT truncate ${n0}/${n1}/test 123
+expect ENOENT truncate ${n0}/${n1} 123
+expect 0 rmdir ${n0}
diff --git a/regress/sys/ffs/tests/truncate/05.t b/regress/sys/ffs/tests/truncate/05.t
new file mode 100644
index 00000000000..e0134729e79
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/05.t
@@ -0,0 +1,27 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/05.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns EACCES when search permission is denied for a component of the path prefix"
+
+n0=`namegen`
+n1=`namegen`
+n2=`namegen`
+
+expect 0 mkdir ${n0} 0755
+cdir=`pwd`
+cd ${n0}
+expect 0 mkdir ${n1} 0755
+expect 0 chown ${n1} 65534 65534
+expect 0 -u 65534 -g 65534 create ${n1}/${n2} 0644
+expect 0 -u 65534 -g 65534 truncate ${n1}/${n2} 123
+expect 123 -u 65534 -g 65534 stat ${n1}/${n2} size
+expect 0 chmod ${n1} 0644
+expect EACCES -u 65534 -g 65534 truncate ${n1}/${n2} 1234
+expect 0 chmod ${n1} 0755
+expect 123 -u 65534 -g 65534 stat ${n1}/${n2} size
+expect 0 -u 65534 -g 65534 truncate ${n1}/${n2} 1234
+expect 1234 -u 65534 -g 65534 stat ${n1}/${n2} size
+expect 0 -u 65534 -g 65534 unlink ${n1}/${n2}
+expect 0 rmdir ${n1}
+cd ${cdir}
+expect 0 rmdir ${n0}
diff --git a/regress/sys/ffs/tests/truncate/06.t b/regress/sys/ffs/tests/truncate/06.t
new file mode 100644
index 00000000000..d7a3eda2816
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/06.t
@@ -0,0 +1,19 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/06.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns EACCES if the named file is not writable by the user"
+
+n0=`namegen`
+n1=`namegen`
+
+expect 0 mkdir ${n0} 0755
+cdir=`pwd`
+cd ${n0}
+expect 0 create ${n1} 0644
+expect EACCES -u 65534 -g 65534 truncate ${n1} 123
+expect 0 chown ${n1} 65534 65534
+expect 0 chmod ${n1} 0444
+expect EACCES -u 65534 -g 65534 truncate ${n1} 123
+expect 0 unlink ${n1}
+cd ${cdir}
+expect 0 rmdir ${n0}
diff --git a/regress/sys/ffs/tests/truncate/07.t b/regress/sys/ffs/tests/truncate/07.t
new file mode 100644
index 00000000000..98c70a0ef58
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/07.t
@@ -0,0 +1,14 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/07.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns ELOOP if too many symbolic links were encountered in translating the pathname"
+
+n0=`namegen`
+n1=`namegen`
+
+expect 0 symlink ${n0} ${n1}
+expect 0 symlink ${n1} ${n0}
+expect ELOOP truncate ${n0}/test 123
+expect ELOOP truncate ${n1}/test 123
+expect 0 unlink ${n0}
+expect 0 unlink ${n1}
diff --git a/regress/sys/ffs/tests/truncate/08.t b/regress/sys/ffs/tests/truncate/08.t
new file mode 100644
index 00000000000..48ab6a843d8
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/08.t
@@ -0,0 +1,52 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/08.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns EPERM if the named file has its immutable or append-only flag set"
+
+n0=`namegen`
+
+expect 0 create ${n0} 0644
+expect 0 chflags ${n0} SF_IMMUTABLE
+expect EPERM truncate ${n0} 123
+expect 0 stat ${n0} size
+expect 0 chflags ${n0} none
+expect 0 truncate ${n0} 123
+expect 0 unlink ${n0}
+
+expect 0 create ${n0} 0644
+expect 0 chflags ${n0} UF_IMMUTABLE
+expect EPERM truncate ${n0} 123
+expect 0 stat ${n0} size
+expect 0 chflags ${n0} none
+expect 0 truncate ${n0} 123
+expect 0 unlink ${n0}
+
+expect 0 create ${n0} 0644
+expect 0 chflags ${n0} SF_APPEND
+expect EPERM truncate ${n0} 123
+expect 0 stat ${n0} size
+expect 0 chflags ${n0} none
+expect 0 truncate ${n0} 123
+expect 0 unlink ${n0}
+
+expect 0 create ${n0} 0644
+expect 0 chflags ${n0} UF_APPEND
+expect EPERM truncate ${n0} 123
+expect 0 stat ${n0} size
+expect 0 chflags ${n0} none
+expect 0 truncate ${n0} 123
+expect 0 unlink ${n0}
+
+expect 0 create ${n0} 0644
+expect 0 chflags ${n0} SF_NOUNLINK
+expect 0 truncate ${n0} 123
+expect 123 stat ${n0} size
+expect 0 chflags ${n0} none
+expect 0 unlink ${n0}
+
+expect 0 create ${n0} 0644
+expect 0 chflags ${n0} UF_NOUNLINK
+expect 0 truncate ${n0} 123
+expect 123 stat ${n0} size
+expect 0 chflags ${n0} none
+expect 0 unlink ${n0}
diff --git a/regress/sys/ffs/tests/truncate/09.t b/regress/sys/ffs/tests/truncate/09.t
new file mode 100644
index 00000000000..897ab0a575a
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/09.t
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/09.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns EISDIR if the named file is a directory"
+
+n0=`namegen`
+
+expect 0 mkdir ${n0} 0755
+expect EISDIR truncate ${n0} 123
+expect 0 rmdir ${n0}
diff --git a/regress/sys/ffs/tests/truncate/10.t b/regress/sys/ffs/tests/truncate/10.t
new file mode 100644
index 00000000000..5479cefde7c
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/10.t
@@ -0,0 +1,27 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/10.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns EROFS if the named file resides on a read-only file system"
+
+n0=`namegen`
+n1=`namegen`
+
+expect 0 mkdir ${n0} 0755
+dd if=/dev/zero of=tmpdisk bs=1k count=1024 2>/dev/null
+vnconfig svnd1 tmpdisk
+newfs /dev/rsvnd1c >/dev/null
+mount /dev/svnd1c ${n0}
+expect 0 create ${n0}/${n1} 0644
+expect 0 truncate ${n0}/${n1} 123
+expect 123 stat ${n0}/${n1} size
+mount -ur /dev/svnd1c
+expect EROFS truncate ${n0}/${n1} 1234
+expect 123 stat ${n0}/${n1} size
+mount -uw /dev/svnd1c
+expect 0 truncate ${n0}/${n1} 1234
+expect 1234 stat ${n0}/${n1} size
+expect 0 unlink ${n0}/${n1}
+umount /dev/svnd1c
+vnconfig -u svnd1
+rm tmpdisk
+expect 0 rmdir ${n0}
diff --git a/regress/sys/ffs/tests/truncate/11.t b/regress/sys/ffs/tests/truncate/11.t
new file mode 100644
index 00000000000..87b339db538
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/11.t
@@ -0,0 +1,11 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/11.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns ETXTBSY the file is a pure procedure (shared text) file that is being executed"
+
+n0=`namegen`
+
+cp -pf `which sleep` ${n0}
+./${n0} 3 &
+expect ETXTBSY truncate ${n0} 123
+expect 0 unlink ${n0}
diff --git a/regress/sys/ffs/tests/truncate/12.t b/regress/sys/ffs/tests/truncate/12.t
new file mode 100644
index 00000000000..c3786f1719d
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/12.t
@@ -0,0 +1,22 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/12.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns EFBIG or EINVAL if the length argument was greater than the maximum file size"
+
+n0=`namegen`
+
+expect 0 create ${n0} 0644
+r=`${FSTEST} truncate ${n0} 999999999999999 2>/dev/null`
+case "${r}" in
+EFBIG|EINVAL)
+ expect 0 stat ${n0} size
+ ;;
+0)
+ expect 999999999999999 stat ${n0} size
+ ;;
+*)
+ echo "not ok ${ntest}"
+ ntest=`expr ${ntest} + 1`
+ ;;
+esac
+expect 0 unlink ${n0}
diff --git a/regress/sys/ffs/tests/truncate/13.t b/regress/sys/ffs/tests/truncate/13.t
new file mode 100644
index 00000000000..30c63cf5ac7
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/13.t
@@ -0,0 +1,11 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/13.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns EINVAL if the length argument was less than 0"
+
+n0=`namegen`
+
+expect 0 create ${n0} 0644
+expect EINVAL truncate ${n0} -1
+expect EINVAL truncate ${n0} -999999
+expect 0 unlink ${n0}
diff --git a/regress/sys/ffs/tests/truncate/14.t b/regress/sys/ffs/tests/truncate/14.t
new file mode 100644
index 00000000000..84723d2d211
--- /dev/null
+++ b/regress/sys/ffs/tests/truncate/14.t
@@ -0,0 +1,7 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/fstest/tests/truncate/14.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
+
+desc="truncate returns EFAULT if the path argument points outside the process's allocated address space"
+
+expect EFAULT truncate NULL 123
+expect EFAULT truncate DEADCODE 123