2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 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
31 /* this should physically correspond to WIN32_STREAM_ID
32 * from winbase.h on Win32. We didn't inlcude cStreamName
33 * as we don't use it and don't need it for a correct struct size.
36 #define WIN32_BACKUP_DATA 1
38 typedef struct _BWIN32_STREAM_ID {
40 int32_t dwStreamAttributes;
42 int32_t dwStreamNameSize;
43 } BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
46 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
49 BWIN32_STREAM_ID header_stream;
50 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
52 /* =======================================================
56 * =======================================================
62 BF_READ, /* BackupRead */
63 BF_WRITE /* BackupWrite */
68 /* Basic Win32 low level I/O file packet */
71 bool use_backup_api; /* set if using BackupRead/Write */
72 int mode; /* set if file is open */
73 HANDLE fh; /* Win32 file handle */
74 int fid; /* fd if doing Unix style */
75 LPVOID lpContext; /* BackupRead/Write context */
76 POOLMEM *errmsg; /* error message buffer */
77 DWORD rw_bytes; /* Bytes read or written */
78 DWORD lerror; /* Last error code */
79 DWORD fattrs; /* Windows file attributes */
80 int berrno; /* errno */
81 int block; /* Count of read/writes */
82 uint64_t total_bytes; /* bytes written */
83 boffset_t offset; /* Delta offset */
84 JCR *jcr; /* jcr for editing job codes */
85 PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
86 int use_backup_decomp; /* set if using BackupRead Stream Decomposition */
87 bool reparse_point; /* set if reparse point */
88 bool cmd_plugin; /* set if we have a command plugin */
89 bool const is_encrypted() const;
92 /* Windows encrypted file system */
93 inline const bool BFILE::is_encrypted() const
94 { return (fattrs & FILE_ATTRIBUTE_ENCRYPTED) != 0; };
96 HANDLE bget_handle(BFILE *bfd);
99 #else /* Linux/Unix systems */
101 /* =======================================================
105 * =======================================================
108 /* Basic Unix low level I/O file packet */
110 int fid; /* file id on Unix */
111 int berrno; /* errno */
112 int32_t lerror; /* not used - simplies Win32 builds */
113 int block; /* Count of read/writes */
114 uint64_t m_flags; /* open flags */
115 uint64_t total_bytes; /* bytes written */
116 boffset_t offset; /* Delta offset */
117 JCR *jcr; /* jcr for editing job codes */
118 PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
119 int use_backup_decomp; /* set if using BackupRead Stream Decomposition */
120 bool reparse_point; /* not used in Unix */
121 bool cmd_plugin; /* set if we have a command plugin */
126 void binit(BFILE *bfd);
127 bool is_bopen(BFILE *bfd);
129 void set_fattrs(BFILE *bfd, struct stat *statp);
131 #define set_fattrs(bfd, fattrs)
133 bool set_win32_backup(BFILE *bfd);
134 bool set_portable_backup(BFILE *bfd);
135 bool set_cmd_plugin(BFILE *bfd, JCR *jcr);
136 bool have_win32_api();
137 bool is_portable_backup(BFILE *bfd);
138 bool is_restore_stream_supported(int stream);
139 bool is_win32_stream(int stream);
140 int bopen(BFILE *bfd, const char *fname, uint64_t flags, mode_t mode);
141 int bopen_rsrc(BFILE *bfd, const char *fname, uint64_t flags, mode_t mode);
142 int bclose(BFILE *bfd);
143 ssize_t bread(BFILE *bfd, void *buf, size_t count);
144 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
145 boffset_t blseek(BFILE *bfd, boffset_t offset, int whence);
146 const char *stream_to_ascii(int stream);
148 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
150 #endif /* __BFILE_H */