本文整理汇总了C++中pwrite64函数的典型用法代码示例。如果您正苦于以下问题:C++ pwrite64函数的具体用法?C++ pwrite64怎么用?C++ pwrite64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pwrite64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_note
static int
write_note(int fd, uint_t type, const void *desc, size_t descsz, off64_t *offp)
{
/*
* Note headers are the same regardless of the data model of the
* ELF file; we arbitrarily use Elf64_Nhdr here.
*/
struct {
Elf64_Nhdr nhdr;
char name[8];
} n;
bzero(&n, sizeof (n));
bcopy("CORE", n.name, 4);
n.nhdr.n_type = type;
n.nhdr.n_namesz = 5;
n.nhdr.n_descsz = roundup(descsz, 4);
if (pwrite64(fd, &n, sizeof (n), *offp) != sizeof (n))
return (-1);
*offp += sizeof (n);
if (pwrite64(fd, desc, n.nhdr.n_descsz, *offp) != n.nhdr.n_descsz)
return (-1);
*offp += n.nhdr.n_descsz;
return (0);
}
示例2: LoadSwapFile2D
// FlowField2D constructor
int FlowField2D::SaveFlowField2D(char* filename){
int fd_g,pf;
ostream* o_stream = &cout;
ofstream* f_stream = (ofstream*)(o_stream);
ssize_t max_write = 1024L*1024L*1024L;
ssize_t one_write = 0L;
ssize_t len = 0L;
off_t off = 0L;
LoadSwapFile2D(filename,GetX(),GetY(),sizeof(FlowNode2D< FP, NUM_COMPONENTS>),&pf,&fd_g,f_stream);
char* TmpPtr=(char*)GetMatrixPtr();
if(GetMatrixSize() > max_write) {
for(off = 0L,one_write = max_write; len < GetMatrixSize(); off += max_write) {
len += pwrite64(fd_g,TmpPtr+off,one_write,off);
if(GetMatrixSize() - len < max_write)
one_write = GetMatrixSize() - len;
}
if(len != GetMatrixSize())
*f_stream << "Error: len(" << len << ") != MatrixSize(" << GetMatrixSize() << ") " << endl << flush;
} else {
len = pwrite64(fd_g,GetMatrixPtr(),GetMatrixSize(),0L);
}
close(fd_g);
return len;
}
示例3: fusecow_write
static int fusecow_write(const char *path, const char *buf, size_t size,
off64_t offset, struct fuse_file_info *fi)
{
(void) fi;
long long int block_number = offset / block_size;
if(offset + size > (block_number+1)*block_size) {
size = (block_number+1)*block_size - offset; // write only one block. write_safe will care
}
int res;
if(write_map_get(block_number)) {
res=pwrite64(fd_write, buf, size, offset);
} else {
int remaining = block_size;
while(remaining) {
res=pread64(fd, copyup_buffer + block_size - remaining, remaining, block_number*block_size);
if(res==0) {
memset(copyup_buffer + block_size - remaining, 0, remaining);
break;
}
if(res==-1) {
if(errno==EINTR) continue;
return -errno;
}
remaining -= res;
}
memcpy(copyup_buffer+offset%block_size, buf, size);
remaining=block_size;
while(remaining) {
fprintf(stderr, "Performing write at offset %lld\n", block_number*block_size);
res=pwrite64(fd_write, copyup_buffer + block_size - remaining, remaining, block_number*block_size);
if(res==-1) {
if(errno==EINTR) continue;
return -errno;
}
remaining -= res;
}
write_map_set(block_number, 1);
res = size;
}
if (res == -1) {
res = -errno;
}
return res;
}
示例4: write_shdr
static int
write_shdr(pgcore_t *pgc, shstrtype_t name, uint_t type, ulong_t flags,
uintptr_t addr, ulong_t offset, size_t size, uint_t link, uint_t info,
uintptr_t addralign, uintptr_t entsize)
{
if (pgc->P->status.pr_dmodel == PR_MODEL_ILP32) {
Elf32_Shdr shdr;
bzero(&shdr, sizeof (shdr));
shdr.sh_name = shstrtab_ndx(&pgc->pgc_shstrtab, name);
shdr.sh_type = type;
shdr.sh_flags = flags;
shdr.sh_addr = (Elf32_Addr)addr;
shdr.sh_offset = offset;
shdr.sh_size = size;
shdr.sh_link = link;
shdr.sh_info = info;
shdr.sh_addralign = addralign;
shdr.sh_entsize = entsize;
if (pwrite64(pgc->pgc_fd, &shdr, sizeof (shdr),
*pgc->pgc_soff) != sizeof (shdr))
return (-1);
*pgc->pgc_soff += sizeof (shdr);
#ifdef _LP64
} else {
Elf64_Shdr shdr;
bzero(&shdr, sizeof (shdr));
shdr.sh_name = shstrtab_ndx(&pgc->pgc_shstrtab, name);
shdr.sh_type = type;
shdr.sh_flags = flags;
shdr.sh_addr = addr;
shdr.sh_offset = offset;
shdr.sh_size = size;
shdr.sh_link = link;
shdr.sh_info = info;
shdr.sh_addralign = addralign;
shdr.sh_entsize = entsize;
if (pwrite64(pgc->pgc_fd, &shdr, sizeof (shdr),
*pgc->pgc_soff) != sizeof (shdr))
return (-1);
*pgc->pgc_soff += sizeof (shdr);
#endif /* _LP64 */
}
return (0);
}
示例5: write_dev_supers
int write_dev_supers(struct btrfs_root *root, struct btrfs_super_block *sb,
struct btrfs_device *device)
{
u64 bytenr;
u32 crc;
int i, ret;
if (root->fs_info->super_bytenr != BTRFS_SUPER_INFO_OFFSET) {
btrfs_set_super_bytenr(sb, root->fs_info->super_bytenr);
crc = ~(u32)0;
crc = btrfs_csum_data(NULL, (char *)sb + BTRFS_CSUM_SIZE, crc,
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
btrfs_csum_final(crc, (char *)&sb->csum[0]);
/*
* super_copy is BTRFS_SUPER_INFO_SIZE bytes and is
* zero filled, we can use it directly
*/
ret = pwrite64(device->fd, root->fs_info->super_copy,
BTRFS_SUPER_INFO_SIZE,
root->fs_info->super_bytenr);
BUG_ON(ret != BTRFS_SUPER_INFO_SIZE);
return 0;
}
for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
bytenr = btrfs_sb_offset(i);
if (bytenr + BTRFS_SUPER_INFO_SIZE > device->total_bytes)
break;
btrfs_set_super_bytenr(sb, bytenr);
crc = ~(u32)0;
crc = btrfs_csum_data(NULL, (char *)sb + BTRFS_CSUM_SIZE, crc,
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
btrfs_csum_final(crc, (char *)&sb->csum[0]);
/*
* super_copy is BTRFS_SUPER_INFO_SIZE bytes and is
* zero filled, we can use it directly
*/
ret = pwrite64(device->fd, root->fs_info->super_copy,
BTRFS_SUPER_INFO_SIZE, bytenr);
BUG_ON(ret != BTRFS_SUPER_INFO_SIZE);
}
return 0;
}
示例6: osd_write
file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
{
UINT32 result;
switch (file->type)
{
case SDLFILE_FILE:
#if defined(SDLMAME_DARWIN) || defined(SDLMAME_BSD)
result = pwrite(file->handle, buffer, count, offset);
if (!result)
#elif defined(SDLMAME_WIN32) || defined(SDLMAME_NO64BITIO) || defined(SDLMAME_OS2) || defined(__CELLOS_LV2__)
lseek(file->handle, (UINT32)offset&0xffffffff, SEEK_SET);
result = write(file->handle, buffer, count);
if (!result)
#elif defined(SDLMAME_UNIX)
result = pwrite64(file->handle, buffer, count, offset);
if (!result)
#else
#error Unknown SDL SUBARCH!
#endif
return error_to_file_error(errno);
if (actual != NULL)
*actual = result;
return FILERR_NONE;
break;
default:
return FILERR_FAILURE;
}
}
示例7: defined
void Driver_FILE::set_frame(const int frameid, const Frame& frame)
{
#if defined(__MACH__)
pthread_mutex_lock(&spinlock);
#else
pthread_spin_lock(&spinlock);
#endif
if(objmask.find(frameid) != objmask.end()){
// if in hash
#ifdef __MACH__
ret = pwrite(fd, frame.content, this->framesize_in_byte, 1L*frameid*this->framesize_in_byte);
#else
ret = pwrite64(fd, frame.content, this->framesize_in_byte, 1L*frameid*this->framesize_in_byte);
#endif
if(ret < 0){
assert(false && "Driver_FILE: fail to write in set()");
}
}else{
assert(false && "Driver_FILE: key not in hash");
}
#if defined(__MACH__)
pthread_mutex_unlock(&spinlock);
#else
pthread_spin_unlock(&spinlock);
#endif
}
示例8: assert
void Driver_FILE::add_frame(const int frameid)
{
assert(frameid >= 0 && "Driver_FILE: only support INTEGER-many frames for now. If you want larger storage, please increase the framesize instead.");
#if defined(__MACH__)
pthread_mutex_lock(&spinlock);
#else
pthread_spin_lock(&spinlock);
#endif
if(objmask.find(frameid) != objmask.end()){
// if already contains the key, error
assert(false && "Driver_FILE: duplicate key init'ed");
}else{
// else, insert using the default constructor
objmask[frameid] = true;
}
#ifdef __MACH__
ret = pwrite(fd, empty_frame.content, this->framesize_in_byte, 1L*frameid*this->framesize_in_byte);
#else
ret = pwrite64(fd, empty_frame.content, this->framesize_in_byte, 1L*frameid*this->framesize_in_byte);
#endif
if(ret < 0){
assert(false && "Driver_FILE: fail to write in init()");
}
#if defined(__MACH__)
pthread_mutex_unlock(&spinlock);
#else
pthread_spin_unlock(&spinlock);
#endif
}
示例9: pci_vfio_write_config
int
pci_vfio_write_config(const struct rte_intr_handle *intr_handle,
const void *buf, size_t len, off_t offs)
{
return pwrite64(intr_handle->vfio_dev_fd, buf, len,
VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) + offs);
}
示例10: zpool_clear_label
/*
* Given a file descriptor, clear (zero) the label information.
*/
int
zpool_clear_label(int fd)
{
struct stat statbuf;
int l;
vdev_label_t *label;
uint64_t size;
if (fstat_blk(fd, &statbuf) == -1)
return (0);
size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);
if ((label = calloc(sizeof (vdev_label_t), 1)) == NULL)
return (-1);
for (l = 0; l < VDEV_LABELS; l++) {
if (pwrite64(fd, label, sizeof (vdev_label_t),
label_offset(size, l)) != sizeof (vdev_label_t)) {
free(label);
return (-1);
}
}
free(label);
return (0);
}
示例11: root_write
static int
root_write(vnode_t *vp, uio_t *uiop, int ioflag, cred_t *cr, caller_context_t *ct)
{
ASSERT(vp->v_fd != -1);
ASSERT(vp->v_type != VBLK || IS_P2ALIGNED(uiop->uio_loffset, 512));
ASSERT(vp->v_type != VBLK || IS_P2ALIGNED(uiop->uio_iov->iov_len, 512));
int error = 0;
ssize_t iolen = pwrite64(vp->v_fd, uiop->uio_iov->iov_base, uiop->uio_iov->iov_len, uiop->uio_loffset);
if(iolen == -1) {
error = errno;
perror("pwrite64");
}
if(iolen != uiop->uio_iov->iov_len)
fprintf(stderr, "root_write(): len: %lli iolen: %lli offset: %lli file: %s\n", (longlong_t) uiop->uio_iov->iov_len, (longlong_t) iolen, (longlong_t) uiop->uio_loffset, vp->v_path);
if(error)
return error;
uiop->uio_resid -= iolen;
return 0;
}
示例12: fusecow_write_safe
static int fusecow_write_safe(const char *path, const char *buf, size_t size,
off64_t offset, struct fuse_file_info *fi)
{
int res=0;
if(strcmp(path, "/") != 0)
return -ENOENT;
size_t remaining = size;
while(remaining) {
int ret=fusecow_write(path, buf+res, remaining, offset+res, fi);
if(ret==0) {
break;
}
if(ret==-1) {
if(errno==EINTR) continue;
return -errno;
}
res+=ret;
remaining-=ret;
}
if(offset+res > st_size) {
fprintf(stderr, "Growing files is known to fail\n");
return -ENOSPC;
st_size = offset+res;
if(mem_write_map!=MAP_FAILED) {
memcpy(mem_write_map+8, &st_size, sizeof st_size);
} else {
pwrite64(fd_write_map, &st_size, sizeof st_size, 8);
}
}
return res;
}
示例13: write_map_set
void write_map_set(long long int block, char val) {
long long int offset = 32 + block/8;
if((mem_write_map!=MAP_FAILED) && (offset > mem_write_map_size) ) {
munmap(mem_write_map, mem_write_map_size);
mem_write_map_size = (block/8/getpagesize()+1)*getpagesize();
ftruncate(fd_write_map, mem_write_map_size);
mem_write_map = mmap(NULL, mem_write_map_size , PROT_READ|PROT_WRITE, MAP_SHARED, fd_write_map, 0);
}
char c;
if(mem_write_map!=MAP_FAILED) {
c = mem_write_map[offset];
} else {
pread64(fd_write_map, &c, 1, offset);
}
char mask = 1 << (block%8);
c &= ~mask;
if(val) {
c |= mask;
}
if(mem_write_map!=MAP_FAILED) {
mem_write_map[offset]=c;
} else {
pwrite64(fd_write_map, &c, 1, offset);
}
}
示例14: write_block
static int write_block(int fd, void *buf, unsigned long block,
unsigned long block_size)
{
char *b;
off64_t offset;
unsigned long remaining;
ssize_t rc;
b = buf;
offset = block * block_size;
remaining = block_size;
while (remaining > 0) {
rc = pwrite64(fd, b, remaining, offset);
if (rc < 0) {
if (errno == EINTR)
continue;
fprintf(stderr, "write failed: %s\n", strerror(errno));
return -1;
}
b += rc;
offset += rc;
remaining -= rc;
}
return 0;
}
示例15: write_verity_state
static int write_verity_state(const char *fname, off64_t offset, int32_t mode)
{
int fd;
int rc = -1;
struct verity_state s = { VERITY_STATE_HEADER, VERITY_STATE_VERSION, mode };
fd = TEMP_FAILURE_RETRY(open(fname, O_WRONLY | O_SYNC | O_CLOEXEC));
if (fd == -1) {
PERROR << "Failed to open " << fname;
goto out;
}
if (TEMP_FAILURE_RETRY(pwrite64(fd, &s, sizeof(s), offset)) != sizeof(s)) {
PERROR << "Failed to write " << sizeof(s) << " bytes to " << fname
<< " to offset " << offset;
goto out;
}
rc = 0;
out:
if (fd != -1) {
close(fd);
}
return rc;
}