free disk space

Discussion in 'C Programming' started by Piotr, Oct 21, 2003.

  1. Piotr

    Piotr Guest

    What is the simple function checking free disk space ?
    thank you
     
    Piotr, Oct 21, 2003
    #1
    1. Advertising

  2. Piotr <> spoke thus:

    > What is the simple function checking free disk space ?


    There isn't one in standard C. If you're using Unix, the du and/or quota
    commands may be useful to you.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Oct 21, 2003
    #2
    1. Advertising

  3. Piotr <> scribbled the following:
    > What is the simple function checking free disk space ?
    > thank you


    There isn't one in standard C. Ask in a platform-specific newsgroup.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
     
    Joona I Palaste, Oct 21, 2003
    #3
  4. On Tue, 21 Oct 2003 12:40:29 +0000, Joona I Palaste wrote:

    > Piotr <> scribbled the following:
    >> What is the simple function checking free disk space ?
    >> thank you

    >
    > There isn't one in standard C.


    open a file,
    write to the file until you get an error, counting bytes
    close and reopen the file to free the space
    close the file

    Now the filesystem should have atleast as much free space as the bytes you
    counted.

    But he'd probably be better of using a platform specific way :)

    --
    NPV

    "the large print giveth, and the small print taketh away"
    Tom Waits - Step right up
     
    Nils Petter Vaskinn, Oct 21, 2003
    #4
  5. Piotr

    Dan Pop Guest

    In <bn38dd$2fis$> "Piotr" <> writes:

    >What is the simple function checking free disk space ?


    No such thing. The C language blissfully ignores the existence of disks
    (although it realises that some devices are seekable and others aren't).

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Oct 21, 2003
    #5
  6. Piotr

    Alex Guest

    Christopher Benson-Manica <> wrote:
    > Piotr <> spoke thus:


    >> What is the simple function checking free disk space ?


    > There isn't one in standard C. If you're using Unix, the du and/or quota
    > commands may be useful to you.


    Off-topic: du? I hope you mean 'df'.

    Alex
     
    Alex, Oct 21, 2003
    #6
  7. [OT] du/df

    Alex <> spoke thus:

    > Off-topic: du? I hope you mean 'df'.


    Perhaps I did - thanks.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Oct 21, 2003
    #7
  8. Piotr

    Mark Gordon Guest

    On Tue, 21 Oct 2003 12:50:11 GMT
    "Nils Petter Vaskinn" <> wrote:

    > On Tue, 21 Oct 2003 12:40:29 +0000, Joona I Palaste wrote:
    >
    > > Piotr <> scribbled the following:
    > >> What is the simple function checking free disk space ?
    > >> thank you

    > >
    > > There isn't one in standard C.

    >
    > open a file,
    > write to the file until you get an error, counting bytes
    > close and reopen the file to free the space
    > close the file
    >
    > Now the filesystem should have atleast as much free space as the bytes
    > you counted.
    >
    > But he'd probably be better of using a platform specific way :)


    What you suggested IS a platform specific way. If you try it on a file
    system with file versioning when you reopen the file it might just
    create a new version of the file leaving the old on on the disk. If you
    use a temporary file instead, it might be held in memory and therefor
    report free space even if the disk is full.
    --
    Mark Gordon
    Paid to be a Geek & a Senior Software Developer
    Although my email address says spamtrap, it is real and I read it.
     
    Mark Gordon, Oct 21, 2003
    #8
  9. On Tue, 21 Oct 2003 21:45:41 +0100, Mark Gordon wrote:

    > What you suggested IS a platform specific way. If you try it on a file
    > system with file versioning when you reopen the file it might just
    > create a new version of the file leaving the old on on the disk.


    Ouch

    > If you
    > use a temporary file instead, it might be held in memory and therefor
    > report free space even if the disk is full.


    Well I wasn't exactly beeing serious, so I didn't try to think about
    everything.

    --
    NPV

    "the large print giveth, and the small print taketh away"
    Tom Waits - Step right up
     
    Nils Petter Vaskinn, Oct 22, 2003
    #9
  10. On Tue, 21 Oct 2003 12:50:11 +0000, Nils Petter Vaskinn wrote:

    > On Tue, 21 Oct 2003 12:40:29 +0000, Joona I Palaste wrote:
    >
    >> Piotr <> scribbled the following:
    >>> What is the simple function checking free disk space ?
    >>> thank you

    >>
    >> There isn't one in standard C.

    >
    > open a file,
    > write to the file until you get an error, counting bytes
    > close and reopen the file to free the space
    > close the file
    >
    > Now the filesystem should have atleast as much free space as the bytes you
    > counted.
    >
    > But he'd probably be better of using a platform specific way :)


    I can just picture doing this on a system with a large storage array...
    say one of those nifty 43TB units. A week or two later and he finally has
    his value... :)
     
    Kelsey Bjarnason, Oct 25, 2003
    #10
  11. "Mark Gordon" <> wrote:
    > "Nils Petter Vaskinn" <> wrote:
    > > > Piotr <> scribbled the following:
    > > >> What is the simple function checking free disk space ?
    > > >> thank you

    > >
    > > open a file,
    > > write to the file until you get an error, counting bytes
    > > close and reopen the file to free the space
    > > close the file
    > >
    > > Now the filesystem should have atleast as much free space as the bytes
    > > you counted.
    > >
    > > But he'd probably be better of using a platform specific way :)

    >
    > What you suggested IS a platform specific way. If you try it on a file
    > system with file versioning when you reopen the file it might just
    > create a new version of the file leaving the old on on the disk. If you
    > use a temporary file instead, it might be held in memory and therefor
    > report free space even if the disk is full.


    Not to mention file systems with limited file sizes, where the available
    disk space may be significantly greater than a file you would create
    using that method. At least the "at least" would apply in such a case :)

    Peter
     
    Peter Pichler, Oct 28, 2003
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jas Shultz
    Replies:
    0
    Views:
    987
    Jas Shultz
    Dec 3, 2003
  2. Marco Schmidt

    Get free disk space under Windows

    Marco Schmidt, Jan 17, 2004, in forum: Java
    Replies:
    13
    Views:
    8,142
  3. Martin Mittnacht

    How to: Free disk space (OS Linux, win)

    Martin Mittnacht, Mar 6, 2004, in forum: Java
    Replies:
    4
    Views:
    468
    Alun Harford
    Mar 7, 2004
  4. Miguel De Anda
    Replies:
    1
    Views:
    936
  5. Replies:
    1
    Views:
    845
    Sebastian Millies
    Nov 2, 2006
Loading...

Share This Page