aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/drivers/common/erl_efile.h
blob: e0b8cfca039871024c59d5e0e72a76b8aed42af8 (plain) (blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * %CopyrightBegin%
 *
 * Copyright Ericsson AB 1997-2010. All Rights Reserved.
 *
 * The contents of this file are subject to the Erlang Public License,
 * Version 1.1, (the "License"); you may not use this file except in
 * compliance with the License. You should have received a copy of the
 * Erlang Public License along with this software. If not, it can be
 * retrieved online at http://www.erlang.org/.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 *
 * %CopyrightEnd%
 */
/*
 * Defines the interfaces between the generic efile driver and its
 * operating-system dependent helpers.
 */

#include "sys.h"
#include "erl_driver.h"

/*
 * Open modes for efile_openfile().
 */
#define EFILE_MODE_READ 1
#define EFILE_MODE_WRITE 2	/* Implies truncating file when used alone. */
#define EFILE_MODE_READ_WRITE 	3
#define EFILE_MODE_APPEND	4
#define EFILE_COMPRESSED 	8
#define EFILE_MODE_EXCL        16
#define EFILE_NO_TRUNCATE      32 /* Special for reopening on VxWorks */

/*
 * Seek modes for efile_seek().
 */
#define	EFILE_SEEK_SET	0
#define	EFILE_SEEK_CUR	1
#define	EFILE_SEEK_END	2

/*
 * File types returned by efile_fileinfo().
 */
#define FT_DEVICE 	1
#define FT_DIRECTORY 	2
#define FT_REGULAR	3
#define FT_SYMLINK	4
#define FT_OTHER	5

/*
 * Access attributes returned by efile_fileinfo() (the bits can be ORed
 * together).
 */
#define FA_NONE    	0
#define FA_WRITE 	1
#define FA_READ		2

/* Some OS'es (i.e. Windows) has filenames in wide charaqcters. That requires special handling */
/* Note that we do *not* honor alignment in the communication to the OS specific driver, */
/* which is not a problem on x86, but might be on other platforms. The OS specific efile */
/* implementation is expected to align if needed */
#ifdef __WIN32__
#define FILENAMES_16BIT 1
#endif

/*
 * An handle to an open directory.  To be cast to the correct type
 * in the system-dependent directory functions.
 */

typedef struct _Efile_Dir_Handle* EFILE_DIR_HANDLE;

/*
 * Error information from the last call.
 */  
typedef struct _Efile_error {
    int posix_errno;		/* Posix error number, as in <errno.h>. */
    int os_errno;		/* Os-dependent error number (not used). */
} Efile_error;

/*
 * This structure contains date and time.
 */
typedef struct _Efile_time {
    unsigned year;		/* (4 digits). */
    unsigned month;		/* (1..12). */
    unsigned day;		/* (1..31). */
    unsigned hour;		/* (0..23). */
    unsigned minute;		/* (0..59). */
    unsigned second;		/* (0..59). */
} Efile_time;


/*
 * Describes what is returned by file:file_info/1.
 */

typedef struct _Efile_info {
    Uint32 size_low;		/* Size of file, lower 32 bits.. */
    Uint32 size_high;		/* Size of file, higher 32 bits. */
    Uint32 type;		/* Type of file -- one of FT_*. */
    Uint32 access;		/* Access to file -- one of FA_*. */
    Uint32 mode;		/* Access permissions -- bit field. */
    Uint32 links;		/* Number of links to file. */
    Uint32 major_device;	/* Major device or file system. */
    Uint32 minor_device;	/* Minor device (for devices). */
    Uint32 inode;		/* Inode number. */
    Uint32 uid;			/* User id of owner. */
    Uint32 gid;			/* Group id of owner. */
    Efile_time accessTime;	/* Last time the file was accessed. */
    Efile_time modifyTime;	/* Last time the file was modified. */
    Efile_time cTime;		/* Creation time (Windows) or last
				 * inode change (Unix).
				 */
} Efile_info;

/*
 * Functions.
 */

int efile_mkdir(Efile_error* errInfo, char* name);
int efile_rmdir(Efile_error* errInfo, char* name);
int efile_delete_file(Efile_error* errInfo, char* name);
int efile_rename(Efile_error* errInfo, char* src, char* dst);
int efile_chdir(Efile_error* errInfo, char* name);
int efile_getdcwd(Efile_error* errInfo, int drive,
		  char* buffer, size_t size);
int efile_readdir(Efile_error* errInfo, char* name, 
		  EFILE_DIR_HANDLE* dir_handle,
		  char* buffer, size_t *size);
int efile_openfile(Efile_error* errInfo, char* name, int flags,
		   int* pfd, Sint64* pSize);
void efile_closefile(int fd);
int efile_fdatasync(Efile_error* errInfo, int fd);
int efile_fsync(Efile_error* errInfo, int fd);
int efile_fileinfo(Efile_error* errInfo, Efile_info* pInfo,
		   char *name, int info_for_link);
int efile_write_info(Efile_error* errInfo, Efile_info* pInfo, char *name);
int efile_write(Efile_error* errInfo, int flags, int fd, 
		char* buf, size_t count);
int efile_writev(Efile_error* errInfo, int flags, int fd, 
		 SysIOVec* iov, int iovcnt, size_t size);
int efile_read(Efile_error* errInfo, int flags, int fd, 
	       char* buf, size_t count, size_t* pBytesRead);
int efile_seek(Efile_error* errInfo, int fd, 
	       Sint64 offset, int origin, Sint64* new_location);
int efile_truncate_file(Efile_error* errInfo, int *fd, int flags);
int efile_pwrite(Efile_error* errInfo, int fd, 
		 char* buf, size_t count, Sint64 offset);
int efile_pread(Efile_error* errInfo, int fd, 
		Sint64 offset, char* buf, size_t count, size_t* pBytesRead);
int efile_readlink(Efile_error* errInfo, char *name, 
		   char* buffer, size_t size);
int efile_altname(Efile_error* errInfo, char *name, 
		  char* buffer, size_t size);
int efile_link(Efile_error* errInfo, char* old, char* new);
int efile_symlink(Efile_error* errInfo, char* old, char* new);
int efile_may_openfile(Efile_error* errInfo, char *name);
int efile_fadvise(Efile_error* errInfo, int fd, Sint64 offset, Sint64 length,
		  int advise);
int efile_sendfile(Efile_error* errInfo, int in_fd, int out_fd,
		      off_t *offset, size_t *nbytes);