MCPcopy Create free account
hub / github.com/coreutils/coreutils / create_hole

Function create_hole

src/copy-file-data.c:64–86  ·  view source on GitHub ↗

Create a hole at the end of the file with descriptor FD and name NAME. The hole is of size SIZE. Assume FD is already at file end, and advance FD past the newly-created hole. Return the resulting position, or -1 on failure. */

Source from the content-addressed store, hash-verified

62 and advance FD past the newly-created hole.
63 Return the resulting position, or -1 on failure. */
64static off_t
65create_hole (int fd, char const *name, off_t size)
66{
67 off_t file_end = lseek (fd, size, SEEK_CUR);
68
69 if (file_end < 0)
70 {
71 error (0, errno, _("cannot lseek %s"), quoteaf (name));
72 return -1;
73 }
74
75 /* Some file systems (like XFS) preallocate when write extending a file.
76 I.e., a previous write() may have preallocated extra space
77 that the seek above will not discard. A subsequent write() could
78 then make this allocation permanent. */
79 if (punch_hole (fd, file_end - size, size) < 0)
80 {
81 error (0, errno, _("error deallocating %s"), quoteaf (name));
82 return -1;
83 }
84
85 return file_end;
86}
87
88/* Does ERR mean the copying operation is not supported or allowed for
89 this file or process, even though the operation was invoked correctly? */

Callers 2

sparse_copyFunction · 0.85
lseek_copyFunction · 0.85

Calls 1

punch_holeFunction · 0.85

Tested by

no test coverage detected