在写入过程中写入usb和usb中的文件时处理异常 [英] Handling exception while writing to a file in usb and usb removed while writing in progress

查看:94
本文介绍了在写入过程中写入usb和usb中的文件时处理异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在用USB写入文件,正在进行中我删除了USB。在代码中我使用fwrite写入文件。我放了一个try {} catch(...){}块来处理异常。异常没有被抓住。



我要求从USB升级固件。所以我使用fread从文件中读取一大块数据并将命令发送到模块。在阅读过程中,我删除了USB。相同的try {} catch(...){}块来处理异常。但例外情况并非被抓获



谢谢

Ajai

Hi,
i am writing to a file in USB and while in progress i removed the USB. In the code i am using fwrite to write to the file. i put a try{} catch(...){} block to handle the exception. Exception wasn''t getting caught.

i have a requirement to upgrade the firware from USB. so i am using fread to read a chunk of data from the file and sending the command to the module. While the reading is in progress, i removed the USB. Same try{} catch(...){} block to handle the exception. but the exception is not gettign caught

Thanks
Ajai

推荐答案

如果可能,您应首先将固件从USB驱动器复制到安全存储器位置,完成后应验证副本上的数据,然后升级固件。



直接从USB密钥升级是不安全的,因为用户可以随时删除密钥。



您至少应该验证所有字节都被复制到临时位置如果可能的话,您可能需要进行校验和或其他验证以确保固件在使用前有效。



无论如何,您应该告诉用户升级时不要删除USB密钥,因为你想要保存在一边,如果出现问题,那么你可以询问用户是否按照说明操作,以确保用户不会滥用你的技术支持。 />


最后,哈应该以足够安全的方式设计rdware。在像你这样的情况下,我建议你有专门用于升级固件的内存。
If possible you should first copy the firmware from the USB drive to a safe memory location and when complete you should validate the data on the copy and then upgrade the firmware.

Directly upgrading from the USB key is not safe as the user can remove the key at any point.

You should at least validate that all bytes were copied to the temporary location and if possible you might want to do a checksum or other validation to ensure that the firmware is valid before using it.

And in any case, you should tell the user not to remove the USB key while upgrading as you want to be on the save side and if somethying goes wrong then you can ask the user if he has followed the instructions to help ensure that users won''t abuse your technical support.

Finally, the hardware should be designed in a way to be safe enough. In a case like yours, I would recommand you to have memory specifically reserved for upgrading the firmware.


这篇关于在写入过程中写入usb和usb中的文件时处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆