]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
de60b4f23f68c8f9f2f8d545df3c5978dc51530e
[bacula/bacula] / bacula / src / findlib / bfile.h
1 /*
2  *  Bacula low level File I/O routines.  This routine simulates
3  *    open(), read(), write(), and close(), but using native routines.
4  *    I.e. on Windows, we use Windows APIs.
5  *
6  *     Kern Sibbald May MMIII
7  */
8 /*
9    Copyright (C) 2000-2005 Kern Sibbald
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2 of
14    the License, or (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public
22    License along with this program; if not, write to the Free
23    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24    MA 02111-1307, USA.
25
26  */
27
28 #ifndef __BFILE_H
29 #define __BFILE_H
30
31 #ifdef HAVE_PYTHON
32 #undef _POSIX_C_SOURCE
33 #include <Python.h>
34 struct Python_IO {
35    PyObject *fo;
36    PyObject *fr;
37    PyObject *fc;
38 };
39 #else
40 struct Python_IO {
41 };
42 #endif
43
44 #ifdef USE_WIN32STREAMEXTRACTION
45 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
46         LONGLONG        liNextHeader;
47         BOOL            bIsInData;
48         WIN32_STREAM_ID header_stream;        
49 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
50 #endif
51
52 /*  =======================================================
53  *
54  *   W I N D O W S
55  *
56  *  =======================================================
57  */
58 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
59
60 #include <windows.h>
61 #include "../lib/winapi.h"
62
63 enum {
64    BF_CLOSED,
65    BF_READ,                           /* BackupRead */
66    BF_WRITE                           /* BackupWrite */
67 };
68
69 /* In bfile.c */
70
71 /* Basic Win32 low level I/O file packet */
72 struct BFILE {
73    int use_backup_api;                /* set if using BackupRead/Write */
74    int mode;                          /* set if file is open */
75    HANDLE fh;                         /* Win32 file handle */
76    int fid;                           /* fd if doing Unix style */
77    LPVOID lpContext;                  /* BackupRead/Write context */
78    POOLMEM *errmsg;                   /* error message buffer */
79    DWORD rw_bytes;                    /* Bytes read or written */
80    DWORD lerror;                      /* Last error code */
81    int berrno;                        /* errno */
82    char *prog;                        /* reader/writer program if any */
83    JCR *jcr;                          /* jcr for editing job codes */
84    Python_IO pio;                     /* Python I/O routines */
85 #ifdef USE_WIN32STREAMEXTRACTION
86    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
87    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
88 #endif
89 };
90
91 HANDLE bget_handle(BFILE *bfd);
92
93 #else   /* Linux/Unix systems */
94
95 /*  =======================================================
96  *
97  *   U N I X
98  *
99  *  =======================================================
100  */
101
102 /* Basic Unix low level I/O file packet */
103 struct BFILE {
104    int fid;                           /* file id on Unix */
105    int berrno;
106    char *prog;                        /* reader/writer program if any */
107    JCR *jcr;                          /* jcr for editing job codes */
108    Python_IO pio;                     /* Python I/O routines */
109 #ifdef USE_WIN32STREAMEXTRACTION
110    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
111    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
112 #endif
113 };
114
115 #endif
116
117 void    binit(BFILE *bfd);
118 bool    is_bopen(BFILE *bfd);
119 bool    set_win32_backup(BFILE *bfd);
120 bool    set_portable_backup(BFILE *bfd);
121 bool    set_prog(BFILE *bfd, char *prog, JCR *jcr);
122 bool    have_win32_api();
123 bool    is_portable_backup(BFILE *bfd);
124 bool    is_stream_supported(int stream);
125 bool    is_win32_stream(int stream);
126 char   *xberror(BFILE *bfd);          /* DO NOT USE  -- use berrno class */
127 int     bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
128 #ifdef HAVE_DARWIN_OS
129 int     bopen_rsrc(BFILE *bfd, const char *fname, int flags, mode_t mode);
130 #endif
131 int     bclose(BFILE *bfd);
132 ssize_t bread(BFILE *bfd, void *buf, size_t count);
133 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
134 off_t   blseek(BFILE *bfd, off_t offset, int whence);
135 const char   *stream_to_ascii(int stream);
136
137 #ifdef USE_WIN32STREAMEXTRACTION
138 BOOL processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, size_t dwSize);
139 #endif
140
141 #endif /* __BFILE_H */