2 * Copyright 2007-2008, Ingo Weinhold, bonefish@cs.tu-berlin.de.
3 * Distributed under the terms of the MIT License.
6 #include "compatibility.h"
10 #if defined(HAIKU_HOST_PLATFORM_FREEBSD)
19 #include "partition_support.h"
22 static const fssh_size_t kMaxIOVecs
= 1024;
26 prepare_iovecs(const struct fssh_iovec
*vecs
, fssh_size_t count
,
27 struct iovec
* systemVecs
)
29 if (count
> kMaxIOVecs
) {
34 for (fssh_size_t i
= 0; i
< count
; i
++) {
35 systemVecs
[i
].iov_base
= vecs
[i
].iov_base
;
36 systemVecs
[i
].iov_len
= vecs
[i
].iov_len
;
44 fssh_readv(int fd
, const struct fssh_iovec
*vector
, fssh_size_t count
)
46 struct iovec systemVecs
[kMaxIOVecs
];
47 if (!prepare_iovecs(vector
, count
, systemVecs
))
51 fssh_size_t length
= 0;
52 if (FSShell::restricted_file_restrict_io(fd
, pos
, length
) < 0)
55 #if !defined(HAIKU_HOST_PLATFORM_FREEBSD)
56 return readv(fd
, systemVecs
, count
);
58 return readv_pos(fd
, lseek(fd
, 0, SEEK_CUR
), systemVecs
, count
);
64 fssh_readv_pos(int fd
, fssh_off_t pos
, const struct fssh_iovec
*vec
,
67 struct iovec systemVecs
[kMaxIOVecs
];
68 if (!prepare_iovecs(vec
, count
, systemVecs
))
71 fssh_size_t length
= 0;
72 if (FSShell::restricted_file_restrict_io(fd
, pos
, length
) < 0)
75 return readv_pos(fd
, pos
, systemVecs
, count
);
80 fssh_writev(int fd
, const struct fssh_iovec
*vector
, fssh_size_t count
)
82 struct iovec systemVecs
[kMaxIOVecs
];
83 if (!prepare_iovecs(vector
, count
, systemVecs
))
87 fssh_size_t length
= 0;
88 if (FSShell::restricted_file_restrict_io(fd
, pos
, length
) < 0)
91 #if !defined(HAIKU_HOST_PLATFORM_FREEBSD)
92 return writev(fd
, systemVecs
, count
);
94 return writev_pos(fd
, lseek(fd
, 0, SEEK_CUR
), systemVecs
, count
);
100 fssh_writev_pos(int fd
, fssh_off_t pos
, const struct fssh_iovec
*vec
,
103 struct iovec systemVecs
[kMaxIOVecs
];
104 if (!prepare_iovecs(vec
, count
, systemVecs
))
107 fssh_size_t length
= 0;
108 if (FSShell::restricted_file_restrict_io(fd
, pos
, length
) < 0)
111 return writev_pos(fd
, pos
, systemVecs
, count
);