static __be32 decode_lockowner(struct xdr_stream *xdr, struct cb_notify_lock_args *args) { __be32 *p; unsigned int len; p = read_buf(xdr, 12); if (unlikely(p == NULL)) return htonl(NFS4ERR_BADXDR); p = xdr_decode_hyper(p, &args->cbnl_owner.clientid); len = be32_to_cpu(*p); p = read_buf(xdr, len); if (unlikely(p == NULL)) return htonl(NFS4ERR_BADXDR); /* Only try to decode if the length is right */ if (len == 20) { p += 2; /* skip "lock id:" */ args->cbnl_owner.s_dev = be32_to_cpu(*p++); xdr_decode_hyper(p, &args->cbnl_owner.id); args->cbnl_valid = true; } else { args->cbnl_owner.s_dev = 0; args->cbnl_owner.id = 0; args->cbnl_valid = false; } return 0; }
pid_t LightProcess::waitpid(pid_t pid, int *stat_loc, int options, int timeout) { if (!Available()) { // light process is not really there return ::waitpid(pid, stat_loc, options); } int id = GetId(); Lock lock(g_procs[id].m_procMutex); fprintf(g_procs[id].m_fout, "waitpid\n%lld %d %d\n", (int64)pid, options, timeout); fflush(g_procs[id].m_fout); char buf[BUFFER_SIZE]; read_buf(g_procs[id].m_fin, buf); if (!buf[0]) return -1; int64 ret; int stat; sscanf(buf, "%lld %d", &ret, &stat); *stat_loc = stat; if (ret < 0) { read_buf(g_procs[id].m_fin, buf); sscanf(buf, "%d", &errno); } return (pid_t)ret; }
int LightProcess::pclose(FILE *f) { if (!Available()) { return ::pclose(f); } int id = GetId(); Lock lock(g_procs[id].m_procMutex); std::map<int64_t, int64_t>::iterator it = g_procs[id].m_popenMap.find((int64_t)f); if (it == g_procs[id].m_popenMap.end()) { // try to close it with normal pclose return ::pclose(f); } int64_t f2 = it->second; g_procs[id].m_popenMap.erase((int64_t)f); fclose(f); fprintf(g_procs[id].m_fout, "pclose\n%" PRId64 "\n", f2); fflush(g_procs[id].m_fout); char buf[BUFFER_SIZE]; read_buf(g_procs[id].m_fin, buf); int ret = -1; sscanf(buf, "%d", &ret); if (ret < 0) { read_buf(g_procs[id].m_fin, buf); sscanf(buf, "%d", &errno); } return ret; }
FILE *LightProcess::LightPopenImpl(const char *cmd, const char *type, const char *cwd) { int id = GetId(); Lock lock(g_procs[id].m_procMutex); fprintf(g_procs[id].m_fout, "popen\n%s\n%s\n%s\n", type, cmd, cwd); fflush(g_procs[id].m_fout); char buf[BUFFER_SIZE]; read_buf(g_procs[id].m_fin, buf); if (strncmp(buf, "error", 5) == 0) { return nullptr; } int64_t fptr = 0; read_buf(g_procs[id].m_fin, buf); sscanf(buf, "%" PRId64, &fptr); if (!fptr) { Logger::Error("Light process failed to return the file pointer."); return nullptr; } int fd = recv_fd(g_procs[id].m_afdt_fd); if (fd < 0) { Logger::Error("Light process failed to send the file descriptor."); return nullptr; } FILE *f = fdopen(fd, type); g_procs[id].m_popenMap[(int64_t)f] = fptr; return f; }
static __be32 decode_layoutrecall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_layoutrecallargs *args) { __be32 *p; __be32 status = 0; uint32_t iomode; args->cbl_addr = svc_addr(rqstp); p = read_buf(xdr, 4 * sizeof(uint32_t)); if (unlikely(p == NULL)) { status = htonl(NFS4ERR_BADXDR); goto out; } args->cbl_layout_type = ntohl(*p++); /* Depite the spec's xdr, iomode really belongs in the FILE switch, * as it is unusable and ignored with the other types. */ iomode = ntohl(*p++); args->cbl_layoutchanged = ntohl(*p++); args->cbl_recall_type = ntohl(*p++); if (args->cbl_recall_type == RETURN_FILE) { args->cbl_range.iomode = iomode; status = decode_fh(xdr, &args->cbl_fh); if (unlikely(status != 0)) goto out; p = read_buf(xdr, 2 * sizeof(uint64_t)); if (unlikely(p == NULL)) { status = htonl(NFS4ERR_BADXDR); goto out; } p = xdr_decode_hyper(p, &args->cbl_range.offset); p = xdr_decode_hyper(p, &args->cbl_range.length); status = decode_stateid(xdr, &args->cbl_stateid); if (unlikely(status != 0)) goto out; } else if (args->cbl_recall_type == RETURN_FSID) { p = read_buf(xdr, 2 * sizeof(uint64_t)); if (unlikely(p == NULL)) { status = htonl(NFS4ERR_BADXDR); goto out; } p = xdr_decode_hyper(p, &args->cbl_fsid.major); p = xdr_decode_hyper(p, &args->cbl_fsid.minor); } else if (args->cbl_recall_type != RETURN_ALL) { status = htonl(NFS4ERR_BADXDR); goto out; } dprintk("%s: ltype 0x%x iomode %d changed %d recall_type %d\n", __func__, args->cbl_layout_type, iomode, args->cbl_layoutchanged, args->cbl_recall_type); out: dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); return status; }
/* read data from source, determine underlying protocol * (if not already known); and process the packet * if needed (for RTP - register packet) * * return the number of octets read from the source * into the buffer */ static ssize_t read_packet( struct dstream_ctx* spc, int fd, char* buf, size_t len ) { ssize_t n = -1; size_t chunk_len = len; assert( spc && buf && len ); assert( fd > 0 ); /* if *RAW* data specified - read AS IS * and exit */ if( UPXDT_RAW == spc->stype ) { return read_buf( fd, buf, len, g_flog ); } /* if it is (or *could* be) RTP, read only MTU bytes */ if( (spc->stype == UPXDT_RTP_TS) || (spc->flags & F_CHECK_FMT) ) chunk_len = (len > spc->mtu) ? spc->mtu : len; #ifdef UDPXY_FILEIO if( spc->flags & F_FILE_INPUT ) { assert( !buf_overrun( buf, len, 0, chunk_len, g_flog ) ); n = read_frecord( fd, buf, chunk_len, &(spc->stype), g_flog ); if( n <= 0 ) return n; } else #endif /* UDPXY_FILEIO */ { assert( !buf_overrun(buf, len, 0, chunk_len, g_flog) ); n = read_buf( fd, buf, chunk_len, g_flog ); if( n <= 0 ) return n; } if( spc->flags & F_CHECK_FMT ) { spc->stype = get_mstream_type( buf, n, g_flog ); switch (spc->stype) { case UPXDT_RTP_TS: /* scattered: exclude RTP headers */ spc->flags |= F_SCATTERED; break; case UPXDT_TS: spc->flags &= ~F_SCATTERED; break; default: spc->stype = UPXDT_RAW; TRACE( (void)tmfputs( "Unrecognized stream type\n", g_flog ) ); break; } /* switch */ TRACE( (void)tmfprintf( g_flog, "Established stream as [%s]\n", fmt2str( spc->stype ) ) ); spc->flags &= ~F_CHECK_FMT; } if( spc->flags & F_SCATTERED ) if( -1 == register_packet( spc, buf, n ) ) return -1; return n; }
static int read_cmd(byte *buf) { int len; if (read_buf(0, buf, 2) != 2) return 0; len = dec_int16(buf); if (read_buf(0, buf, len) != len) return 0; return 1; }
pid_t LightProcess::proc_open(const char *cmd, const std::vector<int> &created, const std::vector<int> &desired, const char *cwd, const std::vector<std::string> &env) { int id = GetId(); Lock lock(g_procs[id].m_procMutex); always_assert(Available()); always_assert(created.size() == desired.size()); if (fprintf(g_procs[id].m_fout, "proc_open\n%s\n%s\n", cmd, cwd) <= 0) { Logger::Error("Failed to send command proc_open"); return -1; } fprintf(g_procs[id].m_fout, "%d\n", (int)env.size()); for (unsigned int i = 0; i < env.size(); i++) { fprintf(g_procs[id].m_fout, "%s\n", env[i].c_str()); } fprintf(g_procs[id].m_fout, "%d\n", (int)created.size()); for (unsigned int i = 0; i < desired.size(); i++) { fprintf(g_procs[id].m_fout, "%d\n", desired[i]); } fflush(g_procs[id].m_fout); bool error_send = false; int save_errno = 0; for (unsigned int i = 0; i < created.size(); i++) { if (!send_fd(g_procs[id].m_afdt_fd, created[i])) { error_send = true; save_errno = errno; break; } } char buf[BUFFER_SIZE]; read_buf(g_procs[id].m_fin, buf); if (strncmp(buf, "error", 5) == 0) { read_buf(g_procs[id].m_fin, buf); sscanf(buf, "%d", &errno); if (error_send) { // On this error, the receiver side returns dummy errno, // use the sender side errno here. errno = save_errno; } return -1; } int64_t pid = -1; sscanf(buf, "%" PRId64, &pid); assert(pid); return (pid_t)pid; }
// read the configue file void init_mysql_conf() { FILE *fp; char buf[BUFFER_SIZE]; host_name[0] = 0; user_name[0] = 0; password[0] = 0; db_name[0] = 0; port_number = 3306; max_running = 3; sleep_time = 3; strcpy(java_xmx, "-Xmx256M"); fp = fopen("./etc/judge.conf", "r"); while (fgets(buf, BUFFER_SIZE - 1, fp)) { read_buf(buf,"OJ_HOST_NAME",host_name); read_buf(buf, "OJ_USER_NAME",user_name); read_buf(buf, "OJ_PASSWORD",password); read_buf(buf, "OJ_DB_NAME",db_name); read_int(buf , "OJ_PORT_NUMBER", &port_number); read_int(buf, "OJ_JAVA_TIME_BONUS", &java_time_bonus); read_int(buf, "OJ_JAVA_MEMORY_BONUS", &java_memory_bonus); read_int(buf , "OJ_SIM_ENABLE", &sim_enable); read_buf(buf,"OJ_JAVA_XMX",java_xmx); read_int(buf,"OJ_HTTP_JUDGE",&http_judge); read_buf(buf,"OJ_HTTP_BASEURL",http_baseurl); read_buf(buf,"OJ_HTTP_USERNAME",http_username); read_buf(buf,"OJ_HTTP_PASSWORD",http_password); read_int(buf , "OJ_OI_MODE", &oi_mode); } }
static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr) { __be32 *p; __be32 status; status = decode_string(xdr, &hdr->taglen, &hdr->tag); if (unlikely(status != 0)) return status; if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) { printk("NFS: NFSv4 CALLBACK %s: client sent tag of length %u\n", __func__, hdr->taglen); return htonl(NFS4ERR_RESOURCE); } p = read_buf(xdr, 12); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); hdr->minorversion = ntohl(*p++); if (hdr->minorversion <= 1) { hdr->cb_ident = ntohl(*p++); } else { pr_warn_ratelimited("NFS: %s: NFSv4 server callback with " "illegal minor version %u!\n", __func__, hdr->minorversion); return htonl(NFS4ERR_MINOR_VERS_MISMATCH); } hdr->nops = ntohl(*p); dprintk("%s: minorversion %d nops %d\n", __func__, hdr->minorversion, hdr->nops); return 0; }
int get_next_line(int const fd, char **line) { static t_stock *d; int ret; ret = 1; if (!line) return (-1); *line = NULL; if (!d) { if (!(d = (t_stock*)malloc(sizeof(t_stock)))) return (-1); if (!((d)->buff = (char **)malloc(sizeof(char *) * 255))) return (-1); } if (d->i[fd] >= d->s[fd] || !d->s[fd]) { if (!d->buff[fd] && !((d)->buff[fd] = (char*)malloc(sizeof(char) * (BUFF_SIZE)))) return (-1); ret = read_buf(fd, d); if (ret == -1 || ret == 0) return (ret); } ret = gnl_do(fd, line, d); return (ret); }
int gnl_do(int const fd, char **line, t_stock *d) { t_ints v; v.size = 0; v.ret = 42; while (v.ret == 42) { if (d->i[fd] >= d->s[fd]) v.ret = read_buf(fd, d); if (v.ret == -1 || v.ret == 0) { if (v.ret == 0) v.ret = 1; return (v.ret); } v.ret = 42; v.i = 0; while (d->buff[fd][v.i + d->i[fd]] != '\n' && d->i[fd] + v.i < d->s[fd]) v.i++; if (!(handle_i(&v, d, line, fd))) return (-1); } return (v.ret); }
int fstyp_zfs(FILE *fp, char *label, size_t labelsize) { vdev_label_t *vdev_label = NULL; vdev_phys_t *vdev_phys; char *zpool_name = NULL; nvlist_t *config = NULL; int err = 0; /* * Read in the first ZFS vdev label ("L0"), located at the beginning * of the vdev and extract the pool name from it. * * TODO: the checksum of label should be validated. */ vdev_label = (vdev_label_t *)read_buf(fp, 0, sizeof(*vdev_label)); if (vdev_label == NULL) return (1); vdev_phys = &(vdev_label->vl_vdev_phys); if ((nvlist_unpack(vdev_phys->vp_nvlist, sizeof(vdev_phys->vp_nvlist), &config, 0)) == 0 && (nvlist_lookup_string(config, "name", &zpool_name) == 0)) { strlcpy(label, zpool_name, labelsize); } else err = 1; nvlist_free(config); free(vdev_label); return (err); }
void LookupInsert(Cache_Annotation *cache, String *name) { // use a separate scratch buffer for annotation CFG lookups. // reading information about bounds can cause a lookup on the block // or initializer CFGs. static Buffer annot_buf; name->IncRef(cache); if (!DoLookupTransaction(m_db_name, name->Value(), &annot_buf)) { cache->Insert(name, NULL); return; } Vector<BlockCFG*> *cfg_list = new Vector<BlockCFG*>(); Buffer read_buf(annot_buf.base, annot_buf.pos - annot_buf.base); BlockCFG::ReadList(&read_buf, cfg_list); annot_buf.Reset(); for (size_t ind = 0; ind < cfg_list->Size(); ind++) cfg_list->At(ind)->MoveRef(NULL, cfg_list); cache->Insert(name, cfg_list); }
int get_next_line(int const fd, char **line) { static t_list *lst = NULL; t_mem *mem; int ret; char *buf; if (!line || !(BUFF_SIZE > 0) || !(mem = get_mem(fd, &lst))) return (-1); if (!(ret = read_mem(mem, line))) { if (!(buf = ft_strnew(BUFF_SIZE))) return (-1); while ((ret = read(fd, buf, BUFF_SIZE))) { if (ret < 0) return (free_str_return(buf, -1)); buf[ret] = '\0'; if ((ret = read_buf(buf, mem, line))) return (free_str_return(buf, ret)); } if (**line) return (free_str_return(buf, 1)); return (free_str_return(buf, 0)); } return (ret); }
static unsigned decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr) { uint32_t *p; unsigned int minor_version; unsigned status; status = decode_string(xdr, &hdr->taglen, &hdr->tag); if (unlikely(status != 0)) return status; /* We do not like overly long tags! */ if (hdr->taglen > CB_OP_TAGLEN_MAXSZ-12 || hdr->taglen < 0) { printk("NFSv4 CALLBACK %s: client sent tag of length %u\n", __FUNCTION__, hdr->taglen); return htonl(NFS4ERR_RESOURCE); } p = read_buf(xdr, 12); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); minor_version = ntohl(*p++); /* Check minor version is zero. */ if (minor_version != 0) { printk(KERN_WARNING "%s: NFSv4 server callback with illegal minor version %u!\n", __FUNCTION__, minor_version); return htonl(NFS4ERR_MINOR_VERS_MISMATCH); } hdr->callback_ident = ntohl(*p++); hdr->nops = ntohl(*p); return 0; }
/* read a sequence of MPEG TS packets (to fit into the given buffer) */ static ssize_t read_ts_file( int fd, char* data, const size_t len, FILE* log ) { const size_t pkt_len = ((len - 1) / TS_SEG_LEN) * TS_SEG_LEN; off_t k = 0; u_int bad_frg = 0; ssize_t n = -1; assert( (fd > 0) && data && len && log); assert( !buf_overrun( data, len, 0, pkt_len, log ) ); n = read_buf( fd, data, pkt_len, log ); if( n <= 0 ) return n; if( 0 != sizecheck( "Bad TS packet stream", pkt_len, n, log, __func__ ) ) return -1; /* make sure we've read TS records, not random data */ for( k = 0; k < (off_t)pkt_len; k += TS_SEG_LEN ) { if( -1 == ts_sigcheck( data[k], k, (u_long)pkt_len, log, __func__ ) ) { ++bad_frg; } } return (bad_frg ? -1 : n); }
int fstyp_ext2fs(FILE *fp, char *label, size_t size) { e2sb_t *fs; char *s_volume_name; fs = (e2sb_t *)read_buf(fp, EXT2FS_SB_OFFSET, 512); if (fs == NULL) return (1); /* Check for magic and versio n*/ if (fs->s_magic == EXT2_SUPER_MAGIC && fs->s_rev_level == EXT2_DYNAMIC_REV) { //G_LABEL_DEBUG(1, "ext2fs file system detected on %s.", // pp->name); } else { free(fs); return (1); } s_volume_name = fs->s_volume_name; /* Terminate label */ s_volume_name[sizeof(fs->s_volume_name) - 1] = '\0'; if (s_volume_name[0] == '/') s_volume_name += 1; strlcpy(label, s_volume_name, size); free(fs); return (0); }
static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr) { __be32 *p; __be32 status; status = decode_string(xdr, &hdr->taglen, &hdr->tag); if (unlikely(status != 0)) return status; /* We do not like overly long tags! */ if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) { printk("NFSv4 CALLBACK %s: client sent tag of length %u\n", __func__, hdr->taglen); return htonl(NFS4ERR_RESOURCE); } p = read_buf(xdr, 12); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); hdr->minorversion = ntohl(*p++); /* Check minor version is zero or one. */ if (hdr->minorversion <= 1) { hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 */ } else { printk(KERN_WARNING "%s: NFSv4 server callback with " "illegal minor version %u!\n", __func__, hdr->minorversion); return htonl(NFS4ERR_MINOR_VERS_MISMATCH); } hdr->nops = ntohl(*p); dprintk("%s: minorversion %d nops %d\n", __func__, hdr->minorversion, hdr->nops); return 0; }
void LookupInsert(Cache_BlockCFG *cache, BlockId *id) { Assert(id->Kind() == B_Function || id->Kind() == B_Loop); String *function = id->Function(); const char *function_name = function->Value(); if (!DoLookupTransaction(BODY_DATABASE, function_name, &scratch_buf)) { id->IncRef(cache); cache->Insert(id, NULL); return; } Buffer read_buf(scratch_buf.base, scratch_buf.pos - scratch_buf.base); Vector<BlockCFG*> cfg_list; BlockCFG::ReadList(&read_buf, &cfg_list); scratch_buf.Reset(); for (size_t ind = 0; ind < cfg_list.Size(); ind++) { BlockCFG *cfg = cfg_list[ind]; BlockId *id = cfg->GetId(); id->IncRef(cache); cfg->MoveRef(NULL, cache); cache->Insert(id, cfg); } }
int fstyp_cd9660(FILE *fp, char *label, size_t size) { char *sector, *volume; int i; sector = read_buf(fp, ISO9660_OFFSET, 512); if (sector == NULL) return (1); if (bcmp(sector, ISO9660_MAGIC, sizeof(ISO9660_MAGIC) - 1) != 0) { free(sector); return (1); } volume = sector + 0x28; bzero(label, size); strlcpy(label, volume, MIN(size, VOLUME_LEN)); free(sector); for (i = size - 1; i > 0; i--) { if (label[i] == '\0') continue; else if (label[i] == ' ') label[i] = '\0'; else break; } return (0); }
void read_int(char *buf, const char *key, int *value) { char buf2[BUFFER_SIZE]; if (read_buf(buf, key, buf2)) { sscanf(buf2, "%d", value); } }
static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_sequenceargs *args) { __be32 *p; int i; __be32 status; status = decode_sessionid(xdr, &args->csa_sessionid); if (status) goto out; status = htonl(NFS4ERR_RESOURCE); p = read_buf(xdr, 5 * sizeof(uint32_t)); if (unlikely(p == NULL)) goto out; args->csa_addr = svc_addr(rqstp); args->csa_sequenceid = ntohl(*p++); args->csa_slotid = ntohl(*p++); args->csa_highestslotid = ntohl(*p++); args->csa_cachethis = ntohl(*p++); args->csa_nrclists = ntohl(*p++); args->csa_rclists = NULL; if (args->csa_nrclists) { args->csa_rclists = kmalloc(args->csa_nrclists * sizeof(*args->csa_rclists), GFP_KERNEL); if (unlikely(args->csa_rclists == NULL)) goto out; for (i = 0; i < args->csa_nrclists; i++) { status = decode_rc_list(xdr, &args->csa_rclists[i]); if (status) goto out_free; } } status = 0; dprintk("%s: sessionid %x:%x:%x:%x sequenceid %u slotid %u " "highestslotid %u cachethis %d nrclists %u\n", __func__, ((u32 *)&args->csa_sessionid)[0], ((u32 *)&args->csa_sessionid)[1], ((u32 *)&args->csa_sessionid)[2], ((u32 *)&args->csa_sessionid)[3], args->csa_sequenceid, args->csa_slotid, args->csa_highestslotid, args->csa_cachethis, args->csa_nrclists); out: dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); return status; out_free: for (i = 0; i < args->csa_nrclists; i++) kfree(args->csa_rclists[i].rcl_refcalls); kfree(args->csa_rclists); goto out; }
static unsigned decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh) { uint32_t *p; p = read_buf(xdr, 4); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); fh->size = ntohl(*p); if (fh->size > NFS4_FHSIZE) return htonl(NFS4ERR_BADHANDLE); p = read_buf(xdr, fh->size); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); memcpy(&fh->data[0], p, fh->size); memset(&fh->data[fh->size], 0, sizeof(fh->data) - fh->size); return 0; }
Buffer PPLResourceFile::Read(size_t offset,u_int buflen) { if(!Check(offset,buflen)) return false; Buffer read_buf(buflen); memcpy(read_buf.data_.get(),((char*)view_map_buffer_)+offset,read_buf.length_); return read_buf; }
/* * If max_errors is 0, then don't stop processing the stream if one of the * callbacks in btrfs_send_ops structure returns an error. If greater than * zero, stop after max_errors errors happened. */ int btrfs_read_and_process_send_stream(int fd, struct btrfs_send_ops *ops, void *user, int honor_end_cmd, u64 max_errors) { int ret; struct btrfs_send_stream sctx; struct btrfs_stream_header hdr; u64 errors = 0; int last_err = 0; sctx.fd = fd; sctx.ops = ops; sctx.user = user; sctx.stream_pos = 0; ret = read_buf(&sctx, (char*)&hdr, sizeof(hdr)); if (ret < 0) goto out; if (ret) { ret = 1; goto out; } if (strcmp(hdr.magic, BTRFS_SEND_STREAM_MAGIC)) { ret = -EINVAL; error("unexpected header"); goto out; } sctx.version = le32_to_cpu(hdr.version); if (sctx.version > BTRFS_SEND_STREAM_VERSION) { ret = -EINVAL; error("stream version %d not supported, please use newer version", sctx.version); goto out; } while (1) { ret = read_and_process_cmd(&sctx); if (ret < 0) { last_err = ret; errors++; if (max_errors > 0 && errors >= max_errors) goto out; } else if (ret > 0) { if (!honor_end_cmd) ret = 0; goto out; } } out: if (last_err && !ret) ret = last_err; return ret; }
static unsigned decode_op_hdr(struct xdr_stream *xdr, unsigned int *op) { uint32_t *p; p = read_buf(xdr, 4); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); *op = ntohl(*p); return 0; }
static unsigned decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) { uint32_t *p; unsigned int attrlen; p = read_buf(xdr, 4); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); attrlen = ntohl(*p); p = read_buf(xdr, attrlen << 2); if (unlikely(p == NULL)) return htonl(NFS4ERR_RESOURCE); if (likely(attrlen > 0)) bitmap[0] = ntohl(*p++); if (attrlen > 1) bitmap[1] = ntohl(*p); return 0; }
static __be32 decode_recallany_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_recallanyargs *args) { __be32 *p; args->craa_addr = svc_addr(rqstp); p = read_buf(xdr, 4); if (unlikely(p == NULL)) return htonl(NFS4ERR_BADXDR); args->craa_objs_to_keep = ntohl(*p++); p = read_buf(xdr, 4); if (unlikely(p == NULL)) return htonl(NFS4ERR_BADXDR); args->craa_type_mask = ntohl(*p); return 0; }
/* * If max_errors is 0, then don't stop processing the stream if one of the * callbacks in btrfs_send_ops structure returns an error. If greater than * zero, stop after max_errors errors happened. */ int btrfs_read_and_process_send_stream(int fd, struct btrfs_send_ops *ops, void *user, int honor_end_cmd, u64 max_errors) { int ret; struct btrfs_send_stream s; struct btrfs_stream_header hdr; u64 errors = 0; int last_err = 0; s.fd = fd; s.ops = ops; s.user = user; ret = read_buf(&s, &hdr, sizeof(hdr)); if (ret < 0) goto out; if (ret) { ret = 1; goto out; } if (strcmp(hdr.magic, BTRFS_SEND_STREAM_MAGIC)) { ret = -EINVAL; fprintf(stderr, "ERROR: Unexpected header\n"); goto out; } s.version = le32_to_cpu(hdr.version); if (s.version > BTRFS_SEND_STREAM_VERSION) { ret = -EINVAL; fprintf(stderr, "ERROR: Stream version %d not supported. " "Please upgrade btrfs-progs\n", s.version); goto out; } while (1) { ret = read_and_process_cmd(&s); if (ret < 0) { last_err = ret; errors++; if (max_errors > 0 && errors >= max_errors) goto out; } else if (ret > 0) { if (!honor_end_cmd) ret = 0; goto out; } } out: if (last_err && !ret) ret = last_err; return ret; }