root/init/main.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. _syscall0
  2. get_options
  3. ramdisk_setup
  4. checksetup
  5. calibrate_delay
  6. parse_options
  7. copy_options
  8. copro_timeout
  9. check_fpu
  10. check_hlt
  11. check_bugs
  12. start_kernel
  13. printf
  14. init

   1 /*
   2  *  linux/init/main.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <stdarg.h>
   8 
   9 #include <asm/system.h>
  10 #include <asm/io.h>
  11 
  12 #include <linux/types.h>
  13 #include <linux/fcntl.h>
  14 #include <linux/config.h>
  15 #include <linux/sched.h>
  16 #include <linux/tty.h>
  17 #include <linux/head.h>
  18 #include <linux/unistd.h>
  19 #include <linux/string.h>
  20 #include <linux/timer.h>
  21 #include <linux/fs.h>
  22 #include <linux/ctype.h>
  23 #include <linux/delay.h>
  24 #include <linux/utsname.h>
  25 #include <linux/ioport.h>
  26 
  27 extern unsigned long * prof_buffer;
  28 extern unsigned long prof_len;
  29 extern char etext, end;
  30 extern char *linux_banner;
  31 asmlinkage void lcall7(void);
  32 struct desc_struct default_ldt;
  33 
  34 /*
  35  * we need this inline - forking from kernel space will result
  36  * in NO COPY ON WRITE (!!!), until an execve is executed. This
  37  * is no problem, but for the stack. This is handled by not letting
  38  * main() use the stack at all after fork(). Thus, no function
  39  * calls - which means inline code for fork too, as otherwise we
  40  * would use the stack upon exit from 'fork()'.
  41  *
  42  * Actually only pause and fork are needed inline, so that there
  43  * won't be any messing with the stack from main(), but we define
  44  * some others too.
  45  */
  46 #define __NR__exit __NR_exit
  47 static inline _syscall0(int,idle)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 static inline _syscall0(int,fork)
  49 static inline _syscall0(int,pause)
  50 static inline _syscall0(int,setup)
  51 static inline _syscall0(int,sync)
  52 static inline _syscall0(pid_t,setsid)
  53 static inline _syscall3(int,write,int,fd,const char *,buf,off_t,count)
  54 static inline _syscall1(int,dup,int,fd)
  55 static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
  56 static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
  57 static inline _syscall1(int,close,int,fd)
  58 static inline _syscall1(int,_exit,int,exitcode)
  59 static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
  60 
  61 static inline pid_t wait(int * wait_stat)
  62 {
  63         return waitpid(-1,wait_stat,0);
  64 }
  65 
  66 static char printbuf[1024];
  67 
  68 extern int console_loglevel;
  69 
  70 extern char empty_zero_page[PAGE_SIZE];
  71 extern void init(void);
  72 extern void init_IRQ(void);
  73 extern void init_modules(void);
  74 extern long console_init(long, long);
  75 extern long kmalloc_init(long,long);
  76 extern long blk_dev_init(long,long);
  77 extern long chr_dev_init(long,long);
  78 extern void sock_init(void);
  79 extern long rd_init(long mem_start, int length);
  80 unsigned long net_dev_init(unsigned long, unsigned long);
  81 extern long bios32_init(long, long);
  82 
  83 extern void hd_setup(char *str, int *ints);
  84 extern void bmouse_setup(char *str, int *ints);
  85 extern void eth_setup(char *str, int *ints);
  86 extern void xd_setup(char *str, int *ints);
  87 extern void floppy_setup(char *str, int *ints);
  88 extern void mcd_setup(char *str, int *ints);
  89 extern void st_setup(char *str, int *ints);
  90 extern void st0x_setup(char *str, int *ints);
  91 extern void tmc8xx_setup(char *str, int *ints);
  92 extern void t128_setup(char *str, int *ints);
  93 extern void pas16_setup(char *str, int *ints);
  94 extern void generic_NCR5380_setup(char *str, int *intr);
  95 extern void aha152x_setup(char *str, int *ints);
  96 extern void aha1542_setup(char *str, int *ints);
  97 extern void aha274x_setup(char *str, int *ints);
  98 extern void buslogic_setup(char *str, int *ints);
  99 extern void scsi_luns_setup(char *str, int *ints);
 100 extern void sound_setup(char *str, int *ints);
 101 #ifdef CONFIG_SBPCD
 102 extern void sbpcd_setup(char *str, int *ints);
 103 #endif CONFIG_SBPCD
 104 #ifdef CONFIG_CDU31A
 105 extern void cdu31a_setup(char *str, int *ints);
 106 #endif CONFIG_CDU31A
 107 void ramdisk_setup(char *str, int *ints);
 108 
 109 #ifdef CONFIG_SYSVIPC
 110 extern void ipc_init(void);
 111 #endif
 112 #ifdef CONFIG_SCSI
 113 extern unsigned long scsi_dev_init(unsigned long, unsigned long);
 114 #endif
 115 
 116 /*
 117  * This is set up by the setup-routine at boot-time
 118  */
 119 #define PARAM   empty_zero_page
 120 #define EXT_MEM_K (*(unsigned short *) (PARAM+2))
 121 #define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
 122 #define SCREEN_INFO (*(struct screen_info *) (PARAM+0))
 123 #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
 124 #define RAMDISK_SIZE (*(unsigned short *) (PARAM+0x1F8))
 125 #define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC))
 126 #define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF))
 127 
 128 /*
 129  * Boot command-line arguments
 130  */
 131 #define MAX_INIT_ARGS 8
 132 #define MAX_INIT_ENVS 8
 133 #define COMMAND_LINE ((char *) (PARAM+2048))
 134 #define COMMAND_LINE_SIZE 256
 135 
 136 extern void time_init(void);
 137 
 138 static unsigned long memory_start = 0;  /* After mem_init, stores the */
 139                                         /* amount of free user memory */
 140 static unsigned long memory_end = 0;
 141 static unsigned long low_memory_start = 0;
 142 
 143 static char term[21];
 144 int rows, cols;
 145 
 146 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
 147 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", term, NULL, };
 148 
 149 static char * argv_rc[] = { "/bin/sh", NULL };
 150 static char * envp_rc[] = { "HOME=/", term, NULL };
 151 
 152 static char * argv[] = { "-/bin/sh",NULL };
 153 static char * envp[] = { "HOME=/usr/root", term, NULL };
 154 
 155 struct drive_info_struct { char dummy[32]; } drive_info;
 156 struct screen_info screen_info;
 157 
 158 unsigned char aux_device_present;
 159 int ramdisk_size;
 160 int root_mountflags = 0;
 161 
 162 static char fpu_error = 0;
 163 
 164 static char command_line[COMMAND_LINE_SIZE] = { 0, };
 165 
 166 char *get_options(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 167 {
 168         char *cur = str;
 169         int i=1;
 170 
 171         while (cur && isdigit(*cur) && i <= 10) {
 172                 ints[i++] = simple_strtoul(cur,NULL,0);
 173                 if ((cur = strchr(cur,',')) != NULL)
 174                         cur++;
 175         }
 176         ints[0] = i-1;
 177         return(cur);
 178 }
 179 
 180 struct {
 181         char *str;
 182         void (*setup_func)(char *, int *);
 183 } bootsetups[] = {
 184         { "reserve=", reserve_setup },
 185         { "ramdisk=", ramdisk_setup },
 186 #ifdef CONFIG_INET
 187         { "ether=", eth_setup },
 188 #endif
 189 #ifdef CONFIG_SCSI
 190         { "max_scsi_luns=", scsi_luns_setup },
 191 #endif
 192 #ifdef CONFIG_BLK_DEV_HD
 193         { "hd=", hd_setup },
 194 #endif
 195 #ifdef CONFIG_CHR_DEV_ST
 196         { "st=", st_setup },
 197 #endif
 198 #ifdef CONFIG_BUSMOUSE
 199         { "bmouse=", bmouse_setup },
 200 #endif
 201 #ifdef CONFIG_SCSI_SEAGATE
 202         { "st0x=", st0x_setup },
 203         { "tmc8xx=", tmc8xx_setup },
 204 #endif
 205 #ifdef CONFIG_SCSI_T128
 206         { "t128=", t128_setup },
 207 #endif
 208 #ifdef CONFIG_SCSI_PAS16
 209         { "pas16=", pas16_setup },
 210 #endif
 211 #ifdef CONFIG_SCSI_GENERIC_NCR5380
 212         { "ncr5380=", generic_NCR5380_setup },
 213 #endif
 214 #ifdef CONFIG_SCSI_AHA152X
 215         { "aha152x=", aha152x_setup},
 216 #endif
 217 #ifdef CONFIG_SCSI_AHA1542
 218         { "aha1542=", aha1542_setup},
 219 #endif
 220 #ifdef CONFIG_SCSI_AHA274X
 221         { "aha274x=", aha274x_setup},
 222 #endif
 223 #ifdef CONFIG_SCSI_BUSLOGIC
 224         { "buslogic=", buslogic_setup},
 225 #endif
 226 #ifdef CONFIG_BLK_DEV_XD
 227         { "xd=", xd_setup },
 228 #endif
 229 #ifdef CONFIG_BLK_DEV_FD
 230         { "floppy=", floppy_setup },
 231 #endif
 232 #ifdef CONFIG_MCD
 233         { "mcd=", mcd_setup },
 234 #endif
 235 #ifdef CONFIG_SOUND
 236         { "sound=", sound_setup },
 237 #endif
 238 #ifdef CONFIG_SBPCD
 239         { "sbpcd=", sbpcd_setup },
 240 #endif CONFIG_SBPCD
 241 #ifdef CONFIG_CDU31A
 242         { "cdu31a=", cdu31a_setup },
 243 #endif CONFIG_CDU31A
 244         { 0, 0 }
 245 };
 246 
 247 void ramdisk_setup(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 248 {
 249    if (ints[0] > 0 && ints[1] >= 0)
 250       ramdisk_size = ints[1];
 251 }
 252 
 253 static int checksetup(char *line)
     /* [previous][next][first][last][top][bottom][index][help] */
 254 {
 255         int i = 0;
 256         int ints[11];
 257 
 258         while (bootsetups[i].str) {
 259                 int n = strlen(bootsetups[i].str);
 260                 if (!strncmp(line,bootsetups[i].str,n)) {
 261                         bootsetups[i].setup_func(get_options(line+n,ints), ints);
 262                         return 1;
 263                 }
 264                 i++;
 265         }
 266         return 0;
 267 }
 268 
 269 unsigned long loops_per_sec = 1;
 270 
 271 static void calibrate_delay(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 272 {
 273         int ticks;
 274 
 275         printk("Calibrating delay loop.. ");
 276         while (loops_per_sec <<= 1) {
 277                 /* wait for "start of" clock tick */
 278                 ticks = jiffies;
 279                 while (ticks == jiffies)
 280                         /* nothing */;
 281                 /* Go .. */
 282                 ticks = jiffies;
 283                 __delay(loops_per_sec);
 284                 ticks = jiffies - ticks;
 285                 if (ticks >= HZ) {
 286                         loops_per_sec = muldiv(loops_per_sec, HZ, ticks);
 287                         printk("ok - %lu.%02lu BogoMips\n",
 288                                 loops_per_sec/500000,
 289                                 (loops_per_sec/5000) % 100);
 290                         return;
 291                 }
 292         }
 293         printk("failed\n");
 294 }
 295 
 296 
 297 /*
 298  * This is a simple kernel command line parsing function: it parses
 299  * the command line, and fills in the arguments/environment to init
 300  * as appropriate. Any cmd-line option is taken to be an environment
 301  * variable if it contains the character '='.
 302  *
 303  *
 304  * This routine also checks for options meant for the kernel - currently
 305  * only the "root=XXXX" option is recognized. These options are not given
 306  * to init - they are for internal kernel use only.
 307  */
 308 static void parse_options(char *line)
     /* [previous][next][first][last][top][bottom][index][help] */
 309 {
 310         char *next;
 311         char *devnames[] = { "hda", "hdb", "sda", "sdb", "sdc", "sdd", "sde", "fd", "xda", "xdb", NULL };
 312         int devnums[]    = { 0x300, 0x340, 0x800, 0x810, 0x820, 0x830, 0x840, 0x200, 0xD00, 0xD40, 0};
 313         int args, envs;
 314 
 315         if (!*line)
 316                 return;
 317         args = 0;
 318         envs = 1;       /* TERM is set to 'console' by default */
 319         next = line;
 320         while ((line = next) != NULL) {
 321                 if ((next = strchr(line,' ')) != NULL)
 322                         *next++ = 0;
 323                 /*
 324                  * check for kernel options first..
 325                  */
 326                 if (!strncmp(line,"root=",5)) {
 327                         int n;
 328                         line += 5;
 329                         if (strncmp(line,"/dev/",5)) {
 330                                 ROOT_DEV = simple_strtoul(line,NULL,16);
 331                                 continue;
 332                         }
 333                         line += 5;
 334                         for (n = 0 ; devnames[n] ; n++) {
 335                                 int len = strlen(devnames[n]);
 336                                 if (!strncmp(line,devnames[n],len)) {
 337                                         ROOT_DEV = devnums[n]+simple_strtoul(line+len,NULL,0);
 338                                         break;
 339                                 }
 340                         }
 341                         continue;
 342                 }
 343                 if (!strcmp(line,"ro")) {
 344                         root_mountflags |= MS_RDONLY;
 345                         continue;
 346                 }
 347                 if (!strcmp(line,"rw")) {
 348                         root_mountflags &= ~MS_RDONLY;
 349                         continue;
 350                 }
 351                 if (!strcmp(line,"debug")) {
 352                         console_loglevel = 10;
 353                         continue;
 354                 }
 355                 if (!strcmp(line,"no-hlt")) {
 356                         hlt_works_ok = 0;
 357                         continue;
 358                 }
 359                 if (!strcmp(line,"no387")) {
 360                         hard_math = 0;
 361                         __asm__("movl %%cr0,%%eax\n\t"
 362                                 "orl $0xE,%%eax\n\t"
 363                                 "movl %%eax,%%cr0\n\t" : : : "ax");
 364                         continue;
 365                 }
 366                 if (checksetup(line))
 367                         continue;
 368                 /*
 369                  * Then check if it's an environment variable or
 370                  * an option.
 371                  */
 372                 if (strchr(line,'=')) {
 373                         if (envs >= MAX_INIT_ENVS)
 374                                 break;
 375                         envp_init[++envs] = line;
 376                 } else {
 377                         if (args >= MAX_INIT_ARGS)
 378                                 break;
 379                         argv_init[++args] = line;
 380                 }
 381         }
 382         argv_init[args+1] = NULL;
 383         envp_init[envs+1] = NULL;
 384 }
 385 
 386 static void copy_options(char * to, char * from)
     /* [previous][next][first][last][top][bottom][index][help] */
 387 {
 388         char c = ' ';
 389         int len = 0;
 390 
 391         for (;;) {
 392                 if (c == ' ' && *(unsigned long *)from == *(unsigned long *)"mem=") {
 393                         memory_end = simple_strtoul(from+4, &from, 0);
 394                         if ( *from == 'K' || *from == 'k' ) {
 395                                 memory_end = memory_end << 10;
 396                                 from++;
 397                         } else if ( *from == 'M' || *from == 'm' ) {
 398                                 memory_end = memory_end << 20;
 399                                 from++;
 400                         }
 401                 }
 402                 c = *(from++);
 403                 if (!c)
 404                         break;
 405                 if (COMMAND_LINE_SIZE <= ++len)
 406                         break;
 407                 *(to++) = c;
 408         }
 409         *to = '\0';
 410 }
 411 
 412 static void copro_timeout(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 413 {
 414         fpu_error = 1;
 415         timer_table[COPRO_TIMER].expires = jiffies+100;
 416         timer_active |= 1<<COPRO_TIMER;
 417         printk("387 failed: trying to reset\n");
 418         send_sig(SIGFPE, last_task_used_math, 1);
 419         outb_p(0,0xf1);
 420         outb_p(0,0xf0);
 421 }
 422 
 423 static void check_fpu(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 424 {
 425         static double x = 4195835.0;
 426         static double y = 3145727.0;
 427         unsigned short control_word;
 428 
 429         if (!hard_math) {
 430 #ifndef CONFIG_MATH_EMULATION
 431                 printk("No coprocessor found and no math emulation present.\n");
 432                 printk("Giving up.\n");
 433                 for (;;) ;
 434 #endif
 435                 return;
 436         }
 437         /*
 438          * check if exception 16 works correctly.. This is truly evil
 439          * code: it disables the high 8 interrupts to make sure that
 440          * the irq13 doesn't happen. But as this will lead to a lockup
 441          * if no exception16 arrives, it depends on the fact that the
 442          * high 8 interrupts will be re-enabled by the next timer tick.
 443          * So the irq13 will happen eventually, but the exception 16
 444          * should get there first..
 445          */
 446         printk("Checking 386/387 coupling... ");
 447         timer_table[COPRO_TIMER].expires = jiffies+50;
 448         timer_table[COPRO_TIMER].fn = copro_timeout;
 449         timer_active |= 1<<COPRO_TIMER;
 450         __asm__("clts ; fninit ; fnstcw %0 ; fwait":"=m" (*&control_word));
 451         control_word &= 0xffc0;
 452         __asm__("fldcw %0 ; fwait": :"m" (*&control_word));
 453         outb_p(inb_p(0x21) | (1 << 2), 0x21);
 454         __asm__("fldz ; fld1 ; fdiv %st,%st(1) ; fwait");
 455         timer_active &= ~(1<<COPRO_TIMER);
 456         if (fpu_error)
 457                 return;
 458         if (!ignore_irq13) {
 459                 printk("Ok, fpu using old IRQ13 error reporting\n");
 460                 return;
 461         }
 462         __asm__("fninit\n\t"
 463                 "fldl %1\n\t"
 464                 "fdivl %2\n\t"
 465                 "fmull %2\n\t"
 466                 "fldl %1\n\t"
 467                 "fsubp %%st,%%st(1)\n\t"
 468                 "fistpl %0\n\t"
 469                 "fwait\n\t"
 470                 "fninit"
 471                 : "=m" (*&fdiv_bug)
 472                 : "m" (*&x), "m" (*&y));
 473         if (!fdiv_bug) {
 474                 printk("Ok, fpu using exception 16 error reporting.\n");
 475                 return;
 476 
 477         }
 478         printk("Ok, FDIV bug i%c86 system\n", '0'+x86);
 479 }
 480 
 481 static void check_hlt(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 482 {
 483         printk("Checking 'hlt' instruction... ");
 484         if (!hlt_works_ok) {
 485                 printk("disabled\n");
 486                 return;
 487         }
 488         __asm__ __volatile__("hlt ; hlt ; hlt ; hlt");
 489         printk("Ok.\n");
 490 }
 491 
 492 static void check_bugs(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 493 {
 494         check_fpu();
 495         check_hlt();
 496 }
 497 
 498 asmlinkage void start_kernel(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 499 {
 500 /*
 501  * Interrupts are still disabled. Do necessary setups, then
 502  * enable them
 503  */
 504         set_call_gate(&default_ldt,lcall7);
 505         ROOT_DEV = ORIG_ROOT_DEV;
 506         drive_info = DRIVE_INFO;
 507         screen_info = SCREEN_INFO;
 508         aux_device_present = AUX_DEVICE_INFO;
 509         memory_end = (1<<20) + (EXT_MEM_K<<10);
 510         memory_end &= PAGE_MASK;
 511         ramdisk_size = RAMDISK_SIZE;
 512         copy_options(command_line,COMMAND_LINE);
 513 #ifdef CONFIG_MAX_16M
 514         if (memory_end > 16*1024*1024)
 515                 memory_end = 16*1024*1024;
 516 #endif
 517         if (MOUNT_ROOT_RDONLY)
 518                 root_mountflags |= MS_RDONLY;
 519         if ((unsigned long)&end >= (1024*1024)) {
 520                 memory_start = (unsigned long) &end;
 521                 low_memory_start = PAGE_SIZE;
 522         } else {
 523                 memory_start = 1024*1024;
 524                 low_memory_start = (unsigned long) &end;
 525         }
 526         low_memory_start = PAGE_ALIGN(low_memory_start);
 527         memory_start = paging_init(memory_start,memory_end);
 528         if (strncmp((char*)0x0FFFD9, "EISA", 4) == 0)
 529                 EISA_bus = 1;
 530         trap_init();
 531         init_IRQ();
 532         sched_init();
 533         parse_options(command_line);
 534         init_modules();
 535 #ifdef CONFIG_PROFILE
 536         prof_buffer = (unsigned long *) memory_start;
 537         /* only text is profiled */
 538         prof_len = (unsigned long) &etext;
 539         prof_len >>= CONFIG_PROFILE_SHIFT;
 540         memory_start += prof_len * sizeof(unsigned long);
 541 #endif
 542         memory_start = console_init(memory_start,memory_end);
 543         memory_start = bios32_init(memory_start,memory_end);
 544         memory_start = kmalloc_init(memory_start,memory_end);
 545         sti();
 546         calibrate_delay();
 547         cli();
 548         memory_start = chr_dev_init(memory_start,memory_end);
 549         memory_start = blk_dev_init(memory_start,memory_end);
 550         sti();
 551 #ifdef CONFIG_SCSI
 552         memory_start = scsi_dev_init(memory_start,memory_end);
 553 #endif
 554 #ifdef CONFIG_INET
 555         memory_start = net_dev_init(memory_start,memory_end);
 556 #endif
 557         memory_start = inode_init(memory_start,memory_end);
 558         memory_start = file_table_init(memory_start,memory_end);
 559         memory_start = name_cache_init(memory_start,memory_end);
 560         mem_init(low_memory_start,memory_start,memory_end);
 561         buffer_init();
 562         time_init();
 563         sock_init();
 564 #ifdef CONFIG_SYSVIPC
 565         ipc_init();
 566 #endif
 567         sti();
 568         check_bugs();
 569 
 570         system_utsname.machine[1] = '0' + x86;
 571         printk(linux_banner);
 572 
 573         move_to_user_mode();
 574         if (!fork())            /* we count on this going ok */
 575                 init();
 576 /*
 577  * task[0] is meant to be used as an "idle" task: it may not sleep, but
 578  * it might do some general things like count free pages or it could be
 579  * used to implement a reasonable LRU algorithm for the paging routines:
 580  * anything that can be useful, but shouldn't take time from the real
 581  * processes.
 582  *
 583  * Right now task[0] just does a infinite idle loop.
 584  */
 585         for(;;)
 586                 idle();
 587 }
 588 
 589 static int printf(const char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
 590 {
 591         va_list args;
 592         int i;
 593 
 594         va_start(args, fmt);
 595         write(1,printbuf,i=vsprintf(printbuf, fmt, args));
 596         va_end(args);
 597         return i;
 598 }
 599 
 600 void init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 601 {
 602         int pid,i;
 603 
 604         setup();
 605         sprintf(term, "TERM=con%dx%d", ORIG_VIDEO_COLS, ORIG_VIDEO_LINES);
 606 
 607         #ifdef CONFIG_UMSDOS_FS
 608         {
 609                 /*
 610                         When mounting a umsdos fs as root, we detect
 611                         the pseudo_root (/linux) and initialise it here.
 612                         pseudo_root is defined in fs/umsdos/inode.c
 613                 */
 614                 extern struct inode *pseudo_root;
 615                 if (pseudo_root != NULL){
 616                         current->fs->root = pseudo_root;
 617                         current->fs->pwd  = pseudo_root;
 618                 }
 619         }
 620         #endif
 621 
 622         (void) open("/dev/tty1",O_RDWR,0);
 623         (void) dup(0);
 624         (void) dup(0);
 625 
 626         execve("/etc/init",argv_init,envp_init);
 627         execve("/bin/init",argv_init,envp_init);
 628         execve("/sbin/init",argv_init,envp_init);
 629         /* if this fails, fall through to original stuff */
 630 
 631         if (!(pid=fork())) {
 632                 close(0);
 633                 if (open("/etc/rc",O_RDONLY,0))
 634                         _exit(1);
 635                 execve("/bin/sh",argv_rc,envp_rc);
 636                 _exit(2);
 637         }
 638         if (pid>0)
 639                 while (pid != wait(&i))
 640                         /* nothing */;
 641         while (1) {
 642                 if ((pid = fork()) < 0) {
 643                         printf("Fork failed in init\n\r");
 644                         continue;
 645                 }
 646                 if (!pid) {
 647                         close(0);close(1);close(2);
 648                         setsid();
 649                         (void) open("/dev/tty1",O_RDWR,0);
 650                         (void) dup(0);
 651                         (void) dup(0);
 652                         _exit(execve("/bin/sh",argv,envp));
 653                 }
 654                 while (1)
 655                         if (pid == wait(&i))
 656                                 break;
 657                 printf("\n\rchild %d died with code %04x\n\r",pid,i);
 658                 sync();
 659         }
 660         _exit(0);
 661 }

/* [previous][next][first][last][top][bottom][index][help] */