#include "usecfs.h" #include const uint8_t test_uuid[UUID_LEN] = { 0xb3, 0x6b, 0x82, 0x05, 0xb6, 0xcd, 0x28, 0xaa, 0xc7, 0x81, 0x2e, 0x2d, 0xfd, 0xdd, 0x5e, 0x70, 0x3f, 0xbf, 0x09, 0x03, 0x1b, 0x5f, 0xbe, 0xc6, 0x09, 0x62, 0xa8, 0x23, 0xe9, 0x99, 0x5e, 0xcb, 0xb4, 0xab, 0x28, 0xdc, 0x14, 0xca, 0x35, 0xb4, 0x7d, 0xfe, 0x26, 0x81, 0x33, 0xd0, 0x4b, 0xc2, 0x49, 0x53, 0x05, 0xc3, 0xe7, 0xbd, 0x9a, 0x50, 0xb8, 0x01, 0x30, 0x0b, 0x62, 0x58, 0xad, 0xbf }; int main(void) { int fd; int buf[40] = { }; int uuid[UUID_LEN]; if (usecfs_init("sEcret", 0, NULL) < 0) { printf("Filesystem is not formatted. Formatting.\n"); if (usecfs_init("sEcret", 1, test_uuid) != 0) { printf("Format failed.\n"); return 1; } } printf("Creating file 'file1' \n"); fd = usecfs_creat("file1"); if (fd < 0) { printf("could not create file (this is OK unless open fails)\n"); fd = usecfs_open("file1"); if (fd < 0) { printf("error: open\n"); return 1; } } printf("Writing to file 'file1' \n"); if (usecfs_write(fd, "test string file 1 content\n", 27) < 0) { printf("error: write.\n"); return 1; } usecfs_close(fd); printf("Re-opening\n"); fd = usecfs_open("file1"); if (fd < 0) { printf("error: open\n"); return 1; } printf("Reading file...\n"); if (usecfs_read(fd, buf, 27) != 27) { printf("error: read.\n"); return 1; } printf("content of file 'file1': "); printf("%s\n", buf); printf("appending 'test string2'\n"); if (usecfs_write(fd, "test string2\n", 13) < 0) { printf("error: write.\n"); return 1; } printf("seek to 0\n"); if (usecfs_seek(fd, 0, 0) != 0) { printf("error: seek.\n"); return 1; } printf("Reading...\n"); if (usecfs_read(fd, buf, 40) < 0) { printf("error: read.\n"); return 1; } printf("%s", buf); usecfs_close(fd); printf("Creating file 'file2' \n"); fd = usecfs_creat("file2"); if (fd < 0) { printf("could not create file (this is OK unless open fails)\n"); fd = usecfs_open("file2"); if (fd < 0) { printf("error: open\n"); return 1; } } usecfs_close(fd); printf("Creating file 'file3' \n"); fd = usecfs_creat("file3"); if (fd < 0) { if (fd < 0) { printf("could not create file (this is OK unless open fails)\n"); fd = usecfs_open("file3"); if (fd < 0) { printf("error: open\n"); return 1; } } } usecfs_close(fd); return 0; }