4 /* Copyright 1999,2001-2004,2007-2009 Alain Knaff.
5 * This file is part of mtools.
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.
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.
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/>.
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
32 # if defined(HAVE_LLSEEK) || defined(HAVE_LSEEK64)
33 /* we have llseek. Now, what's its type called? loff_t or offset_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
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
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
56 # define MT_OFF_T off64_t
57 # define MT_SIZE_T off64_t
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
66 typedef MT_OFF_T mt_off_t;
67 typedef MT_SIZE_T mt_size_t;
70 /* testing: meant to flag dubious assignments between 32 bit length types
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)
88 #if defined(HAVE_LLSEEK) || defined(HAVE_LSEEK64)
91 # define SEEK_BITS (sizeof(off_t) * 8 - 1)
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;
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);
102 mt_size_t getfree(Stream_t *Stream);
103 int getfreeMinBytes(Stream_t *Stream, mt_size_t ref);
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,
110 int mt_lseek(int fd, mt_off_t where, int whence);
113 unsigned int log_2(int);