{"id":1759,"date":"2012-02-15T15:30:53","date_gmt":"2012-02-15T10:00:53","guid":{"rendered":"http:\/\/www.e-consystems.com\/blog\/windowsce\/?p=787"},"modified":"2023-08-15T12:34:27","modified_gmt":"2023-08-15T07:04:27","slug":"windows-ce-6-0-file-copy-issue-while-exposing-sdhc-card-as-mass-storage-in-pc","status":"publish","type":"post","link":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/windows-ce-6-0-file-copy-issue-while-exposing-sdhc-card-as-mass-storage-in-pc\/","title":{"rendered":"Error copying files to SDHC card exposed as mass storage"},"content":{"rendered":"<p><strong>Error Message: <\/strong><\/p>\n<p><strong>Title:<\/strong> &ldquo;Error Copying File or Folder&rdquo;<\/p>\n<p>&ldquo;Cannot copy &lt;filename&gt;:  The request could not be performed because of an I\/O device error.&rdquo;<\/p>\n<p align=\"center\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.e-consystems.com\/images\/Blog\/Blog-Error-Copying-File-Folder.jpg\" width=\"507\" height=\"126\" \/><\/p>\n<p>When you try to copy files to SDHC  card (which is exposed as mass storage through USB client), you may get this  error in the middle of file copy. This is due to <strong>miscalculation of number of bytes available<\/strong> in the SDHC card by  SDBUS driver.<\/p>\n<p>Calculation of card capacity is  done based on the C_SIZE value from the CSD (Card-Specific Data) register in  the card.<\/p>\n<p>For SDHC, capacity of the card is  calculated using the below formula:<\/p>\n<p>Capacity = <strong>(C_SIZE + 1)<\/strong> * 0x80000 and sector count is calculated as given  below<\/p>\n<p>Sector Count = Capacity \/ 0x200 (Here,  0x200 is the size of a sector in bytes)<\/p>\n<p>(Where 4112 &lt;= C_SIZE &lt;= 65375 i.e., (approx. 2 GB) &lt; capacity  &lt; 32 GB)<\/p>\n<p>In WinCE SDBUS driver the  capacity of card is calculated wrongly with the below formula<\/p>\n<p>Capacity = <strong>(C_SIZE ) <\/strong>* 0x400 * 0x200<\/p>\n<p>The addition 1 to C_SIZE is not  used which makes the card size to be reduced by 0x80000 bytes.<\/p>\n<p>PC recognizes the memory card  with actual size and tries to copy the file to those sectors, which is  restricted by the SDMemory driver. As the write sector fails when writing to  those sectors, PC retries it up to 5 times and finally it pops up the error  message as shown above.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<p>I have used a 8GB Transcend Pen Drive, the C_SIZE read  from the CSD is 0x3C15 (15381 in decimal).<\/p>\n<p>As per SDBUS driver formula the  capacity of card is 8064073728 bytes and sector count is 15750144. So the  SDMemory will restrict the memory access after 15750144th sector.  Since PC side calculates the sector count separately based on the CSD data, it  computes with actual formula and it will access sectors up to 15751168. <\/p>\n<p>So when PC tries to write after  15750144th sector, SDMemory driver will return as invalid parameter  which cause the file copy error as shown above.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Fix to be done:<\/strong><\/p>\n<p>SDBUS Driver needs to be modified  which is available in WINCE600\\PUBLIC\\COMMON\\OAK\\DRIVERS\\ SDCARD\\<strong>SDBUS<\/strong><\/p>\n<p>Before making changes in SDBUS  driver clone the driver to local platform folder using sysgen capture tool.<\/p>\n<p>For information regarding sysgen  capture tool check the following link:<\/p>\n<p><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ee504692(v=winembedded.60).aspx\">https:\/\/msdn.microsoft.com\/en-us\/library\/ee504692(v=winembedded.60).aspx<\/a><\/p>\n<p><strong>Code Change:<\/strong><\/p>\n<p>In InfoQueryCSD function of  sddevinfo.cpp the capacity calculation is done. Change the DeviceSize  calculation for SD v2.0 (SD_CSD_VERSION_CODE_2_0) as shown below. <\/p>\n<p>Add + 1 to C_SIZE before  multiplying with 0x200 and 0x400 for capacity calculation in SDBus driver. <\/p>\n<p>Text in red color is the change  to be done.<\/p>\n<table width=\"580\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tr>\n<td width=\"580\" align=\"center\" valign=\"middle\">\n<table width=\"94%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tr>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>m_SDCardInfo.SDMMCInformation.ullDeviceSize <\/td>\n<\/tr>\n<tr>\n<td height=\"12\"><\/td>\n<\/tr>\n<tr>\n<td height=\"22\" valign=\"top\" align=\"left\">= ((ULONGLONG) GET_BIT_SLICE_FROM_CSD( pCSD,<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tr>\n<td width=\"48%\" height=\"57\">&nbsp;<\/td>\n<td width=\"52%\" align=\"left\" valign=\"top\"><em>SD_CSD20_CSIZE_BIT_SLICE,<br \/>\n              SD_CSD20_CSIZE_SLICE_SIZE  ) <span style=\"color:#FF0000\"> <strong>+ 1<\/strong><\/span>)<br \/>\n              * 0x200 * 0x400;<\/em><\/td>\n<\/tr>\n<\/table>\n<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;<\/td>\n<\/tr>\n<\/table>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Error Message: Title: &ldquo;Error Copying File or Folder&rdquo; &ldquo;Cannot copy &lt;filename&gt;: The request could not&#8230;<\/p>\n","protected":false},"author":7,"featured_media":1390,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[213],"tags":[275,75,82,320],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/1759"}],"collection":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/comments?post=1759"}],"version-history":[{"count":1,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/1759\/revisions"}],"predecessor-version":[{"id":2933,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/1759\/revisions\/2933"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/media\/1390"}],"wp:attachment":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/media?parent=1759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/categories?post=1759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/tags?post=1759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}