git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Seek back to current filepos when mmap()ing with NO_MMAP

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 15, 2006, 16:27 UTC
Message-ID
<Pine.LNX.4.63.0611151727000.13772@wbgn013.biozentrum.uni-wuerzburg.de>

"git-index-pack --fix-thin" relies on mmap() not changing the current file position (otherwise the pack will be corrupted when writing the final SHA1). Meet that expectation.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	Sorry for not catching that earlier. It only affects platforms
	where you have to set NO_MMAP=YesPlease, anyway.
 compat/mmap.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/compat/mmap.c b/compat/mmap.c
index 55cb120..a4d2e50 100644
--- a/compat/mmap.c
+++ b/compat/mmap.c
@@ -7,6 +7,7 @@
 void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset)
 {
 	int n = 0;
+	off_t current_offset = lseek(fd, 0, SEEK_CUR);
 
 	if (start != NULL || !(flags & MAP_PRIVATE))
 		die("Invalid usage of gitfakemmap.");
@@ -39,6 +40,11 @@ void *gitfakemmap(void *start, size_t le
 		n += count;
 	}
 
+	if (current_offset != lseek(fd, current_offset, SEEK_SET)) {
+		errno = EINVAL;
+		return MAP_FAILED;
+	}
+
 	return start;
 }
 
-- 
dummy-dirty
Next: Morten Welinder
Message 1 of 4 in “Seek back to current filepos when mmap()ing with NO_MMAP”
  1. Seek back to current filepos when mmap()ing with NO_MMAPJohannes Schindelin, Nov 15, 2006
  2. Morten WelinderNov 15, 2006
  3. Johannes SchindelinNov 15, 2006
  4. Alex RiesenNov 15, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.