The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
free some space in file system fu4d UNIX for Dummies Questions & Answers 6 04-11-2008 04:27 AM
command to find free disk space on solaris harishankar SUN Solaris 2 08-26-2007 11:47 AM
How to re-allocate disk space on solaris 10 duke0001 UNIX for Advanced & Expert Users 2 12-13-2006 11:14 AM
free disk space calc ninjanesto High Level Programming 1 11-10-2006 11:03 AM
Free size for File System videsh77 UNIX for Dummies Questions & Answers 7 02-03-2005 06:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-21-2006
yidu yidu is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 1
Lightbulb How to get free disk space size in C/C++ program( Solaris system)

How to get free disk space size in C/C++ program( Solaris system)?
Is there any standard function or system function? Just like "df" or
"getdfree" in Linux.
  #2 (permalink)  
Old 08-21-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
How do you want to do it? Run a system() call that runs 'df' or do you want to do this via system calls? For the latter, check the man page of statvfs(2). For the first method, check the man page of system(3).
  #3 (permalink)  
Old 08-23-2006
vrghost vrghost is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 1
Needed to write something to get information from the disks and send it to a web app, so here is the code (the html stuff removed), this should give you the info (works on our AIX servers atleast). Only thing is it does give a slightly higher free space value than df, not certain what is causing it.

Code:
/*
################################################################################
##                              diskstat.c                                    ##
################################################################################
## diskstat returns (or will soon return to be more precice) webified diskstat for specific disk, should change to     ##
## XML'ified info at some point.....                                          ##
################################################################################
*/

#include <sys/statvfs.h>

int main( int argc, char *argv[] )
{
        struct statvfs fiData;
        struct statvfs *fpData;
        char fnPath[128];
        int i;

        if( argc < 2 ) {
                printf("Usage, webdisk DEVICE0 ..... DEVICEX\n");
                return(2);
        }

        //Lets loopyloop through the argvs
        for( i = 1 ; i<argc; i++ ) {
                strcpy(fnPath, argv[i]);
                if((statvfs(fnPath,&fiData)) < 0 ) {
                        printf("Failed to stat %s:\n", fnPath);
                } else {
                        printf("Disk %s: \n", fnPath);
                        printf("\tblock size: %u\n", fiData.f_bsize);
                        printf("\ttotal no blocks: %i\n", fiData.f_blocks);
                        printf("\tfree blocks: %i\n", fiData.f_bfree);
                }
        }
}

For the other members of the struct, check sys/statvfs.h.

Just compile and send it the mountpoint of the disk.
So for example ./a.out /

BTW Thanks blowtorch for pointing me in the right direction whith statvls.
  #4 (permalink)  
Old 08-07-2007
prasad11 prasad11 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 1
Exclamation need to help to test in linux

hi,

i have written the code to find free space for linux using native code of java like below.

#include <sys/statvfs.h>

JNIEXPORT jlong JNICALL Java_NativeUtils_getDiskFreeSpace
(JNIEnv *env, jclass obj, jstring path) {
struct statvfs fiData;
struct statvfs *fpData;
//char fnPath[128];
int i;
const char *str = (*env)->GetStringUTFChars(env, path, 0);
jlong ret;

if((statvfs(str,&fiData)) < 0 ) {
printf("Failed to stat %s:\n", str);
} else {
printf("\tblock size: %u\n", fiData.f_bsize);
}
(*env)->ReleaseStringUTFChars(env, path, str);
ret = (jlong)fiData.QuadPart;
return ret;
}

if any person is having the linux os and can u please test and get back to me

thanks,
prasad
  #5 (permalink)  
Old 01-30-2009
vazzdoin vazzdoin is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 1
I used ur code and compliled it using gcc compiler on Linux. But its giving the following error.

error: `JNIEXPORT' does not name a type


any solution to that ???
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0