1 /* Copyright (C) 2001-2019 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 #ifndef __RAMFS_H__
17 #define __RAMFS_H__
18 
19 #include "stream.h"
20 
21 #define RAMFS_BLOCKSIZE 1024
22 
23 typedef struct _ramfs ramfs;
24 typedef struct _ramdirent ramdirent;
25 typedef struct _ramhandle ramhandle;
26 typedef struct _ramfs_enum ramfs_enum;
27 
28 /*
29   ramfs_new: NOMEM
30   ramfs_open: NOTFOUND
31   ramfs_unlink: NOTFOUND
32   ramfs_enum_new: NOMEM
33   ramfs_enum_next: none
34   ramfs_enum_end: none
35   ramfile_read: none
36   ramfile_write: NOSPACE, NOMEM, NOACCESS
37   ramfile_seek: none
38   ramfile_pos: none
39   ramfile_close: none
40 */
41 
42 /* Error constants */
43 #define RAMFS_NOTFOUND 2
44 #define RAMFS_NOACCESS 5
45 #define RAMFS_NOMEM 6
46 #define RAMFS_NOSPACE 7
47 
48 /* Open mode flags */
49 #define RAMFS_READ   s_mode_read      /* 1 */
50 #define RAMFS_WRITE  s_mode_write    /* 2 */
51 #define RAMFS_SEEK   s_mode_seek      /* 4 */
52 #define RAMFS_APPEND s_mode_append  /* 8 */
53 #define RAMFS_CREATE 16
54 #define RAMFS_TRUNC  32
55 
56 #define RAMFS_SEEK_SET 0
57 #define RAMFS_SEEK_CUR 1
58 #define RAMFS_SEEK_END 2
59 
60 ramfs * ramfs_new(gs_memory_t *mem, int size); /* size is in KiB */
61 void ramfs_destroy(gs_memory_t *, ramfs * fs);
62 int ramfs_error(const ramfs * fs);
63 ramhandle * ramfs_open(gs_memory_t *mem, ramfs * fs,const char * filename,int mode);
64 int ramfs_blocksize(ramfs * fs);
65 int ramfs_blocksfree(ramfs * fs);
66 int ramfs_unlink(ramfs * fs,const char *filename);
67 int ramfs_rename(ramfs * fs,const char *oldname,const char *newname);
68 ramfs_enum * ramfs_enum_new(ramfs * fs);
69 char* ramfs_enum_next(ramfs_enum * e);
70 void ramfs_enum_end(ramfs_enum * e);
71 int ramfile_read(ramhandle * handle,void * buf,int len);
72 int ramfile_write(ramhandle * handle,const void * buf,int len);
73 int ramfile_seek(ramhandle * handle,int pos,int whence);
74 int ramfile_eof(ramhandle * handle);
75 int ramfile_tell(ramhandle * handle);
76 int ramfile_size(ramhandle * handle);
77 void ramfile_close(ramhandle * handle);
78 int ramfile_error(ramhandle * handle);
79 
80 #endif /* __RAMFS_H__ */
81