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 Copyright (C) 2003-2006 Kern Sibbald
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.
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.
27 #undef _POSIX_C_SOURCE
40 /* this should physically correspond to WIN32_STREAM_ID
41 * from winbase.h on Win32. We didn't inlcude cStreamName
42 * as we don't use it and don't need it for a correct struct size.
45 #define WIN32_BACKUP_DATA 1
47 typedef struct _BWIN32_STREAM_ID {
49 int32_t dwStreamAttributes;
51 int32_t dwStreamNameSize;
52 } BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
55 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
58 BWIN32_STREAM_ID header_stream;
59 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
61 /* =======================================================
65 * =======================================================
67 #if defined(HAVE_WIN32)
71 BF_READ, /* BackupRead */
72 BF_WRITE /* BackupWrite */
77 /* Basic Win32 low level I/O file packet */
79 bool use_backup_api; /* set if using BackupRead/Write */
80 int mode; /* set if file is open */
81 HANDLE fh; /* Win32 file handle */
82 int fid; /* fd if doing Unix style */
83 LPVOID lpContext; /* BackupRead/Write context */
84 POOLMEM *errmsg; /* error message buffer */
85 DWORD rw_bytes; /* Bytes read or written */
86 DWORD lerror; /* Last error code */
87 int berrno; /* errno */
88 char *prog; /* reader/writer program if any */
89 JCR *jcr; /* jcr for editing job codes */
90 Python_IO pio; /* Python I/O routines */
91 PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
92 int use_backup_decomp; /* set if using BackupRead Stream Decomposition */
95 HANDLE bget_handle(BFILE *bfd);
97 #else /* Linux/Unix systems */
99 /* =======================================================
103 * =======================================================
106 /* Basic Unix low level I/O file packet */
108 int fid; /* file id on Unix */
110 char *prog; /* reader/writer program if any */
111 JCR *jcr; /* jcr for editing job codes */
112 Python_IO pio; /* Python I/O routines */
113 PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
114 int use_backup_decomp; /* set if using BackupRead Stream Decomposition */
119 void binit(BFILE *bfd);
120 bool is_bopen(BFILE *bfd);
121 bool set_win32_backup(BFILE *bfd);
122 bool set_portable_backup(BFILE *bfd);
123 bool set_prog(BFILE *bfd, char *prog, JCR *jcr);
124 bool have_win32_api();
125 bool is_portable_backup(BFILE *bfd);
126 bool is_restore_stream_supported(int stream);
127 bool is_win32_stream(int stream);
128 char *xberror(BFILE *bfd); /* DO NOT USE -- use berrno class */
129 int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
130 #ifdef HAVE_DARWIN_OS
131 int bopen_rsrc(BFILE *bfd, const char *fname, int flags, mode_t mode);
133 int bclose(BFILE *bfd);
134 ssize_t bread(BFILE *bfd, void *buf, size_t count);
135 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
136 off_t blseek(BFILE *bfd, off_t offset, int whence);
137 const char *stream_to_ascii(int stream);
139 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
141 #endif /* __BFILE_H */