ham_status_t os_pwrite(ham_fd_t fd, ham_offset_t addr, const void *buffer, ham_offset_t bufferlen) { ham_status_t st; st=os_seek(fd, addr, HAM_OS_SEEK_SET); if (st) return (st); return (os_write(fd, buffer, bufferlen)); }
/* Fill a given buffer with the given block in volume. */ int volume_readinbuf(volume * vol,void* buf, long block) { UInt16 blksize_bits; ASSERT( block < vol->maxblocks); blksize_bits = vol->blksize_bits; block += vol->startblock; if( os_seek(vol->os_fd, block, blksize_bits) == block) if( 1 == os_read(vol->os_fd, buf, 1, blksize_bits)) return 0; return -1; }
ham_status_t os_truncate(ham_fd_t fd, ham_offset_t newsize) { ham_status_t st; st=os_seek(fd, newsize, HAM_OS_SEEK_SET); if (st) return (st); if (!SetEndOfFile((HANDLE)fd)) { char buf[256]; st=(ham_status_t)GetLastError(); ham_log(("SetEndOfFile failed with OS status %u (%s)", st, DisplayError(buf, sizeof(buf), st))); return (HAM_IO_ERROR); } return (HAM_SUCCESS); }
void cw_close(CompoundWriter *cw) { OutStream *os = NULL; int i; if (cw->ids->size <= 0) { RAISE(STATE_ERROR, "Tried to merge compound file with no entries"); } os = cw->store->new_output(cw->store, cw->name); os_write_vint(os, ary_size(cw->file_entries)); /* Write the directory with all offsets at 0. * Remember the positions of directory entries so that we can adjust the * offsets later */ for (i = 0; i < ary_size(cw->file_entries); i++) { cw->file_entries[i].dir_offset = os_pos(os); os_write_u64(os, 0); /* for now */ os_write_string(os, cw->file_entries[i].name); } /* Open the files and copy their data into the stream. Remember the * locations of each file's data section. */ for (i = 0; i < ary_size(cw->file_entries); i++) { cw->file_entries[i].data_offset = os_pos(os); cw_copy_file(cw, &cw->file_entries[i], os); } /* Write the data offsets into the directory of the compound stream */ for (i = 0; i < ary_size(cw->file_entries); i++) { os_seek(os, cw->file_entries[i].dir_offset); os_write_u64(os, cw->file_entries[i].data_offset); } if (os) { os_close(os); } hs_destroy(cw->ids); ary_free(cw->file_entries); free(cw); }
ham_status_t os_pread(ham_fd_t fd, ham_offset_t addr, void *buffer, ham_offset_t bufferlen) { ham_status_t st; DWORD read=0; st=os_seek(fd, addr, HAM_OS_SEEK_SET); if (st) return (st); if (!ReadFile((HANDLE)fd, buffer, (DWORD)bufferlen, &read, 0)) { char buf[256]; st=(ham_status_t)GetLastError(); ham_log(("ReadFile failed with OS status %u (%s)", st, DisplayError(buf, sizeof(buf), st))); return (HAM_IO_ERROR); } return (read==bufferlen ? 0 : HAM_IO_ERROR); }
s32 FFS_Seek(s32 fd, s32 offset, s32 mode) { return os_seek(fd, offset, mode); }
void ramo_reset(OutStream *os) { os_seek(os, 0); os->file.rf->len = 0; }