1 /* Copyright 1999-2003,2006,2008,2009 Alain Knaff.
2 * This file is part of mtools.
4 * Mtools is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Mtools is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
18 #include "sysincludes.h"
25 const mt_off_t max_off_t_31 = MAX_OFF_T_B(31); /* Floppyd */
26 const mt_off_t max_off_t_32 = MAX_OFF_T_B(32); /* Directory */
27 const mt_off_t max_off_t_41 = MAX_OFF_T_B(41); /* SCSI */
28 const mt_off_t max_off_t_seek = MAX_OFF_T_B(SEEK_BITS); /* SCSI */
30 const mt_off_t max_off_t_31 = MAX_OFF_T_B(10); /* Floppyd */
31 const mt_off_t max_off_t_41 = MAX_OFF_T_B(10); /* SCSI */
32 const mt_off_t max_off_t_seek = MAX_OFF_T_B(10); /* SCSI */
35 int fileTooBig(mt_off_t off) {
36 return (off & ~max_off_t_32) != 0;
39 off_t truncBytes32(mt_off_t off)
41 if (fileTooBig(off)) {
42 fprintf(stderr, "Internal error, offset too big\n");
48 mt_off_t sectorsToBytes(Stream_t *Stream, off_t off)
51 return (mt_off_t) off << This->sectorShift;
54 #if defined HAVE_LLSEEK
55 # ifndef HAVE_LLSEEK_PROTOTYPE
56 extern long long llseek (int fd, long long offset, int origin);
60 #if defined HAVE_LSEEK64
61 # ifndef HAVE_LSEEK64_PROTOTYPE
62 extern long long lseek64 (int fd, long long offset, int origin);
67 int mt_lseek(int fd, mt_off_t where, int whence)
69 #if defined HAVE_LSEEK64
70 if(lseek64(fd, where, whence) >= 0)
74 #elif defined HAVE_LLSEEK
75 if(llseek(fd, where, whence) >= 0)
80 if (lseek(fd, (off_t) where, whence) >= 0)
87 unsigned int log_2(int size)