Patch title: Release 94 bulk changes
Abstract:
File: /pliant/fullpliant/linuxrc.c
Key:
    Removed line
    Added line
   
// gcc -O2 -march=i486 -mregparm=3 -s -nostdlib -o /tmp/init /pliant/pliant/language/startup/start.s /pliant/pliant/fullpliant/linuxrc.c

#include "../language/os/linux_kernel.c"

#define false 0
#define true 1
#define null ((void *)0)

struct timespec {
  int tv_sec,tv_nsec; };

inline static _syscall3(int,open,const char *,name,int,flags,int,rights)
inline static _syscall3(int,read,int,fd,char *,buf,off_t,count)
inline static _syscall3(int,write,int,fd,const char *,buf,off_t,count)
inline static _syscall1(int,close,int,fd)
inline static _syscall1(int,chroot,const char *,path)
inline static _syscall1(int,chdir,const char *,path)
inline static _syscall5(int,mount,const char *,dev,const char *,dir,const char *,fs,int,flags,const char *,opt)
inline static _syscall2(int,umount2,const char *,target,int,flags)
inline static _syscall2(int,pivot_root,const char *,new_root,const char *,put_old)
inline static _syscall2(int,nanosleep,struct timespec *,req,struct timespec *,rem)
inline static _syscall3(int,execve,char *,filename,char **,argv,char **,env)

char **process_args;
char **process_env;
char *env[]={"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin",null};
char *args[]={"/bin/init",null};


char *units[]={"/dev/hda","/dev/hdb","/dev/hdc","/dev/hdd","/dev/sda","/dev/sdb","/dev/sdc","/dev/sdd","/dev/sde","/dev/sdf","/dev/sdg","/dev/sdh","/dev/sdi","/dev/sdj","/dev/sdk","/dev/sdl",null};

void unit_label(const char *device,char *label) {
  unsigned char buffer[0x10000]; int i,fd; 
  label[0]=0;
  fd=open(device,0,0);
  if(fd>=0) {
    if(read(fd,buffer,0x10000)==0x10000) {
      if(buffer[0x438]==0x53 && buffer[0x439]==0xEF) { // EXT2
        for(i=0; i<16; i++)
          label[i]=buffer[0x478+i];
        label[16]=0;
      } else if(buffer[0x8000]==1 && buffer[0x8001]=='C' && buffer[0x8002]=='D' && buffer[0x8003]=='0') { // ISO9660
        for(i=0; i<16; i++)
          label[i]=buffer[0x8028+i]!=' '?buffer[0x8028+i]:0;
        label[16]=0; } }
    close(fd); } } 


int same(const char *s1,const char *s2) {
  int i;
  for(i=0;; i++) {
    if(s1[i]!=s2[i])
      return 0;
    if(s1[i]==0)
      return 1; } }

/*
void startup() {
  char label[17];
  int i,j;
  for(i=0; units[i]!=null; i++) {
    for(j=0; units[i][j]!=0; j++);
    write(1,units[i],j);
    write(1," '",2);
    unit_label(units[i],label);
    for(j=0; label[j]!=0; j++);
    write(1,label,j);
    write(1,"'\n",2); } }
*/

void startup() {
  char label[17];
  int lap,i,j;
  struct timespec ts;
  for(lap=0;; lap++) {
    for(i=0; units[i]!=null; i++) {
      unit_label(units[i],label);
      if(same(label,"pliant_usb") || (lap>=5 && same(label,"pliant_cdrom"))) {
        write(1,"Boot on ",8);
        for(j=0; units[i][j]!=0; j++);
        write(1,units[i],j);
        if(mount(units[i],"/mnt/root","ext2",0x0C0ED0001,""))
          mount(units[i],"/mnt/root","iso9660",0x0C0ED0001,"");
        chroot("/mnt/root");
        chdir("/");
        pivot_root("/","/mnt/initrd");
        chroot("/");
        chdir("/");
        umount2("/mnt/initrd",0);
        execve(args[0],args,env); } }
    ts.tv_sec=2; ts.tv_nsec=0; nanosleep(&ts,null);
    write(1,". ",2); } }