void *buddy_allocation(info_p handle, long n_bytes){ if(n_bytes > handle->n_bytes){ printf("Buddy Alloc Error: Request Size too large\n"); return NULL; } long size = find_smallest_block(n_bytes); if(size < (long)power(2,handle->parm1)){ size = (long)power(2,handle->parm1); } printf("Looking for block size: %lu\n", size); int bitmap[handle->overhead * 8]; encode_bitmap(handle->memptr-handle->overhead, handle->overhead, bitmap); int indx = find_bit(bitmap, 1, handle->n_bytes, size, (long)power(2,handle->parm1)); indx -= 50; //Decode the encoded index if(indx < 0){ printf("Bitmap: Could not find free space\n"); return NULL; } printf("Bitmap: Index Found: %d\n", indx); void *returnptr = find_memory(indx, handle); decode_bitmap(handle->memptr-handle->overhead, handle->overhead, bitmap); printf("Buddy Alloc: Allocated Space at %p\n", returnptr); return returnptr; }
void buddy_free(info_p handle, void *freeaddr){ //printf("Buddy free\n"); //printf("n_bytes, %lu\n", handle->n_bytes); //Find level and subindex of memory int levels = calculate_levels(handle->n_bytes, (long)power(2,handle->parm1)); //printf("levels: %d\n", levels-1); long memsize = handle->n_bytes >> (levels-1); //printf("Smallest memory: %lu\n", memsize); int i=0; while((handle->memptr+(i*memsize)) != freeaddr){ i++; if(i*memsize>handle->n_bytes){ printf("buddy_free: invalid memory address\n"); return; } } //printf("memptr: %p; freemem: %p\n", handle->memptr, freeaddr); //printf("Freeing Memory at level %d, subindex %d\n", levels-1, i); int bitmap[handle->overhead * 8]; encode_bitmap(handle->memptr-handle->overhead, handle->overhead, bitmap); int bitindex = power(2,levels-1)+i-1; //printf("bitmap indx: %d\n", bitindex); while(bitmap[bitindex] != 1){ bitindex=bitindex>>1; } printf("Freeing Bitmap index: %d at address %p\n", bitindex, freeaddr); bitmap[bitindex] = 0; decode_bitmap(handle->memptr-handle->overhead, handle->overhead, bitmap); }
static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, void *argp) { struct cb_getattrargs *args = argp; __be32 status; status = decode_fh(xdr, &args->fh); if (unlikely(status != 0)) return status; return decode_bitmap(xdr, args->bitmap); }
static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_getattrargs *args) { __be32 status; status = decode_fh(xdr, &args->fh); if (unlikely(status != 0)) goto out; status = decode_bitmap(xdr, args->bitmap); out: dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); return status; }
static unsigned decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_getattrargs *args) { unsigned status; status = decode_fh(xdr, &args->fh); if (unlikely(status != 0)) goto out; args->addr = &rqstp->rq_addr; status = decode_bitmap(xdr, args->bitmap); out: dprintk("%s: exit with status = %d\n", __FUNCTION__, status); return status; }
static __be32 decode_recallany_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_recallanyargs *args) { uint32_t bitmap[2]; __be32 *p, status; p = read_buf(xdr, 4); if (unlikely(p == NULL)) return htonl(NFS4ERR_BADXDR); args->craa_objs_to_keep = ntohl(*p++); status = decode_bitmap(xdr, bitmap); if (unlikely(status)) return status; args->craa_type_mask = bitmap[0]; return 0; }
comp_flow_list* get_flow_packets(display_rule *dr,char *path,capture_time *time_cap) { file_list* file_names; comp_flow_list *start_flow=0,*end_flow=0; file_names=get_filename(time_cap,path); while(file_names) { int file_index=get_file_index(file_names->filename); flow_rec_nos* t=decode_bitmap(get_final_bitmap(dr,file_names->filename,path),MAX_FLOW_REC); traverse_flow_list(t,path,file_index); printf("\nFilename is:%s",file_names->filename); if(start_flow==0) start_flow=end_flow=get_comp_flow_list_node(t); else { end_flow->down=get_comp_flow_list_node(t); end_flow=end_flow->down; } file_names=file_names->next; } return start_flow; }