Subject: Re: Linux compatibility issue for i386, alpha and m68k
To: Emmanuel Dreyfus <p99dreyf@criens.u-psud.fr>
From: Hubert Feyrer <hubert.feyrer@informatik.fh-regensburg.de>
List: tech-kern
Date: 02/11/2001 00:36:24
On Sun, 11 Feb 2001, Emmanuel Dreyfus wrote:
> Ok, this was a Linux binary run on NetBSD, right? It would be nice to
> have the Linux binary running on Linux too.

OK: 

Script started on Sun Feb 11 01:01:28 2001
hub-r% gcc 
hub-r% 
hub-r% cat x.c

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

#ifdef __NetBSD__
#include <dirent.h>
#include <stdlib.h>
#include <sys/types.h>
#endif /* __NetBSD__ */

#ifdef __linux__
       #include <unistd.h>
#include <linux/types.h>
       #include <linux/dirent.h>
       #include <linux/unistd.h>
_syscall3(int, getdents, uint, fd, struct dirent *, dirp, uint, count);
#if 0
#include <linux/types.h>
#include <linux/dirent.h>
#include <linux/unistd.h>

_syscall3(int, getdents, uint, fd, struct dirent *, dirp, uint, count);
#endif
#endif /* __linux__ */

#define BUF_SIZE 4096

int main (int argc, char** argv) {
        int j,fd, res;
        struct dirent* entry;
        char buf[BUF_SIZE];
        size_t nbytes;
        off_t cur;
        char* filename = ".";

        if (argc > 1) 
                filename = argv[1];

        fd = open (filename, O_RDONLY, 0);
        if (fd == -1) {
                perror ("open() failed");
                exit (-1);
        }

        nbytes=BUF_SIZE;

        res = getdents (fd, buf, nbytes);
        if (res == -1) {
                perror ("getdents() failed");
                exit (-1);
        }
        
        cur = lseek (fd, 0, SEEK_CUR);
        if (cur==(off_t)-1) {
                perror ("lseek() failed\n");
                exit (-1);
        }

        printf ("fd=%d\n", fd);
        printf ("res=%d\n", res);
        printf ("offset=%d\n", cur);

        entry = (struct dirent *)buf;
   while (entry->d_reclen != 0) {
#ifdef __linux__
                printf ("d_ino=0x%x\n", entry->d_ino);
                printf ("d_off=0x%x\n", entry->d_off);
                printf ("d_reclen=0x%x\n", entry->d_reclen);
                printf ("d_name=%s\n", &entry->d_name);
#endif __linux__
#ifdef __NetBSD__
                printf ("d_fileno=0x%x\n", entry->d_fileno);
                printf ("d_reclen=0x%x\n", entry->d_reclen);
                printf ("d_namlen=0x%x\n", entry->d_namlen);
                printf ("d_name=%s\n", &entry->d_name);
#endif __NetBSD__
                printf ("\n");
                entry = (struct dirent *)((long)entry +
(long)(entry->d_reclen));
        }
}
hub-r% 
hub-r% 
hub-r% gcc x.c -o x
x.c: In function `main':
x.c:48: warning: passing arg 2 of `getdents' from incompatible pointer type
hub-r% 
hub-r% 
hub-r% ls -a
#crontab.18018#		  del.datei		    hsc.980621451
#crontab.26813#		  del.datei2		    hsc.980629312
-bar			  dodex.10693		    hsc.981011412
.			  dodex.18781		    hsc.981013999
..			  dodex.21073		    hsc.981110090
.config			  dodex.3663		    hsc.981242953
.s.PGSQL.5432		  dodex.6806		    hsc.981301312
.snmp-exec-cache	  dodex.8952		    hsc.981679646
.tin_log		  doex16820		    hsc.981831637
05074aaa		  doex3085		    index.html
05141aaa		  dohist.dbg		    l
31176eba		  filelist.pacman	    linux-sun
BLOWFISH		  foo			    lists.tar
BN			  fuser			    logix-tmp
BNLIB			  fuser2		    mail-verteiler.dir.20176
CRYPT			  hadley.log		    mail-verteiler.dir.2472
D.smurfC0048		  hf			    mailqfile
D.smurfC0049		  hista21703		    majordomo.debug
DES			  hista24326		    minicom
ENVELOPE		  hsc.975977287		    mm-buildroot
Future_Crew_s3m.tar.gz	  hsc.976651975		    mtrace
HASH			  hsc.976813709		    mueller.tar
IDEA			  hsc.976930516		    nacctd.debug
KEYMGMT			  hsc.977136357		    named
L24883-5TMP.html	  hsc.977143533		    profile.tgz
L24883-6TMP.txt		  hsc.977179832		    resend.debug
L24883-7TMP.html	  hsc.977519125		    rpm-tmp.80633
L27339-5TMP.html	  hsc.977910915		    rudimail.sh
LIBDES			  hsc.977958944		    rudimail.txt
MISC			  hsc.978184531		    screen-root
RC			  hsc.978283256		    screen-root _prefix
SAFER			  hsc.978285077		    screenrc.salt
TEST			  hsc.978789148		    screenrc.tst
ZLIB			  hsc.979010360		    screens
Zipfile.zip		  hsc.979051045		    ssh-1.2.26-101.i386.rpm
adolf-comic.tgz		  hsc.979652113		    ssh-feyrer
algo			  hsc.979662529		    strace
apiwo			  hsc.979856566		    suckcv
backup.log		  hsc.980071003		    sun-r
blaeh			  hsc.980090534		    tausys.log
blubb.sh		  hsc.980171905		    ts
blubb.txt		  hsc.980357162		    tulip.c
chrisi			  hsc.980359221		    www
cinemaxx.3778		  hsc.980428755		    www.ccc.de.tar.gz
cinemaxx.3875		  hsc.980438412		    x
cscreen			  hsc.980439840		    x.c
cscreen.boot		  hsc.980615059
d			  hsc.980621269
hub-r% ./x
fd=3
res=1132
offset=1024
d_ino=0x801
d_off=0xc
d_reclen=0xc
d_name=.

d_ino=0x2
d_off=0x18
d_reclen=0x10
d_name=..

d_ino=0x86b
d_off=0x2c
d_reclen=0x14
d_name=del.datei

d_ino=0x8b6
d_off=0x40
d_reclen=0x18
d_name=del.datei2

d_ino=0x847
d_off=0x54
d_reclen=0x18
d_name=backup.log

d_ino=0x82d
d_off=0x64
d_reclen=0x14
d_name=mtrace

d_ino=0x802
d_off=0x7c
d_reclen=0x18
d_name=hsc.975977287

d_ino=0x880
d_off=0x90
d_reclen=0x18
d_name=resend.debug

d_ino=0x8df
d_off=0xa4
d_reclen=0x18
d_name=dodex.8952

d_ino=0x8f5
d_off=0xb8
d_reclen=0x18
d_name=dohist.dbg

d_ino=0xec179
d_off=0xc8
d_reclen=0x14
d_name=screens

d_ino=0x83a
d_off=0xdc
d_reclen=0x18
d_name=hista21703

d_ino=0x8fb
d_off=0xf8
d_reclen=0x18
d_name=dodex.10693

d_ino=0x8c2
d_off=0x10c
d_reclen=0x14
d_name=lists.tar

d_ino=0x8cb
d_off=0x124
d_reclen=0x1c
d_name=majordomo.debug

d_ino=0x84e
d_off=0x130
d_reclen=0x10
d_name=ts

d_ino=0x808
d_off=0x148
d_reclen=0x18
d_name=hsc.976651975

d_ino=0x807
d_off=0x164
d_reclen=0x18
d_name=hsc.976813709

d_ino=0x80f
d_off=0x178
d_reclen=0x18
d_name=nacctd.debug

d_ino=0x90f
d_off=0x18c
d_reclen=0x18
d_name=dodex.6806

d_ino=0x979
d_off=0x19c
d_reclen=0x14
d_name=chrisi

d_ino=0x88f
d_off=0x1b0
d_reclen=0x18
d_name=dodex.18781

d_ino=0x14f029
d_off=0x1bc
d_reclen=0x10
d_name=www

d_ino=0x66179
d_off=0x1d0
d_reclen=0x14
d_name=linux-sun

d_ino=0x8ea
d_off=0x1e4
d_reclen=0x18
d_name=hista24326

d_ino=0x986
d_off=0x200
d_reclen=0x18
d_name=dodex.3663

d_ino=0x97a
d_off=0x210
d_reclen=0x14
d_name=strace

d_ino=0x80d
d_off=0x228
d_reclen=0x18
d_name=hsc.976930516

d_ino=0x837
d_off=0x23c
d_reclen=0x14
d_name=mailqfile

d_ino=0xbb05d
d_off=0x24c
d_reclen=0x14
d_name=suckcv

d_ino=0x869
d_off=0x25c
d_reclen=0x14
d_name=31176eba

d_ino=0x900
d_off=0x26c
d_reclen=0x14
d_name=tulip.c

d_ino=0x806
d_off=0x284
d_reclen=0x18
d_name=.s.PGSQL.5432

d_ino=0x980
d_off=0x298
d_reclen=0x18
d_name=dodex.21073

d_ino=0x8a9
d_off=0x2ac
d_reclen=0x18
d_name=D.smurfC0048

d_ino=0x9c3
d_off=0x2bc
d_reclen=0x14
d_name=.config

d_ino=0x8b0
d_off=0x2d0
d_reclen=0x18
d_name=D.smurfC0049

d_ino=0x818
d_off=0x2e8
d_reclen=0x18
d_name=hsc.977136357

d_ino=0x8b4
d_off=0x2fc
d_reclen=0x18
d_name=hadley.log

d_ino=0x8bd
d_off=0x30c
d_reclen=0x14
d_name=doex3085

d_ino=0x9c7
d_off=0x31c
d_reclen=0x14
d_name=.tin_log

d_ino=0x8de
d_off=0x330
d_reclen=0x18
d_name=tausys.log

d_ino=0xcb82e
d_off=0x340
d_reclen=0x10
d_name=apiwo

d_ino=0x81d
d_off=0x358
d_reclen=0x18
d_name=hsc.977143533

d_ino=0x81b
d_off=0x370
d_reclen=0x18
d_name=hsc.977179832

d_ino=0x821
d_off=0x38c
d_reclen=0x18
d_name=hsc.977519125

d_ino=0x844
d_off=0x3a0
d_reclen=0x18
d_name=mueller.tar

d_ino=0x80a
d_off=0x3b8
d_reclen=0x18
d_name=hsc.977910915

d_ino=0x836
d_off=0x3d4
d_reclen=0x18
d_name=hsc.977958944

d_ino=0x866
d_off=0x3e8
d_reclen=0x14
d_name=blubb.txt

d_ino=0x9f84e
d_off=0x3f4
d_reclen=0x10
d_name=algo

d_ino=0x4f008
d_off=0x400
d_reclen=0x10
d_name=hf

hub-r% uname -a
Linux hub-r.franken.de 2.2.6 #5 SMP Wed Apr 28 15:50:38 CEST 1999 i586 unknown
hub-r% ^D
Script done on Sun Feb 11 01:02:04 2001



 - Hubert

-- 
Hubert Feyrer <hubert.feyrer@informatik.fh-regensburg.de>