summaryrefslogtreecommitdiff
path: root/emulators/qemu/files/patch-bg
blob: 26d0bf2833bced116a2e2fc50b67abf866140926 (plain) (blame)
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
Index: qemu/qemu-mkcow.c
@@ -21,6 +21,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "config-host.h"
+ 
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -36,6 +38,12 @@
 #include <sys/stat.h>
 #include <netinet/in.h>
 
+#ifdef _BSD
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/disk.h>
+#endif
+
 #include "cow.h"
 
 #include "bswap.h"
@@ -56,6 +64,13 @@ int cow_create(int cow_fd, const char *i
             perror(image_filename);
             exit(1);
         }
+#ifdef _BSD
+        struct stat sb;
+        if (!fstat(fd,&sb) && (S_IFCHR & sb.st_mode)) {
+            if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&image_sectors))
+                image_sectors = lseek(fd, 0LL, SEEK_END);
+        } else
+#endif                      
         image_sectors = lseek64(fd, 0, SEEK_END);
         if (fstat(fd, &st) != 0) {
             close(fd);