Fill st_ino in stat replies.
[vcfs.git] / utils.c
CommitLineData
d5cf5351 1#define _LARGEFILE64_SOURCE
2#define _XOPEN_SOURCE 500
3#include <stdlib.h>
4#include <unistd.h>
5#include <errno.h>
6
7#include "utils.h"
8
9int readall(int fd, void *buf, size_t len, loff_t offset)
10{
11 int ret;
12
13 while(len > 0) {
14 /*
15 if(lseek(fd, offset, SEEK_SET) != offset)
16 return(-1);
17 ret = read(fd, buf, len);
18 */
19 ret = pread64(fd, buf, len, offset);
20 if(ret < 0)
21 return(-1);
22 if(ret == 0) {
23 errno = ENODATA;
24 return(-1);
25 }
26 buf += ret;
27 len -= ret;
28 offset += ret;
29 }
30 return(0);
31}
32
33int writeall(int fd, const void *buf, size_t len, loff_t offset)
34{
35 int ret;
36
37 while(len > 0) {
38 /*
39 if(lseek(fd, offset, SEEK_SET) != offset)
40 return(-1);
41 ret = write(fd, buf, len);
42 */
43 ret = pwrite64(fd, buf, len, offset);
44 if(ret < 0)
45 return(-1);
46 buf += ret;
47 len -= ret;
48 offset += ret;
49 }
50 return(0);
51}