]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
a3ac4e733b0a98bd902df445dff34fc9129a4282
[bacula/bacula] / bacula / src / findlib / bfile.h
1 /*
2  *  Bacula low level File I/O routines.  This routine simulates
3  *    open(), read(), write(), and close(), but using native routines.
4  *    I.e. on Windows, we use Windows APIs.
5  *
6  *     Kern Sibbald May MMIII
7  */
8 /*
9    Copyright (C) 2003-2005 Kern Sibbald
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License
13    version 2 as amended with additional clauses defined in the
14    file LICENSE in the main source directory.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
19    the file LICENSE for additional details.
20
21  */
22
23 #ifndef __BFILE_H
24 #define __BFILE_H
25
26 #ifdef HAVE_PYTHON
27 #undef _POSIX_C_SOURCE
28 #include <Python.h>
29 struct Python_IO {
30    PyObject *fo;
31    PyObject *fr;
32    PyObject *fc;
33 };
34 #else
35 struct Python_IO {
36 };
37 #endif
38
39 #ifdef USE_WIN32STREAMEXTRACTION
40 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
41         LONGLONG        liNextHeader;
42         BOOL            bIsInData;
43         WIN32_STREAM_ID header_stream;        
44 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
45 #endif
46
47 /*  =======================================================
48  *
49  *   W I N D O W S
50  *
51  *  =======================================================
52  */
53 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
54
55 #include <windows.h>
56 #include "../lib/winapi.h"
57
58 enum {
59    BF_CLOSED,
60    BF_READ,                           /* BackupRead */
61    BF_WRITE                           /* BackupWrite */
62 };
63
64 /* In bfile.c */
65
66 /* Basic Win32 low level I/O file packet */
67 struct BFILE {
68    int use_backup_api;                /* set if using BackupRead/Write */
69    int mode;                          /* set if file is open */
70    HANDLE fh;                         /* Win32 file handle */
71    int fid;                           /* fd if doing Unix style */
72    LPVOID lpContext;                  /* BackupRead/Write context */
73    POOLMEM *errmsg;                   /* error message buffer */
74    DWORD rw_bytes;                    /* Bytes read or written */
75    DWORD lerror;                      /* Last error code */
76    int berrno;                        /* errno */
77    char *prog;                        /* reader/writer program if any */
78    JCR *jcr;                          /* jcr for editing job codes */
79    Python_IO pio;                     /* Python I/O routines */
80 #ifdef USE_WIN32STREAMEXTRACTION
81    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
82    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
83 #endif
84 };
85
86 HANDLE bget_handle(BFILE *bfd);
87
88 #else   /* Linux/Unix systems */
89
90 /*  =======================================================
91  *
92  *   U N I X
93  *
94  *  =======================================================
95  */
96
97 /* Basic Unix low level I/O file packet */
98 struct BFILE {
99    int fid;                           /* file id on Unix */
100    int berrno;
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 #ifdef USE_WIN32STREAMEXTRACTION
105    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
106    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
107 #endif
108 };
109
110 #endif
111
112 void    binit(BFILE *bfd);
113 bool    is_bopen(BFILE *bfd);
114 bool    set_win32_backup(BFILE *bfd);
115 bool    set_portable_backup(BFILE *bfd);
116 bool    set_prog(BFILE *bfd, char *prog, JCR *jcr);
117 bool    have_win32_api();
118 bool    is_portable_backup(BFILE *bfd);
119 bool    is_stream_supported(int stream);
120 bool    is_win32_stream(int stream);
121 char   *xberror(BFILE *bfd);          /* DO NOT USE  -- use berrno class */
122 int     bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
123 #ifdef HAVE_DARWIN_OS
124 int     bopen_rsrc(BFILE *bfd, const char *fname, int flags, mode_t mode);
125 #endif
126 int     bclose(BFILE *bfd);
127 ssize_t bread(BFILE *bfd, void *buf, size_t count);
128 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
129 off_t   blseek(BFILE *bfd, off_t offset, int whence);
130 const char   *stream_to_ascii(int stream);
131
132 #ifdef USE_WIN32STREAMEXTRACTION
133 BOOL processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, size_t dwSize);
134 #endif
135
136 #endif /* __BFILE_H */