]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / findlib / bfile.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2018 Kern Sibbald
5
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.
8
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.
13
14    This notice must be preserved when any source code is 
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
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.
23  *
24  *     Kern Sibbald May MMIII
25  */
26
27 #ifndef __BFILE_H
28 #define __BFILE_H
29
30 #include "win32filter.h"
31
32 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
33         int64_t          liNextHeader;
34         bool             bIsInData;
35         BWIN32_STREAM_ID header_stream;
36 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
37
38 /*  =======================================================
39  *
40  *   W I N D O W S
41  *
42  *  =======================================================
43  */
44 #ifdef HAVE_WIN32
45
46 enum {
47    BF_CLOSED,
48    BF_READ,                           /* BackupRead */
49    BF_WRITE                           /* BackupWrite */
50 };
51
52 /* In bfile.c */
53
54 /* Basic Win32 low level I/O file packet */
55 class BFILE {
56 public:
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;
77 };
78
79 /* Windows encrypted file system */
80 inline const bool BFILE::is_encrypted() const
81   { return (fattrs & FILE_ATTRIBUTE_ENCRYPTED) != 0; };
82
83 HANDLE bget_handle(BFILE *bfd);
84
85
86 #else   /* Linux/Unix systems */
87
88 /*  =======================================================
89  *
90  *   U N I X
91  *
92  *  =======================================================
93  */
94
95 /* Basic Unix low level I/O file packet */
96 struct BFILE {
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 */
109 };
110
111 #endif
112
113 void    binit(BFILE *bfd);
114 bool    is_bopen(BFILE *bfd);
115 #ifdef HAVE_WIN32
116 void    set_fattrs(BFILE *bfd, struct stat *statp);
117 #else
118 #define set_fattrs(bfd, fattrs)
119 #endif
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);
134
135 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
136
137 #endif /* __BFILE_H */