예제 #1
0
int fakestatfs(const char *path, STATFS_STRUCT *str)
# endif            
# if STATFS_TYPE > 0
{
    char curdirtmp[MAXPATHLEN];
    
    if (chroot_base == NULL) {
        return STATFS(path, str);
    }
    if (fakexlate(curdirtmp, sizeof curdirtmp, path) != 0) {
        return -1;
    }    
    return STATFS(curdirtmp, str);
}
예제 #2
0
void DoExtDiskSpace(tBuffer *bIn, tBuffer *bOut, u_int32_t id)
{
	struct STATFS stfs;
	tFSPath	*realPath;
	char *path;

	path = convertFromUtf8(BufferGetString(bIn), 1);
	realPath = FSCheckPath(path);
	DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH]Path: %s", path));
	if (realPath != NULL && !HAS_BIT(gl_var->flagsDisable, SFTP_DISABLE_STATSFS))
	{
		DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH]Realpath: %s", realPath->realPath));
		if (STATFS(realPath->realPath, &stfs) == 0)
		{
			tBuffer *b;

			b = BufferNew();
			BufferPutInt8(b, SSH2_FXP_EXTENDED_REPLY);
			BufferPutInt32(b, id);
			BufferPutInt64(b, (u_int64_t) stfs.f_blocks * (u_int64_t) stfs.f_bsize);
			BufferPutInt64(b, (u_int64_t) stfs.f_bfree * (u_int64_t) stfs.f_bsize);
			BufferPutInt64(b, 0);
			BufferPutInt64(b, (u_int64_t) stfs.f_bavail * (u_int64_t) stfs.f_bsize);
			BufferPutInt32(b, stfs.f_bsize);
			BufferPutPacket(bOut, b);
		}
		else
			SendStatus(bOut, id, errnoToPortable(errno));
	}
	else
		SendStatus(bOut, id, SSH2_FX_PERMISSION_DENIED);
	FSDestroyPath(realPath);
	free(path);
}
예제 #3
0
/******************************************************************************
NAME
   vc_hostfs_freespace

SYNOPSIS
   int vc_hostfs_freespace(const char *path)

FUNCTION
   Returns the amount of free space on the physical file system that contains
   path.

RETURNS
   Successful completion: free space
   Otherwise: -1
******************************************************************************/
int64_t vc_hostfs_freespace64(const char *inPath)
{
   char *path = strdup( inPath );
   int64_t ret;
   STRUCT_STATFS fsStat;

   // Replace all '\' with '/'
   backslash_to_slash( path );

   ret = (int64_t) STATFS( path, &fsStat );

   if (ret == 0)
   {
      ret = fsStat.f_bsize * fsStat.f_bavail;
   }
   else
   {
      ret = -1;
   }

   DEBUG_MINOR( "vc_hostfs_freespace64 for '%s' returning %" PRId64 "", path, ret );

   free( path );
   return ret;
}
예제 #4
0
bool
ArkUtils::diskHasSpace(const TQString &dir, TDEIO::filesize_t size)
  // check if disk has enough space to accommodate (a) new file(s) of
  // the given size in the partition containing the given directory
{
  kdDebug( 1601 ) << "diskHasSpace() " << "dir: " << dir << " Size: " << size << endl;
  
  struct STATFS buf;
  if (STATFS(TQFile::encodeName(dir), &buf) == 0)
  {
    double nAvailable = (double)buf.f_bavail * buf.f_bsize;
    if ( nAvailable < (double)size )
    {
      KMessageBox::error(0, i18n("You have run out of disk space."));
      return false;
    }
  }
  else
  {
    // something bad happened
    kdWarning( 1601 ) << "diskHasSpace() failed" << endl;
    // Q_ASSERT(0);
  }
  return true;
}
예제 #5
0
//----------------------------------------------------------------------------------------
PRInt64 nsFileSpec::GetDiskSpaceAvailable() const
//----------------------------------------------------------------------------------------
{
    PRInt64 bytes; /* XXX dougt needs to fix this */
    LL_I2L(bytes , LONG_MAX); // initialize to all the space in the world?


#if defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_STATVFS_H)

    char curdir [MAXPATHLEN];
    if (mPath.IsEmpty())
    {
        (void) getcwd(curdir, MAXPATHLEN);
        if (!curdir)
            return bytes;  /* hope for the best as we did in cheddar */
    }
    else
        sprintf(curdir, "%.200s", (const char*)mPath);
 
    struct STATFS fs_buf;
#if defined(__QNX__) && !defined(HAVE_STATVFS) /* Maybe this should be handled differently? */
    if (STATFS(curdir, &fs_buf, 0, 0) < 0)
#else
    if (STATFS(curdir, &fs_buf) < 0)
#endif
        return bytes; /* hope for the best as we did in cheddar */
 
#ifdef DEBUG_DISK_SPACE
    printf("DiskSpaceAvailable: %d bytes\n", 
       fs_buf.f_bsize * (fs_buf.f_bavail - 1));
#endif

    PRInt64 bsize,bavail;
    LL_I2L( bsize,  fs_buf.f_bsize );
    LL_I2L( bavail, fs_buf.f_bavail - 1 );
    LL_MUL( bytes, bsize, bavail );
    return bytes;

#else 
    /*
    ** This platform doesn't have statfs or statvfs, so we don't have much
    ** choice but to "hope for the best as we did in cheddar".
    */
    return bytes;
#endif /* HAVE_SYS_STATFS_H or HAVE_SYS_STATVFS_H */

} // nsFileSpec::GetDiskSpace()
예제 #6
0
파일: filegui.c 프로젝트: CTU-OSP/mc
/* --------------------------------------------------------------------------------------------- */
static gboolean
filegui__check_attrs_on_fs (const char *fs_path)
{
    STRUCT_STATVFS stfs;

    if (!setup_copymove_persistent_attr)
        return FALSE;

#if USE_STATVFS && defined(STAT_STATVFS)
    if (statvfs_works () && statvfs (fs_path, &stfs) != 0)
        return TRUE;
#else
    if (STATFS (fs_path, &stfs) != 0)
        return TRUE;
#endif

#if (USE_STATVFS && defined(HAVE_STRUCT_STATVFS_F_TYPE)) || \
        (!USE_STATVFS && defined(HAVE_STRUCT_STATFS_F_TYPE))
    switch ((filegui_nonattrs_fs_t) stfs.f_type)
    {
    case MSDOS_SUPER_MAGIC:
    case NTFS_SB_MAGIC:
    case PROC_SUPER_MAGIC:
    case SMB_SUPER_MAGIC:
    case NCP_SUPER_MAGIC:
    case USBDEVICE_SUPER_MAGIC:
        return FALSE;
    default:
        break;
    }
#elif defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME) || defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
    if (strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "msdos") == 0
        || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "msdosfs") == 0
        || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "ntfs") == 0
        || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "procfs") == 0
        || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "smbfs") == 0
        || strstr (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "fusefs") != NULL)
        return FALSE;
#elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
    if (strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "pcfs") == 0
        || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "ntfs") == 0
        || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "proc") == 0
        || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "smbfs") == 0
        || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "fuse") == 0)
        return FALSE;
#endif

    return TRUE;
}
예제 #7
0
파일: spool.c 프로젝트: Orc/postoffice
int
mkspool(struct letter *let)
{
    static char tempfile[sizeof(TEMPPFX)+20+1];
    int f;

#if HAVE_STRUCT_STATFS || HAVE_STRUCT_STATVFS
#if HAVE_STATFS
#   define STATFS statfs
#   define F_BSIZE f_bsize
#else
#   define STATFS statvfs
#   define F_BSIZE f_frsize
#endif

    struct STATFS df;
    unsigned long size;

    if ( let->env && (let->env->minfree > 0) ) {
	if (STATFS(QUEUEDIR, &df) != 0) {
	    syslog(LOG_ERR, "stat(v)fs(%s): %m", QUEUEDIR);
	    return 0;
	}

	size = let->env->minfree / df.F_BSIZE;

	if (df.f_bavail < size) { 
	    syslog(LOG_ERR, "Disk too full (need %ld blocks, have %ld free)",
			    (long)let->env->minfree, (long)df.f_bavail);
	    return 0;
	}
    }
#endif

    strcpy(tempfile, TEMPPFX "XXXXXX");

    umask(077);
    if ( (f = mkstemp(tempfile)) == -1 || (let->body = fdopen(f, "w+")) == 0) {
	if (f != -1) close(f);
	syslog(LOG_ERR, "%s: %m", tempfile);
	return 0;
    }
    let->tempfile = tempfile;
    return 1;
}
예제 #8
0
static void DoExtDiskSpaceOpenSSH_Path(tBuffer *bOut, u_int32_t id, const char *path)
{
	struct STATFS stfs;
	tFSPath	*realPath;

	DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]Path: %s", path));
	realPath = FSCheckPath(path);
	if (realPath != NULL && !HAS_BIT(gl_var->flagsDisable, SFTP_DISABLE_STATSFS))
	{
		DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]Realpath: %s", realPath->realPath));
		if (STATFS(realPath->realPath, &stfs) == 0)
		{
			tBuffer *b;

			b = BufferNew();
			BufferPutInt8(b, SSH2_FXP_EXTENDED_REPLY);
			BufferPutInt32(b, id);
			BufferPutInt64(b, stfs.f_bsize); /* file system block size */
			BufferPutInt64(b, stfs.f_frsize); /* fundamental fs block size */
			BufferPutInt64(b, stfs.f_blocks); /* number of blocks (unit f_frsize) */
			BufferPutInt64(b, stfs.f_bfree); /* free blocks in file system */
			BufferPutInt64(b, stfs.f_bavail); /* free blocks for non-root */
			BufferPutInt64(b, stfs.f_files); /* total file inodes */
			BufferPutInt64(b, stfs.f_ffree); /* free file inodes */
			BufferPutInt64(b, stfs.f_favail); /* free file inodes for to non-root */
			BufferPutInt64(b, stfs.f_fsid); /* file system id */
			BufferPutInt64(b, stfs.f_flag); /* bit mask of f_flag values */
			BufferPutInt64(b, stfs.f_namemax); /* maximum filename length */
			BufferPutPacket(bOut, b);
			BufferDelete(b);
		}
		else
		{
			DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]error: %s", strerror(errno)));
			SendStatus(bOut, id, errnoToPortable(errno));
		}
	}
	else
	{
		DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]FSCheckPath failed"));
		SendStatus(bOut, id, SSH2_FX_PERMISSION_DENIED);
	}
	FSDestroyPath(realPath);
}
예제 #9
0
파일: filegui.c 프로젝트: ilia-maslakov/mc
static gboolean
filegui__check_attrs_on_fs (const char *fs_path)
{
#ifdef STATFS
    STRUCT_STATFS stfs;

    if (!setup_copymove_persistent_attr)
        return FALSE;

    if (STATFS (fs_path, &stfs) != 0)
        return TRUE;

#ifdef __linux__
    switch ((filegui_nonattrs_fs_t) stfs.f_type)
    {
    case MSDOS_SUPER_MAGIC:
    case NTFS_SB_MAGIC:
    case PROC_SUPER_MAGIC:
    case SMB_SUPER_MAGIC:
    case NCP_SUPER_MAGIC:
    case USBDEVICE_SUPER_MAGIC:
        return FALSE;
    default:
        break;
    }
#elif defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) \
      || defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)
    if (!strcmp (stfs.f_fstypename, "msdos")
        || !strcmp (stfs.f_fstypename, "msdosfs")
        || !strcmp (stfs.f_fstypename, "ntfs")
        || !strcmp (stfs.f_fstypename, "procfs")
        || !strcmp (stfs.f_fstypename, "smbfs") || strstr (stfs.f_fstypename, "fusefs"))
        return FALSE;
#elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
    if (!strcmp (stfs.f_basetype, "pcfs")
        || !strcmp (stfs.f_basetype, "ntfs")
        || !strcmp (stfs.f_basetype, "proc")
        || !strcmp (stfs.f_basetype, "smbfs") || !strcmp (stfs.f_basetype, "fuse"))
        return FALSE;
#endif
#endif /* STATFS */

    return TRUE;
}
예제 #10
0
int
nsSetupTypeDlg::DSAvailable(void)
{
    // returns disk space available in kilobytes

    int dsAvail = -1;

#if defined(HAVE_SYS_STATVFS_H) || defined(HAVE_SYS_STATFS_H)
    struct STATFS buf;
    int rv;

    if (gCtx->opt->mDestination)
    {
        rv = STATFS(gCtx->opt->mDestination, &buf);
        if (rv == 0)
        {
            if (buf.f_bsize > 1024 && (buf.f_bsize%1024 == 0))
            {
                // normally the block size is >= 1024 and a multiple
                // so we can shave off the last three digits before 
                // finding the product of the block size and num blocks
                // which is important for large disks

                dsAvail = (buf.f_bsize/1024) * (buf.f_bavail);
            }
            else
            {
                // attempt to stuff into a 32 bit int even though
                // we convert from bytes -> kilobytes later
                // (may fail to compute on very large disks whose
                // block size is not a multiple of 1024 -- highly 
                // improbable)

                dsAvail = (buf.f_bsize * buf.f_bavail)/1024;
            }
        }
    }
#endif // HAVE_SYS_STATVFS_H -or- HAVE_SYS_STATFS_H 

    return dsAvail;
}
예제 #11
0
int GetDiskParameter( char *path, 
		      char *volume_name, 
		      LONGLONG *avail_bytes,
		      LONGLONG *total_disk_space
		    )
{

#ifdef WIN32
  struct _diskfree_t diskspace;
#else
#if defined( SVR4 ) || defined( OSF1 ) || defined( __NetBSD__ )
  struct statvfs statfs_struct;
#else
#ifdef ultrix
  struct fs_data statfs_struct;
#else
#ifdef QNX
  long total_blocks, free_blocks;
  int fd;
#else
  struct statfs statfs_struct;
#endif /* QNX */
#endif /* ultrix */
#endif /* SVR4 */
#endif /* WIN32 */

  char *p;
  char *fname;
  int  result;
  LONGLONG bfree;
  LONGLONG this_disk_space;


#ifdef WIN32
  if( ( result = _getdiskfree( 0, &diskspace ) ) == 0 )
#else
#ifdef __DJGPP__
  if( ( result = statfs( path, &statfs_struct ) ) == 0 )
#else
#ifdef QNX
   fd = open(path, O_RDONLY );
  if( ( result = disk_space( fd, &free_blocks, &total_blocks ) ) == 0 )
#else

  if( ( result = STATFS( path, &statfs_struct, sizeof( statfs_struct ), 0 ) ) == 0 )
#endif /* QNX */
#endif /* __DJGPP__ */
#endif /* WIN32 */
  {
    if( volume_name )
    {
      /* Name ermitteln */
      /*----------------*/

      if( mode == DISK_MODE || mode == USER_MODE )
      {
  
#ifdef linux
	switch( statfs_struct.f_type ) {
	  case 0xEF51:
	       fname = "EXT2-OLD"; break;
	  case 0xEF53:
	       fname = "EXT2"; break;
	  case 0x137D:
	       fname = "EXT"; break;
	  case 0x9660:
	       fname = "ISOFS"; break;
	  case 0x137F:
	       fname = "MINIX"; break;
	  case 0x138F:
	       fname = "MINIX2"; break;
	  case 0x2468:
	       fname = "MINIX-NEW"; break;
	  case 0x4d44:
	       fname = "DOS"; break;
	  case 0x6969:
	       fname = "NFS"; break;
	  case 0x9fa0:
	       fname = "PROC"; break;
	  case 0x012FD16D:
	       fname = "XIAFS"; break;
	  default:
	       fname = "LINUX";
	}
#else
#ifdef __GNU__
       switch( statfs_struct.f_type ) {
         case FSTYPE_UFS:
              fname = "UFS"; break;
         case FSTYPE_NFS:
              fname = "NFS"; break;
         case FSTYPE_GFS:
              fname = "GFS"; break;
         case FSTYPE_LFS:
              fname = "LFS"; break;
         case FSTYPE_SYSV:
              fname = "SYSV"; break;
         case FSTYPE_FTP:
              fname = "FTP"; break;
         case FSTYPE_TAR:
              fname = "TAR"; break;
         case FSTYPE_AR:
              fname = "AR"; break;
         case FSTYPE_CPIO:
              fname = "CPIO"; break;
         case FSTYPE_MSLOSS:
              fname = "DOS"; break;
         case FSTYPE_CPM:
              fname = "CPM"; break;
         case FSTYPE_HFS:
              fname = "HFS"; break;
         case FSTYPE_DTFS:
              fname = "DTFS"; break;
         case FSTYPE_GRFS:
              fname = "GRFS"; break;
         case FSTYPE_TERM:
              fname = "TERM"; break;
         case FSTYPE_DEV:
              fname = "DEV"; break;
         case FSTYPE_PROC:
              fname = "PROC"; break;
         case FSTYPE_IFSOCK:
              fname = "IFSOCK"; break;
         case FSTYPE_AFS:
              fname = "AFS"; break;
         case FSTYPE_DFS:
              fname = "DFS"; break;
         case FSTYPE_PROC9:
              fname = "PROC9"; break;
         case FSTYPE_SOCKET:
              fname = "SOCKET"; break;
         case FSTYPE_MISC:
              fname = "MISC"; break;
         case FSTYPE_EXT2FS:
              fname = "EXT2FS"; break;
         case FSTYPE_HTTP:
              fname = "HTTP"; break;
         case FSTYPE_MEMFS:
              fname = "MEM"; break;
         case FSTYPE_ISO9660:
              fname = "ISO9660"; break;
         default:
              fname = "HURD";
       }
#else
#if defined( sun56 ) || defined( sun ) || defined( hpux ) || defined( __NeXT__ ) || defined( ultrix ) || defined ( __FreeBSD__ ) || defined (__APPLE__)
        fname = "UNIX";
#else
#ifdef WIN32
        fname = "WIN-NT";
#else
#ifdef __DJGPP__
        fname = "DJGPP";
#else
#ifdef QNX
        fname = "QNX";
#else
#if defined( SVR4 ) || defined( OSF1 )
        fname = statfs_struct.f_fstr;
#else
#if defined(__OpenBSD__) || defined(__NetBSD__)
        fname = statfs_struct.f_fstypename;
#else
        fname = statfs_struct.f_fname;
#endif /* __OpenBSD__ || __NetBSD__ */
#endif /* SVR4 */
#endif /* __DJGPP__ */
#endif /* QNX */
#endif /* WIN32 */
#endif /* sun / hpux / __NeXT__ ultrix */
#endif /* __GNU__ */
#endif /* linux */

        (void) strncpy( volume_name, 
	                fname,
		        MINIMUM( DISK_NAME_LENGTH, strlen( fname ) )
		      );
        volume_name[ MINIMUM( DISK_NAME_LENGTH, strlen( fname ))] = '\0';
      }
      else
      {  
        /* TAR/ZOO/ZIP-FILE_MODE */
        /*-----------------------*/
        
        if( ( p = strrchr( statistic.login_path, FILE_SEPARATOR_CHAR ) ) == NULL ) 
          p = statistic.login_path;
        else p++;
  
        (void) strncpy( volume_name, p, sizeof( statistic.disk_name ) );
        volume_name[sizeof( statistic.disk_name )] = '\0';
      }
    } /* volume_name */

#ifdef WIN32
    *avail_bytes = (long) diskspace.bytes_per_sector *
                   (long) diskspace.sectors_per_cluster *
                   (long) diskspace.avail_clusters;
    this_disk_space = 900000000L; /* for now.. */
#else

#if (defined( SVR4 ) || defined( OSF1 )) && !defined( __DGUX__ )
    bfree = getuid() ? statfs_struct.f_bavail : statfs_struct.f_bfree;
    if( bfree < 0L ) bfree = 0L;
    *avail_bytes = bfree * statfs_struct.f_frsize;
    this_disk_space   = statfs_struct.f_blocks * statfs_struct.f_frsize;
#else
#if defined( _IBMR2 ) || defined( linux ) || defined( sun ) || defined( __NeXT__ ) || defined( __GNU__ )
    bfree = getuid() ? statfs_struct.f_bavail : statfs_struct.f_bfree;
    if( bfree < 0L ) bfree = 0L;
    *avail_bytes = bfree * statfs_struct.f_bsize;
    this_disk_space   = statfs_struct.f_blocks * statfs_struct.f_blocks;
#else
#ifdef SVR3
    bfree = statfs_struct.f_bfree;
    if( bfree < 0L ) bfree = 0L;
    *avail_bytes = bfree * BLKSIZ;  /* SYSV */
    this_disk_space   = statfs_struct.f_blocks * BLKSIZ;
#else 
#if defined( ultrix )
    bfree = statfs_struct.fd_req.bfree;
    if( bfree < 0L ) bfree = 0L;
#else 
#if defined( QNX )
    *avail_bytes = free_blocks * 512;
    this_disk_space = total_blocks * 512;
#else
    bfree = statfs_struct.f_bfree;
    if( bfree < 0L ) bfree = 0L;
    *avail_bytes = bfree * statfs_struct.f_bsize;
    this_disk_space   = statfs_struct.f_blocks * statfs_struct.f_bsize;
#endif /* QNX */
#endif /* ultrix */
#endif /* SVR3 */
#endif /* SVR4/!__DGUX__ */
#endif /* _IBMR2/linux/sun/__NeXT__/__GNU__ */
#endif /* WIN32 */
    
    if( total_disk_space )
    {
      *total_disk_space = this_disk_space;
    }
  }
#ifdef QNX
  close(fd);
#endif
  return( result );
}