2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2018 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Bacula low level File I/O routines. This routine simulates
21 * open(), read(), write(), and close(), but using native routines.
22 * I.e. on Windows, we use Windows APIs.
24 * Kern Sibbald May MMIII
30 #include "win32filter.h"
32 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
35 BWIN32_STREAM_ID header_stream;
36 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
38 /* =======================================================
42 * =======================================================
48 BF_READ, /* BackupRead */
49 BF_WRITE /* BackupWrite */
54 /* Basic Win32 low level I/O file packet */
57 bool use_backup_api; /* set if using BackupRead/Write */
58 int mode; /* set if file is open */
59 HANDLE fh; /* Win32 file handle */
60 int fid; /* fd if doing Unix style */
61 LPVOID lpContext; /* BackupRead/Write context */
62 PVOID pvContext; /* Windows encryption (EFS) context */
63 POOLMEM *errmsg; /* error message buffer */
64 DWORD rw_bytes; /* Bytes read or written */
65 DWORD lerror; /* Last error code */
66 DWORD fattrs; /* Windows file attributes */
67 int berrno; /* errno */
68 int block; /* Count of read/writes */
69 uint64_t total_bytes; /* bytes written */
70 boffset_t offset; /* Delta offset */
71 JCR *jcr; /* jcr for editing job codes */
72 Win32Filter win32filter; /* context for decomposition of win32 backup streams */
73 int use_backup_decomp; /* set if using BackupRead Stream Decomposition */
74 bool reparse_point; /* set if reparse point */
75 bool cmd_plugin; /* set if we have a command plugin */
76 bool const is_encrypted() const;
79 /* Windows encrypted file system */
80 inline const bool BFILE::is_encrypted() const
81 { return (fattrs & FILE_ATTRIBUTE_ENCRYPTED) != 0; };
83 HANDLE bget_handle(BFILE *bfd);
86 #else /* Linux/Unix systems */
88 /* =======================================================
92 * =======================================================
95 /* Basic Unix low level I/O file packet */
97 int fid; /* file id on Unix */
98 int berrno; /* errno */
99 int32_t lerror; /* not used - simplies Win32 builds */
100 int block; /* Count of read/writes */
101 uint64_t m_flags; /* open flags */
102 uint64_t total_bytes; /* bytes written */
103 boffset_t offset; /* Delta offset */
104 JCR *jcr; /* jcr for editing job codes */
105 Win32Filter win32filter; /* context for decomposition of win32 backup streams */
106 int use_backup_decomp; /* set if using BackupRead Stream Decomposition */
107 bool reparse_point; /* not used in Unix */
108 bool cmd_plugin; /* set if we have a command plugin */
113 void binit(BFILE *bfd);
114 bool is_bopen(BFILE *bfd);
116 void set_fattrs(BFILE *bfd, struct stat *statp);
118 #define set_fattrs(bfd, fattrs)
120 bool set_win32_backup(BFILE *bfd);
121 bool set_portable_backup(BFILE *bfd);
122 bool set_cmd_plugin(BFILE *bfd, JCR *jcr);
123 bool have_win32_api();
124 bool is_portable_backup(BFILE *bfd);
125 bool is_restore_stream_supported(int stream);
126 bool is_win32_stream(int stream);
127 int bopen(BFILE *bfd, const char *fname, uint64_t flags, mode_t mode);
128 int bopen_rsrc(BFILE *bfd, const char *fname, uint64_t flags, mode_t mode);
129 int bclose(BFILE *bfd);
130 ssize_t bread(BFILE *bfd, void *buf, size_t count);
131 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
132 boffset_t blseek(BFILE *bfd, boffset_t offset, int whence);
133 const char *stream_to_ascii(int stream);
135 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
137 #endif /* __BFILE_H */