File: git-libstore-file-512b-block

package info (click to toggle)
hurd 1%3A0.9.git20250801-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 37,308 kB
  • sloc: ansic: 538,797; sh: 5,143; asm: 2,998; makefile: 2,303; perl: 589; pascal: 484; awk: 157
file content (46 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
commit 2257593d583b2016d73d4b6eb7a76bda751c1c5a
Author: Stéphane Glondu <glondu@debian.org>
Date:   Sat Aug 23 10:57:03 2025 +0200

    libstore: use 512-byte blocks if file size is a multiple
    
    As suggested in:
    
      https://lists.debian.org/aKheR0SX8yI5Aw9Q@begin

diff --git a/libstore/file.c b/libstore/file.c
index c54eee91..80d6812a 100644
--- a/libstore/file.c
+++ b/libstore/file.c
@@ -271,16 +271,29 @@ store_file_create (file_t file, int flags, struct store **store)
   struct store_run run;
   struct stat stat;
   error_t err = io_stat (file, &stat);
+  size_t block_size;
+  size_t sector_size = 512;
 
   if (err)
     return err;
 
   run.start = 0;
-  run.length = stat.st_size;
+
+  /* Try to use a sector as block size.  */
+  if ((stat.st_size % sector_size) == 0)
+    {
+      block_size = sector_size;
+      run.length = stat.st_size / sector_size;
+    }
+  else
+    {
+      block_size = 1;
+      run.length = stat.st_size;
+    }
 
   flags |= STORE_ENFORCED;	/* 'cause it's the whole file.  */
 
-  return _store_file_create (file, flags, 1, &run, 1, store);
+  return _store_file_create (file, flags, block_size, &run, 1, store);
 }
 
 /* Like store_file_create, but doesn't query the file for information.  */