Initial import package mtools: Programs for accessing MS-DOS disks without mounting...
[profile/ivi/mtools.git] / llong.h
1 #ifndef MTOOLS_LLONG_H
2 #define MTOOLS_LLONG_H
3
4 /*  Copyright 1999,2001-2004,2007-2009 Alain Knaff.
5  *  This file is part of mtools.
6  *
7  *  Mtools is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  Mtools is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with Mtools.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #if 1
22
23
24 #ifdef HAVE_OFF_T_64
25 /* if off_t is already 64 bits, be happy, and don't worry about the
26  * loff_t and llseek stuff */
27 #define MT_OFF_T off_t
28 #define MT_SIZE_T size_t
29 #endif
30
31 #ifndef MT_OFF_T
32 # if defined(HAVE_LLSEEK) || defined(HAVE_LSEEK64)
33 /* we have llseek. Now, what's its type called? loff_t or offset_t ? */
34 #  ifdef HAVE_LOFF_T
35 #   define MT_OFF_T loff_t
36 /* use the same type for size. Better to get signedness wrong than width */
37 #   define MT_SIZE_T loff_t
38 #  else
39 #   ifdef HAVE_OFFSET_T
40 #    define MT_OFF_T offset_t
41 /* use the same type for size. Better to get signedness wrong than width */
42 #    define MT_SIZE_T offset_t
43 #   endif
44 #  endif
45 # endif
46 #endif
47
48 #ifndef MT_OFF_T
49 /* we still don't have a suitable mt_off_t type...*/
50 # ifdef HAVE_LONG_LONG
51 /* ... first try long long ... */
52 #  define MT_OFF_T long long
53 #  define MT_SIZE_T unsigned long long
54 # else
55 #  ifdef HAVE_OFF64_T
56 #   define MT_OFF_T off64_t
57 #   define MT_SIZE_T off64_t
58 #  else
59 /* ... and if that fails, fall back on good ole' off_t */
60 #   define MT_OFF_T off_t
61 #   define MT_SIZE_T size_t
62 #  endif
63 # endif
64 #endif
65
66 typedef MT_OFF_T mt_off_t;
67 typedef MT_SIZE_T mt_size_t;
68
69 #else
70 /* testing: meant to flag dubious assignments between 32 bit length types
71  * and 64 bit ones */
72 typedef struct {
73         unsigned int lo;
74         int high;
75 } *mt_off_t;
76
77 typedef struct {
78         unsigned int lo;
79         unsigned int high;
80 } *mt_size_t;
81
82 #endif
83
84 #define min(a,b) ((a) < (b) ? (a) : (b))
85 #define MAX_OFF_T_B(bits) \
86         ((((mt_off_t) 1 << min(bits-1, sizeof(mt_off_t)*8 - 2)) -1) << 1 | 1)
87
88 #if defined(HAVE_LLSEEK) || defined(HAVE_LSEEK64)
89 # define SEEK_BITS 63
90 #else
91 # define SEEK_BITS (sizeof(off_t) * 8 - 1)
92 #endif
93
94 extern const mt_off_t max_off_t_31;
95 extern const mt_off_t max_off_t_41;
96 extern const mt_off_t max_off_t_seek;
97
98 extern off_t truncBytes32(mt_off_t off);
99 extern int fileTooBig(mt_off_t off);
100 mt_off_t sectorsToBytes(Stream_t *This, off_t off);
101
102 mt_size_t getfree(Stream_t *Stream);
103 int getfreeMinBytes(Stream_t *Stream, mt_size_t ref);
104
105 Stream_t *find_device(char drive, int mode, struct device *out_dev,
106                       union bootsector *boot,
107                       char *name, int *media, mt_size_t *maxSize,
108                       int *isRop);
109
110 int mt_lseek(int fd, mt_off_t where, int whence);
111
112
113 unsigned int log_2(int);
114
115 #endif