minix_200 @Wiki

make_image()

最終更新:

匿名ユーザー

- view
だれでも歓迎! 編集





以下全文

void make_image(char *image, char **procv)
/* Collect a set of files in an image, each "segment" is nicely padded out
* to SECTOR_SIZE, so it may be read from disk into memory without trickery.
*/
{
  FILE *imagef, *procf;
  char *proc, *file;
  int procn;
  struct image_header ihdr;
  struct exec phdr;
  struct stat st;

  making_image= 1;

  if ((imagef= fopen(image, "w")) == nil) {
    fatal(image);
  }

  for (procn= 0; (proc= *procv++) != nil; procn++) {
    /* Remove the label from the file name. */
    if ((file= strchr(proc, ':')) != nil)
      file++;
    else
      file= proc;

    /* Real files please, may need to seek. */
    if (stat(file, &st) < 0
      || (errno= EISDIR, !S_ISREG(st.st_mode))
      || (procf= fopen(file, "r")) == nil
    ) fatal(proc);

    /* Read a.out header. */
    read_header(1, proc, procf, &ihdr);

    /* Scratch. */
    phdr= ihdr.process;

    /* The symbol table is always stripped off. */
    ihdr.process.a_syms= 0;
    ihdr.process.a_flags &= ~A_NSYM;

    /* Write header padded to fill a sector */
    bwrite(imagef, image, &ihdr, sizeof(ihdr));

    padimage(image, imagef, SECTOR_SIZE - sizeof(ihdr));

    /* A page aligned executable needs the header in text. */
    if (phdr.a_flags & A_PAL) {
      rewind(procf);
      phdr.a_text+= phdr.a_hdrlen;
    }

    /* Copy text and data of proc to image. */
    if (phdr.a_flags & A_SEP) {
      /* Separate I&D: pad text & data separately. */

      copyexec(proc, procf, image, imagef, phdr.a_text);
      copyexec(proc, procf, image, imagef, phdr.a_data);
    } else {
      /* Common I&D: keep text and data together. */

      copyexec(proc, procf, image, imagef,
            phdr.a_text + phdr.a_data);
    }

    /* Done with proc. */
    (void) fclose(procf);
  }
  /* Done with image. */

  if (fclose(imagef) == EOF) fatal(image);

  printf(" ------ ------ ------ -------\n");
  printf("%8ld%8ld%8ld%9ld total\n",
    total_text, total_data, total_bss,
    total_text + total_data + total_bss);
}

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

目安箱バナー