linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: "SATHISH.J" <sathish.j@tatainfotech.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: exec format error
Date: Mon, 11 Jun 2001 07:08:08 +0100	[thread overview]
Message-ID: <12339.992239688@redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.10.10106111022240.7084-100000@blrmail>
In-Reply-To: <Pine.LNX.4.10.10106111022240.7084-100000@blrmail>

[-- Attachment #1: Type: text/plain, Size: 942 bytes --]


sathish.j@tatainfotech.com said:
> I have written a file system in 2.2.14 kernel similar to ramfs on 2.5
> kernel. I am able to register,mount and do file and directory
> operations. I tried to write a C program and compile it. The
> compilation gave me the object file. When i tried to run the object
> file it gave me an error  " cannot execute binary file". I entered gdb
> and  I could get the error "exec format error". What is exec format
> error and what is it because of? Please help me out with this info.

Assuming you did compile an executable, not just try to execute the .o file,
then your filesystem probably corrupted the executable. Building and linking
programs stresses parts of the filesystem that your other tests cannot
reach. In particular, it does lots of seeking and writing to places other
than the end of the file, which isn't trivial to do from a shell script. 

Try running the attached test program.


--
dwmw2


[-- Attachment #2: holey.c --]
[-- Type: text/plain , Size: 3076 bytes --]

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

/*  #define FILE_SIZE 50 * 4096 + 1 */
#define FILE_SIZE 106497
#define FILE_NAME "/mnt/jffs2/holey_file"
#define ITERATIONS 100000

#define SEED 123456789
#define min(x,y) ((x)<(y) ? (x):(y))
int randint (int low, int high)
{
  int normalized;

  normalized = (int) ( (float) rand() / ( (float) RAND_MAX / (float) (high - low + 1) ) );
  return (normalized + low);
}


int main (int argc, char *argv[])
{

  unsigned char holey_image[FILE_SIZE],
                holey_image_mem[FILE_SIZE], buf[FILE_SIZE];
  char *fname = malloc (strlen(FILE_NAME) + 8);
  char *errmsg = malloc (100);
  int holey_f;
  int start, size;
  int i, j;
  unsigned char c;
  int err;
  int written, newly_written, nwritten;

  srand (SEED);

  sprintf (fname, "%s%s%d", FILE_NAME, "-", getpid()); /* random file name to scribble on */

  if ((holey_f = open (fname, O_RDWR | O_CREAT | O_TRUNC, 
			S_IRUSR | S_IWUSR)) < 0) {
    perror ("Can't open holey file.");
    exit (-1);
  }

  c = (char) 0;
  /* initialize in memory check array, and buffer */
  for (i = 0; i < FILE_SIZE; i++) {
    holey_image[i] = holey_image_mem[i] = (char) 0;
    buf[i] = c++;
  }

 /* make a file with a big hole at the beginning */
  if (lseek (holey_f, FILE_SIZE-1, SEEK_SET) != FILE_SIZE-1) {
    perror ("Initial write of holey file failed");
    exit (-1);
  }

  c = '1';
  if (write (holey_f, &c, 1) != 1) {
    perror ("Write at and of hole failed");
    exit (-1);
  }
  holey_image[FILE_SIZE-1] = c;

  written = newly_written = 0;

  for (i = 0; i < ITERATIONS; i++) {

    size = randint (1, FILE_SIZE); /* how much to write */
    start = randint (0, (FILE_SIZE - size)); /* where to write it */
 /*     printf ("Start=%d, size=%d.\n", start, size); */

    lseek (holey_f, start, SEEK_SET);
    if ( (nwritten = write (holey_f, &buf, size)) != size) {
      sprintf (errmsg, "Could only write %d of %d bytes", nwritten, size); 
      perror (errmsg);
      exit (-1);
    }
    printf("%d bytes written to %d\n", size , start);

    written += size;
    newly_written += size;

    if (newly_written > 10000000) {
      printf ("%d bytes written.\n", written);
      newly_written = 0;
    }

    /* do the same copy in memory */
    memcpy (&holey_image[start], buf, size);
    memset(&holey_image_mem, 0x5a, FILE_SIZE);
    /* check to make certain that entire file looks like it's supposed to */
    lseek (holey_f, 0, SEEK_SET);
    if ( (read (holey_f, &holey_image_mem, FILE_SIZE)) != FILE_SIZE) {
      perror ("Rereading of file failed");
      exit (-1);
    }
   
    err = memcmp (&holey_image, &holey_image_mem, FILE_SIZE);
    if (err) {

      /* find the offset where they differ */
      j = 0;
      while (holey_image[j] == holey_image_mem[j]) 
	j++;

      printf ("File image is incorrect at offset %d. buf is %2.2X, file %2.2X\n", j, holey_image[j], holey_image_mem[j]);
      exit (-1);
    }

  } /* for (i... */

} /* main */
    
  

      reply	other threads:[~2001-06-11  6:10 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.10.10106031716330.3971-100000@blrmail>
2001-06-04 16:34 ` Reg mkdir syscall SATHISH.J
2001-06-05  5:02   ` H. Peter Anvin
2001-06-08  6:26 ` Reg compiling of source code SATHISH.J
2001-06-14  7:52   ` Reg-directory size SATHISH.J
2001-06-14  8:53     ` Daniel Phillips
2001-06-14 10:23     ` RAM filesystem directory size SATHISH.J
2001-06-15 10:22       ` Reg file system hash function SATHISH.J
2001-06-15 10:30         ` Russell King
2001-06-17  8:06         ` Reg:dentry->d_mounts value SATHISH.J
2001-06-17  8:14           ` Reg:magic number of the filesystem SATHISH.J
2001-06-17  8:21             ` Reg:use of file_system_type structure SATHISH.J
2001-06-17  8:21               ` Alexander Viro
2001-06-18  7:56               ` function of getname() function SATHISH.J
2001-06-18  7:42                 ` Alexander Viro
2001-06-18  7:47                 ` Tigran Aivazian
2001-06-18  8:35                 ` Reg:current a pointer to task_struct SATHISH.J
2001-06-18  8:49                   ` Reg putname() function SATHISH.J
2001-06-18  9:06                   ` Reg:current a pointer to task_struct george anzinger
2001-06-20  9:41                 ` filldir() function SATHISH.J
2001-06-20 22:26                   ` Jan Kara
2001-06-25  7:11                   ` Reg Kernel Debugger kdb SATHISH.J
2001-06-25  7:33                     ` siva kumar
2001-06-25  8:36                     ` Keith Owens
2001-06-26  4:54                     ` Reg Kernel Debugger kgdb SATHISH.J
2001-06-26 10:01                       ` using gdb to debug kernel SATHISH.J
2001-06-26 10:57                         ` Lars Marowsky-Bree
2001-06-26 11:10                         ` Reg installing a patch on linux SATHISH.J
2001-06-26 16:17                     ` Reg Kernel Debugger kgdb Timur Tabi
2001-06-21 12:06               ` Reg:use of file_system_type structure Anuradha Ratnaweera
2001-06-17  8:26             ` Reg:magic number of the filesystem Alexander Viro
2001-06-11  4:59 ` exec format error SATHISH.J
2001-06-11  6:08   ` David Woodhouse [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12339.992239688@redhat.com \
    --to=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sathish.j@tatainfotech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).