See if all unit_8 array is all 0 or all ff

is there a way, through comparison or some other manner to compare a uint8_t blk[512]; array and see if the entire array is all 0 or all ff without having to look at the individual bytes, i am really just looking for a boolean response of yes there is something there or no its empty.

No. Hint - sometimes you can do that as you insert members, instead of waiting until later...

Why do you need this function? It sounds like an XY problem.

sd.card()->readSector(tSector, blk)

no i dont think i can in this case

i am trying to see if a sector is blank or if it contains some data to make a display like the old computers had for a block map, the code i have works but takes a bit over an hour per gb because it has to look at each individual byte, i have some code that will let it skip out but its still not quick enough.

     for (uint32_t tSector = 0; tSector <= 1; tSector++) {
        if ( tSector % 100 == 0 ) {
          tft.drawString(("CYCLE: " + String(tSector) + " out of: " + String(size)), 57, 50 + tft.fontHeight() * 6, 1);
        }
        if (sd.card()->readSector(tSector, blk)) {
          for (uint32_t tByte = 0; tByte <= 512; tByte++) {
            if (blk[tByte] != 255 | blk[tByte] != 0) {
              tByte = 513;
              blkEpty[blockCount] = 1;
            } else {
              blkEpty[blockCount] = 0;
            }
          }
        }
        bitCount++;
        if (bitCount >= bitsPerBool) {
          blockCount++;
          bitCount = 0;
        }
      }

Why are you bypassing the SD file system? Running FORTH? :slight_smile:

was attempting to analyse the actual disk in picture form , used to be cool to watch on old windows systems.

image

however you can run forth on pi pico. :slight_smile:

A look at the FAT will tell you more.

the FAT doesnt give you (from what ive seen) information on if a sector is empty or full, can i have a suggestion as to what in the fat i would look at to accomplish something like this ?

tbh i dont care what information it looks at i just want a rainbow chart giving a visual map of the sd card. sectors was my first instinct.

It's irrelevant whether a sector appears empty or full, the FAT tells you whether it's allocated or not. If it's allocated, you can consider it "full". If not, "empty" or "available". The stuff that's written there doesn't matter and you can't learn anything useful from it. When you delete a file, the sectors aren't usually cleared out, they are just marked as unallocated. That is how data recovery is even possible.

A sector is always full. All of them.

then that is what i am absolutely looking for . maybe i just read the room wrong so i am looking for allocation of the sectors , now i know what to google,

i read :

https://codeandlife.com/2012/04/02/simple-fat-and-sd-tutorial-part-1/
https://www.compuphase.com/mbr_fat.htm

... so there is no functions for this in sdfat?

or do i manually read a secor that the information is on and then decipher myself

i suppose i could use

contiguousRange()

recursively on every file on the file system ... sound wrong but it would be faster, what would it tell you about a fragmented file i wonder ?

so firs build list of files, then check contiguousRange() then get firstSector(), and then get fileSize(), then calculate the bytes per sector and then i have the file end sector, and i can then map that to the map, would be the correct proceedure?

again what if a file is not contiguous?

this could also be the beginning of code to keep track of the free space then without having to call that time consuming function volFree = sd.vol()->freeClusterCount();

my misunderstanding of contiguousRange() cleared itself up today. i found this one and only example which shows it just checks if the file has a contiguous block assignment posting here for posterity.

if (!_file.contiguousRange(&bgnBlock, &endBlock)) {
	  Serial.println("contiguousRange failed");
	  while(true){}
	}
          for (uint32_t tByte = 0; tByte <= 512; tByte++) {
            if (blk[tByte] != 255 | blk[tByte] != 0) {
              tByte = 513;
              blkEpty[blockCount] = 1;
            } else {
              blkEpty[blockCount] = 0;
            }
          }

I doubt that the loop checking for empty is the cause of your performance problem. It ought to be significantly faster than readSector(), for instance.
Have you tried just leaving it out to see if the code gets faster, overall? (assuming that you still read the sector, of course.)

tbyte = 513 is a terrible way to terminate the loop early, IMO. You should use break.

The 512 bytes in a sector are numbered 0 to 511. You are checking the 513th byte of every sector. It should be:

          for (uint32_t tByte = 0; tByte < 512; tByte++) {
            if (blk[tByte] != 255 | blk[tByte] != 0) {