public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] reading size and used space on compact flash (CF) card?
@ 2012-06-29 13:16 Ken Yee
  2012-06-29 22:42 ` Frank Pagliughi
  0 siblings, 1 reply; 2+ messages in thread
From: Ken Yee @ 2012-06-29 13:16 UTC (permalink / raw)
  To: ecos-discuss

I haven't been able to dig anything up on this using the search engine or Google.
Has anyone been able to read the size and free space left on a CF card (which uses the IDE driver)?

Closest thing I found was this code that I modified slightly:

    int get_size() {
        cyg_disk_info_t cf_info;
        char cf_model[41];
        cyg_io_handle_t cf_handle;
        cyg_uint32 len = sizeof(cyg_disk_info_t);

        int error = cyg_io_lookup(CFDEV_, &cf_handle);
        if (error!=0) {
            printf("lookup error:%i\n",error);
            return 0;
        } else {
            error = cyg_io_get_config(cf_handle,0,&cf_info,&len); //
            //printf("cf get_config error: %i %i\n",error,-EINVAL); // should get -EINVAL???
            uint32_t block_size = cf_info.block_size;
            uint32_t blocks_num = cf_info.blocks_num;
            uint32_t phys_block_size = cf_info.phys_block_size;
            bool is_connected = cf_info.connected;
            memset(cf_model, 0, sizeof(cf_model));
            strncpy(cf_model,cf_info.ident.model_num,sizeof(cf_model));
            printf("block size:%d, phys_block_size:%d, num_blocks:%d, connected:%d, model:%s\n"
                     ,block_size,phys_block_size,blocks_num,is_connected,cf_model);
            // block_size should be 512 bytes and we want to return megabytes
            block_size = 1;	// hack for now because it's returning 33MB for block size from the current API :-P
            return (((blocks_num/1024)*block_size)/1024);
        }

    }


But as mentioned in the code, it's returning crazy numbers in the 33MB range no matter what size CF card I install (I've tried 32MB and 128MB :-(
Is there any other official API to read the size of it or any other IDE devices?

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [ECOS] reading size and used space on compact flash (CF) card?
  2012-06-29 13:16 [ECOS] reading size and used space on compact flash (CF) card? Ken Yee
@ 2012-06-29 22:42 ` Frank Pagliughi
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Pagliughi @ 2012-06-29 22:42 UTC (permalink / raw)
  To: Ken Yee; +Cc: ecos-discuss

On 06/29/2012 09:15 AM, Ken Yee wrote:
> ...
>          } else {
>              error = cyg_io_get_config(cf_handle,0,&cf_info,&len); //
>              //printf("cf get_config error: %i %i\n",error,-EINVAL); // should get -EINVAL???
>              uint32_t block_size = cf_info.block_size;
>              uint32_t blocks_num = cf_info.blocks_num;
>              uint32_t phys_block_size = cf_info.phys_block_size;
>              bool is_connected = cf_info.connected;
>
> ...
> But as mentioned in the code, it's returning crazy numbers in the 33MB range no matter what size CF card I install (I've tried 32MB and 128MB :-(
> Is there any other official API to read the size of it or any other IDE devices?
>

You are not using the proper key when querying for the disk information. 
You need to use CYG_IO_GET_CONFIG_DISK_INFO (not zero) as in:

     error = cyg_io_get_config(cf_handle, CYG_IO_GET_CONFIG_DISK_INFO, 
&cf_info, &len);

When you use the unrecognized key of zero, the function returns the 
error code -EINVAL because it doesn't recognize the query. With the 
proper query the function should return 0 for success.

Frank

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-29 22:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-29 13:16 [ECOS] reading size and used space on compact flash (CF) card? Ken Yee
2012-06-29 22:42 ` Frank Pagliughi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).