Disk Space

Hi,
I used the disk_space function(to get the disk space on my hard drive) as
given in the book and it always returns
-1(error). Does anyone know why?

Thanks,
Shashank

Shashank wrote:

Hi,
I used the disk_space function(to get the disk space on my hard drive) as
given in the book and it always returns
-1(error). Does anyone know why?

What was the value of errno ?

Padraig

Thanks,
Shashank

Padraig Furlong <Padraig.Furlong@rte.ie> wrote:


Shashank wrote:

Hi,
I used the disk_space function(to get the disk space on my hard drive) as
given in the book and it always returns
-1(error). Does anyone know why?

What was the value of errno ?

Works for me.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/disk.h>

void main()
{
int ret;
long free, total;

ret = disk_space( 0, &free, &total );
printf(“disk_space returned:%d, errno: %d\n”, ret, errno);
printf(“free block: %d, total blocks: %d\n”, free, total );
}

If I do “ds < /”
disk_space returned:0, errno: 15
free block: 4888559, total blocks: 11261502

If I do “ds < /dev/ser1”
disk_space returned:-1, errno: 89
free block: 2, total blocks: 40548

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Hi,
The errno I got while using disk_space
was 89.

Thanks,
Shashank

“Padraig Furlong” <Padraig.Furlong@rte.ie> wrote in message
news:3CEBB686.9060105@rte.ie

Shashank wrote:

Hi,
I used the disk_space function(to get the disk space on my hard drive) as
given in the book and it always returns
-1(error). Does anyone know why?

What was the value of errno ?

Padraig


Thanks,
Shashank
\

Shashank <sbalijepalli@precitech.com> wrote:

Hi,
The errno I got while using disk_space
was 89.

89 is the same one I got while talking to /dev/ser1 – if you type
in “errno 89” and the command line you get:

errno 89: Function not implemented

In other words, you’re not talking to someone who supports disk_space(),
that is, probably not a hard drive.

Also, you can’t apply disk_space() to the raw partition – it must
be a mounted file system.

ds < /dev/hd0t78
gives errno of 22 (EINVAL)

ds < /hd2
gives appropriate data
(on my machine /dev/hd0t78 is mounted as /hd2)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Hi,
How can i get the disk space of my raw partition.
I have not mounted my hard drive.

Thanks,
Shashank


“David Gibbs” <dagibbs@qnx.com> wrote in message
news:acgmdf$kne$4@nntp.qnx.com

Shashank <> sbalijepalli@precitech.com> > wrote:
Hi,
The errno I got while using disk_space
was 89.

89 is the same one I got while talking to /dev/ser1 – if you type
in “errno 89” and the command line you get:

errno 89: Function not implemented

In other words, you’re not talking to someone who supports disk_space(),
that is, probably not a hard drive.

Also, you can’t apply disk_space() to the raw partition – it must
be a mounted file system.

ds < /dev/hd0t78
gives errno of 22 (EINVAL)

ds < /hd2
gives appropriate data
(on my machine /dev/hd0t78 is mounted as /hd2)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Shashank <sbalijepalli@precitech.com> wrote:

How can i get the disk space of my raw partition.
I have not mounted my hard drive.

You cannot get free space on an unmounted partition (“free space” after
all is a logical not a physical concept, so some sort of filesystem
must be mounted in order to distinguish what free/used mean). You can
obtain the total/physical size of any device/partition with the stat()
or disk_get_entry() calls …

Hi,
Is there a way to get the space occupied by files in a directory ? Also is
there a function to check if the network is alive. For eg. if someone
disconnects the cable
from the Ethernet card can this be determined in the application.?

Thanks,
Shashank



“John Garvey” <jgarvey@qnx.com> wrote in message
news:ach39v$1cn$1@nntp.qnx.com

Shashank <> sbalijepalli@precitech.com> > wrote:
How can i get the disk space of my raw partition.
I have not mounted my hard drive.

You cannot get free space on an unmounted partition (“free space” after
all is a logical not a physical concept, so some sort of filesystem
must be mounted in order to distinguish what free/used mean). You can
obtain the total/physical size of any device/partition with the stat()
or disk_get_entry() calls …

“Shashank” <sbalijepalli@precitech.com> wrote in message
news:acioc4$n1a$1@inn.qnx.com

Hi,
Is there a way to get the space occupied by files in a directory ? Also is
there a function to check if the network is alive. For eg. if someone
disconnects the cable
from the Ethernet card can this be determined in the application.?

Thanks,
Shashank

  1. space used by directories

opendir() the parent dir
readdir() each dirent
if it is a directory
stat() that directory to get its size
recurse into it if desired (go back to opendir() )
2. best way to determine if a node is up is to try to send a message to it’s
Proc (pid 1 ON THE OTHER NODE, hint you must set up a VC). I usually use
qnx_getclock() but there is probably a more efficient request.

Hi,
Is’nt there a simpler way rather than recurse through directories. I
basically need the space occupied by files on my Hard drive and how much
space is left before the Hard drive is full?

Your help is appreciated.
Shashank

“Bill Caroselli (Q-TPS)” <QTPS@EarthLink.net> wrote in message
news:acj4f8$2jr$1@inn.qnx.com

“Shashank” <> sbalijepalli@precitech.com> > wrote in message
news:acioc4$n1a$> 1@inn.qnx.com> …
Hi,
Is there a way to get the space occupied by files in a directory ? Also
is
there a function to check if the network is alive. For eg. if someone
disconnects the cable
from the Ethernet card can this be determined in the application.?

Thanks,
Shashank

  1. space used by directories
    opendir() the parent dir
    readdir() each dirent
    if it is a directory
    stat() that directory to get its size
    recurse into it if desired (go back to opendir() )
  2. best way to determine if a node is up is to try to send a message to
    it’s
    Proc (pid 1 ON THE OTHER NODE, hint you must set up a VC). I usually use
    qnx_getclock() but there is probably a more efficient request.

I thought that someone already suggested disk_space() and you rejected it
for some reason. But now it sounds like that is all you need.

You pass is a file descriptor for an open file. It will determine what
partition that file is on and tell you for that partition.

  1. the total number of 512 byte blocks
  2. the number of 512 byte blocks remaining (free)

“Shashank” <sbalijepalli@precitech.com> wrote in message
news:acj6m3$40c$1@inn.qnx.com

Hi,
Is’nt there a simpler way rather than recurse through directories. I
basically need the space occupied by files on my Hard drive and how much
space is left before the Hard drive is full?

Your help is appreciated.
Shashank

“Bill Caroselli (Q-TPS)” <> QTPS@EarthLink.net> > wrote in message
news:acj4f8$2jr$> 1@inn.qnx.com> …
“Shashank” <> sbalijepalli@precitech.com> > wrote in message
news:acioc4$n1a$> 1@inn.qnx.com> …
Hi,
Is there a way to get the space occupied by files in a directory ?
Also
is
there a function to check if the network is alive. For eg. if someone
disconnects the cable
from the Ethernet card can this be determined in the application.?

Thanks,
Shashank

  1. space used by directories
    opendir() the parent dir
    readdir() each dirent
    if it is a directory
    stat() that directory to get its size
    recurse into it if desired (go back to opendir() )
  2. best way to determine if a node is up is to try to send a message to
    it’s
    Proc (pid 1 ON THE OTHER NODE, hint you must set up a VC). I usually
    use
    qnx_getclock() but there is probably a more efficient request.
    \

“Bill Caroselli (Q-TPS)” <QTPS@earthlink.net> wrote:

  1. best way to determine if a node is up is to try to send a message to it’s
    Proc (pid 1 ON THE OTHER NODE, hint you must set up a VC). I usually use
    qnx_getclock() but there is probably a more efficient request.

qnx_vc_attach() to nid & PROC_PID is the cheapest. Anything else
requires that, plus more, some additional message. Don’t forget your
detach either.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:acjom1$22s$1@nntp.qnx.com

“Bill Caroselli (Q-TPS)” <> QTPS@earthlink.net> > wrote:
2. best way to determine if a node is up is to try to send a message to
it’s
Proc (pid 1 ON THE OTHER NODE, hint you must set up a VC). I usually
use
qnx_getclock() but there is probably a more efficient request.

qnx_vc_attach() to nid & PROC_PID is the cheapest. Anything else
requires that, plus more, some additional message. Don’t forget your
detach either.

True, but when I have two processes on different nodes that need to know the

other is up I just start out with the vc and don’t detach it until it does
fail.
Isn’t setting up a VC actually a fairly expensive operation?

“Bill Caroselli (Q-TPS)” <QTPS@earthlink.net> wrote:

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:acjom1$22s$> 1@nntp.qnx.com> …
“Bill Caroselli (Q-TPS)” <> QTPS@earthlink.net> > wrote:
2. best way to determine if a node is up is to try to send a message to
it’s
Proc (pid 1 ON THE OTHER NODE, hint you must set up a VC). I usually
use
qnx_getclock() but there is probably a more efficient request.

qnx_vc_attach() to nid & PROC_PID is the cheapest. Anything else
requires that, plus more, some additional message. Don’t forget your
detach either.

True, but when I have two processes on different nodes that need to know the
other is up I just start out with the vc and don’t detach it until it does
fail.
Isn’t setting up a VC actually a fairly expensive operation?

Yes, it is. But something like qnx_getclock() will setup the VC, do
some extra operation, then tear down the VC. That is, anything that
doesn’t already have a VC setup will require one, so JUST doing the
VC attach will be cheaper than anything else.

Of course, keeping a VC up, and messaging accross it periodically is
even cheaper. (Assuming you’re not tracking too many nodes, in which
case you may have too many VCs around.)

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.