项目外接了固态硬盘,需要读取数据并保存到SSD中
于是我写了个应用程序,大概思路是把读取数据放到内存缓冲区,之后缓冲取满放进SSD中,清空缓存区,循环存入读取,明天有时间测试一下,先记录一下。
#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"
#define BUFFER_SIZE 100 * 1024 * 1024 /* 100MB */
/*
函数名: int ssd(int index)
函数功能: 向SSD中存储数据,先存储到内存缓冲区,缓冲区满转移至SSD,之后清空缓冲区
输入参数: index:SSD的编号;范围:0~2。
输出参数: 0--成功,-1--失败
*/
int ssd(int index){
int fd;
/* 创建缓冲区 */
char *buffer = (char *)malloc(BUFFER_SIZE);
/* 用于记录缓冲区已使用的大小 */
size_t usedSize = 0;
if (buffer == NULL) {
printf("Failed to allocate memory for buffer\n");
return -1;
}
while(1){
const char *data = "SampleData";/*替换为实际存入数据*/