diff --git a/libc/inc/ipc/ipc.h b/libc/inc/ipc/ipc.h index ed2413d..ce0ad4c 100644 --- a/libc/inc/ipc/ipc.h +++ b/libc/inc/ipc/ipc.h @@ -5,6 +5,8 @@ #pragma once + + /// @brief Permission details of an IPC object. struct ipc_perm { /// Key supplied to msgget(2). @@ -22,3 +24,11 @@ struct ipc_perm { /// Sequence number. unsigned short __seq; }; + + +/// @brief Returns a possible key +/// @param path file path +/// @param id integer +/// @return IPC key +key_t ftok( char *path, int id); + diff --git a/libc/src/ipc/ipc.c b/libc/src/ipc/ipc.c index 7e1a213..af82f51 100644 --- a/libc/src/ipc/ipc.c +++ b/libc/src/ipc/ipc.c @@ -10,6 +10,11 @@ #include "ipc/sem.h" #include "ipc/shm.h" #include "ipc/msg.h" +//#include "fs/vfs_types.h" +//#include "fs/vfs.h" +#include "fcntl.h" +#include "sys/stat.h" +#include "stdio.h" _syscall3(void *, shmat, int, shmid, const void *, shmaddr, int, shmflg) @@ -33,3 +38,31 @@ _syscall5(long, msgrcv, int, msqid, struct msgbuf *, msgp, size_t, msgsz, long, _syscall3(long, msgctl, int, msqid, int, cmd, struct msqid_ds *, buf) +key_t ftok(char *path, int id){ + + + /*int fd; + + fd=open(path, O_RDONLY, 0777);*/ + + /* + if (() == -1){ + errno = ENOENT; + return -1; + } + */ + struct stat_t st; //struct containing the serial number and the device number of the file + if (stat(path, &st)<0){ + errno = ENOENT; + //printf("Error finding the serial number, check Errno...\n"); + return -1; + } + //printf("Serial number: %d\n", st.st_ino); + + + //taking the upper 8 bits from the lower 8 bits of id, the second upper 8 bits from the lower 8 bits of the device number of the provided pathname, and the lower 16 bits from the lower 16 bits of the inode number of the provided pathname + + return ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 0xffu) << 24)); + +} + diff --git a/programs/tests/t_semget.c b/programs/tests/t_semget.c index dab2594..ac221e3 100644 --- a/programs/tests/t_semget.c +++ b/programs/tests/t_semget.c @@ -1,8 +1,17 @@ //test -#include +#include "ipc/sem.h" +#include "stdio.h" int main() { - long i = semget(0,0,0); //checking if the syscalls are already linked + + key_t i = ftok("/test80.txt", 5); //checking if the syscalls are already linked + //long i = semget(0,0,0); + if (i == -1){ + printf("Error with IPC_KEY\n"); + return -1; + } + + printf("IPC_KEY: %d\n", i); return 0; -} +} \ No newline at end of file