mas01cr@400: #include "audioDB.h" mas01cr@400: extern "C" { mas01cr@400: #include "audioDB_API.h" mas01cr@400: } mas01cr@400: mas01cr@400: /* FIXME: we should not export this symbol to users of the library. */ mas01cr@400: int audiodb_sync_header(adb_t *adb) { mas01cr@400: off_t pos; mas01cr@400: pos = lseek(adb->fd, (off_t) 0, SEEK_CUR); mas01cr@400: if(pos == (off_t) -1) { mas01cr@400: goto error; mas01cr@400: } mas01cr@400: if(lseek(adb->fd, (off_t) 0, SEEK_SET) == (off_t) -1) { mas01cr@400: goto error; mas01cr@400: } mas01cr@400: if(write(adb->fd, adb->header, O2_HEADERSIZE) != O2_HEADERSIZE) { mas01cr@400: goto error; mas01cr@400: } mas01cr@400: mas01cr@400: /* can be fsync() if fdatasync() is racily exciting and new */ mas01cr@400: fdatasync(adb->fd); mas01cr@400: if(lseek(adb->fd, pos, SEEK_SET) == (off_t) -1) { mas01cr@400: goto error; mas01cr@400: } mas01cr@400: return 0; mas01cr@400: mas01cr@400: error: mas01cr@400: return 1; mas01cr@400: } mas01cr@400: mas01cr@400: int audiodb_power(adb_t *adb) { mas01cr@400: /* FIXME: we should probably include in adb_t information about mas01cr@400: * which mode (O_RDONLY|O_RDWR) the database was opened, so that we mas01cr@400: * can check that it's writeable. */ mas01cr@400: if(adb->header->length > 0) { mas01cr@400: return 1; mas01cr@400: } mas01cr@400: mas01cr@400: adb->header->flags |= O2_FLAG_POWER; mas01cr@400: return audiodb_sync_header(adb); mas01cr@400: }