]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
First cut berrno unified Unix/Win32 errno handling
[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-2004 Kern Sibbald and John Walker
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 /*  =======================================================
32  *
33  *   W I N D O W S 
34  *
35  *  =======================================================
36  */
37 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
38
39 #include <windows.h>
40 #include "winapi.h"
41
42 enum {
43    BF_CLOSED,
44    BF_READ,                           /* BackupRead */
45    BF_WRITE                           /* BackupWrite */
46 };
47
48 /* In bfile.c */
49
50 /* Basic low level I/O file packet */
51 struct BFILE {
52    int use_backup_api;                /* set if using BackupRead/Write */
53    int mode;                          /* set if file is open */
54    HANDLE fh;                         /* Win32 file handle */
55    int fid;                           /* fd if doing Unix style */
56    LPVOID lpContext;                  /* BackupRead/Write context */
57    POOLMEM *errmsg;                   /* error message buffer */
58    DWORD rw_bytes;                    /* Bytes read or written */
59    DWORD lerror;                      /* Last error code */
60    int berrno;                        /* errno */
61 };      
62
63 HANDLE bget_handle(BFILE *bfd);
64
65 #else   /* Linux/Unix systems */
66
67 /*  =======================================================
68  *
69  *   U N I X 
70  *
71  *  =======================================================
72  */
73
74 /* Basic low level I/O file packet */
75 struct BFILE {
76    int fid;                           /* file id on Unix */
77    int berrno;
78 };      
79
80 #endif
81
82 void    binit(BFILE *bfd);
83 int     is_bopen(BFILE *bfd);
84 int     set_win32_backup(BFILE *bfd);
85 int     set_portable_backup(BFILE *bfd);
86 int     have_win32_api();
87 int     is_portable_backup(BFILE *bfd);
88 int     is_stream_supported(int stream);
89 int     is_win32_stream(int stream);
90 char   *berror(BFILE *bfd);
91 int     bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
92 int     bclose(BFILE *bfd);
93 ssize_t bread(BFILE *bfd, void *buf, size_t count);
94 ssize_t bwrite(BFILE *bfd, void *buf, size_t count);
95 off_t   blseek(BFILE *bfd, off_t offset, int whence);
96 const char   *stream_to_ascii(int stream);
97
98 #endif /* __BFILE_H */