]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/bfile.h
Backport from BEE
[bacula/bacula] / bacula / src / findlib / bfile.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2003-2014 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from many
7    others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    Bacula® is a registered trademark of Kern Sibbald.
15 */
16 /*
17  *  Bacula low level File I/O routines.  This routine simulates
18  *    open(), read(), write(), and close(), but using native routines.
19  *    I.e. on Windows, we use Windows APIs.
20  *
21  *     Kern Sibbald May MMIII
22  */
23
24 #ifndef __BFILE_H
25 #define __BFILE_H
26
27
28 /* this should physically correspond to WIN32_STREAM_ID
29  * from winbase.h on Win32. We didn't inlcude cStreamName
30  * as we don't use it and don't need it for a correct struct size.
31  */
32
33 #define WIN32_BACKUP_DATA 1
34
35 typedef struct _BWIN32_STREAM_ID {
36         int32_t        dwStreamId;
37         int32_t        dwStreamAttributes;
38         int64_t        Size;
39         int32_t        dwStreamNameSize;
40 } BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
41
42
43 typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
44         int64_t          liNextHeader;
45         bool             bIsInData;
46         BWIN32_STREAM_ID header_stream;
47 } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
48
49 /*  =======================================================
50  *
51  *   W I N D O W S
52  *
53  *  =======================================================
54  */
55 #if defined(HAVE_WIN32)
56
57 enum {
58    BF_CLOSED,
59    BF_READ,                           /* BackupRead */
60    BF_WRITE                           /* BackupWrite */
61 };
62
63 /* In bfile.c */
64
65 /* Basic Win32 low level I/O file packet */
66 struct BFILE {
67    bool use_backup_api;               /* set if using BackupRead/Write */
68    int mode;                          /* set if file is open */
69    HANDLE fh;                         /* Win32 file handle */
70    int fid;                           /* fd if doing Unix style */
71    LPVOID lpContext;                  /* BackupRead/Write context */
72    POOLMEM *errmsg;                   /* error message buffer */
73    DWORD rw_bytes;                    /* Bytes read or written */
74    DWORD lerror;                      /* Last error code */
75    int berrno;                        /* errno */
76    int block;                         /* Count of read/writes */
77    uint64_t total_bytes;              /* bytes written */
78    boffset_t offset;                  /* Delta offset */
79    JCR *jcr;                          /* jcr for editing job codes */
80    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
81    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
82    bool reparse_point;                /* set if reparse point */
83    bool cmd_plugin;                   /* set if we have a command plugin */
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;                        /* errno */
101    int32_t lerror;                    /* not used - simplies Win32 builds */
102    int block;                         /* Count of read/writes */
103    uint64_t m_flags;                  /* open flags */
104    uint64_t total_bytes;              /* bytes written */
105    boffset_t offset;                  /* Delta offset */
106    JCR *jcr;                          /* jcr for editing job codes */
107    PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */
108    int use_backup_decomp;             /* set if using BackupRead Stream Decomposition */
109    bool reparse_point;                /* not used in Unix */
110    bool cmd_plugin;                   /* set if we have a command plugin */
111 };
112
113 #endif
114
115 void    binit(BFILE *bfd);
116 bool    is_bopen(BFILE *bfd);
117 bool    set_win32_backup(BFILE *bfd);
118 bool    set_portable_backup(BFILE *bfd);
119 bool    set_cmd_plugin(BFILE *bfd, JCR *jcr);
120 bool    have_win32_api();
121 bool    is_portable_backup(BFILE *bfd);
122 bool    is_restore_stream_supported(int stream);
123 bool    is_win32_stream(int stream);
124 int     bopen(BFILE *bfd, const char *fname, uint64_t flags, mode_t mode);
125 int     bopen_rsrc(BFILE *bfd, const char *fname, uint64_t flags, mode_t mode);
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 boffset_t blseek(BFILE *bfd, boffset_t offset, int whence);
130 const char   *stream_to_ascii(int stream);
131
132 bool processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, ssize_t dwSize);
133
134 #endif /* __BFILE_H */