//! Create a new text file //! //! @param sz_name contains the file name (ASCII or UNICODE ) //! @param u8_txt_format text format to use (UNI_TYPE_UTF8, UNI_TYPE_UTF16BE, UNI_TYPE_UTF16LE, UNI_TYPE_ASCII) //! //! @return false in case of error, see global value "fs_g_status" for more detail //! @return true otherwise //! bool reader_txt_new( const FS_STRING sz_name , uint8_t u8_txt_format ) { // Table to store the header of text file uint8_t string_header[UNI_MAX_HEADER_SIZE]; uint8_t u8_header_size; // Create empty file if ( !nav_file_create( sz_name )) return false; fs_g_nav_entry.u8_txt_format = u8_txt_format; // Write at the beginning of file the text header u8_header_size = unicode_header_get( string_header, fs_g_nav_entry.u8_txt_format ); file_write_buf( string_header , u8_header_size ); return true; }
//! //! This function writes to a file. //! //! @param fd file descriptor. //! @param buf pointer from where data are written. //! @param count amount of bytes to write //! //! @return ssize_t : amount of data written (-1 if error) //! ssize_t write(int fd, const void *buf, size_t count) { ssize_t WriteCount = -1; if (fd < 0) { return (-1); } // take the mutex for nav access fsaccess_take_mutex(); nav_select( fd ); WriteCount = (ssize_t)file_write_buf((uint8_t *)buf , (uint16_t)count); // give the mutex for nav access fsaccess_give_mutex(); return(WriteCount); }
/*! \brief Main function. Execution starts here. */ int main(void) { sysclk_init(); irq_initialize_vectors(); cpu_irq_enable(); // Initialize the sleep manager sleepmgr_init(); board_init(); ui_init(); // Reset File System nav_reset(); // Start USB host stack uhc_start(); // The USB management is entirely managed by interrupts. // As a consequence, the user application does only have : // - to play with the power modes // - to create a file on each new LUN connected while (true) { sleepmgr_enter_sleep(); if (main_usb_sof_counter > 2000) { main_usb_sof_counter = 0; uint8_t lun; for (lun = 0; (lun < uhi_msc_mem_get_lun()) && (lun < 8); lun++) { // Mount drive nav_drive_set(lun); if (!nav_partition_mount()) { if (fs_g_status == FS_ERR_HW_NO_PRESENT) { // The test can not be done, if LUN is not present lun_state &= ~(1 << lun); // LUN test reseted continue; } lun_state |= (1 << lun); // LUN test is done. ui_test_finish(false); // Test fail continue; } // Check if LUN has been already tested if (lun_state & (1 << lun)) { continue; } // Create a test file on the disk if (!nav_file_create((FS_STRING) "uhi_msc_test.txt")) { if (fs_g_status != FS_ERR_FILE_EXIST) { if (fs_g_status == FS_LUN_WP) { // Test can be done only on no write protected device continue; } lun_state |= (1 << lun); // LUN test is done. ui_test_finish(false); // Test fail continue; } } if (!file_open(FOPEN_MODE_APPEND)) { if (fs_g_status == FS_LUN_WP) { // Test can be done only on no write protected device continue; } lun_state |= (1 << lun); // LUN test is done. ui_test_finish(false); // Test fail continue; } if (!file_write_buf((uint8_t*)MSG_TEST, sizeof(MSG_TEST))) { lun_state |= (1 << lun); // LUN test is done. ui_test_finish(false); // Test fail continue; } file_close(); lun_state |= (1 << lun); // LUN test is done. ui_test_finish(true); // Test pass } if ((lun == 0) || (lun_state == 0)) { ui_test_flag_reset(); } } } }
/* * clipboard_data_to_file - データをファイルに保存 */ BOOL clipboard_data_to_file(DATA_INFO *di, const TCHAR *file_name, const int filter_index, TCHAR *err_str) { HMETAFILE hMeta; HENHMETAFILE enh_meta; BYTE *tmp; DWORD size; if (di->data == NULL) { if (file_write_buf(file_name, NULL, 0, err_str) == FALSE) { return FALSE; } return TRUE; } switch (di->format) { case CF_OWNERDISPLAY: return FALSE; case CF_DSPMETAFILEPICT: case CF_METAFILEPICT: // メタファイル if ((tmp = GlobalLock(di->data)) == NULL) { message_get_error(GetLastError(), err_str); return FALSE; } if ((hMeta = CopyMetaFile(((METAFILEPICT *)tmp)->hMF, file_name)) == NULL) { message_get_error(GetLastError(), err_str); GlobalUnlock(di->data); return FALSE; } DeleteMetaFile(hMeta); GlobalUnlock(di->data); break; case CF_DSPENHMETAFILE: case CF_ENHMETAFILE: // 拡張メタファイル if ((enh_meta = CopyEnhMetaFile(di->data, file_name)) == NULL) { message_get_error(GetLastError(), err_str); return FALSE; } DeleteEnhMetaFile(enh_meta); break; default: // その他 // データをバイト列に変換 if ((tmp = clipboard_data_to_bytes(di, &size)) == NULL) { message_get_error(GetLastError(), err_str); return FALSE; } // ファイルに書き込む if (file_write_buf(file_name, tmp, di->size, err_str) == FALSE) { mem_free(&tmp); return FALSE; } mem_free(&tmp); break; } return TRUE; }