-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwritetest.c
44 lines (31 loc) · 888 Bytes
/
writetest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
//#include <malloc.h>
#define BUFFER_LENGTH 4096 // Should be a multiple of NVMe block size, as we DMA straight from it without checking
char buffer[BUFFER_LENGTH];
int main(void) {
int fd;
ssize_t result;
// char *buffer = malloc(BUFFER_LENGTH);
// char *buffer = memalign(4096, BUFFER_LENGTH);
printf("Starting write test...\n");
fd = open("/dev/chardisk0", O_WRONLY);
if (fd < 0) {
perror("Failed to open the device");
return errno;
}
sprintf(buffer, "Hello! This is a string written from user space.");
printf("Writing to the device...\n");
result = write(fd, buffer, BUFFER_LENGTH);
printf("Result: %zd\n", result);
if (result < 0) {
perror("Failed to write the message to the device");
return errno;
}
// free(buffer);
return 0;
}