Implementation of user_entity

client.c

#include <sys/mount.h>

#include <fcntl.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

static void fatal(const char *msg)

{

perror(msg);

exit(EXIT_FAILURE);

}

int main(void)

{

char message[] = "Hello, World!";

char buf[512];

int ret;

int fd;

if (mkdir("/c", S_IRWXU | S_IRWXG | S_IRWXO))

fatal("create mountpoint failed");

if (mount("Ahci0Port0,0", "/c", "fat32", 0, ""))

fatal("mount failed");

fd = open("/c/new_file", O_WRONLY | O_CREAT | O_EXCL);

if (fd < 0)

fatal("create file failed");

ret = write(fd, message, strlen(message));

if (ret < 0)

fatal("write failed");

if (close(fd) < 0)

fatal("close failed");

fd = open("/c/new_file", O_RDONLY);

if (fd < 0)

fatal("open file failed");

ret = read(fd, buf, sizeof(buf));

if (ret < 0)

fatal("read failed");

printf("%.*s\n", ret, buf);

if (close(fd) < 0)

fatal("close failed");

return EXIT_SUCCESS;

}

Page top