本文整理汇总了C++中pwrite函数 的典型用法代码示例。如果您正苦于以下问题:C++ pwrite函数的具体用法?C++ pwrite怎么用?C++ pwrite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pwrite函数 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: switch
int keydiv_dtable::create(int dfd, const char * name, const params & config, dtype::ctype key_type)
{
int r, kdd_dfd, meta;
divider_list dividers;
const dtable_factory * base;
params base_config;
kddtable_header header;
header.magic = KDDTABLE_MAGIC;
header.version = KDDTABLE_VERSION;
switch(key_type)
{
case dtype::UINT32:
header.key_type = 1;
r = load_dividers<int, uint32_t>(config, 0, ÷rs);
break;
case dtype::DOUBLE:
header.key_type = 2;
r = load_dividers<float, double>(config, 0, ÷rs);
break;
case dtype::STRING:
header.key_type = 3;
r = load_dividers<istr, istr>(config, 0, ÷rs);
break;
case dtype::BLOB:
header.key_type = 4;
r = load_dividers<blob, blob>(config, 0, ÷rs, true);
break;
default:
return -EINVAL;
}
header.dt_count = dividers.size() + 1;
/* make sure we don't overflow the header field */
if(header.dt_count != dividers.size() + 1)
return -EINVAL;
base = dtable_factory::lookup(config, "base");
if(!base)
return -EINVAL;
if(!config.get("base_config", &base_config, params()))
return -EINVAL;
r = mkdirat(dfd, name, 0755);
if(r < 0)
return r;
kdd_dfd = openat(dfd, name, O_RDONLY);
if(kdd_dfd < 0)
{
unlinkat(dfd, name, AT_REMOVEDIR);
return kdd_dfd;
}
for(uint32_t i = 0; i < header.dt_count; i++)
{
char name[32];
sprintf(name, "kdd_data.%u", i);
r = base->create(kdd_dfd, name, base_config, key_type);
if(r < 0)
goto fail;
}
meta = openat(kdd_dfd, "kdd_meta", O_WRONLY | O_CREAT, 0644);
if(meta < 0)
{
r = meta;
goto fail;
}
r = pwrite(meta, &header, sizeof(header), 0);
close(meta);
if(r != sizeof(header))
goto fail;
close(kdd_dfd);
return 0;
fail:
close(kdd_dfd);
util::rm_r(dfd, name);
return (r < 0) ? r : -1;
}
开发者ID:nathansgreen, 项目名称:anvil, 代码行数:79, 代码来源:keydiv_dtable.cpp
示例2:
void
runtime·badsignal(void)
{
runtime·pwrite(2, badsignal, sizeof badsignal - 1, -1LL);
runtime·exits(badsignal);
}
开发者ID:blackbeans, 项目名称:golang, 代码行数:6, 代码来源:os_plan9.c
示例3: write_filemarks
int
write_filemarks(uint32_t count, uint8_t *sam_stat)
{
uint32_t blk_number;
uint64_t data_offset;
ssize_t nwrite;
if (!tape_loaded(sam_stat)) {
return -1;
}
/* Applications assume that writing a filemark (even writing zero
filemarks) will force-flush any data buffered in the drive to media
so that after the write-filemarks call returns there is no
possibility that any data previously written could be lost due
to a power hit. Provide a similar guarantee here.
*/
if (count == 0) {
MHVTL_DBG(2, "Flushing data - 0 filemarks written");
fsync(datafile);
fsync(indxfile);
fsync(metafile);
return 0;
}
if (check_for_overwrite(sam_stat)) {
return -1;
}
/* Preserve existing raw_pos data we need, then clear raw_pos and
fill it in with new data.
*/
blk_number = raw_pos.hdr.blk_number;
data_offset = raw_pos.data_offset;
memset(&raw_pos, 0, sizeof(raw_pos));
raw_pos.data_offset = data_offset;
raw_pos.hdr.blk_type = B_FILEMARK; /* Header type */
raw_pos.hdr.blk_flags = 0;
raw_pos.hdr.blk_number = blk_number;
raw_pos.hdr.blk_size = 0;
raw_pos.hdr.disk_blk_size = 0;
/* Now write out one header per filemark. */
for ( ; count > 0; count--, blk_number++) {
raw_pos.hdr.blk_number = blk_number;
MHVTL_DBG(3, "Writing filemark: block %d", blk_number);
nwrite = pwrite(indxfile, &raw_pos, sizeof(raw_pos),
blk_number * sizeof(raw_pos));
if (nwrite != sizeof(raw_pos)) {
mkSenseBuf(MEDIUM_ERROR, E_WRITE_ERROR, sam_stat);
MHVTL_ERR("Index file write failure,"
" pos: %" PRId64 ": %s",
(uint64_t)blk_number * sizeof(raw_pos),
strerror(errno));
return -1;
}
add_filemark(blk_number);
}
/* Provide the force-flush guarantee. */
fsync(datafile);
fsync(indxfile);
fsync(metafile);
return mkEODHeader(blk_number, data_offset);
}
开发者ID:aroundrobin, 项目名称:mhvtl, 代码行数:76, 代码来源:vtlcart.c
示例4: snprintf
int journal::init_crfd(const istr & commit_name)
{
int r;
off_t filesize, nextcr = 0;
struct timeval settime[2] = {{0, 0}, {0, 0}};
commit_record zero = {0, 0}, cr;
/* Only append more empy records to the commit file if it is already open
* otherwise create a new commit record file. */
if(crfd < 0)
{
istr cname = commit_name;
if(!cname)
{
char commit_number[16];
snprintf(commit_number, sizeof(commit_number), "%d", commits);
cname = path + J_COMMIT_EXT + commit_number;
}
crfd = openat(dfd, cname, O_CREAT | O_RDWR, 0644);
if(crfd < 0)
return -1;
}
filesize = lseek(crfd, 0, SEEK_END);
util::memset(zero.checksum, 0, sizeof(zero.checksum));
/* find out where the last good commit record is */
while((r = pread(crfd, &cr, sizeof(cr), nextcr)))
{
if(r < (int) sizeof(cr))
break;
if(!cr.offset && !cr.length && !memcmp(&cr.checksum, &zero.checksum, J_CHECKSUM_LEN))
break;
nextcr += r;
}
/* We set the mtime for the commit record file in the future to prevent
* the inode metadata being updated with every write - this uses a hack
* in Featherstitch to optimize for patchgroups. */
/* atime */
settime[0].tv_sec = time(NULL);
/* mtime is current time plus 10 years, or the end of 31-bit time, whichever is later */
settime[1].tv_sec = settime[0].tv_sec + 315360000;
if(settime[1].tv_sec < 2147483647)
settime[1].tv_sec = 2147483647;
if((r = futimes(crfd, settime)) < 0)
goto error;
if(filesize < (nextcr + (int) sizeof(cr)))
{
/* zero out the rest of the file J_ADD_N_COMMITS records at a time */
uint8_t zbuffer[1000 * sizeof(zero)];
util::memset(zbuffer, 0, sizeof(zbuffer));
while((filesize - nextcr) < J_ADD_N_COMMITS * (int) sizeof(zbuffer))
{
r = pwrite(crfd, zbuffer, sizeof(zbuffer), filesize);
if(r <= 0)
goto error;
filesize += r;
}
/* necessary? */
fsync(crfd);
}
return nextcr;
error:
if(crfd > 0)
{
close(crfd);
crfd = -1;
}
return r < 0 ? r : -1;
}
开发者ID:GSathish, 项目名称:casamia-datastore, 代码行数:74, 代码来源:journal.cpp
示例5: masterconn_download_data
void masterconn_download_data(masterconn *eptr,const uint8_t *data,uint32_t length) {
uint64_t offset;
uint32_t leng;
uint32_t crc;
ssize_t ret;
if (eptr->metafd<0) {
syslog(LOG_NOTICE,"MATOML_DOWNLOAD_DATA - file not opened");
eptr->mode = KILL;
return;
}
if (length<16) {
syslog(LOG_NOTICE,"MATOML_DOWNLOAD_DATA - wrong size (%"PRIu32"/16+data)",length);
eptr->mode = KILL;
return;
}
passert(data);
offset = get64bit(&data);
leng = get32bit(&data);
crc = get32bit(&data);
if (leng+16!=length) {
syslog(LOG_NOTICE,"MATOML_DOWNLOAD_DATA - wrong size (%"PRIu32"/16+%"PRIu32")",length,leng);
eptr->mode = KILL;
return;
}
if (offset!=eptr->dloffset) {
syslog(LOG_NOTICE,"MATOML_DOWNLOAD_DATA - unexpected file offset (%"PRIu64"/%"PRIu64")",offset,eptr->dloffset);
eptr->mode = KILL;
return;
}
if (offset+leng>eptr->filesize) {
syslog(LOG_NOTICE,"MATOML_DOWNLOAD_DATA - unexpected file size (%"PRIu64"/%"PRIu64")",offset+leng,eptr->filesize);
eptr->mode = KILL;
return;
}
#ifdef HAVE_PWRITE
ret = pwrite(eptr->metafd,data,leng,offset);
#else /* HAVE_PWRITE */
lseek(eptr->metafd,offset,SEEK_SET);
ret = write(eptr->metafd,data,leng);
#endif /* HAVE_PWRITE */
if (ret!=(ssize_t)leng) {
mfs_errlog_silent(LOG_NOTICE,"error writing metafile");
if (eptr->downloadretrycnt>=5) {
masterconn_download_end(eptr);
} else {
eptr->downloadretrycnt++;
masterconn_download_next(eptr);
}
return;
}
if (crc!=mycrc32(0,data,leng)) {
syslog(LOG_NOTICE,"metafile data crc error");
if (eptr->downloadretrycnt>=5) {
masterconn_download_end(eptr);
} else {
eptr->downloadretrycnt++;
masterconn_download_next(eptr);
}
return;
}
/*if (fsync(eptr->metafd)<0) {
mfs_errlog_silent(LOG_NOTICE,"error syncing metafile");
if (eptr->downloadretrycnt>=5) {
masterconn_download_end(eptr);
} else {
eptr->downloadretrycnt++;
masterconn_download_next(eptr);
}
return;
}*/
eptr->dloffset+=leng;
eptr->downloadretrycnt=0;
masterconn_download_next(eptr);
}
开发者ID:windreamer, 项目名称:moosefs, 代码行数:74, 代码来源:masterconn.c
示例6: nandwrite_mlc
//.........这里部分代码省略.........
if (read_next) {
erase_buffer(writebuf, readlen);
/* Read up to one page data */
while (tinycnt < readlen) {
cnt = read(image, writebuf + tinycnt, readlen - tinycnt);
if (cnt == 0) { /* EOF */
break;
} else if (cnt < 0) {
perror ("File I/O error on input");
retCode = -3;
goto closeall;
}
tinycnt += cnt;
}
imglen -= tinycnt;
read_next = false;
}
for (nblock = 0; nblock < CONFIG_BLOCK_REPLICATION; nblock++)
{
// offs = mtdoffset + nblock * blocksize + skip * blocksize;
offs = mtdoffset + skip * blocksize;
// skip bad blocks
ret = nand_block_isbad(dev, offs);
if (ret < 0) {
retCode = -5;
goto closeall;
} else if (ret == 1) {
#if 0
loff_t checkblock;
char have_copy = 0;
if (!quiet) {
fprintf(stderr, "Skip bad block at address 0x%x, (block %u)\n",
offs, offs / blocksize);
}
badblocks++;
// make sure we have at least one copy
for (checkblock = 0; checkblock < CONFIG_BLOCK_REPLICATION; checkblock++)
{
offs = mtdoffset + checkblock * blocksize + skip * blocksize;
ret = nand_block_isbad(dev, offs);
if (ret < 0) goto closeall;
else if (ret == 0) {
have_copy = 1;
break;
}
}
if (!have_copy)
{
printf("Too many bad blocks\n");
goto closeall;
}
skip += blockskip;
continue;
#else
if (!quiet) {
uint32_t block_mask = meminfo->erasesize - 1;
printf("Bad block 0x%x\n", (offs & (~block_mask)));
}
if (++badblocks >= CONFIG_BLOCK_REPLICATION) {
printf("Too many bad blocks\n");
retCode = -4;
goto closeall;
}
skip += blockskip;
continue;
#endif
}
for (npage = 0; npage < CONFIG_PAGE_REPLICATION; npage++)
{
offs = mtdoffset + npage * pagesize + skip * blocksize;
/* Write out the Page data */
if (pwrite(dev, writebuf, pagesize, offs) != pagesize) {
fprintf(stderr, "Bad page for copy %u of block %x for address %x\n",
npage, nblock, offs);
}
}
skip += blockskip;
read_next = true;
} // for nblock
mtdoffset += pagesize * CONFIG_PAGE_REPLICATION;
} // while (imglen > 0)
closeall:
if (writebuf) {
free(writebuf);
}
close(image);
if (imglen > 0)
{
fprintf(stderr, "Data was only partially written due to error\n");
}
return retCode;
}
开发者ID:yjhjstz, 项目名称:pandorabox, 代码行数:101, 代码来源:nandwrite_mlc.c
示例7: write_process_memory
/* write data to a process memory space */
int write_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, const char *src )
{
struct thread *thread = get_ptrace_thread( process );
int ret = 0;
long data = 0;
data_size_t len;
long *addr;
unsigned long first_mask, first_offset, last_mask, last_offset;
if (!thread) return 0;
if ((unsigned long)ptr != ptr)
{
set_error( STATUS_ACCESS_DENIED );
return 0;
}
/* compute the mask for the first long */
first_mask = ~0;
first_offset = ptr % sizeof(long);
memset( &first_mask, 0, first_offset );
/* compute the mask for the last long */
last_offset = (size + first_offset) % sizeof(long);
if (!last_offset) last_offset = sizeof(long);
last_mask = 0;
memset( &last_mask, 0xff, last_offset );
addr = (long *)(unsigned long)(ptr - first_offset);
len = (size + first_offset + sizeof(long) - 1) / sizeof(long);
if (suspend_for_ptrace( thread ))
{
if (!check_process_write_access( thread, addr, len ))
{
set_error( STATUS_ACCESS_DENIED );
goto done;
}
if (len > 3)
{
char procmem[24];
int fd;
sprintf( procmem, "/proc/%u/mem", process->unix_pid );
if ((fd = open( procmem, O_WRONLY )) != -1)
{
ssize_t r = pwrite( fd, src, size, ptr );
close( fd );
if (r == size)
{
ret = 1;
goto done;
}
}
}
/* first word is special */
if (len > 1)
{
memcpy( (char *)&data + first_offset, src, sizeof(long) - first_offset );
src += sizeof(long) - first_offset;
if (write_thread_long( thread, addr++, data, first_mask ) == -1) goto done;
first_offset = 0;
len--;
}
else last_mask &= first_mask;
while (len > 1)
{
memcpy( &data, src, sizeof(long) );
src += sizeof(long);
if (write_thread_long( thread, addr++, data, ~0ul ) == -1) goto done;
len--;
}
/* last word is special too */
memcpy( (char *)&data + first_offset, src, last_offset - first_offset );
if (write_thread_long( thread, addr, data, last_mask ) == -1) goto done;
ret = 1;
done:
resume_after_ptrace( thread );
}
return ret;
}
开发者ID:qqzhang, 项目名称:uk-1.0, 代码行数:87, 代码来源:ptrace.c
示例8: xmp_write
static int xmp_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
(void) fi;
(void) offset;
int res=0;
int action = COPY;
ssize_t vsize = 0;
char *tval = NULL;
char fpath[PATH_MAX];
xmp_getfullpath(fpath, path);
vsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, NULL, 0);
tval = malloc(sizeof(*tval)*(vsize));
vsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, tval, vsize);
if (vsize < 0 || memcmp(tval, "false", 5) == 0){
if(errno == ENODATA){
fprintf(stderr, "Encryption flag not set, file cannot be read.\n");
}
fprintf(stderr, "File unencrypted, reading...\n");
}
/* If the attribute exists and is true get size of decrypted file */
else if (memcmp(tval, "true", 4) == 0){
fprintf(stderr, "File encrypted, decrypting...\n");
action = DECRYPT;
}
/* If the file to be written to is encrypted */
if (action == DECRYPT){
FILE *fd = fopen(fpath, "rb+");
const char *tpath = ftemp(fpath, ".write");
FILE *dfd = fopen(tpath, "wb+");
fseek(fd, 0, SEEK_END);
fseek(fd, 0, SEEK_SET);
if(!do_crypt(fd, dfd, DECRYPT, ENCFS_DATA->passkey)){
fprintf(stderr, "Decryption failed, error code: %d\n", res);
}
fseek(fd, 0, SEEK_SET);
res = fwrite(buf, 1, size, dfd);
if (res == -1)
res = -errno;
fseek(dfd, 0, SEEK_SET);
if(!do_crypt(dfd, fd, ENCRYPT, ENCFS_DATA->passkey)){
fprintf(stderr, "Encryption failed, error code: %d\n", res);
}
fclose(fd);
fclose(dfd);
remove(tpath);
}
/* If the file to be written to is unencrypted */
else if (action == COPY){
int fd1;
fprintf(stderr, "File unencrypted, reading...\n");
fd1 = open(fpath, O_WRONLY);
if (fd1 == -1)
return -errno;
res = pwrite(fd1, buf, size, offset);
if (res == -1)
res = -errno;
close(fd1);
}
free(tval);
return res;
}
开发者ID:kevinjpickard, 项目名称:CSCI-3753, 代码行数:81, 代码来源:pa5-encfs.c
示例9: ADIOI_XFS_WriteContig
void ADIOI_XFS_WriteContig(ADIO_File fd, void *buf, int count,
MPI_Datatype datatype, int file_ptr_type,
ADIO_Offset offset, ADIO_Status *status, int *error_code)
{
int err=-1, datatype_size, len, diff, size, nbytes;
void *newbuf;
static char myname[] = "ADIOI_XFS_WRITECONTIG";
MPI_Type_size(datatype, &datatype_size);
len = datatype_size * count;
fd->fp_sys_posn = -1; /* set it to null, since we are using pwrite */
if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
if (!(fd->direct_write)) /* direct I/O not enabled */
err = pwrite(fd->fd_sys, buf, len, offset);
else { /* direct I/O enabled */
/* (1) if mem_aligned && file_aligned
use direct I/O to write up to correct io_size
use buffered I/O for remaining */
if (!(((long) buf) % fd->d_mem) && !(offset % fd->d_miniosz))
ADIOI_XFS_Aligned_Mem_File_Write(fd, buf, len, offset, &err);
/* (2) if !file_aligned
use buffered I/O to write up to file_aligned
At that point, if still mem_aligned, use (1)
else copy into aligned buf and then use (1) */
else if (offset % fd->d_miniosz) {
diff = fd->d_miniosz - (offset % fd->d_miniosz);
diff = ADIOI_MIN(diff, len);
nbytes = pwrite(fd->fd_sys, buf, diff, offset);
buf = ((char *) buf) + diff;
offset += diff;
size = len - diff;
if (!(((long) buf) % fd->d_mem)) {
ADIOI_XFS_Aligned_Mem_File_Write(fd, buf, size, offset, &err);
nbytes += err;
}
else {
newbuf = (void *) memalign(XFS_MEMALIGN, size);
if (newbuf) {
memcpy(newbuf, buf, size);
ADIOI_XFS_Aligned_Mem_File_Write(fd, newbuf, size, offset, &err);
nbytes += err;
free(newbuf);
}
else nbytes += pwrite(fd->fd_sys, buf, size, offset);
}
err = nbytes;
}
/* (3) if !mem_aligned && file_aligned
copy into aligned buf, then use (1) */
else {
newbuf = (void *) memalign(XFS_MEMALIGN, len);
if (newbuf) {
memcpy(newbuf, buf, len);
ADIOI_XFS_Aligned_Mem_File_Write(fd, newbuf, len, offset, &err);
free(newbuf);
}
else err = pwrite(fd->fd_sys, buf, len, offset);
}
}
if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += err;
#ifdef HAVE_STATUS_SET_BYTES
if (err != -1) MPIR_Status_set_bytes(status, datatype, err);
#endif
if (err == -1) {
*error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
myname, __LINE__, MPI_ERR_IO, "**io",
"**io %s", strerror(errno));
}
else *error_code = MPI_SUCCESS;
}
开发者ID:aosm, 项目名称:openmpi, 代码行数:81, 代码来源:ad_xfs_write.c
示例10: xmp_read
//.........这里部分代码省略.........
return -EBUSY;
}
}
int i;
struct elm_read_req prefetch_req = req;
for (i=0; i<prefetch_aggressiveness; i++) {
prefetch_req.offset += prefetch_req.size;
prefetch_req.sem = NULL;
prefetch_req.refcnt = 0;
prefetch_req.p_response = NULL;
if (prefetch_req.offset + prefetch_req.size
> info->st_buf.st_size)
{
/* XXX */
break;
}
/* Prefetch requests are advisory only.
* If the queue is full, it may not be an error.
*/
if (circ_enq(&req_queue, &prefetch_req)) {
break;
}
}
int q_cnt = circ_cnt(&req_queue);
fprintf(fp_sync, "req_queue_cnt = %d\n", q_cnt);
fflush(fp_sync);
pthread_cond_signal(&req_condition);
pthread_mutex_unlock(&req_queue_lock);
if (get_rc == 0) {
/* If it was already in cache no need to wait.
*/
return res;
}
/* Wait for the response */
sem_wait(&sem);
fprintf(fp_sync, "got response\n");
fflush(fp_sync);
pthread_mutex_lock(&cache_lock);
/* Check the response */
result = &response;
if (result->rc >= 0) {
memcpy(buf,
result->data,
result->rc);
}
res = result->rc;
if (*result->refcnt > 0) {
*result->refcnt -= 1;
}
cache_report(fp_sync, cache_hit_bytes, cache_miss_bytes);
pthread_mutex_unlock(&cache_lock);
sem_destroy(&sem);
return res;
}
static int xmp_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
int fd;
int res;
(void) fi;
fd = open(path, O_WRONLY);
if (fd == -1)
return -errno;
res = pwrite(fd, buf, size, offset);
if (res == -1)
res = -errno;
close(fd);
return res;
}
开发者ID:zhangwei1984, 项目名称:prefetch, 代码行数:101, 代码来源:loop.refactored.c
示例11: cfs_write
static int cfs_write(const char *path, const char *buf, size_t length, off_t offset, struct fuse_file_info *info)
{
update_dir_cache(path, offset + length, 0, 0);
return pwrite(((openfile *)(uintptr_t)info->fh)->fd, buf, length, offset);
}
开发者ID:gokuale, 项目名称:hubicfuse, 代码行数:5, 代码来源:cloudfuse.c
示例12: resize_gpt_partition
int resize_gpt_partition(const char *devname, __u64 new_size)
{
unsigned char buf[SECTOR_SIZE*GPT_DATA_SIZE]; // LBA1 header, LBA2-34 partition entry
int fd;
int part, ret;
struct GptHeader *pt;
struct GptEntry *pe;
__u32 pt_crc32, pe_crc32, orig_crc;
off_t size;
__u64 tmp;
ret = has_partition(devname, &part);
if (ret)
return ret;
if (!part)
return 0;
ret = ploop_get_size(devname, &size);
if (ret)
return ret;
// Resize up to max available space
if (new_size == 0)
new_size = size;
if (new_size > size) {
ploop_err(0, "Unable to resize GPT partition:"
" incorrect parameter new_size=%llu size=%lu",
new_size, (long)size);
return SYSEXIT_PARAM;
}
ploop_log(1, "Resizing GPT partition to %ld", (long)new_size);
fd = open(devname, O_RDWR);
if (fd == -1) {
ploop_err(errno, "open %s", devname);
return SYSEXIT_OPEN;
}
// skip LBA0 Protective MBR
ret = pread(fd, buf, sizeof(buf), SECTOR_SIZE);
if (ret == -1) {
ploop_err(errno, "pread %s", devname);
goto err;
}
pt = (struct GptHeader *)buf;
pe = (struct GptEntry *)(&buf[SECTOR_SIZE * GPT_HEADER_SIZE]);
// Validate crc
orig_crc = pt->header_crc32;
pt->header_crc32 = 0;
pt_crc32 = ploop_crc32((unsigned char *)pt, pt->header_size);
if (pt_crc32 != orig_crc) {
ploop_err(0, "GPT validation failed orig crc %x != %x",
orig_crc, pt_crc32);
ret = -1;
goto err;
}
// change GPT header
pt->alternate_lba = new_size - 1;
pt->last_usable_lba = new_size - GPT_DATA_SIZE - 1;
pe->ending_lba = (pt->last_usable_lba >> 3 << 3) - 1;
// Recalculate crc32
pe_crc32 = ploop_crc32((unsigned char *)pe, SECTOR_SIZE * GPT_PT_ENTRY_SIZE);
pt->partition_entry_array_crc32 = pe_crc32;
pt->header_crc32 = 0;
pt_crc32 = ploop_crc32((unsigned char *)pt, pt->header_size);
pt->header_crc32 = pt_crc32;
ploop_log(0, "Storing GPT");
ret = pwrite(fd, pt, SECTOR_SIZE * GPT_DATA_SIZE, SECTOR_SIZE);
if (ret == -1) {
ploop_err(errno, "Failed to store primary GPT %s", devname);
goto err;
}
ret = fsync(fd);
if (ret) {
ploop_err(errno, "Can't fsync %s", devname);
ret = SYSEXIT_FSYNC;
goto err;
}
// Store secondary GPT entries
tmp = pt->my_lba;
pt->my_lba = pt->alternate_lba;
pt->alternate_lba = tmp;
pt->partition_entry_lba = pt->last_usable_lba + 1;
// Recalculate crc32
pt->header_crc32 = 0;
pt_crc32 = ploop_crc32((unsigned char *)pt, pt->header_size);
pt->header_crc32 = pt_crc32;
ret = pwrite(fd, pe, SECTOR_SIZE * GPT_PT_ENTRY_SIZE,
(new_size - GPT_DATA_SIZE)*SECTOR_SIZE);
if (ret == -1) {
ploop_err(errno, "Failed to store secondary GPT %s", devname);
goto err;
//.........这里部分代码省略.........
开发者ID:varung, 项目名称:ploop, 代码行数:101, 代码来源:gpt.c
示例13: fifolog_write_output
static int
fifolog_write_output(struct fifolog_writer *f, int fl, time_t now)
{
long h, l = f->ff->zs->next_out - f->obuf;
ssize_t i, w;
int retval = 0;
h = 4; /* seq */
be32enc(f->obuf, f->seq);
f->obuf[h] = f->flag;
h += 1; /* flag */
if (f->flag & FIFOLOG_FLG_SYNC) {
be32enc(f->obuf + h, now);
h += 4; /* timestamp */
}
assert(l <= (long)f->ff->recsize); /* NB: l includes h */
assert(l >= h);
/* We will never write an entirely empty buffer */
if (l == h)
return (0);
if (l < (long)f->ff->recsize && fl == Z_NO_FLUSH)
return (0);
w = f->ff->recsize - l;
if (w > 255) {
be32enc(f->obuf + f->ff->recsize - 4, w);
f->obuf[4] |= FIFOLOG_FLG_4BYTE;
} else if (w > 0) {
f->obuf[f->ff->recsize - 1] = (uint8_t)w;
f->obuf[4] |= FIFOLOG_FLG_1BYTE;
}
f->cnt[FIFOLOG_PT_BYTES_POST] += l - h;
i = pwrite(f->ff->fd, f->obuf, f->ff->recsize,
(f->recno + 1) * f->ff->recsize);
if (i != f->ff->recsize)
retval = -1;
else
retval = 1;
f->cnt[FIFOLOG_PT_WRITES]++;
f->cnt[FIFOLOG_PT_RUNTIME] = now - f->starttime;
f->lastwrite = now;
/*
* We increment these even on error, so as to properly skip bad,
* sectors or other light trouble.
*/
f->seq++;
f->recno++;
f->flag = 0;
memset(f->obuf, 0, f->obufsize);
f->ff->zs->next_out = f->obuf + 5;
f->ff->zs->avail_out = f->obufsize - 5;
return (retval);
}
开发者ID:JabirTech, 项目名称:Source, 代码行数:61, 代码来源:fifolog_write_poll.c
示例14: tagsistant_write
/**
* write() equivalent
*
* @param path the path of the file to be written
* @param buf buffer holding write() data
* @param size how many bytes should be written (size of *buf)
* @param offset starting of the write
* @param fi struct fuse_file_info used for open() flags
* @return(0 on success, -errno otherwise)
*/
int tagsistant_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
int res = 0, tagsistant_errno = 0, fh = 0;
TAGSISTANT_START("WRITE on %s [size: %lu offset: %lu]", path, (unsigned long) size, (long unsigned int) offset);
tagsistant_querytree *qtree = tagsistant_querytree_new(path, 0, 0, 1, 1);
// -- malformed --
if (QTREE_IS_MALFORMED(qtree))
TAGSISTANT_ABORT_OPERATION(ENOENT);
// -- alias --
if (QTREE_IS_ALIAS(qtree) && qtree->alias) {
res = size;
gchar *_buf = g_strndup(buf, size);
// end the string at the first carriage return or line feed character
gchar *path_ptr = rindex(_buf, '\n');
if (path_ptr) *path_ptr = '/';
path_ptr = rindex(_buf, '\r');
if (path_ptr) *path_ptr = '/';
// remove double slashes
GRegex *rx = g_regex_new("//", 0, 0, NULL);
gchar *_buf2 = g_regex_replace(rx, _buf, -1, 0, "/", 0, NULL);
g_regex_unref(rx);
g_free(_buf);
_buf = _buf2;
// get the size of the buffer
size_t max_size = MIN(size, TAGSISTANT_ALIAS_MAX_LENGTH - 1);
size_t real_size = MIN(max_size, strlen(_buf));
// copy the buffer to a temporary variable
gchar *value = g_strndup(_buf, real_size);
// save the buffer on disk
tagsistant_sql_alias_set(qtree->dbi, qtree->alias, value);
g_free(value);
g_free(_buf);
} else
// -- object on disk --
if (QTREE_POINTS_TO_OBJECT(qtree)) {
if (!qtree->full_archive_path) {
dbg('F', LOG_ERR, "Null qtree->full_archive_path");
TAGSISTANT_ABORT_OPERATION(EFAULT);
}
#if TAGSISTANT_ENABLE_FILE_HANDLE_CACHING
if (fi->fh) {
tagsistant_get_file_handle(fi, fh);
res = pwrite(fh, buf, size, offset);
tagsistant_errno = errno;
}
if ((-1 == res) || (0 == fh)) {
if (fh) close(fh);
fh = open(qtree->full_archive_path, fi->flags|O_WRONLY);
if (fh) res = pwrite(fh, buf, size, offset);
else res = -1;
tagsistant_errno = errno;
}
tagsistant_set_file_handle(fi, fh);
#else
fh = open(qtree->full_archive_path, fi->flags|O_WRONLY);
if (fh) {
res = pwrite(fh, buf, size, offset);
tagsistant_errno = errno;
close(fh);
} else {
TAGSISTANT_ABORT_OPERATION(errno);
}
#endif
}
// -- tags --
// -- stats --
// -- relations --
else TAGSISTANT_ABORT_OPERATION(EROFS);
// dbg('F', LOG_ERR, "Yeah!");
TAGSISTANT_EXIT_OPERATION:
//.........这里部分代码省略.........
开发者ID:chebee7i, 项目名称:Tagsistant, 代码行数:101, 代码来源:write.c
示例15: rtems_aio_handle
static void *
rtems_aio_handle (void *arg)
{
rtems_aio_request_chain *r_chain = arg;
rtems_aio_request *req;
rtems_chain_control *chain;
rtems_chain_node *node;
int result, policy;
struct sched_param param;
AIO_printf ("Thread started\n");
while (1) {
/* acquire the mutex of the current fd chain.
we don't need to lock the queue mutex since we can
add requests to idle fd chains or even active ones
if the working request has been extracted from the
chain */
result = pthread_mutex_lock (&r_chain->mutex);
if (result != 0)
return NULL;
chain = &r_chain->perfd;
/* If the locked chain is not empty, take the first
request extract it, unlock the chain and process
the request, in this way the user can supply more
requests to this fd chain */
if (!rtems_chain_is_empty (chain)) {
AIO_printf ("Get new request from not empty chain\n");
node = rtems_chain_first (chain);
req = (rtems_aio_request *) node;
/* See _POSIX_PRIORITIZE_IO and _POSIX_PRIORITY_SCHEDULING
discussion in rtems_aio_enqueue () */
pthread_getschedparam (pthread_self(), &policy, ¶m);
param.sched_priority = req->priority;
pthread_setschedparam (pthread_self(), req->policy, ¶m);
rtems_chain_extract (node);
pthread_mutex_unlock (&r_chain->mutex);
switch (req->aiocbp->aio_lio_opcode) {
case LIO_READ:
AIO_printf ("read\n");
result = pread (req->aiocbp->aio_fildes,
(void *) req->aiocbp->aio_buf,
req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
break;
case LIO_WRITE:
AIO_printf ("write\n");
result = pwrite (req->aiocbp->aio_fildes,
(void *) req->aiocbp->aio_buf,
req->aiocbp->aio_nbytes, req->aiocbp->aio_offset);
break;
case LIO_SYNC:
AIO_printf ("sync\n");
result = fsync (req->aiocbp->aio_fildes);
break;
default:
result = -1;
}
if (result == -1) {
req->aiocbp->return_value = -1;
req->aiocbp->error_code = errno;
} else {
req->aiocbp->return_value = result;
req->aiocbp->error_code = 0;
}
// notification needed for lio
} else {
/* If the fd chain is empty we unlock the fd chain
and we lock the queue chain, this will ensure that
we have at most one request comming to our fd chain
when we check.
If there was no request added sleep for 3 seconds and
wait for a signal on chain, this will unlock the queue.
The fd chain is already unlocked */
struct timespec timeout;
AIO_printf ("Chain is empty [WQ], wait for work\n");
pthread_mutex_unlock (&r_chain->mutex);
pthread_mutex_lock (&aio_request_queue.mutex);
if (rtems_chain_is_empty (chain))
{
clock_gettime (CLOCK_REALTIME, &timeout);
timeout.tv_sec += 3;
//.........这里部分代码省略.........
开发者ID:AlexShiLucky, 项目名称:rtems, 代码行数:101, 代码来源:aio_misc.c
示例16: main
void
main(int argc, char *argv[])
{
int fd, i;
int n = 1000, m;
int s = 1;
double *t, t0, t1;
unsigned char *buf;
double a, d, max, min;
m = OREAD;
ARGBEGIN{
case 'n':
n = atoi(ARGF());
break;
case 's':
s = unittoull(ARGF());
if(s < 1 || s > 1024*1024)
sysfatal("bad size");
break;
case 'r':
m = OREAD;
break;
case 'w':
m = OWRITE;
break;
}ARGEND
fd = 0;
if(argc == 1){
fd = open(argv[0], m);
if(fd < 0)
sysfatal("could not open file: %s: %r", argv[0]);
}
buf = malloc(s);
t = malloc(n*sizeof(double));
t0 = nsec();
for(i=0; i<n; i++){
if(m == OREAD){
if(pread(fd, buf, s, 0) < s)
sysfatal("bad read: %r");
}else{
if(pwrite(fd, buf, s, 0) < s)
sysfatal("bad write: %r");
}
t1 = nsec();
t[i] = (t1 - t0)*1e-3;
t0 = t1;
}
a = 0.;
d = 0.;
max = 0.;
min = 1e12;
for(i=0; i<n; i++){
a += t[i];
if(max < t[i])
max = t[i];
if(min > t[i])
min = t[i];
}
a /= n;
for(i=0; i<n; i++)
d += (a - t[i]) * (a - t[i]);
d /= n;
d = sqrt(d);
print("avg = %.0fµs min = %.0fµs max = %.0fµs dev = %.0fµs\n", a, min, max, d);
exits(0);
}
开发者ID:dancrossnyc, 项目名称:harvey, 代码行数:76, 代码来源:9ping.c
示例17: copy_one_extent
static int copy_one_extent(struct btrfs_root *root, int fd,
struct extent_buffer *leaf,
struct btrfs_file_extent_item *fi, u64 pos)
{
struct btrfs_multi_bio *multi = NULL;
struct btrfs_device *device;
char *inbuf, *outbuf = NULL;
ssize_t done, total = 0;
u64 bytenr;
u64 ram_size;
u64 disk_size;
u64 num_bytes;
u64 length;
u64 size_left;
u64 dev_bytenr;
u64 offset;
u64 count = 0;
int compress;
int ret;
int dev_fd;
int mirror_num = 1;
int num_copies;
compress = btrfs_file_extent_compression(leaf, fi);
bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
disk_size = btrfs_file_extent_disk_num_bytes(leaf, fi);
ram_size = btrfs_file_extent_ram_bytes(leaf, fi);
offset = btrfs_file_extent_offset(leaf, fi);
num_bytes = btrfs_file_extent_num_bytes(leaf, fi);
size_left = disk_size;
if (compress == BTRFS_COMPRESS_NONE)
bytenr += offset;
if (verbose && offset)
printf("offset is %Lu\n", offset);
/* we found a hole */
if (disk_size == 0)
return 0;
inbuf = malloc(size_left);
if (!inbuf) {
error("not enough memory");
return -ENOMEM;
}
if (compress != BTRFS_COMPRESS_NONE) {
outbuf = calloc(1, ram_size);
if (!outbuf) {
error("not enough memory");
free(inbuf);
return -ENOMEM;
}
}
again:
length = size_left;
ret = btrfs_map_block(root->fs_info, READ, bytenr, &length, &multi,
mirror_num, NULL);
if (ret) {
error("cannot map block logical %llu length %llu: %d",
(unsigned long long)bytenr,
(unsigned long long)length, ret);
goto out;
}
device = multi->stripes[0].dev;
dev_fd = device->fd;
device->total_ios++;
dev_bytenr = multi->stripes[0].physical;
free(multi);
if (size_left < length)
length = size_left;
done = pread(dev_fd, inbuf+count, length, dev_bytenr);
/* Need both checks, or we miss negative values due to u64 conversion */
if (done < 0 || done < length) {
num_copies = btrfs_num_copies(root->fs_info, bytenr, length);
mirror_num++;
/* mirror_num is 1-indexed, so num_copies is a valid mirror. */
if (mirror_num > num_copies) {
ret = -1;
error("exhausted mirrors trying to read (%d > %d)",
mirror_num, num_copies);
goto out;
}
fprintf(stderr, "Trying another mirror\n");
goto again;
}
mirror_num = 1;
size_left -= length;
count += length;
bytenr += length;
if (size_left)
goto again;
if (compress == BTRFS_COMPRESS_NONE) {
while (total < num_bytes) {
done = pwrite(fd, inbuf+total, num_bytes-total,
pos+total);
if (done < 0) {
//.........这里部分代码省略.........
开发者ID:kdave, 项目名称:btrfs-progs, 代码行数:101, 代码来源:cmds-restore.c
示例18: assert
int journal::commit()
{
commit_record cr;
if(erasure)
return -EINVAL;
if(commits > playbacks)
/* must play back previous commit first */
return -EINVAL;
assert(playbacks == commits);
if(!records)
return 0;
/* initialize crfd or if it is almost full add more empty records to it */
if(crfd < 0 || !(commits % (J_ADD_N_COMMITS * 1000)))
if(init_crfd(istr::null) < 0)
return -1;
cr.offset = prev_cr.offset + prev_cr.length;
cr.length = data_file.end() - cr.offset;
if(checksum(cr.offset, cr.offset + cr.length, cr.checksum) < 0)
return -1;
#if HAVE_FSTITCH /* {{{ */
patchgroup_id_t commit;
commit = patchgroup_create(0);
if(commit <= 0)
return -1;
patchgroup_label(commit, "commit");
/* add the external dependency, if any */
assert(!ext_count);
if(external > 0)
{
if(ext_success && patchgroup_add_depend(commit, external) < 0)
goto fail;
patchgroup_abandon(external);
external = 0;
}
if(patchgroup_add_depend(commit, records) < 0)
{
fail:
patchgroup_release(commit);
patchgroup_abandon(commit);
return -1;
}
if(last_commit > 0 && patchgroup_add_depend(commit, last_commit) < 0)
goto fail;
if(prev && prev->last_commit && !commits && patchgroup_add_depend(commit, prev->last_commit) < 0)
goto fail;
patchgroup_release(commit);
if(patchgroup_engage(commit) < 0)
{
/* this basically can't happen */
patchgroup_abandon(commit);
return -1;
}
#endif /* }}} */
data_file.flush();
if(pwrite(crfd, &cr, sizeof(cr), commits * sizeof(cr)) != sizeof(cr))
{
#if HAVE_FSTITCH /* {{{ */
int save = errno;
patchgroup_disengage(commit);
/* the truncate() really should be part of records, but
* since commit depends on records, we'll substitute it */
patchgroup_abandon(records);
/* make sure the pointer is not past the end of the file */
errno = save;
#endif /* }}} */
return -1;
}
#if HAVE_FSTITCH /* {{{ */
patchgroup_disengage(commit);
patchgroup_abandon(records);
if(last_commit)
patchgroup_abandon(last_commit);
last_commit = commit;
#else /* }}} */
char commit_number[16];
istr old_commit, new_commit;
last_commit = commits;
snprintf(commit_number, sizeof(commit_number), "%d", last_commit);
old_commit = path + J_COMMIT_EXT + commit_number;
snprintf(commit_number, sizeof(commit_number), "%d", commits + 1);
new_commit = path + J_COMMIT_EXT + commit_number;
int r = renameat(dfd, old_commit, dfd, new_commit);
if(r < 0)
return r;
#endif
records = 0;
++commits;
prev_cr = cr;
return 0;
}
开发者ID:GSathish, 项目名称:casamia-datastore, 代码行数:98, 代码来源:journal.cpp
六六分期app的软件客服如何联系?不知道吗?加qq群【895510560】即可!标题:六六分期
阅读:19194| 2023-10-27
今天小编告诉大家如何处理win10系统火狐flash插件总是崩溃的问题,可能很多用户都不知
阅读:9988| 2022-11-06
今天小编告诉大家如何对win10系统删除桌面回收站图标进行设置,可能很多用户都不知道
阅读:8327| 2022-11-06
今天小编告诉大家如何对win10系统电脑设置节能降温的设置方法,想必大家都遇到过需要
阅读:8696| 2022-11-06
我们在使用xp系统的过程中,经常需要对xp系统无线网络安装向导设置进行设置,可能很多
阅读:8639| 2022-11-06
今天小编告诉大家如何处理win7系统玩cf老是与主机连接不稳定的问题,可能很多用户都不
阅读:9658| 2022-11-06
电脑对日常生活的重要性小编就不多说了,可是一旦碰到win7系统设置cf烟雾头的问题,很
阅读:8624| 2022-11-06
我们在日常使用电脑的时候,有的小伙伴们可能在打开应用的时候会遇见提示应用程序无法
阅读:7998| 2022-11-06
今天小编告诉大家如何对win7系统打开vcf文件进行设置,可能很多用户都不知道怎么对win
阅读:8656| 2022-11-06
今天小编告诉大家如何对win10系统s4开启USB调试模式进行设置,可能很多用户都不知道怎
阅读:7535| 2022-11-06
请发表评论