home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / install / kernel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-10  |  1.8 KB  |  86 lines

  1. #include <errno.h>
  2. #include <fcntl.h>
  3. #include <newt.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6.  
  7. #include "fs.h"
  8. #include "install.h"
  9. #include "intl.h"
  10. #include "kernel.h"
  11. #include "log.h"
  12. #include "windows.h"
  13.  
  14. static int copyFile(char * sourceName, char * destName) {
  15.     int source, dest, i;
  16.     char buf[16384];
  17.  
  18.     logMessage("coping %s to %s\n", sourceName, destName);
  19.  
  20.     source = open(sourceName, O_RDONLY);
  21.     if (source < 0) {
  22.     newtWinMessage(_("Error"), _("Ok"), 
  23.                _("file %s missing from source directory"), sourceName);
  24.     return INST_ERROR;
  25.     }
  26.  
  27.     dest = creat(destName, 0644);
  28.     if (dest < 0) {
  29.     newtWinMessage(_("Error"), _("Ok"), 
  30.             _("failed to create file %s"), destName);
  31.     close(source);
  32.     return INST_ERROR;
  33.     }
  34.  
  35.     while ((i = read(source, buf, sizeof(buf))) > 0) {
  36.     if (write(dest, buf, i) != i) {
  37.         newtWinMessage(_("Error"), _("Ok"), 
  38.                _("error writing to file %s: %s"),
  39.                    destName, strerror(errno));
  40.  
  41.         close(source);
  42.         close(dest);
  43.         unlink(destName);
  44.         return 1;
  45.     }
  46.     }
  47.  
  48.     if (i < 0) {
  49.     newtWinMessage(_("Error"), _("Ok"), 
  50.             _("error reading from file %s: %s"), 
  51.             sourceName, strerror(errno));
  52.     }
  53.  
  54.     close(source);
  55.     close(dest);
  56.     
  57.     if (i < 0)
  58.     return 1;
  59.  
  60.     return 0;
  61. }
  62.  
  63. int kernelCopy(char * filename) {
  64.     int rc = 0;
  65.  
  66.     if (!filename) {
  67.     do {
  68.         newtWinMessage(_("Kernel"), _("Ok"),
  69.                 _("Please insert your boot disk in your first "
  70.                   "disk drive if it's not already present."));
  71.     } while (doMount("fd0", "/tmp/bootdisk", "ext2", 1, 0));
  72.  
  73.     winStatus(34, 3, _("Kernel"), _("Copying kernel from floppy..."));
  74.     rc = copyFile("/tmp/bootdisk/vmlinux.gz", "/mnt/vmlinux.gz");
  75.     sync();
  76.     newtPopWindow();
  77.     } else {
  78.     winStatus(34, 3, _("Kernel"), _("Copying kernel from floppy..."));
  79.     rc = copyFile(filename, "/mnt/vmlinux.gz");
  80.     sync();
  81.     newtPopWindow();
  82.     }
  83.  
  84.     return rc;
  85. }
  86.