]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
a727a141e7d4e0996523cb078cfb56ba4a70d49f
[bacula/bacula] / bacula / src / findlib / bfile.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2003-2010 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *  Bacula low level File I/O routines.  This routine simulates
30  *    open(), read(), write(), and close(), but using native routines.
31  *    I.e. on Windows, we use Windows APIs.
32  *
33  *     Kern Sibbald May MMIII
34  */
35
36 #ifndef __BFILE_H
37 #define __BFILE_H
38
39
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.
43  */
44
45 #define WIN32_BACKUP_DATA 1
46
47 typedef struct _BWIN32_STREAM_ID {
48         int32_t        dwStreamId;
49         int32_t        dwStreamAttributes;
50         int64_t        Size;
51         int32_t        dwStreamNameSize;        
52 } BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
53
54
55 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
56         int64_t          liNextHeader;
57         bool             bIsInData;
58         BWIN32_STREAM_ID header_stream;        
59 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
60
61 /*  =======================================================
62  *
63  *   W I N D O W S
64  *
65  *  =======================================================
66  */
67 #if defined(HAVE_WIN32)
68
69 enum {
70    BF_CLOSED,
71    BF_READ,                           /* BackupRead */
72    BF_WRITE                           /* BackupWrite */
73 };
74
75 /* In bfile.c */
76
77 /* Basic Win32 low level I/O file packet */
78 struct BFILE {
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    bofset_t offset;                   /* Delta offset */
89    JCR *jcr;                          /* jcr for editing job codes */
90    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
91    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
92    bool reparse_point;                /* set if reparse point */ 
93    bool cmd_plugin;                   /* set if we have a command plugin */
94 };
95
96 HANDLE bget_handle(BFILE *bfd);
97
98 #else   /* Linux/Unix systems */
99
100 /*  =======================================================
101  *
102  *   U N I X
103  *
104  *  =======================================================
105  */
106
107 /* Basic Unix low level I/O file packet */
108 struct BFILE {
109    int fid;                           /* file id on Unix */
110    int m_flags;                       /* open flags */
111    int berrno;                        /* errno */
112    int32_t lerror;                    /* not used - simplies Win32 builds */
113    boffset_t offset;                  /* Delta offset */
114    JCR *jcr;                          /* jcr for editing job codes */
115    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
116    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
117    bool reparse_point;                /* not used in Unix */
118    bool cmd_plugin;                   /* set if we have a command plugin */
119 };
120
121 #endif
122
123 void    binit(BFILE *bfd);
124 bool    is_bopen(BFILE *bfd);
125 bool    set_win32_backup(BFILE *bfd);
126 bool    set_portable_backup(BFILE *bfd);
127 bool    set_cmd_plugin(BFILE *bfd, JCR *jcr);
128 bool    have_win32_api();
129 bool    is_portable_backup(BFILE *bfd);
130 bool    is_restore_stream_supported(int stream);
131 bool    is_win32_stream(int stream);
132 char   *xberror(BFILE *bfd);          /* DO NOT USE  -- use berrno class */
133 int     bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
134 int     bopen_rsrc(BFILE *bfd, const char *fname, int flags, mode_t mode);
135 int     bclose(BFILE *bfd);
136 ssize_t bread(BFILE *bfd, void *buf, size_t count);
137 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
138 boffset_t blseek(BFILE *bfd, boffset_t offset, int whence);
139 const char   *stream_to_ascii(int stream);
140
141 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
142
143 #endif /* __BFILE_H */