Use the right function for the kernel-side logging.
This commit is contained in:
@@ -4,37 +4,40 @@
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "stdio.h"
|
||||
#include "fs/vfs.h"
|
||||
|
||||
/// Size of the buffer.
|
||||
#define BUFFER_SIZE 256
|
||||
|
||||
int writeFeedback()
|
||||
{
|
||||
mode_t mode = 000777;
|
||||
char buffer[100 + 1];
|
||||
const char* name = "feedback.txt";
|
||||
|
||||
mode_t mode = 000777;
|
||||
char buffer[BUFFER_SIZE];
|
||||
const char *name = "feedback.txt";
|
||||
|
||||
int fptr = 0;
|
||||
//fptr = sys_open("/../../../files/home/feedback.txt", O_WRONLY | O_CREAT | O_TRUNC , mode);
|
||||
//fptr = sys_open("/../../../files/home/feedback.txt", O_RDONLY | O_CREAT | O_EXCL , mode);
|
||||
//fptr = sys_open("/../../../files/home/feedback.txt", O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
fptr = sys_open(name, O_CREAT | O_WRONLY , S_IRUSR | S_IWUSR);
|
||||
// NOTE: You should check if the file exists, or create it, during the boot
|
||||
// phase of the system. Choose a place where to put it, a location like
|
||||
// `/var/scheduling_feedback.txt`.
|
||||
vfs_file_t *file = vfs_open(name, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
|
||||
|
||||
if(fptr == -1){
|
||||
printf("suca");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (file == NULL) {
|
||||
printf("Error: Failed to open feedback file.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Reading up to MAX_READ bytes from STDIN.
|
||||
ssize_t numRead = sys_read(fptr, buffer, 100);
|
||||
// NOTE: You need also to save the offset where you are reading or writing
|
||||
// the file. You are not using the simplified read() or write(), this one is
|
||||
// a kernel-side function.
|
||||
ssize_t numRead, offset = 0;
|
||||
|
||||
buffer[numRead] = '\0';
|
||||
printf("Input data: %s\n", buffer);
|
||||
// Reading up to MAX_READ bytes from STDIN.
|
||||
numRead = vfs_read(file, buffer, offset, BUFFER_SIZE);
|
||||
buffer[numRead] = '\0';
|
||||
printf("Input data: %s\n", buffer);
|
||||
|
||||
|
||||
//write to file
|
||||
//sys_write(fptr,"ciao",4);
|
||||
//printf("suca"); //questo va
|
||||
sys_close(fptr); //il problema è qui, se chiudiamo il file non arriviamo al login, se non chiudiamo il file invece proviamo a fare login ma non riusciamo perchè non riesce ad aprire passwd
|
||||
return 1;
|
||||
//write to file
|
||||
//vfs_write(file,"ciao",4);
|
||||
//printf("suca"); //questo va
|
||||
vfs_close(file); //il problema è qui, se chiudiamo il file non arriviamo al login, se non chiudiamo il file invece proviamo a fare login ma non riusciamo perchè non riesce ad aprire passwd
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user