]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
eba40823446a1fbcd0f3fa452293cf7ed7f37b1e
[bacula/bacula] / bacula / src / findlib / bfile.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 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
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.
34  */
35
36 #define WIN32_BACKUP_DATA 1
37
38 typedef struct _BWIN32_STREAM_ID {
39         int32_t        dwStreamId;
40         int32_t        dwStreamAttributes;
41         int64_t        Size;
42         int32_t        dwStreamNameSize;
43 } BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
44
45
46 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
47         int64_t          liNextHeader;
48         bool             bIsInData;
49         BWIN32_STREAM_ID header_stream;
50 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
51
52 /*  =======================================================
53  *
54  *   W I N D O W S
55  *
56  *  =======================================================
57  */
58 #ifdef HAVE_WIN32
59
60 enum {
61    BF_CLOSED,
62    BF_READ,                           /* BackupRead */
63    BF_WRITE                           /* BackupWrite */
64 };
65
66 /* In bfile.c */
67
68 /* Basic Win32 low level I/O file packet */
69 class BFILE {
70 public:
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;
90 };
91
92 /* Windows encrypted file system */
93 inline const bool BFILE::is_encrypted() const
94   { return (fattrs & FILE_ATTRIBUTE_ENCRYPTED) != 0; };
95
96 HANDLE bget_handle(BFILE *bfd);
97
98
99 #else   /* Linux/Unix systems */
100
101 /*  =======================================================
102  *
103  *   U N I X
104  *
105  *  =======================================================
106  */
107
108 /* Basic Unix low level I/O file packet */
109 struct BFILE {
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 */
122 };
123
124 #endif
125
126 void    binit(BFILE *bfd);
127 bool    is_bopen(BFILE *bfd);
128 #ifdef HAVE_WIN32
129 void    set_fattrs(BFILE *bfd, struct stat *statp);
130 #else
131 #define set_fattrs(bfd, fattrs)
132 #endif
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);
147
148 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
149
150 #endif /* __BFILE_H */