3 * libjio - A library for Journaled I/O
4 * Alberto Bertogli (albertogli@telpin.com.ar)
21 /* like lockf, but lock always from the beginning of the file */
22 off_t
plockf(int fd
, int cmd
, off_t offset
, off_t len
)
32 } else if (cmd
& _F_WRITE
) {
38 } else if (cmd
& _F_TLOCK
) {
40 } else if (cmd
& F_UNLOCK
) {
42 op
= F_SETLKW
; /* not very relevant */
45 fl
.l_whence
= SEEK_SET
;
49 return fcntl(fd
, op
, &fl
);
52 /* like pread but either fails, or return a complete read; if we return less
53 * than count is because EOF was reached */
54 ssize_t
spread(int fd
, void *buf
, size_t count
, off_t offset
)
61 rv
= pread(fd
, (char *) buf
+ c
, count
- c
, offset
+ c
);
73 /* incomplete read, keep on reading */
80 /* like spread() but for pwrite() */
81 ssize_t
spwrite(int fd
, const void *buf
, size_t count
, off_t offset
)
88 rv
= pwrite(fd
, (char *) buf
+ c
, count
- c
, offset
+ c
);
94 /* error/nothing was written */
97 /* incomplete write, keep on writing */
104 /* build the journal directory name out of the filename */
105 int get_jdir(const char *filename
, char *jdir
)
110 baset
= strdup(filename
);
113 base
= basename(baset
);
115 dirt
= strdup(filename
);
120 snprintf(jdir
, PATH_MAX
, "%s/.%s.jio", dir
, base
);
128 /* build the filename of a given transaction */
129 int get_jtfile(const char *filename
, int tid
, char *jtfile
)
134 baset
= strdup(filename
);
137 base
= basename(baset
);
139 dirt
= strdup(filename
);
144 snprintf(jtfile
, PATH_MAX
, "%s/.%s.jio/%d", dir
, base
, tid
);