]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
dhb left console.cpp uncompileable. Modified a comment in mainwin.cpp
[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    Bacula® - The Network Backup Solution
10
11    Copyright (C) 2003-2006 Free Software Foundation Europe e.V.
12
13    The main author of Bacula is Kern Sibbald, with contributions from
14    many others, a complete list can be found in the file AUTHORS.
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation plus additions
18    that are listed in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; if not, write to the Free Software
27    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of John Walker.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
33    Switzerland, email:ftf@fsfeurope.org.
34 */
35
36 #ifndef __BFILE_H
37 #define __BFILE_H
38
39 #ifdef HAVE_PYTHON
40 #undef _POSIX_C_SOURCE
41 #include <Python.h>
42 struct Python_IO {
43    PyObject *fo;
44    PyObject *fr;
45    PyObject *fc;
46 };
47 #else
48 struct Python_IO {
49 };
50 #endif
51
52
53 /* this should physically correspond to WIN32_STREAM_ID
54  * from winbase.h on Win32. We didn't inlcude cStreamName
55  * as we don't use it and don't need it for a correct struct size.
56  */
57
58 #define WIN32_BACKUP_DATA 1
59
60 typedef struct _BWIN32_STREAM_ID {
61         int32_t        dwStreamId;
62         int32_t        dwStreamAttributes;
63         int64_t        Size;
64         int32_t        dwStreamNameSize;        
65 } BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
66
67
68 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
69         int64_t          liNextHeader;
70         bool             bIsInData;
71         BWIN32_STREAM_ID header_stream;        
72 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
73
74 /*  =======================================================
75  *
76  *   W I N D O W S
77  *
78  *  =======================================================
79  */
80 #if defined(HAVE_WIN32)
81
82 enum {
83    BF_CLOSED,
84    BF_READ,                           /* BackupRead */
85    BF_WRITE                           /* BackupWrite */
86 };
87
88 /* In bfile.c */
89
90 /* Basic Win32 low level I/O file packet */
91 struct BFILE {
92    bool use_backup_api;               /* set if using BackupRead/Write */
93    int mode;                          /* set if file is open */
94    HANDLE fh;                         /* Win32 file handle */
95    int fid;                           /* fd if doing Unix style */
96    LPVOID lpContext;                  /* BackupRead/Write context */
97    POOLMEM *errmsg;                   /* error message buffer */
98    DWORD rw_bytes;                    /* Bytes read or written */
99    DWORD lerror;                      /* Last error code */
100    int berrno;                        /* errno */
101    char *prog;                        /* reader/writer program if any */
102    JCR *jcr;                          /* jcr for editing job codes */
103    Python_IO pio;                     /* Python I/O routines */
104    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
105    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
106 };
107
108 HANDLE bget_handle(BFILE *bfd);
109
110 #else   /* Linux/Unix systems */
111
112 /*  =======================================================
113  *
114  *   U N I X
115  *
116  *  =======================================================
117  */
118
119 /* Basic Unix low level I/O file packet */
120 struct BFILE {
121    int fid;                           /* file id on Unix */
122    int berrno;
123    char *prog;                        /* reader/writer program if any */
124    JCR *jcr;                          /* jcr for editing job codes */
125    Python_IO pio;                     /* Python I/O routines */
126    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
127    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
128 };
129
130 #endif
131
132 void    binit(BFILE *bfd);
133 bool    is_bopen(BFILE *bfd);
134 bool    set_win32_backup(BFILE *bfd);
135 bool    set_portable_backup(BFILE *bfd);
136 bool    set_prog(BFILE *bfd, char *prog, JCR *jcr);
137 bool    have_win32_api();
138 bool    is_portable_backup(BFILE *bfd);
139 bool    is_restore_stream_supported(int stream);
140 bool    is_win32_stream(int stream);
141 char   *xberror(BFILE *bfd);          /* DO NOT USE  -- use berrno class */
142 int     bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
143 #ifdef HAVE_DARWIN_OS
144 int     bopen_rsrc(BFILE *bfd, const char *fname, int flags, mode_t mode);
145 #endif
146 int     bclose(BFILE *bfd);
147 ssize_t bread(BFILE *bfd, void *buf, size_t count);
148 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
149 boffset_t blseek(BFILE *bfd, boffset_t offset, int whence);
150 const char   *stream_to_ascii(int stream);
151
152 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
153
154 #endif /* __BFILE_H */