llong.c

Go to the documentation of this file.
00001 #include "sysincludes.h"
00002 #include "stream.h"
00003 #include "fsP.h"
00004 #include "llong.h"
00005 #include "mtools.h"
00006 
00007 /* Warnings about integer overflow in expression can be ignored.  These are
00008  * due to the way that maximal values for those integers are computed: 
00009  * intentional overflow from smallest negative number (1000...) to highest 
00010  * positive number (0111...) by substraction of 1 */
00011 #ifdef __GNUC__
00012 /*
00013 #warning "The following warnings about integer overflow in expression can be safely ignored"
00014 */
00015 #endif
00016 
00017 #if 1
00018 const mt_off_t max_off_t_31 = MAX_OFF_T_B(31); /* Floppyd */
00019 const mt_off_t max_off_t_41 = MAX_OFF_T_B(41); /* SCSI */
00020 const mt_off_t max_off_t_seek = MAX_OFF_T_B(SEEK_BITS); /* SCSI */
00021 #else
00022 const mt_off_t max_off_t_31 = MAX_OFF_T_B(10); /* Floppyd */
00023 const mt_off_t max_off_t_41 = MAX_OFF_T_B(10); /* SCSI */
00024 const mt_off_t max_off_t_seek = MAX_OFF_T_B(10); /* SCSI */
00025 #endif
00026 
00027 off_t truncBytes32(mt_off_t off)
00028 {
00029         if (off & ~max_off_t_31) {
00030                 fprintf(stderr, "Internal error, offset too big\n");
00031                 exit(1);
00032         }
00033         return (off_t) off;
00034 }
00035 
00036 mt_off_t sectorsToBytes(Stream_t *Stream, off_t off)
00037 {
00038         DeclareThis(Fs_t);
00039         return (mt_off_t) off << This->sectorShift;
00040 }
00041 
00042 #if defined HAVE_LLSEEK
00043 # ifndef HAVE_LLSEEK_PROTOTYPE
00044 extern long long llseek (int fd, long long offset, int origin);
00045 # endif
00046 #endif
00047 
00048 #if defined HAVE_LSEEK64
00049 # ifndef HAVE_LSEEK64_PROTOTYPE
00050 extern long long lseek64 (int fd, long long offset, int origin);
00051 # endif
00052 #endif
00053 
00054 
00055 int mt_lseek(int fd, mt_off_t where, int whence)
00056 {
00057 #if defined HAVE_LSEEK64
00058         if(lseek64(fd, where, whence) >= 0)
00059                 return 0;
00060         else
00061                 return -1;
00062 #elif defined HAVE_LLSEEK
00063         if(llseek(fd, where, whence) >= 0)
00064                 return 0;
00065         else
00066                 return -1;              
00067 #else
00068         if (lseek(fd, (off_t) where, whence) >= 0)
00069                 return 0;
00070         else
00071                 return 1;
00072 #endif
00073 }
00074 
00075 int log_2(int size)
00076 {
00077         int i;
00078 
00079         for(i=0; i<24; i++) {
00080                 if(1 << i == size)
00081                         return i;
00082         }
00083         return 24;
00084 }

Generated on Fri Apr 14 22:56:55 2006 for minix by  doxygen 1.4.6