void process_chunk(struct buffer_h *buf, int channel) { unsigned int i; Sample sample; for (i=0; i<buf->num_samples; i++) { sample = buf->data[DATA_OFFSET(buf->num_channels, i, channel)]; printf("%d\n", sample); } }
/* * Write data into one dslot. */ int cb_dcache_write_block(struct cb_dcache *priv, u_int dslot, const void *src, u_int off, u_int len) { /* Sanity check */ assert(dslot < priv->max_blocks); assert(off <= priv->block_size); assert(len <= priv->block_size); assert(off + len <= priv->block_size); /* Write data */ return cb_dcache_write(priv, DATA_OFFSET(priv, dslot) + off, src != NULL ? src : priv->zero_block, len); }
/* * Read data from one dslot. */ int cb_dcache_read_block(struct cb_dcache *priv, u_int dslot, void *dest, u_int off, u_int len) { /* Sanity check */ assert(dslot < priv->max_blocks); assert(off <= priv->block_size); assert(len <= priv->block_size); assert(off + len <= priv->block_size); /* Read data */ return cb_dcache_read(priv, DATA_OFFSET(priv, dslot) + off, dest, len); }
static int cb_dcache_init_free_list(struct cb_dcache *priv, cb_dcache_visit_t *visitor, void *arg) { off_t required_size; struct stat sb; u_int num_entries; u_int num_dslots_used; u_int base_dslot; u_int i; int r; /* Logging */ (*priv->log)(LOG_INFO, "reading meta-data from cache file `%s'", priv->filename); /* Inspect all directory entries */ for (num_dslots_used = base_dslot = 0; base_dslot < priv->max_blocks; base_dslot += num_entries) { struct dir_entry entries[DIRECTORY_READ_CHUNK]; /* Read in the next chunk of directory entries */ num_entries = priv->max_blocks - base_dslot; if (num_entries > DIRECTORY_READ_CHUNK) num_entries = DIRECTORY_READ_CHUNK; if ((r = cb_dcache_read(priv, DIR_OFFSET(base_dslot), entries, num_entries * sizeof(*entries))) != 0) { (*priv->log)(LOG_ERR, "error reading cache file `%s' directory: %s", priv->filename, strerror(r)); return r; } /* For each dslot: if free, add to the free list, else notify visitor */ for (i = 0; i < num_entries; i++) { const struct dir_entry *const entry = &entries[i]; const u_int dslot = base_dslot + i; if (memcmp(entry, &zero_entry, sizeof(*entry)) == 0) { if ((r = cb_dcache_push(priv, dslot)) != 0) return r; } else { if (dslot + 1 > num_dslots_used) /* keep track of the number of dslots in use */ num_dslots_used = dslot + 1; if (visitor != NULL && (r = (*visitor)(arg, dslot, entry->block_num, entry->md5)) != 0) return r; } } } /* Reverse the free list so we allocate lower numbered slots first */ for (i = 0; i < priv->free_list_len / 2; i++) { const cb_block_t temp = priv->free_list[i]; priv->free_list[i] = priv->free_list[priv->free_list_len - i - 1]; priv->free_list[priv->free_list_len - i - 1] = temp; } /* Verify the cache file is not truncated */ required_size = DIR_OFFSET(priv->max_blocks); if (num_dslots_used > 0) { if (required_size < DATA_OFFSET(priv, num_dslots_used)) required_size = DATA_OFFSET(priv, num_dslots_used); } if (fstat(priv->fd, &sb) == -1) { r = errno; (*priv->log)(LOG_ERR, "error reading cache file `%s' length: %s", priv->filename, strerror(r)); return r; } if (sb.st_size < required_size) { (*priv->log)(LOG_ERR, "cache file `%s' is truncated (has size %ju < %ju bytes)", priv->filename, (uintmax_t)sb.st_size, (uintmax_t)required_size); return EINVAL; } /* Discard any unreferenced data beyond the last entry */ if (sb.st_size > required_size && ftruncate(priv->fd, required_size) == -1) { r = errno; (*priv->log)(LOG_ERR, "error trimming cache file `%s' to %ju bytes: %s", priv->filename, (uintmax_t)required_size, strerror(r)); return EINVAL; } /* Report results */ (*priv->log)(LOG_INFO, "loaded cache file `%s' with %u free and %u used blocks (max index %u)", priv->filename, priv->free_list_len, priv->max_blocks - priv->free_list_len, num_dslots_used); /* Done */ return 0; }
int unexec (char *new_name, char *old_name, unsigned int emacs_edata, unsigned int dummy1, unsigned int dummy2) { /* /dld.sl data */ struct dynamic *ld = 0; /* old and new state */ int old_fd; int new_fd; struct exec old_hdr; struct exec new_hdr; struct stat old_buf; /* some process specific "constants" */ unsigned long n_pagsiz; caddr_t dynamic_beg; caddr_t current_break = (caddr_t) sbrk (0); /* dynamically linked image? -- if so, find dld.sl structures */ if (dynamic_addr) { ld = (struct dynamic *) dynamic_addr; #ifdef DEBUG printf ("dl_text = %#x\n", ld->text); printf ("dl_data = %#x\n", ld->data); printf ("dl_bss = %#x\n", ld->bss); printf ("dl_end = %#x\n", ld->end); printf ("dl_dmodule = %#x\n", ld->dmodule); printf ("dl_dlt = %#x\n", ld->dlt); printf ("dl_plt = %#x\n", ld->plt); #endif } /* open the old and new files, figuring out how big the old one is so that we can map it in */ old_fd = unexec_open (old_name, O_RDONLY, 0); new_fd = unexec_open (new_name, O_RDWR | O_CREAT | O_TRUNC, 0666); /* setup the header and the statbuf for old_fd */ unexec_read (old_fd, 0, (char *) &old_hdr, sizeof (old_hdr)); unexec_fstat (old_fd, &old_buf); /* set up some important constants */ n_pagsiz = EXEC_PAGESIZE; /* setup beginning of data to copy from executable */ if (ld) dynamic_beg = ld->dmodule; else dynamic_beg = (caddr_t)EXEC_ALIGN (old_hdr.a_text) + old_hdr.a_data; /* set up the new exec */ new_hdr = old_hdr; new_hdr.a_text = MASK_DOWN (emacs_edata, n_pagsiz); new_hdr.a_data = MASK_UP (current_break, n_pagsiz) - EXEC_ALIGN(new_hdr.a_text); new_hdr.a_bss = 0; #ifdef DEBUG printf ("old text %#x\n", old_hdr.a_text); printf ("new text %#x\n", new_hdr.a_text); printf ("old data %#x\n", old_hdr.a_data); printf ("new data %#x\n", new_hdr.a_data); printf ("old bss %#x\n", old_hdr.a_bss); printf ("new bss %#x\n", new_hdr.a_bss); #endif /* set up this variable, in case we want to reset "the break" when restarting */ sbrk_of_0_at_unexec = ((unsigned long) MASK_UP (current_break, n_pagsiz)); /* Write out the first approximation to the new file. The sizes of each section will be correct, but there will be a number of corrections that will need to be made. */ { long old_datoff = DATA_OFFSET (old_hdr); long new_datoff = DATA_OFFSET (new_hdr); long old_dataddr = EXEC_ALIGN (old_hdr.a_text); long new_dataddr = EXEC_ALIGN (new_hdr.a_text); long new_mcaloff = MODCAL_OFFSET (new_hdr); long old_mcaloff = MODCAL_OFFSET (old_hdr); long newtext_size = new_hdr.a_text - old_dataddr; long newdata1_size = (unsigned long)dynamic_beg - new_dataddr; long dyn_size = (EXEC_ALIGN (old_hdr.a_text) + old_hdr.a_data) - (unsigned long)dynamic_beg; long newdata2_size = (unsigned long)current_break - ((unsigned long)dynamic_beg + dyn_size); long pad_size = MASK_UP (current_break, n_pagsiz) - ((unsigned long) current_break); #ifdef DEBUG printf ("current break is %#lx\n", current_break); printf ("old_dataddr = %#lx, dynamic_beg = %#lx\n", old_dataddr, dynamic_beg); #endif /* * First, write the text segment with new header -- copy * everything until the start of the data segment from the old * file */ #ifdef DEBUG printf ("copying %#lx bytes of text from 0\n", old_datoff); #endif unexec_copy (new_fd, old_fd, 0, 0, old_datoff); /* pad out the text segment */ #ifdef DEBUG printf ( "text pad size is %#x\n", old_dataddr - old_hdr.a_text); #endif unexec_pad (new_fd, old_dataddr - old_hdr.a_text); /* * Update debug header spoo */ if (new_hdr.a_extension > 0) { new_hdr.a_extension += LESYM_OFFSET(new_hdr) - LESYM_OFFSET(old_hdr); } /* * go back and write the new header. */ unexec_write (new_fd, 0, (char *) &new_hdr, sizeof (new_hdr)); /* * Copy the part of the data segment which becomes text from the * running image. */ #ifdef DEBUG printf ("copying %#lx bytes of new text from %#lx to position %#lx\n", newtext_size, old_dataddr, TEXT_OFFSET(new_hdr) + old_dataddr); #endif unexec_write (new_fd, TEXT_OFFSET(new_hdr) + old_dataddr, (caddr_t)old_dataddr, newtext_size); #ifdef DEBUG printf ("new DATA_OFFSET is %#lx\n", new_datoff); #endif /* * Copy the part of the old data segment which will be data * in the new executable (before the dynamic stuff) * from the running image. */ #ifdef DEBUG printf ("copying %#lx bytes of data from %#lx to position %#lx\n", newdata1_size, new_dataddr, new_datoff); #endif unexec_write (new_fd, new_datoff, (caddr_t)new_dataddr, newdata1_size); /* copy the dynamic part of the data segment from the old executable */ if (dyn_size) { #ifdef DEBUG printf ("copying %#lx bytes of dyn data from executable" " at address %#lx to position %#lx\n", dyn_size, dynamic_beg, new_datoff + newdata1_size); #endif unexec_copy (new_fd, old_fd, old_datoff + newtext_size + newdata1_size, new_datoff + newdata1_size, dyn_size); } /* copy remaining data (old bss) from the running image */ #ifdef DEBUG printf ("copying %#lx bytes of data from %#lx to position %#lx\n", newdata2_size, new_dataddr + newdata1_size + dyn_size, new_datoff + newdata1_size + dyn_size); #endif unexec_write (new_fd, new_datoff + newdata1_size + dyn_size, (caddr_t)(new_dataddr + newdata1_size + dyn_size), newdata2_size); /* pad out the data segment */ #ifdef DEBUG printf ( "pad size is %#x\n", pad_size); #endif unexec_pad (new_fd, pad_size); /* Finally, copy the rest of the junk from the old file. */ #ifdef DEBUG printf ("Copying %#lx bytes of junk from %#lx (old) to %#lx (new)\n", old_buf.st_size - old_mcaloff, old_mcaloff, new_mcaloff); #endif unexec_copy (new_fd, old_fd, old_mcaloff, new_mcaloff, old_buf.st_size - old_mcaloff); { long curpos, offset; struct _debug_header dhdr; int new_header_delta; new_header_delta = LESYM_OFFSET(new_hdr) - LESYM_OFFSET(old_hdr); if ((new_header_delta > 0) && ((offset = EXT_OFFSET(old_hdr)) > 0)) { curpos = lseek(new_fd, 0, SEEK_CUR); lseek(old_fd, offset, 0); if (read(old_fd, &dhdr, sizeof(dhdr)) == sizeof(dhdr)) { dhdr.header_offset += new_header_delta; dhdr.gntt_offset += new_header_delta; dhdr.lntt_offset += new_header_delta; dhdr.slt_offset += new_header_delta; dhdr.vt_offset += new_header_delta; dhdr.xt_offset += new_header_delta; lseek(new_fd, EXT_OFFSET(new_hdr), SEEK_SET); if (write(new_fd, &dhdr, sizeof(dhdr)) != sizeof(dhdr)) { unexec_error("Unable to write debug information to \"%s\"\n", 1, new_name); } lseek(new_fd, curpos, SEEK_SET); } else { unexec_error("Unable to read debug information from \"%s\"\n", 1, old_name); } } } } /* make the output file executable -- then quit */ unexec_fchmod (new_fd, 0755); close (old_fd); close (new_fd); return 0; }
int high_total; int high_free; int low_total; int low_free; int swap_total; int swap_free; int cached; int swap_cached; int active; int inactive_dirty; int inactive_clean; } data_t; static objnode_info_t infodb[] = { { "cpqLinOsMemTotal", sizeof(int), SIGNED_TYPE, READ_ONLY, ENABLED, DATA_OFFSET(data_t, total), NULL }, { "cpqLinOsMemFree", sizeof(int), SIGNED_TYPE, READ_ONLY, ENABLED, DATA_OFFSET(data_t, free), NULL }, { "cpqLinOsMemHighTotal", sizeof(int), SIGNED_TYPE, READ_ONLY, ENABLED, DATA_OFFSET(data_t, high_total), NULL }, { "cpqLinOsMemHighFree", sizeof(int), SIGNED_TYPE, READ_ONLY, ENABLED, DATA_OFFSET(data_t, high_free), NULL }, { "cpqLinOsMemLowTotal", sizeof(int), SIGNED_TYPE, READ_ONLY, ENABLED, DATA_OFFSET(data_t, low_total), NULL }, { "cpqLinOsMemLowFree", sizeof(int), SIGNED_TYPE, READ_ONLY, ENABLED, DATA_OFFSET(data_t, low_free), NULL