Author Topic: Disk Space..  (Read 13783 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Disk Space..
« on: July 02, 2010, 10:13:02 AM »
Hi Mark,
  Occasionally I wish to read the  amount of  free space on the SD card, what is the best way of doing this?

Also , where do I get information on the disk size?

Thanks
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Disk Space..
« Reply #1 on: July 02, 2010, 12:11:35 PM »
Hi Neil

You can get disk information by calling:

UTDISK *ptrDiskInfo = fnGetDiskInfo(DISK_D);


The free disk space is contained there as long as the info block is valid - if not the number of free clusters needs to be counted (which can take quite a long time though). See the "DIR" command in debug.c for the method:

            if ((ptrDiskInfo->ucDiskFlags & FSINFO_VALID) && (ptrDiskInfo->utFileInfo.ulFreeClusterCount != 0xffffffff)) {
                fnDebugDec((ptrDiskInfo->utFileInfo.ulFreeClusterCount * ptrDiskInfo->utFAT.ucSectorsPerCluster * ptrDiskInfo->utFAT.usBytesPerSector), 0);
                fnDebugMsg(" bytes free\r\n");
            }
            else {
                iFATstalled = STALL_COUNTING_CLUSTERS;
                utFreeClusters(DISK_D, OWN_TASK);                        // start count of free clusters - the result will be displayed on completion
                return 1;
            }



The disk size if (ptrDiskInfo->ulSD_sectors * ptrDiskInfo->utFAT.usBytesPerSector) where ptrDiskInfo->utFAT.usBytesPerSector is generally 512 bytes.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: Disk Space..
« Reply #2 on: July 02, 2010, 06:25:09 PM »
Hi Mark,
  What makes the info block valid?

Thanks
neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Disk Space..
« Reply #3 on: July 02, 2010, 08:51:14 PM »
Hi Neil

the info block is validated when the card is formatted. It is then updated each time content is modified, thus keeping an overview of the amount of data on the card and the next cluster that is available to be used. This improves efficiency when the remaining space needs to be known and also when assigning new clusters due to the fact that free clusters don't need to be searched for and counted.

The info block is however not guarantied. It may be missing or may get corrupted in which case the SW will need to ignore it any do more work to get the information.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: Disk Space..
« Reply #4 on: January 20, 2011, 08:48:17 PM »
Hi Mark,
 If the number of free clusters needs to be counted to get the disk space, does this mean that no other disk activity can be carried out while it is in progress. Data has to be saved every minute, can it take longer than 1 minute to get the info?

Thanks
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Disk Space..
« Reply #5 on: January 22, 2011, 03:51:08 PM »
Hi Neil

The time taken to calculate the when the info table is not valid depends on the size fo the card. With cards of 4G it takes maybe 10s or so.
If you corrupt the sector containing the info table you can task this four your card and settings.

The fact that the space is being calculated shouldn't affect normal read/write operation. However, normal write operation may get a it slower if the info table is no longer valid since it also needs to do more work to find new clusters.

Regards

Mark


Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: Disk Space..
« Reply #6 on: August 09, 2011, 09:13:33 AM »
Hi Mark,
 If I do the following to start getting disk space:

  iFATstalled = STALL_COUNTING_CLUSTERS;
  utFreeClusters(DISK_D, OWN_TASK);

what happens if a disk operation is carried out before the above is completed, is there a chance of corruption on the write or disk space?

Thanks
Neil



Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Disk Space..
« Reply #7 on: August 09, 2011, 03:09:53 PM »
Hi Neil

utFreeClusters() simply reads through the FAT area and counts the clusters that are free.

Reads shouldn't interfere with it, as it shouldn't interfer with reads.

Also writes/deletes shouldn't be affected by the cluster clount.

The only thing that may happen is that the count value is not exact when a write is performed at the same time since the function may have counted a cluster as empty, which is no longer empty when it has completed the complete count. This would normally be a small deviation (a new count would then give the correct value) and not an issue. The cluster count will generally not necessarily be accurate once a write or delete has been subsequently performed, so thsi is a normal situation.

Regards

Mark