~ubuntu-branches/debian/jessie/ufsutils/jessie

« back to all changes in this revision

Viewing changes to debian/patches/00_portable_berase.patch

  • Committer: Package Import Robot
  • Author(s): Robert Millan
  • Date: 2014-05-22 18:05:36 UTC
  • mfrom: (11.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20140522180536-nsmuhw6ryv9awr88
Tags: 10.0-3
Fix FTBFS due to missing <libutil.h> by adding a libutil-freebsd-dev
build-dep (Closes: #741088). Thanks Cyril Brulebois.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
Replace DIOCGDELETE call in berase() with a portable implementation instead
3
 
of just disabling it.
4
 
 
5
 
Patch from upstream (r228349).
6
 
 
7
 
--- a/lib/libufs/block.c
8
 
+++ b/lib/libufs/block.c
9
 
@@ -139,10 +139,56 @@
10
 
        return (cnt);
11
 
 }
12
 
 
13
 
+#ifdef __FreeBSD_kernel__
14
 
+
15
 
+static int
16
 
+berase_helper(struct uufsd *disk, ufs2_daddr_t blockno, ufs2_daddr_t size)
17
 
+{
18
 
+       off_t ioarg[2];
19
 
+
20
 
+       ioarg[0] = blockno * disk->d_bsize;
21
 
+       ioarg[1] = size;
22
 
+       return (ioctl(disk->d_fd, DIOCGDELETE, ioarg));
23
 
+}
24
 
+
25
 
+#else
26
 
+
27
 
+static int
28
 
+berase_helper(struct uufsd *disk, ufs2_daddr_t blockno, ufs2_daddr_t size)
29
 
+{
30
 
+       char *zero_chunk;
31
 
+       off_t offset, zero_chunk_size, pwrite_size;
32
 
+       int rv;
33
 
+
34
 
+       offset = blockno * disk->d_bsize;
35
 
+       zero_chunk_size = 65536 * disk->d_bsize;
36
 
+       zero_chunk = calloc(1, zero_chunk_size);
37
 
+       if (zero_chunk == NULL) {
38
 
+               ERROR(disk, "failed to allocate memory");
39
 
+               return (-1);
40
 
+       }
41
 
+       while (size > 0) { 
42
 
+               pwrite_size = size;
43
 
+               if (pwrite_size > zero_chunk_size)
44
 
+                       pwrite_size = zero_chunk_size;
45
 
+               rv = pwrite(disk->d_fd, zero_chunk, pwrite_size, offset);
46
 
+               if (rv == -1) {
47
 
+                       ERROR(disk, "failed writing to disk");
48
 
+                       break;
49
 
+               }
50
 
+               size -= rv;
51
 
+               offset += rv;
52
 
+               rv = 0;
53
 
+       }
54
 
+       free(zero_chunk);
55
 
+       return (rv);
56
 
+}
57
 
+
58
 
+#endif
59
 
+
60
 
 int
61
 
 berase(struct uufsd *disk, ufs2_daddr_t blockno, ufs2_daddr_t size)
62
 
 {
63
 
-       off_t ioarg[2];
64
 
        int rv;
65
 
 
66
 
        ERROR(disk, NULL);
67
 
@@ -151,8 +197,5 @@
68
 
                ERROR(disk, "failed to open disk for writing");
69
 
                return(rv);
70
 
        }
71
 
-       ioarg[0] = blockno * disk->d_bsize;
72
 
-       ioarg[1] = size;
73
 
-       rv = ioctl(disk->d_fd, DIOCGDELETE, ioarg);
74
 
-       return (rv);
75
 
+       return (berase_helper(disk, blockno, size));
76
 
 }