SEFile
Userspace drivers to manage a secure filesystem
 All Data Structures Files Functions Variables Typedefs Enumerator Macros Groups
se3comm.h
1 #pragma once
2 #ifdef _WIN32
3 #include <Windows.h>
4 #pragma comment(lib,"Advapi32.lib")
5 #else
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <errno.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <malloc.h>
12 #include <fcntl.h>
13 #endif
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #include "se3c0def.h"
20 
21 #ifdef _DEBUG
22 #include <stdio.h>
23 #define se3_trace(msg) printf msg
24 #else
25 #define se3_trace(msg)
26 #endif
27 #include <stdlib.h>
28 #include <stdbool.h>
29 #include <stdint.h>
30 #include <stddef.h>
31 #include <time.h>
32 #include <string.h>
33 
34 #define SE3_SN_SIZE (32)
35 
36 #ifdef _WIN32
37  typedef struct {
38  OVERLAPPED ol;
39  HANDLE h;
40  } se3_file;
41  typedef wchar_t se3_char;
42 #define SE3_MAGIC_FILE (L".se3magic")
43 #define SE3_OSSEP (L'\\')
44 #define SE3_MAX_PATH (256)
45 #else
46  typedef struct {
47  int fd;
48  void* buf; //[512] memalign
49  bool locked;
50  } se3_file;
51  typedef char se3_char;
52 #define SE3_MAGIC_FILE (".se3magic")
53 #define SE3_OSSEP ('/')
54 #define SE3_MAX_PATH (256)
55 #endif
56 
57 #define SE3_MAGIC_FILE_LEN (9)
58 
59  typedef struct se3_discover_info_ {
60  uint8_t serialno[SE3_SERIAL_SIZE];
61  uint8_t hello_msg[SE3_HELLO_SIZE];
62  uint16_t status;
64 
65 #define SE3_DRIVE_BUF_MAX (1024)
66 
67 
68  typedef struct se3_drive_it_ {
69  se3_char* path;
70 
71  se3_char buf_[SE3_DRIVE_BUF_MAX + 1];
72  size_t buf_len_;
73 #ifdef _WIN32
74  size_t pos_;
75 #else
76  FILE* fp_;
77 #endif
78  } se3_drive_it;
79 
80  void se3c_rand(size_t len, uint8_t* buf);
81 
82  void se3c_drive_init(se3_drive_it* it);
83  bool se3c_drive_next(se3_drive_it* it);
84 
85  bool se3c_write(uint8_t* buf, se3_file hfile, size_t block, size_t size, uint32_t timeout);
86  bool se3c_read(uint8_t* buf, se3_file hfile, size_t block, size_t size, uint32_t timeout);
87  bool se3c_info(se3_char* path, uint64_t deadline, se3_discover_info* info);
88  bool se3c_open(se3_char* path, uint64_t deadline, se3_file* phfile, se3_discover_info* disco);
89  void se3c_close(se3_file hfile);
90  //bool se3c_flock_acquire(se3_file hfile, clock_t deadline);
91  //void se3c_flock_release(se3_file hfile);
92  uint64_t se3c_deadline(uint32_t timeout);
93  void se3c_pathcopy(se3_char* dest, se3_char* src);
94  uint64_t se3c_clock();
95 
96 #ifdef _WIN32
97 #define se3c_sleep() Sleep(0)
98 #else
99 #define se3c_sleep() usleep(1000)
100 #endif
101 
102 #define SE3C_MAGIC_TIMEOUT (1000)
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 
109 
Definition: se3comm.h:68
Definition: se3comm.h:37
Definition: se3comm.h:59