Sponsored Content
Top Forums Programming how to get the file system size Post 302167184 by Franklin52 on Wednesday 13th of February 2008 05:17:44 PM
Old 02-13-2008
The problem is an integer overflow.
Declare the variables free_blk and blk_size as long and change the format of the last printf statement as follow:

Code:
#include <sys/statvfs.h>
#include <stdio.h>

int main(){

  struct statvfs buffer;
  int status;
  long free_blk;
  long blk_size;

  status = statvfs("/", &buffer);

  printf("free blocks: %u\n",buffer.f_bavail);
  printf("block size: %u\n",buffer.f_bsize);

  free_blk = buffer.f_bavail;
  blk_size = buffer.f_bsize;
  printf("total size: %Ld\n",free_blk*blk_size);
  return 0;
}

Regards
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Free size for File System

How to find the free size currently FileSystem has, on the disk mounted? I know 'df' lists all the mounted disks, but I am interested to know details for the filesystem, in which currently I am working. (7 Replies)
Discussion started by: videsh77
7 Replies

2. UNIX for Advanced & Expert Users

File system size change

Good morning folks! I'm new here.. trying to find an answer on how to resize filesystem. Need to add some space to c0t0d0s5, /var... Is it possible at all? JV (9 Replies)
Discussion started by: jvinn
9 Replies

3. AIX

file system size

Dear ALL Today I faced one problem in the file system, during invoking the command #df -k , I saw /usr reached to 95% Used, could any one give advice ? thanks & regarded (7 Replies)
Discussion started by: magasem
7 Replies

4. Solaris

increasing file system size

Hi Can anyone explain me how to increase the filesystem size. We can do it when the system is running? It needs an reboot? (8 Replies)
Discussion started by: rogerben
8 Replies

5. AIX

increase the size of file system

Hi all, we are usig aix 4.3 and i need to increase the size of "/u01" file sytem which is mounted on logical volume "lv00", but "/u01" file system size is 9 GB and logical volume "lvoo" size 9 GB.how do i increase the size of /u01.do i increase the size of logical volume "lv00" and then... (2 Replies)
Discussion started by: younusdba
2 Replies

6. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

7. Shell Programming and Scripting

file size on the operating system

When I do df -h, I see that one of my partitions is out of space. Then when I do du -h, I get thousands of files. How do I only look at files over a specific size. I want directories over 500m to be returned only. (2 Replies)
Discussion started by: guessingo
2 Replies

8. Shell Programming and Scripting

Script to check file system size

Dears, the output of this command df -h | tr -s ' ' | cut -f5 -d' ' is capacity 24% 0% 0% 0% 0% 1% 0% 24% 24% 0% 93% 1% (4 Replies)
Discussion started by: xxmasrawy
4 Replies

9. AIX

File system percentage to the hole size ?

Hi, I'd like to know how can I figure out my disk space area on AIX machine, for example to the situation of ( df -g ) which I have in my system : the area used by (/opt/oracle) file system is (98%) now. the free area on (/opt/oracle) is (0.75) now. the total size in Gigabyte... (1 Reply)
Discussion started by: arm
1 Replies

10. HP-UX

[Solved] Increase the file system size

Dear Friends, I would like to increase the size of a file system from 10GB to 15GB. System is runing on HP-UX 11.31. Please help in the matter. Regards, Bhagawati Pandey (3 Replies)
Discussion started by: BPANDEY
3 Replies
STATVFS(3)						     Linux Programmer's Manual							STATVFS(3)

NAME
statvfs, fstatvfs - get file system statistics SYNOPSIS
#include <sys/statvfs.h> int statvfs(const char *path, struct statvfs *buf); int fstatvfs(int fd, struct statvfs *buf); DESCRIPTION
The function statvfs() returns information about a mounted file system. path is the pathname of any file within the mounted file system. buf is a pointer to a statvfs structure defined approximately as follows: struct statvfs { unsigned long f_bsize; /* file system block size */ unsigned long f_frsize; /* fragment size */ fsblkcnt_t f_blocks; /* size of fs in f_frsize units */ fsblkcnt_t f_bfree; /* # free blocks */ fsblkcnt_t f_bavail; /* # free blocks for unprivileged users */ fsfilcnt_t f_files; /* # inodes */ fsfilcnt_t f_ffree; /* # free inodes */ fsfilcnt_t f_favail; /* # free inodes for unprivileged users */ unsigned long f_fsid; /* file system ID */ unsigned long f_flag; /* mount flags */ unsigned long f_namemax; /* maximum filename length */ }; Here the types fsblkcnt_t and fsfilcnt_t are defined in <sys/types.h>. Both used to be unsigned long. The field f_flag is a bit mask (of mount flags, see mount(8)). Bits defined by POSIX are ST_RDONLY Read-only file system. ST_NOSUID Set-user-ID/set-group-ID bits are ignored by exec(3). It is unspecified whether all members of the returned struct have meaningful values on all file systems. fstatvfs() returns the same information about an open file referenced by descriptor fd. RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ERRORS
EACCES (statvfs()) Search permission is denied for a component of the path prefix of path. (See also path_resolution(7).) EBADF (fstatvfs()) fd is not a valid open file descriptor. EFAULT Buf or path points to an invalid address. EINTR This call was interrupted by a signal. EIO An I/O error occurred while reading from the file system. ELOOP (statvfs()) Too many symbolic links were encountered in translating path. ENAMETOOLONG (statvfs()) path is too long. ENOENT (statvfs()) The file referred to by path does not exist. ENOMEM Insufficient kernel memory was available. ENOSYS The file system does not support this call. ENOTDIR (statvfs()) A component of the path prefix of path is not a directory. EOVERFLOW Some values were too large to be represented in the returned struct. CONFORMING TO
POSIX.1-2001. NOTES
The Linux kernel has system calls statfs(2) and fstatfs(2) to support this library call. The current glibc implementations of pathconf(path, _PC_REC_XFER_ALIGN); pathconf(path, _PC_ALLOC_SIZE_MIN); pathconf(path, _PC_REC_MIN_XFER_SIZE); respectively use the f_frsize, f_frsize, and f_bsize fields of the return value of statvfs(path,buf). SEE ALSO
statfs(2) COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2003-08-22 STATVFS(3)
All times are GMT -4. The time now is 07:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy