]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
kes Add code to tell the OS that we no longer need a cached
[bacula/bacula] / bacula / src / findlib / bfile.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2003-2007 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 two of the GNU General Public
10    License as published by the Free Software Foundation plus additions
11    that are listed 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 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 John Walker.
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 #ifdef HAVE_PYTHON
40 #undef _POSIX_C_SOURCE
41 #include <Python.h>
42 struct Python_IO {
43    PyObject *fo;
44    PyObject *fr;
45    PyObject *fc;
46 };
47 #else
48 struct Python_IO {
49 };
50 #endif
51
52
53 /* this should physically correspond to WIN32_STREAM_ID
54  * from winbase.h on Win32. We didn't inlcude cStreamName
55  * as we don't use it and don't need it for a correct struct size.
56  */
57
58 #define WIN32_BACKUP_DATA 1
59
60 typedef struct _BWIN32_STREAM_ID {
61         int32_t        dwStreamId;
62         int32_t        dwStreamAttributes;
63         int64_t        Size;
64         int32_t        dwStreamNameSize;        
65 } BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
66
67
68 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
69         int64_t          liNextHeader;
70         bool             bIsInData;
71         BWIN32_STREAM_ID header_stream;        
72 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
73
74 /*  =======================================================
75  *
76  *   W I N D O W S
77  *
78  *  =======================================================
79  */
80 #if defined(HAVE_WIN32)
81
82 enum {
83    BF_CLOSED,
84    BF_READ,                           /* BackupRead */
85    BF_WRITE                           /* BackupWrite */
86 };
87
88 /* In bfile.c */
89
90 /* Basic Win32 low level I/O file packet */
91 struct BFILE {
92    bool use_backup_api;               /* set if using BackupRead/Write */
93    int mode;                          /* set if file is open */
94    HANDLE fh;                         /* Win32 file handle */
95    int fid;                           /* fd if doing Unix style */
96    LPVOID lpContext;                  /* BackupRead/Write context */
97    POOLMEM *errmsg;                   /* error message buffer */
98    DWORD rw_bytes;                    /* Bytes read or written */
99    DWORD lerror;                      /* Last error code */
100    int berrno;                        /* errno */
101    char *prog;                        /* reader/writer program if any */
102    JCR *jcr;                          /* jcr for editing job codes */
103    Python_IO pio;                     /* Python I/O routines */
104    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
105    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
106 };
107
108 HANDLE bget_handle(BFILE *bfd);
109
110 #else   /* Linux/Unix systems */
111
112 /*  =======================================================
113  *
114  *   U N I X
115  *
116  *  =======================================================
117  */
118
119 /* Basic Unix low level I/O file packet */
120 struct BFILE {
121    int fid;                           /* file id on Unix */
122    int m_flags;                       /* open flags */
123    int berrno;
124    char *prog;                        /* reader/writer program if any */
125    JCR *jcr;                          /* jcr for editing job codes */
126    Python_IO pio;                     /* Python I/O routines */
127    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
128    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
129 };
130
131 #endif
132
133 void    binit(BFILE *bfd);
134 bool    is_bopen(BFILE *bfd);
135 bool    set_win32_backup(BFILE *bfd);
136 bool    set_portable_backup(BFILE *bfd);
137 bool    set_prog(BFILE *bfd, char *prog, JCR *jcr);
138 bool    have_win32_api();
139 bool    is_portable_backup(BFILE *bfd);
140 bool    is_restore_stream_supported(int stream);
141 bool    is_win32_stream(int stream);
142 char   *xberror(BFILE *bfd);          /* DO NOT USE  -- use berrno class */
143 int     bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
144 #ifdef HAVE_DARWIN_OS
145 int     bopen_rsrc(BFILE *bfd, const char *fname, int flags, mode_t mode);
146 #endif
147 int     bclose(BFILE *bfd);
148 ssize_t bread(BFILE *bfd, void *buf, size_t count);
149 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
150 boffset_t blseek(BFILE *bfd, boffset_t offset, int whence);
151 const char   *stream_to_ascii(int stream);
152
153 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
154
155 #endif /* __BFILE_H */