]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
This commit was manufactured by cvs2svn to create tag
[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) 2000-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 as
13    published by the Free Software Foundation; either version 2 of
14    the License, or (at your option) any later version.
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 GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public
22    License along with this program; if not, write to the Free
23    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24    MA 02111-1307, USA.
25
26  */
27
28 #ifndef __BFILE_H
29 #define __BFILE_H
30
31 #ifdef HAVE_PYTHON
32 #undef _POSIX_C_SOURCE
33 #include <Python.h>
34 struct Python_IO {
35    PyObject *fo;
36    PyObject *fr;
37    PyObject *fc;
38 };
39 #else
40 struct Python_IO {
41 };
42 #endif
43
44 /*  =======================================================
45  *
46  *   W I N D O W S
47  *
48  *  =======================================================
49  */
50 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
51
52 #include <windows.h>
53 #include "../lib/winapi.h"
54
55 enum {
56    BF_CLOSED,
57    BF_READ,                           /* BackupRead */
58    BF_WRITE                           /* BackupWrite */
59 };
60
61 /* In bfile.c */
62
63 /* Basic Win32 low level I/O file packet */
64 struct BFILE {
65    int use_backup_api;                /* set if using BackupRead/Write */
66    int mode;                          /* set if file is open */
67    HANDLE fh;                         /* Win32 file handle */
68    int fid;                           /* fd if doing Unix style */
69    LPVOID lpContext;                  /* BackupRead/Write context */
70    POOLMEM *errmsg;                   /* error message buffer */
71    DWORD rw_bytes;                    /* Bytes read or written */
72    DWORD lerror;                      /* Last error code */
73    int berrno;                        /* errno */
74    char *prog;                        /* reader/writer program if any */
75    JCR *jcr;                          /* jcr for editing job codes */
76    Python_IO pio;                     /* Python I/O routines */
77 };
78
79 HANDLE bget_handle(BFILE *bfd);
80
81 #else   /* Linux/Unix systems */
82
83 /*  =======================================================
84  *
85  *   U N I X
86  *
87  *  =======================================================
88  */
89
90 /* Basic Unix low level I/O file packet */
91 struct BFILE {
92    int fid;                           /* file id on Unix */
93    int berrno;
94    char *prog;                        /* reader/writer program if any */
95    JCR *jcr;                          /* jcr for editing job codes */
96    Python_IO pio;                     /* Python I/O routines */
97 };
98
99 #endif
100
101 void    binit(BFILE *bfd);
102 bool    is_bopen(BFILE *bfd);
103 bool    set_win32_backup(BFILE *bfd);
104 bool    set_portable_backup(BFILE *bfd);
105 bool    set_prog(BFILE *bfd, char *prog, JCR *jcr);
106 bool    have_win32_api();
107 bool    is_portable_backup(BFILE *bfd);
108 bool    is_restore_stream_supported(int stream);
109 bool    is_win32_stream(int stream);
110 char   *xberror(BFILE *bfd);          /* DO NOT USE  -- use berrno class */
111 int     bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
112 #ifdef HAVE_DARWIN_OS
113 int     bopen_rsrc(BFILE *bfd, const char *fname, int flags, mode_t mode);
114 #endif
115 int     bclose(BFILE *bfd);
116 ssize_t bread(BFILE *bfd, void *buf, size_t count);
117 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
118 off_t   blseek(BFILE *bfd, off_t offset, int whence);
119 const char   *stream_to_ascii(int stream);
120
121 #endif /* __BFILE_H */