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.
6 * Kern Sibbald May MMIII
9 Bacula® - The Network Backup Solution
11 Copyright (C) 2003-2006 Free Software Foundation Europe e.V.
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.
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.
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
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.
40 #undef _POSIX_C_SOURCE
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.
58 #define WIN32_BACKUP_DATA 1
60 typedef struct _BWIN32_STREAM_ID {
62 int32_t dwStreamAttributes;
64 int32_t dwStreamNameSize;
65 } BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
68 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
71 BWIN32_STREAM_ID header_stream;
72 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
74 /* =======================================================
78 * =======================================================
80 #if defined(HAVE_WIN32)
84 BF_READ, /* BackupRead */
85 BF_WRITE /* BackupWrite */
90 /* Basic Win32 low level I/O file packet */
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 */
108 HANDLE bget_handle(BFILE *bfd);
110 #else /* Linux/Unix systems */
112 /* =======================================================
116 * =======================================================
119 /* Basic Unix low level I/O file packet */
121 int fid; /* file id on Unix */
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 */
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);
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);
152 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
154 #endif /* __BFILE_H */