-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_handler.h
47 lines (36 loc) · 1.09 KB
/
file_handler.h
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
45
46
47
#ifndef FILE_HANDLER_H
#define FILE_HANDLER_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <semaphore.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdbool.h>
#define FILES_DIR "files"
#define MAX_FILES 100
#define MAX_FILENAME_LEN 256
// File access modes
typedef enum
{
READ_MODE,
WRITE_MODE
} access_mode_t;
// Initialize the file handler system
int file_handler_init(void);
// Clean up resources when server shuts down
void file_handler_cleanup(void);
// Request access to a file, returns 0 on success, -1 on failure
int request_file_access(const char *filename, access_mode_t mode);
// Release file access when done
void release_file_access(const char *filename, access_mode_t mode);
// Check if a file exists in the files directory
bool file_exists(const char *filename);
// Get full path to a file in the files directory
char *get_file_path(const char *filename);
// Directory operations for upload mutual exclusion
void lock_directory_for_upload(void);
void unlock_directory_for_upload(void);
#endif // FILE_HANDLER_H