1 #include <TargetConditionals.h>
3 #if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
10 #import <Foundation/Foundation.h>
12 #include "hfs-tests.h"
13 #include "test-utils.h"
14 #include "disk-image.h"
18 #define DISK_IMAGE "/tmp/file_too_big.sparseimage"
20 int run_file_too_big(__unused test_ctx_t *ctx)
24 disk_image_t *di = disk_image_create(DISK_IMAGE, &(disk_image_opts_t){
28 struct timeval start, end, elapsed;
31 asprintf(&file, "%s/file-too-big", di->mount_point);
32 assert_with_errno((fd = open(file, O_RDWR | O_CREAT, 0666)) >= 0);
34 assert_no_err(gettimeofday(&start, NULL));
36 assert(pwrite(fd, &fd, 4, 128 * 1024ull * 1024 * 1024 * 1024) == -1
39 assert_no_err(close(fd));
41 assert_no_err(gettimeofday(&end, NULL));
43 timersub(&end, &start, &elapsed);
44 assert(elapsed.tv_sec < 1);
48 assert_no_err(gettimeofday(&start, NULL));
50 assert(truncate(file, 128 * 1024ull * 1024 * 1024 * 1024) == -1);
51 assert_with_errno(errno == ENOSPC);
53 assert_no_err(gettimeofday(&end, NULL));
55 timersub(&end, &start, &elapsed);
56 assert(elapsed.tv_sec < 1);
60 assert_no_err(gettimeofday(&start, NULL));
62 assert((fd = open(file, O_RDWR)) >= 0);
65 .fst_flags = F_ALLOCATEALL,
66 .fst_posmode = F_PEOFPOSMODE,
67 .fst_length = 128 * 1024ull * 1024 * 1024 * 1024,
70 assert(fcntl(fd, F_PREALLOCATE, &fst) == -1 && errno == ENOSPC);
71 assert(fst.fst_bytesalloc == 0);
73 assert_no_err(close(fd));
75 assert_no_err(gettimeofday(&end, NULL));
77 timersub(&end, &start, &elapsed);
78 assert(elapsed.tv_sec < 1);
80 // And check preallocate works without the F_ALLOCATEALL flag
82 assert((fd = open(file, O_RDWR)) >= 0);
86 assert(fcntl(fd, F_PREALLOCATE, &fst) == -1 && errno == ENOSPC);
88 // It should have allocated at least 32 MB
89 assert(fst.fst_bytesalloc > 32 * 1024 * 1024);
91 assert_no_err(close(fd));
96 #endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)