summaryrefslogtreecommitdiffstats
path: root/testsuites/fstests/fsrdwr/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/fstests/fsrdwr/init.c')
-rw-r--r--testsuites/fstests/fsrdwr/init.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/testsuites/fstests/fsrdwr/init.c b/testsuites/fstests/fsrdwr/init.c
index 9821cffe19..e8576b4b7a 100644
--- a/testsuites/fstests/fsrdwr/init.c
+++ b/testsuites/fstests/fsrdwr/init.c
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <memory.h>
#include <unistd.h>
+#include <errno.h>
#include "fstest.h"
#include "pmacros.h"
@@ -748,6 +749,61 @@ block_read_and_write (void)
test_case_leave ();
}
+static void
+write_until_no_space_is_left (void)
+{
+ static const char file [] = "zero";
+ int fd;
+ struct stat st;
+ int status;
+ blksize_t block_size;
+ char *out;
+ ssize_t chunk_size;
+ ssize_t written;
+ off_t total;
+
+ /* Use the root directory to account for some FAT12 or FAT16 specialities */
+ printf ("test case: %s\n", __func__);
+
+ fd = open (file, O_RDWR | O_CREAT | O_TRUNC, mode);
+ rtems_test_assert (fd >= 0);
+
+ status = fstat (fd, &st);
+ rtems_test_assert (status == 0);
+ rtems_test_assert (st.st_size == 0);
+ rtems_test_assert (st.st_blksize > 0);
+ block_size = st.st_blksize;
+
+ out = calloc (1, block_size);
+ rtems_test_assert (out != NULL);
+
+ total = 0;
+ chunk_size = block_size / 2;
+ do {
+ errno = 0;
+
+ written = write (fd, out, chunk_size);
+ if (written > 0) {
+ total += written;
+ }
+
+ chunk_size = block_size;
+ } while (written > 0);
+
+ rtems_test_assert (written == -1);
+ rtems_test_assert (errno == ENOSPC || errno == EFBIG);
+
+ status = close (fd);
+ rtems_test_assert (status == 0);
+
+ /* Do not use fstat() to do the path evaluation again */
+ status = lstat (file, &st);
+ rtems_test_assert (status == 0);
+ rtems_test_assert (st.st_size == total);
+
+ free (out);
+}
+
void
test (void)
{
@@ -756,4 +812,5 @@ test (void)
truncate_test03 ();
truncate_to_zero ();
block_read_and_write ();
+ write_until_no_space_is_left ();
}