예제 #1
0
void FAT32_WriteDirectoryTableEntry(FS_File *file, uint8_t *data) {
	uint8_t i=0;
	// Move data to beginning of the file's directory entry
	data += file->dirTableBlockOffset;

	for (i=0;i<8;i++) {
		if (file->name[i] == '\0') {
			break;
		} else {
			data[i] = toupper(file->name[i]);
		}
	}
	for (;i<8;i++) {
		data[i] = ' ';
	}

	for (i=0;i<3;i++) {
		if (file->ext[i] == '\0') {
			break;
		} else {
			data[i+8] = toupper(file->ext[i]);
		}
	}
	for (;i<3;i++) {
		data[i+8] = ' ';
	}

	for (i=0x0b;i<0x20;i++) {
		data[i] = 0x00;
	}

	Int32ToFATSplitData(data+0x14, data+0x1a, file->startCluster);
}
예제 #2
0
/**
 * Initializes FAT data for a new file.
 * This fills in the first FAT block and updates the directory table entry.
 * No data is committed not is data moved to the FS buffer - that must be done separately.
 *
 * @pre The file is new (just created).
 *
 * @param file File to initialize.
 * @return Status.
 * @retval 0 Success.
 * @retval -1 Failure.
 */
int8_t FAT32_InitializeFileFAT(FAT32FileOpt *file) {
	// Fill the first FAT block
	FAT32_AllocateFATBlock(file);

	// Use the newly allocated FAT block
	FAT32_SwitchNextBlock(file);

	// Fill out file parameters using allocated data
	file->startCluster = file->currentCluster;
	Int32ToFATSplitData(file->directoryTableBlockData + file->directoryTableBlockOffset + 0x14,
			file->directoryTableBlockData + file->directoryTableBlockOffset + 0x1a,
			file->startCluster);
	FAT32_UpdateDirectoryTableEntry(file);

	DBG_DATA_printf("File initialized (cluster=0x%08lx, block=0x%08lx, size=%lu)", file->currentCluster, file->currentLBA, file->size);
}