Shop OBEX P1 Docs P2 Docs Learn Events
FSRW "space remaining" function..? — Parallax Forums

FSRW "space remaining" function..?

CarlosFandangoCarlosFandango Posts: 67
edited 2009-01-14 22:12 in Propeller 1
Hi All, I am working on an app that (amongst other things) writes files to an SD card over the serial link using FSRW. A function that returns the amount of remaining free space on the card would be extremely useful; although I can see a way that this could be done, I'd like to ask if anyone has already implemented this first. I'm not keen on introducing any bugs at this stage - if there is code available that someone is be willing to share, I would be very grateful.

Thanks!

-CF

Comments

  • CarlosFandangoCarlosFandango Posts: 67
    edited 2008-10-18 12:22
    Darn it, I found this thread on the forum from last year

    http://forums.parallax.com/forums/default.aspx?f=25&m=201345

    Where this is requested. Rokicki, if you're reading this, did you ever implement this function at all?

    -CF
  • rokickirokicki Posts: 1,000
    edited 2008-10-19 02:23
    Howdy; I haven't written the function. It would take a full scan over the FAT itself, but
    that shouldn't be too bad.

    -tom
  • CarlosFandangoCarlosFandango Posts: 67
    edited 2008-10-19 08:46
    rokicki said...
    Howdy; I haven't written the function. It would take a full scan over the FAT itself, but
    that shouldn't be too bad.

    Hi Tom... well, as I said, it would be very useful to me. The device I'm working on offers the ability to upload files to the SD, but doing this blindly without having any idea of how much free space there is is probably not a good idea. Ideally I would query the device via comms, and find out if there is enough room for the file I want to upload, and if not, report an error.

    So far I've used your code with only a few minor modifications (block level access mainly) but these have been very simple and didn't require your work to be totally understood. I think I could modify it further to get the free space, but it would take me I don't know how long and would certainly result in multiple breakages... so I guess I'm asking if you feel like adding this?!

    -CF
  • rokickirokicki Posts: 1,000
    edited 2008-10-19 18:25
    If I add it it won't be for a while; I'm in Honolulu right now far away from my propellers and scopes.

    There's probably a simple clever way to do it much like the directory reading code, where you just
    adjust the block pointer to be pointing at the FAT and then scan linearly, looking for free FAT entries.
  • CarlosFandangoCarlosFandango Posts: 67
    edited 2008-10-19 18:44
    Tom said...
    If I add it it won't be for a while; I'm in Honolulu right now far away from my propellers and scopes.

    That sounds great! Better than being in London anyway, it's bl**dy freezing here... mind you at least it's not raining (not until tomorrow...!)

    Anyway, no worries - I just asked on the offchance really. I'll add it, I'm sure it won't take too much effort. As of right now though I don't understand that much about the SD card structure at all, thanks to your efforts I haven't needed to(!) - if you can give me some tips about the FAT structure then that would help me a lot right now.

    -CF
  • m.r.b.m.r.b. Posts: 36
    edited 2009-01-14 22:12
    Try this....



    You should insert this (public) method into FSRW somewhere, and it will do what you asked!!!roll.gif

    I needed to add it for something I was doing....

    [noparse][[/noparse]code]

    Pub PdriveStats(Type):Space|Ctr
    {{
    '·· Returns drive capacity information, in bytes
    '
    '·· If Type is True...
    '·· Returns amount of free space left on the drive

    '
    '·· If Type is False...
    '·· Returns amount of total space allocated for files (regardless of whether used or not)
    }}

    · If Type 'Calculate free space, on drive, in clusters
    ·
    ··· Repeat Ctr from 2 to totclusters-1· 'Count through the FAT...
    ····· If byte[noparse][[/noparse]readfat(Ctr)]==0 'If the fat for this cluster = 0 (unused)
    ······· Space++ 'Increment counter
    ·······
    · else 'Total drive space = totclusters
    ·
    ··· Space := totclusters

    · 'Convert clusters to bytes
    · Space <<= (clustershift+sectorshift)


    [noparse][[/noparse]/code]


    Regards M.R.B.
Sign In or Register to comment.