Exemplo n.º 1
0
/*!
 * \brief Label database, with \p aversion in host order.
 */
int
uphys_setlabel(struct ubik_dbase *adbase, afs_int32 afile,
	       struct ubik_version *aversion)
{
    struct ubik_hdr thdr;
    afs_int32 code, fd;

    fd = uphys_open(adbase, afile);
    if (fd < 0)
	return UNOENT;

    memset(&thdr, 0, sizeof(thdr));

    thdr.version.epoch = htonl(aversion->epoch);
    thdr.version.counter = htonl(aversion->counter);
    thdr.magic = htonl(UBIK_MAGIC);
    thdr.size = htons(HDRSIZE);
    code = write(fd, &thdr, sizeof(thdr));
    fsync(fd);			/* preserve over crash */
    uphys_close(fd);
    if (code != sizeof(thdr)) {
	return EIO;
    }
    return 0;
}
Exemplo n.º 2
0
int
uphys_sync(struct ubik_dbase *adbase, afs_int32 afile)
{
    afs_int32 code, fd;
    fd = uphys_open(adbase, afile);
    code = fsync(fd);
    uphys_close(fd);
    return code;
}
Exemplo n.º 3
0
int
uphys_read(struct ubik_dbase *adbase, afs_int32 afile,
	   void *abuffer, afs_int32 apos, afs_int32 alength)
{
    int fd;
    afs_int32 code;

    fd = uphys_open(adbase, afile);
    if (fd < 0)
	return -1;
    code = lseek(fd, apos + HDRSIZE, 0);
    if (code < 0) {
	uphys_close(fd);
	return -1;
    }
    code = read(fd, abuffer, alength);
    uphys_close(fd);
    return code;
}
Exemplo n.º 4
0
/*!
 * \brief Get database label, with \p aversion in host order.
 */
int
uphys_getlabel(struct ubik_dbase *adbase, afs_int32 afile,
	       struct ubik_version *aversion)
{
    struct ubik_hdr thdr;
    afs_int32 code, fd;

    fd = uphys_open(adbase, afile);
    if (fd < 0)
	return UNOENT;
    code = read(fd, &thdr, sizeof(thdr));
    if (code != sizeof(thdr)) {
	uphys_close(fd);
	return EIO;
    }
    aversion->epoch = ntohl(thdr.version.epoch);
    aversion->counter = ntohl(thdr.version.counter);
    uphys_close(fd);
    return 0;
}
Exemplo n.º 5
0
int
uphys_truncate(struct ubik_dbase *adbase, afs_int32 afile,
	       afs_int32 asize)
{
    afs_int32 code, fd;
    fd = uphys_open(adbase, afile);
    if (fd < 0)
	return UNOENT;
    code = ftruncate(fd, asize + HDRSIZE);
    uphys_close(fd);
    return code;
}
Exemplo n.º 6
0
int
uphys_write(struct ubik_dbase *adbase, afs_int32 afile,
	    void *abuffer, afs_int32 apos, afs_int32 alength)
{
    int fd;
    afs_int32 code;
    afs_int32 length;

    fd = uphys_open(adbase, afile);
    if (fd < 0)
	return -1;
    code = lseek(fd, apos + HDRSIZE, 0);
    if (code < 0) {
	uphys_close(fd);
	return -1;
    }
    length = write(fd, abuffer, alength);
    code = uphys_close(fd);
    if (code)
	return -1;
    else
	return length;
}
Exemplo n.º 7
0
int
uphys_stat(struct ubik_dbase *adbase, afs_int32 afid, struct ubik_stat *astat)
{
    int fd;
    struct stat tstat;
    afs_int32 code;

    fd = uphys_open(adbase, afid);
    if (fd < 0)
	return fd;
    code = fstat(fd, &tstat);
    uphys_close(fd);
    if (code < 0) {
	return code;
    }
    astat->mtime = tstat.st_mtime;
    code = tstat.st_size - HDRSIZE;
    if (code < 0)
	astat->size = 0;
    else
	astat->size = code;
    return 0;
}