예제 #1
0
long localdiskspace( void )
{
    struct dfree d;
    getdfree( 0, &d );

    return( (longword) d.df_avail * (longword)d.df_bsec * (longword)d.df_sclus );
}
예제 #2
0
static BOOL CheckFreeSpace(char *path)
{
#ifdef __WATCOMC__
    struct diskfree_t space;
#else
    struct dfree space;
    getdfree(path[0] - 'A' + 1, &space);
#endif

#ifdef __WATCOMC__
    if (!_getdiskfree(path[0] - 'A' + 1, &space))
#else
    if (space.df_sclus != 0xFFFF)
#endif
    {
#ifdef __WATCOMC__
        unsigned long bytes = ((unsigned long) space.avail_clusters *
                               (unsigned long) space.bytes_per_sector *
                               (unsigned long) space.sectors_per_cluster);
#else
        unsigned long bytes = ((unsigned long) space.df_avail *
                               (unsigned long) space.df_bsec *
                               (unsigned long) space.df_sclus);
#endif
        LIST_LOOP loop;
        
        if (idTimeStamps && idTimeStamps != lpIDs->idNull)
        {
            unsigned long size = 0L;
            ATOMID idFile;
            
            kpc_init_loop(idTimeStamps, &loop);
            while (idFile = KppNextListElement(&loop)) {
                struct stat st;
                
                KppNextListElement(&loop);
                KppGetAtomName(idFile, &return_buffer, RET_BUFFER_LEN);
                if (!stat(return_buffer, &st))
                    size += st.st_size;
            }
            if (bytes < size)
            {
                return_buffer[0] = path[0];
                return_buffer[1] = '\0';
                
                return PostAlertYesNo(NULL, IDE_DISKSPACE,
                                      return_buffer, ES, ES) == IDYES;
            }
        }
    }
    
    return TRUE;
}
예제 #3
0
static rspf_int32 available_space( char *drive )
{
   struct dfree disktable;
   int disknum;

   if (!drive) return 0;

   disknum=toupper(drive[0])-'A'+1;
   getdfree(disknum,&disktable);
   return (rspf_int32) disktable.df_avail *
	  (rspf_int32) disktable.df_sclus *
	  (rspf_int32) disktable.df_bsec;
}
예제 #4
0
파일: memtypes.c 프로젝트: CivilPol/sdcboot
int
DiskLargeEnough (char *imagefile, unsigned long floppysize)
{
  int disk;
  struct dfree free;

  if (imagefile[0] != 0 && imagefile[1] == ':')
    disk = toupper (imagefile[0]) - 65;
  else
    disk = getdisk ();

  getdfree (disk + 1, &free);	/* absread doesn't work on FAT16! */

  return (floppysize <= (long) free.df_avail * (long) free.df_bsec *
	  (long) free.df_sclus);
}
예제 #5
0
파일: movedir.c 프로젝트: CivilPol/sdcboot
/*-------------------------------------------------------------------------*/
static int xcopy_file(const char *src_filename,
                const char *dest_filename) 
{
  struct stat src_statbuf;
  struct dfree disktable;
  unsigned long free_diskspace;
  unsigned char dest_drive;

  /* Get the destination drive */
  if (dest_filename[1] == ':')
      dest_drive = dest_filename[0];
  else
      dest_drive = getdisk() + 'A' - 1;
  
  
  /* get info of source and destination file */
  stat((char *)src_filename, &src_statbuf);

  /* get amount of free disk space in destination drive */
  getdfree(dest_drive-'A'+1, &disktable);
  free_diskspace = (unsigned long) disktable.df_avail *
                   disktable.df_sclus * disktable.df_bsec;

  /* check free space on destination disk */
  if (src_statbuf.st_size > free_diskspace) 
  {
#ifdef USE_KITTEN
      error(1,29,"Insufficient disk space in destination path");
#else
      error("Insufficient disk space in destination path");
#endif
      return(0);
  }

  /* Copy file data */
  return copy_file(src_filename, dest_filename);
}
예제 #6
0
파일: memtypes.c 프로젝트: CivilPol/sdcboot
int
InitializeFittingMemory (unsigned long size, int HardDiskOk,
			 unsigned long *allocated,
			 /* Needed to check wether a swap file is
			    not created on the source or destination
			    drive: */
			 char sdrv, char tdrv)
{
  char *tempvar = NULL;
  struct dfree free;
  int curdisk, tempdisk, run = 1;
  unsigned long farfree;
  struct IniParserStruct *ParsedData;

  ParsedData = GetParsedData ();

  Initialised = TRUE;
  AmofProcessed = 0;

  CloseFunc = DoNothing;
  PrepareToReadFunc = ResetAmof;
  PrepareToWriteFunc = ResetAmof;

  /* First of all see wether main memory is not large enough */
  farfree = farcoreleft ();
  if (farfree > size)
    {
      FarBlock = (char far *) farmalloc (size);

      LastOffset = FP_OFF (FarBlock);
      LastSegment = FP_SEG (FarBlock);
      SavedSegment = LastSegment = LastSegment + LastOffset / 16;
      SavedOffset = LastOffset = LastOffset % 16;

      MemType = BUFFERS;
      CloseFunc = CloseBuffers;
      ReadFunc = BufferRead;
      WriteFunc = BufferWrite;
      PrepareToReadFunc = PrepareForChangingBuffers;
      PrepareToWriteFunc = PrepareForChangingBuffers;

      *allocated = size;
    }


  /* See wether EMS is installed. */
  if ((!MemType) && ParsedData->UseEMS && ((EMSBase = EMSbaseaddress ()) != 0))
    {
      /* See if there is enough memory. */
      if ((size / 16384) + 1 < EMSpages ())
	{
	  Handle = EMSalloc ((int) (size / 16384) + 1);
	  if (Handle >= 0)
	    {
	      CloseFunc = CloseEMS;
	      WriteFunc = EMSWrite;
	      ReadFunc = EMSRead;
	      MemType = EMS;
	    }

	  *allocated = size;
	}
    }

  /* See wether XMS is installed. */
  if (ParsedData->UseXMS && (!MemType) && XMSinit ())
    {
      /* See if there is enough memory. */
      if (size < XMScoreleft ())
	{
	  Handle = XMSalloc (size);
	  if (Handle != 0)
	    {
	      MemType = XMS;
	      CloseFunc = CloseXMS;
	      WriteFunc = XMSWrite;
	      ReadFunc = XMSRead;
	    }

	  *allocated = size;
	}
    }

  /* See wether the hard disk can be used. */
  if (!MemType && HardDiskOk)
    {
      tempvar = getenv ("temp");
      if (!tempvar)
	tempvar = getenv ("TEMP");
      if (tempvar && tempvar[0])
	strcpy (tempfile, tempvar);
      else
	strcpy (tempfile, "C:\\");

      /* Make sure that the disk where the temporary file is created
         is not either the source of the target of the disk copy.     */
      if ((toupper (tempfile[0]) == toupper (sdrv)) ||
	  (toupper (tempfile[0]) == toupper (tdrv)))
	strcpy (tempfile, "C:\\");

      curdisk = getdisk ();
      tempdisk = toupper (tempfile[0]) - 65;

      /* If the TEMP environment variable doesn't have a path form,
         use the root of c: instead. */
      if ((tempdisk < 0) || (tempdisk > 26) || (tempfile[1] != ':'))
	{
	  strcpy (tempfile, "C:\\");
	  tempdisk = 2;
	}

      for (;;)
	{
	  setdisk (tempdisk);
	  if (getdisk () == tempdisk)
	    {
	      unsigned long total;

	      setdisk (curdisk);

	      getdfree (tempdisk + 1, &free);
	      total = (long) free.df_avail * (long) free.df_bsec *
		(long) free.df_sclus;

	      if (total >= size)
		{
                  char* pSFNSlot;
                  ConvertToSFN(tempfile, ENVVAR_ID);
                  pSFNSlot = GetSFN(ENVVAR_ID);
                  if (pSFNSlot)
                  {
                     strcpy(tempfile, pSFNSlot);
		     Handle = creattemp (tempfile, 0);
		     if (Handle != -1)
		     {
		        MemType = HARDDISK;
		        CloseFunc = CloseDisk;
		        ReadFunc = DiskRead;
		        WriteFunc = DiskWrite;
		        PrepareToReadFunc = PrepareForReadingDisk;
		        PrepareToWriteFunc = PrepareForWritingDisk;
		        *allocated = size;
		        break;
		     }
                  }
		}
	    }
	  if (tempdisk != 2 || run == 1)	/* if not C drive. */
	    {
	      run++;
	      strcpy (tempfile, "C:\\");
	      tempdisk = 2;	/* try C drive instead. */
	    }
	  else
	    break;
	}
    }

  /* See if there is enough memory left on the far heap. */
  if (!MemType && farfree > BUFFERSIZE)
    {
      size = farfree - (farfree % BUFFERSIZE);
      FarBlock = (char far *) farmalloc (size);

      LastOffset = FP_OFF (FarBlock);
      LastSegment = FP_SEG (FarBlock);
      SavedSegment = LastSegment = LastSegment + LastOffset / 16;
      SavedOffset = LastOffset = LastOffset % 16;

      MemType = BUFFERS;
      CloseFunc = CloseBuffers;
      ReadFunc = BufferRead;
      WriteFunc = BufferWrite;
      PrepareToReadFunc = PrepareForChangingBuffers;
      PrepareToWriteFunc = PrepareForChangingBuffers;

      *allocated = size;
    }

  return MemType;
}
예제 #7
0
void PushRect(rect * R, int *err)
{
	/* We don't really use ERR, but its for compatibility */
	savelist *lastsave = savetail;
	long savesize = ImageSize(R);

	/* And we don't give a shit about size. */

	savetail = farcalloc(sizeof(savelist), 1L);
	savetail->prev = lastsave;
	savetail->im = NULL;
	if (memok(savesize))
	{
		safe_alloc = 1;
		savetail->im = (image far *) farcalloc(savesize, 1L);
	}
	savetail->R = farmalloc(sizeof(rect));
	*(savetail->R) = *R;

	if (!savetail->im)
	{
		char tbuf[128];
		char tbuf2[128];
		FILE *fd;
		image *tmp;
		char *pathname = getenv("TMP");
		unsigned char drive;
		struct dfree dtable;
		long dfree;

#ifdef AXTDEBUG
		printf("\nLook out, I'm pushing to disk.");
#endif

		/* Find out if there is enough space left on the thing */
      if (pathname && access(pathname,0))
         pathname = NULL;
		if (pathname && pathname[1] == ':')
			drive = toupper(pathname[0]) - 'A' + 1;
		else
			drive = 0;

		getdfree(drive, &dtable);

		if (dtable.df_sclus == 0xffff && drive)
		{
			drive = 0;
			getdfree(drive, &dtable);
			pathname = NULL;
			/* and so this doesn't happen again */
			putenv("TMP=");
		}

		dfree = (long) dtable.df_avail
		 * (long) dtable.df_bsec * (long) dtable.df_sclus;

		if (dfree > savesize)
		{
			rect R1;

			sprintf(tbuf, "%lx.dat", savetail);
			TempFileName(tbuf2, tbuf);
			fd = fopen(tbuf2, "wb");

			if (fd)
			{
				int i;
				unsigned long cl = farcoreleft();
				int lines;
				long n;

				if (cl > 2048L)
					cl -= 2048L;	/* Safety margin */

				R1 = *R;
				R1.Ymax = R1.Ymin;

				i = 1;
				while (i < R->Ymax)
				{
					R1.Ymax = R1.Ymin + i;
					n = ImageSize(&R1);
					if (n < cl)
					{
						savesize = n;
						lines = i;
					}
					i *= 2;
				}




				/*
				 * Let's see how many rows at a time we can
				 * save
				 */
				savetail->lines = lines;
				savetail->blocks = (R->Ymax - R->Ymin + 1) / lines;

				tmp = farmalloc(savesize);
				//setvbuf(fd, (char *) tmp, _IOFBF, (size_t) savesize);
				R1 = *R;
				R1.Ymax = R1.Ymin + lines - 1;
				for (i = R->Ymin; i <= R->Ymax; i += lines)
				{
					R1.Ymax = min(R1.Ymax, R->Ymax);
					ReadImage(&R1, tmp);
					fwrite(tmp, 1, (int) ImageSize(&R1), fd);
					OffsetRect(&R1, 0, lines);
				}
				fclose(fd);
				farfree(tmp);
				tmp = NULL;
				savetail->filename = strdup(tbuf2);
				*err = 0;
				return;
			}
		}

		sprintf(tbuf, "Can't allocate %ld bytes", savesize);
		ErrorBox(tbuf);
		*err = 1;
		farfree(savetail->R);
		savetail->R = NULL;
		farfree(savetail);
		savetail = NULL;
		savetail = lastsave;
	}
	else
	{
		ReadImage(savetail->R, savetail->im);
		*err = 0;
	}
}
예제 #8
0
파일: xcopy.c 프로젝트: FDOS/xcopy
/*-------------------------------------------------------------------------*/
void xcopy_file(const char *src_filename,
                const char *dest_filename) {
  int dest_file_exists;
  int fileattrib;
  struct stat src_statbuf;
  struct stat dest_statbuf;
  struct dfree disktable;
  unsigned long free_diskspace;
  char ch;
  char msg_prompt[255];


  if (switch_prompt) {
    /* ask for confirmation to create file */
    ch = confirm(dest_filename,
      catgets(cat, 3, 2, "Yes"),
      catgets(cat, 3, 3, "No"), NULL, NULL);
    if (ch == 2 /* 'N' */) {
      /* no -> skip file */
      return;
    }
  }

  /* check if source and destination file are equal */
  if (stricmp(src_filename, dest_filename) == 0) {
    printf("%s - %s\n", catgets(cat, 1, 21, "File cannot be copied onto itself"), src_filename);
    catclose(cat);
    exit(4);
  }

  /* check source file for read permission */
  /* (only usefull under an OS with the ability to deny read access) */
  if (access(src_filename, R_OK) != 0) {
    printf("%s - %s\n", catgets(cat, 1, 22, "Read access denied"), src_filename);
    if (switch_continue) {
      return;
    }
    else {
      catclose(cat);
      exit(5);
    }
  }

  /* get info of source and destination file */
  stat((char *)src_filename, &src_statbuf);
  dest_file_exists = !stat((char *)dest_filename, &dest_statbuf);

  /* get amount of free disk space in destination drive */
  getdfree(dest_drive, &disktable);
  free_diskspace = (unsigned long) disktable.df_avail *
                   disktable.df_sclus * disktable.df_bsec;

  if (dest_file_exists) {
    if (switch_date) {
      if (switch_date < 0) {
        /* check, that only newer files are copied */
        if (src_statbuf.st_mtime <= dest_statbuf.st_mtime) {
          return;
        }
      }
      else {
        /* check, that only files changed on or after the specified date */
        /* are copied                                                    */
        if (src_statbuf.st_mtime < switch_date) {
          return;
        }
      }
    }

    switch (switch_confirm) {
      case 1:
        /* skip file */
        return;
      case 2:
        /* ask for confirmation to overwrite file */
        strmcpy(msg_prompt,
          catgets(cat, 3, 1, "Overwrite"), sizeof(msg_prompt));
        strmcat(msg_prompt, " ", sizeof(msg_prompt));
        strmcat(msg_prompt, dest_filename, sizeof(msg_prompt));
        ch = confirm(msg_prompt,
          catgets(cat, 3, 2, "Yes"),
          catgets(cat, 3, 3, "No"),
          catgets(cat, 3, 4, "Overwrite all"),
          catgets(cat, 3, 5, "Skip all"));
        switch (ch) {
          case 2: /* 'N' */
            /* no -> skip file */
            return;
          case 3: /* 'O' */
            /* overwrite all -> set confirm switch */
            switch_confirm = 0;
            break;
          case 4: /* 'S' */
            /* skip all -> set confirm switch */
            switch_confirm = 1;
            return;
        }
        break;
    }

    /* check free space on destination disk */
    /* *** was wrong, was: "if (src... > free... - dest...) ..." */
    if ( (src_statbuf.st_size > dest_statbuf.st_size) &&
         ((src_statbuf.st_size - dest_statbuf.st_size) > free_diskspace) ) {
      printf("%s - %s\n", catgets(cat, 1, 23, "Insufficient disk space in destination path"), dest_filename);
      catclose(cat);
      exit(39);
    }

    /* get file attribute from destination file */
    fileattrib = _chmod(dest_filename, 0);

    /* check destination file for write permission */
    if ((fileattrib & (64 ^ FA_RDONLY)) != 0) {
      if (!switch_readonly) {
        printf("%s - %s\n", catgets(cat, 1, 24, "Write access denied"), dest_filename);
        if (switch_continue) {
          return;
        }
        else {
          catclose(cat);
          exit(5);
        }
      }

      /* check, if file copying should be simulated */
      if (!switch_listmode) {
        /* remove readonly attribute from destination file */
        fileattrib = fileattrib ^ FA_RDONLY;
        _chmod(dest_filename, 1, fileattrib);
      }
    }
  }
  else {
    /* check free space on destination disk */
    if (src_statbuf.st_size > free_diskspace) {
      printf("%s - %s\n", catgets(cat, 1, 25, "Insufficient disk space in destination path"), dest_filename);
      catclose(cat);
      exit(39);
    }
  }

  if (!switch_quiet) {
    printf("%s %s", catgets(cat, 1, 26, "Copying"), src_filename);
    if (switch_fullnames) {
      printf(" -> %s\n", dest_filename);
    }
    else {
      printf("\n");
    }
  }

  /* check, if file copying should be simulated */
  if (!switch_listmode) {
    copy_file(src_filename, dest_filename, switch_continue);

    if (switch_archive_reset) {
      /* remove archive attribute from source file */
      fileattrib = _chmod(src_filename, 0);
      _chmod(src_filename, 1, fileattrib ^ FA_ARCH);
    }
  }

  file_counter++;
}