Loading ...
Sorry, an error occurred while loading the content.

Re: fat32 library improvement?

Expand Messages
  • Matthew Schinkel
    Here are the files, I think you ll only need fat32.jal. http://www.borntechi.com/temp/18f67j50_fat32_sd_card.zip When creating more then one dir, the 2nd one
    Message 1 of 42 , Mar 1 3:19 AM
    • 0 Attachment
      Here are the files, I think you'll only need fat32.jal.

      http://www.borntechi.com/temp/18f67j50_fat32_sd_card.zip

      When creating more then one dir, the 2nd one does not contain "." and "..". This makes me think there is a space allocation issue.

      I suggest you first try to create more then one FILE and put data in them to see if that works ok. Maybe even try without these new files first. I didn't have time to test this yesterday.

      Use the following to make a file:

      fat32_file_create() -- create a file
      fat32_file_open() -- open the file
      fat32_set_file_size() -- set the file's size
      fat32_sector_buffer[x] = data -- put data in buffer
      fat32_write_file_sector_number(0) -- write data to file sector 0
      fat32_write_file_sector() -- write data to disk



      --- In jallist@yahoogroups.com, Camil Staps <camil-226@...> wrote:
      >
      >
      > Hi,
      >
      > But After the procedure has added the directory the file list is refreshed, so why wouldn't it work for more than one dir?
      > It of course is okay to take some rest here, you've done a lot a lot in the past few days! Thanks! Could you please send the code (that doesn't work for more than one dir) of the procedure so that I can try to test and improve?
    • Matthew Schinkel
      Yes, dir_create is working good and no space for short file names. Matt.
      Message 42 of 42 , Mar 5 8:04 AM
      • 0 Attachment
        Yes, dir_create is working good and no space for short file names.

        Matt.

        --- In jallist@yahoogroups.com, Camil Staps <camil-226@...> wrote:
        >
        > Many thanks! I'll have a look this week, but I'll be very busy so it will take some time.
        > But is it right that the dir_create procedure and the set_file_size are working correctly and that the file_entry_data doesn't return spaces from short file names anymore?
        >
        > Camil
        >
        > www.camilstaps.nl
        >
        > Op 5 mrt. 2012 om 04:37 heeft "Matthew Schinkel" <mattschinkel@...> het volgende geschreven:
        >
        > I uploaded a more permanent fix. You no longer need to close a file after setting it's size.
        >
        > There may still be a faster way but it would take a lot more work.
        >
        > Matt.
        >
        > --- In jallist@yahoogroups.com, "Matthew Schinkel" <mattschinkel@> wrote:
        > >
        > > There is a faster way to do it. The file should not need to be closed and re-opened after fat32_set_file_size. The same thing happens with files. Here is code to make and write to a file:
        > >
        > >
        > > var byte filename[] = "TEST "
        > > var dword sector_step
        > > var word byte_step
        > > var byte result
        > >
        > > -- create the file/dir name.
        > > const byte ext[] = " "
        > > fat32_is_directory = FALSE -- It is a file at the moment.
        > > fat32_is_read_only = FALSE
        > > fat32_is_hidden = FALSE
        > > fat32_is_system = FALSE
        > > fat32_is_volume_id = FALSE
        > > fat32_is_archive = FALSE
        > > result = fat32_file_create(filename, ext)
        > >
        > >
        > > -- open the file
        > > var byte ignore_return1 = fat32_file_open(fat32_dir_file_count - 1)
        > >
        > > serial_data = "*"
        > > serial_data = "*"
        > > serial_data = "*"
        > > print_dword_dec(serial_data, fat32_file_cluster_address)
        > > serial_data = "*"
        > > serial_data = "*"
        > > serial_data = "*"
        > >
        > > -- set the file size.
        > > -- dir can hold 2048 short file names. (65536/32)
        > > fat32_set_file_size(65536)
        > >
        > > fat32_file_close()
        > > ignore_return1 = fat32_file_open(fat32_dir_file_count - 1)
        > >
        > > for 512 using byte_step loop
        > > fat32_sector_buffer[byte_step] = "A"
        > > end loop
        > > for 8 using sector_step loop
        > > fat32_write_file_sector_number(sector_step)
        > > end loop
        > >
        > > fat32_file_close()
        > >
        > >
        > > Matt.
        > >
        > > --- In jallist@yahoogroups.com, Camil Staps <camil-226@> wrote:
        > > >
        > > >
        > > > Many thanks, Matt. Why exactly is this only a temporary solution?
        > > >
        > > > Camil
        > > >
        > > > To: jallist@yahoogroups.com
        > > > From: mattschinkel@
        > > > Date: Fri, 2 Mar 2012 23:12:25 +0000
        > > > Subject: [jallist] Re: fat32 library improvement?
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > > I managed to find a temporary fix. I added these lines after set_file_size:
        > > >
        > > >
        > > >
        > > > fat32_file_close()
        > > >
        > > > ignore_return1 = fat32_file_open(fat32_dir_file_count - 1)
        > > >
        > > >
        > > >
        > > > Here's the full proc:
        > > >
        > > >
        > > >
        > > > function fat32_dir_create(byte in dirname[]) return byte is
        > > >
        > > > var dword sector_step
        > > >
        > > > var word byte_step
        > > >
        > > > var byte result
        > > >
        > > >
        > > >
        > > > -- create the file/dir name.
        > > >
        > > > const byte ext[] = " "
        > > >
        > > > fat32_is_directory = FALSE -- It is a file at the moment.
        > > >
        > > > fat32_is_read_only = FALSE
        > > >
        > > > fat32_is_hidden = FALSE
        > > >
        > > > fat32_is_system = FALSE
        > > >
        > > > fat32_is_volume_id = FALSE
        > > >
        > > > fat32_is_archive = FALSE
        > > >
        > > > result = fat32_file_create(dirname, ext)
        > > >
        > > >
        > > >
        > > > -- return if failed to create file
        > > >
        > > > if result == 0 then
        > > >
        > > > return 0
        > > >
        > > > end if
        > > >
        > > >
        > > >
        > > > -- open the file
        > > >
        > > > var byte ignore_return1 = fat32_file_open(fat32_dir_file_count - 1)
        > > >
        > > >
        > > >
        > > > -- set the file size.
        > > >
        > > > -- dir can hold 2048 short file names. (65536/32)
        > > >
        > > > fat32_set_file_size(65536)
        > > >
        > > >
        > > >
        > > > fat32_file_close()
        > > >
        > > > ignore_return1 = fat32_file_open(fat32_dir_file_count - 1)
        > > >
        > > >
        > > >
        > > > -- set the data to be written (all zero's)
        > > >
        > > > for 512 using byte_step loop
        > > >
        > > > fat32_sector_buffer[byte_step] = 0x00
        > > >
        > > > end loop
        > > >
        > > > for 8 using sector_step loop
        > > >
        > > > fat32_write_file_sector_number(sector_step)
        > > >
        > > > end loop
        > > >
        > > >
        > > >
        > > > -- make the first sector's directories "." and ".."
        > > >
        > > > const byte fat32_dir_first_sector[64] = {
        > > >
        > > > 0x2E,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x10,0x00,0x0E,0xE7,0x8E,
        > > >
        > > > 0x5A,0x40,0x5A,0x40,0x00,0x00,0xE8,0x8E,0x5A,0x40,0x03,0x00,0x00,0x00,0x00,0x00,
        > > >
        > > > 0x2E,0x2E,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x10,0x00,0x0E,0xE7,0x8E,
        > > >
        > > > 0x5A,0x40,0x5A,0x40,0x00,0x00,0xE8,0x8E,0x5A,0x40,0x00,0x00,0x00,0x00,0x00,0x00
        > > >
        > > > }
        > > >
        > > >
        > > >
        > > > -- put the constant array into the first sector of the file (soon to be dir)
        > > >
        > > > for 64 using byte_step loop
        > > >
        > > > var byte temp = fat32_dir_first_sector[byte_step] -- compiler bug? need to assign to variable first.
        > > >
        > > > fat32_sector_buffer[byte_step] = temp
        > > >
        > > > end loop
        > > >
        > > >
        > > >
        > > > -- set "." cluster location (current dir)
        > > >
        > > > fat32_sector_buffer[21] = _fat32_file_cluster_address[3]
        > > >
        > > > fat32_sector_buffer[20] = _fat32_file_cluster_address[2]
        > > >
        > > > fat32_sector_buffer[27] = _fat32_file_cluster_address[1]
        > > >
        > > > fat32_sector_buffer[26] = _fat32_file_cluster_address[0]
        > > >
        > > >
        > > >
        > > > -- set ".." cluster location (parent dir)
        > > >
        > > > fat32_sector_buffer[32 + 21] = _fat32_dir_cluster_address[3]
        > > >
        > > > fat32_sector_buffer[32 + 20] = _fat32_dir_cluster_address[2]
        > > >
        > > > fat32_sector_buffer[32 + 27] = _fat32_dir_cluster_address[1]
        > > >
        > > > fat32_sector_buffer[32 + 26] = _fat32_dir_cluster_address[0]
        > > >
        > > >
        > > >
        > > > fat32_write_file_sector_number(0) -- write to file sector 0
        > > >
        > > >
        > > >
        > > > ;-- print the sector that was just written to the file
        > > >
        > > > ;fat32_read_file_sector_number(0)
        > > >
        > > > ;fat32_print_sector_buffer_hex(serial_data,16)
        > > >
        > > >
        > > >
        > > > -- change the file into a directory by changing it's attributes.
        > > >
        > > > -- Also set it's size to 0
        > > >
        > > > fat32_is_directory = TRUE
        > > >
        > > > ;fat32_file_size = 0
        > > >
        > > > fat32_file_entry_data(FAT32_FILE, _FAT32_PUT, _FAT32_ATTRIB); + _FAT32_SIZE)
        > > >
        > > >
        > > >
        > > > fat32_file_close()
        > > >
        > > >
        > > >
        > > > return result
        > > >
        > > > end function
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > > [Non-text portions of this message have been removed]
        > > >
        > >
        >
        >
        >
        > [Non-text portions of this message have been removed]
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.