source: trunk/minix/commands/i386/mtools-3.9.7/llong.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.8 KB
Line 
1#include "sysincludes.h"
2#include "stream.h"
3#include "fsP.h"
4#include "llong.h"
5#include "mtools.h"
6
7/* Warnings about integer overflow in expression can be ignored. These are
8 * due to the way that maximal values for those integers are computed:
9 * intentional overflow from smallest negative number (1000...) to highest
10 * positive number (0111...) by substraction of 1 */
11#ifdef __GNUC__
12/*
13#warning "The following warnings about integer overflow in expression can be safely ignored"
14*/
15#endif
16
17#if 1
18const mt_off_t max_off_t_31 = MAX_OFF_T_B(31); /* Floppyd */
19const mt_off_t max_off_t_41 = MAX_OFF_T_B(41); /* SCSI */
20const mt_off_t max_off_t_seek = MAX_OFF_T_B(SEEK_BITS); /* SCSI */
21#else
22const mt_off_t max_off_t_31 = MAX_OFF_T_B(10); /* Floppyd */
23const mt_off_t max_off_t_41 = MAX_OFF_T_B(10); /* SCSI */
24const mt_off_t max_off_t_seek = MAX_OFF_T_B(10); /* SCSI */
25#endif
26
27off_t truncBytes32(mt_off_t off)
28{
29 if (off & ~max_off_t_31) {
30 fprintf(stderr, "Internal error, offset too big\n");
31 exit(1);
32 }
33 return (off_t) off;
34}
35
36mt_off_t sectorsToBytes(Stream_t *Stream, off_t off)
37{
38 DeclareThis(Fs_t);
39 return (mt_off_t) off << This->sectorShift;
40}
41
42#if defined HAVE_LLSEEK
43# ifndef HAVE_LLSEEK_PROTOTYPE
44extern long long llseek (int fd, long long offset, int origin);
45# endif
46#endif
47
48#if defined HAVE_LSEEK64
49# ifndef HAVE_LSEEK64_PROTOTYPE
50extern long long lseek64 (int fd, long long offset, int origin);
51# endif
52#endif
53
54
55int mt_lseek(int fd, mt_off_t where, int whence)
56{
57#if defined HAVE_LSEEK64
58 if(lseek64(fd, where, whence) >= 0)
59 return 0;
60 else
61 return -1;
62#elif defined HAVE_LLSEEK
63 if(llseek(fd, where, whence) >= 0)
64 return 0;
65 else
66 return -1;
67#else
68 if (lseek(fd, (off_t) where, whence) >= 0)
69 return 0;
70 else
71 return 1;
72#endif
73}
74
75int log_2(int size)
76{
77 int i;
78
79 for(i=0; i<24; i++) {
80 if(1 << i == size)
81 return i;
82 }
83 return 24;
84}
Note: See TracBrowser for help on using the repository browser.