]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
Win32 BackupStream decomposition "alpha version"
[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) 2003-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
13    version 2 as amended with additional clauses defined in the
14    file LICENSE in the main source directory.
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 
19    the file LICENSE for additional details.
20
21  */
22
23 #ifndef __BFILE_H
24 #define __BFILE_H
25
26 #ifdef HAVE_PYTHON
27 #undef _POSIX_C_SOURCE
28 #include <Python.h>
29 struct Python_IO {
30    PyObject *fo;
31    PyObject *fr;
32    PyObject *fc;
33 };
34 #else
35 struct Python_IO {
36 };
37 #endif
38
39 #ifdef USE_WIN32STREAMEXTRACTION
40
41 /* this should physically correspond to WIN32_STREAM_ID
42  * from winbase.h on Win32. We didn't inlcude cStreamName
43  * as we don't use it and don't need it for a correct struct size.
44  */
45
46 typedef struct _BWIN32_STREAM_ID {
47         int32_t        dwStreamId;
48         int32_t        dwStreamAttributes;
49         int64_t        Size;
50         int32_t        dwStreamNameSize;        
51 } BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
52
53
54 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
55         int64_t          liNextHeader;
56         bool             bIsInData;
57         BWIN32_STREAM_ID header_stream;        
58 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
59 #endif
60
61 /*  =======================================================
62  *
63  *   W I N D O W S
64  *
65  *  =======================================================
66  */
67 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
68
69 #include <windows.h>
70 #include "../lib/winapi.h"
71
72 enum {
73    BF_CLOSED,
74    BF_READ,                           /* BackupRead */
75    BF_WRITE                           /* BackupWrite */
76 };
77
78 /* In bfile.c */
79
80 /* Basic Win32 low level I/O file packet */
81 struct BFILE {
82    int use_backup_api;                /* set if using BackupRead/Write */
83    int mode;                          /* set if file is open */
84    HANDLE fh;                         /* Win32 file handle */
85    int fid;                           /* fd if doing Unix style */
86    LPVOID lpContext;                  /* BackupRead/Write context */
87    POOLMEM *errmsg;                   /* error message buffer */
88    DWORD rw_bytes;                    /* Bytes read or written */
89    DWORD lerror;                      /* Last error code */
90    int berrno;                        /* errno */
91    char *prog;                        /* reader/writer program if any */
92    JCR *jcr;                          /* jcr for editing job codes */
93    Python_IO pio;                     /* Python I/O routines */
94 #ifdef USE_WIN32STREAMEXTRACTION
95    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
96    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
97 #endif
98 };
99
100 HANDLE bget_handle(BFILE *bfd);
101
102 #else   /* Linux/Unix systems */
103
104 /*  =======================================================
105  *
106  *   U N I X
107  *
108  *  =======================================================
109  */
110
111 /* Basic Unix low level I/O file packet */
112 struct BFILE {
113    int fid;                           /* file id on Unix */
114    int berrno;
115    char *prog;                        /* reader/writer program if any */
116    JCR *jcr;                          /* jcr for editing job codes */
117    Python_IO pio;                     /* Python I/O routines */
118 #ifdef USE_WIN32STREAMEXTRACTION
119    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
120    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
121 #endif
122 };
123
124 #endif
125
126 void    binit(BFILE *bfd);
127 bool    is_bopen(BFILE *bfd);
128 bool    set_win32_backup(BFILE *bfd);
129 bool    set_portable_backup(BFILE *bfd);
130 bool    set_prog(BFILE *bfd, char *prog, JCR *jcr);
131 bool    have_win32_api();
132 bool    is_portable_backup(BFILE *bfd);
133 bool    is_stream_supported(int stream);
134 bool    is_win32_stream(int stream);
135 char   *xberror(BFILE *bfd);          /* DO NOT USE  -- use berrno class */
136 int     bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
137 #ifdef HAVE_DARWIN_OS
138 int     bopen_rsrc(BFILE *bfd, const char *fname, int flags, mode_t mode);
139 #endif
140 int     bclose(BFILE *bfd);
141 ssize_t bread(BFILE *bfd, void *buf, size_t count);
142 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
143 off_t   blseek(BFILE *bfd, off_t offset, int whence);
144 const char   *stream_to_ascii(int stream);
145
146 #ifdef USE_WIN32STREAMEXTRACTION
147 BOOL processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, size_t dwSize);
148 #endif
149
150 #endif /* __BFILE_H */