Chinaunix
标题:
fseek 里到达极限 ?? gcc for sparc
[打印本页]
作者:
babyyellow
时间:
2008-08-29 12:24
标题:
fseek 里到达极限 ?? gcc for sparc
在 solaris 10 sparc 64 的v890 上安装了gcc
写一个小程序读一个18g 的问题, 输入的参数是没有问题的,
但是在fseek 函数中 送进去的 offset= 8192 * 1015825
好像fseek 只能到达offset = 8192 * 491537 位置
编译的时候加了 -m64 和 -D_FILE_OFFSET_BITS=64
大虾门帮忙分析下是什么问题呢??
#include "mydul.h"
int read_buffer( FILE *fp, int rdba, char *buffer)
{
unsigned int file_no, blk_no;
file_no = FILEID(rdba);
blk_no = BLOCKID(rdba) +1 ;
blk_no = 1015825 ;
if (fp == NULL)
{
printf("file is not open yet %s %d\n\n", __FILE__ , __LINE__);
perror("file *fp");
exit(-1);
}
if( (fseek(fp,(long long )(BLKSIZE * blk_no),SEEK_SET)) == -1)
{
printf("fseek error !! %s,%d\n", __FILE__ , __LINE__ );
perror("fseek");
exit(-1);
}
fread(buffer,BLKSIZE,1,fp) ;
printf(" we have read \n");
// {
// printf("read buffer error! %s,%d\n", __FILE__,__LINE__);
// perror("fread");
// exit(-1);
//}
}
/*
get_extmap_dict( char * buffer, extmap_dict *extmap_dict) {
char *p;
p=buffer;
memcpy(extmap_dict,p+OFFSETEXTMAPDICT,SIZEOFEXTMAPDICT);
}
void prt_extmap_dict( extmap_dict * extmap_dict) {
printf("Seg extmap dict :\n\
ext_cnt :0x%x = %d \n\
next_extmap :0x%x\n\
object_id :0x%x = %d \n\
flag :0x%\n",\
extmap_dict->ext_cnt,\
extmap_dict->n_extmap_rdba,\
extmap_dict->obj_id,\
extmap_dict->flag);
}
*/
extent_item * get_ext_byextmap(FILE *fp ,int extmap_rdba){
int i=0,j=0 ;
int f_no , blk_no ;
text buffer[BLKSIZE+1];
extmap_dict extmap_dic;
extent_item *ext_arrary, *p;
extent_cnt *cnt_arrary, *p1;
extent_data *data_arrary, *p2;
block_head blk_head ;
if (fp == NULL) {
printf(" FILE *fp is not open yet , %s ,%d \n",__FILE__,__LINE__);
perror("FILE *fp");
return NULL;
}
// initialize
memset(&f_no,0,sizeof(int));
memset(&blk_no,0,sizeof(int));
memset(buffer,0,BLKSIZE+1);
memset(&extmap_dic,0,sizeof(extmap_dict));
ext_arrary = NULL;
cnt_arrary = NULL;
data_arrary = NULL;
f_no = FILEID(extmap_rdba);
blk_no= BLOCKID(extmap_rdba);
printf(" file# %d, blk# %d\n",f_no,blk_no);
if ( (read_buffer( fp , extmap_rdba , buffer) ) == -1) {
perror("read_buffer");
printf("read_bffer error!!, %s , %d \n",__FILE__,__LINE__);
return NULL ;
}
get_blk_head(buffer,&blk_head);
prt_blk_hd(&blk_head,0);
get_extmap_dict(buffer,&extmap_dic) ;
printf("we have get extmap_dic\n");
prt_extmap_dict(&extmap_dic);
if ( extmap_dic.ext_cnt > 0 ) {
printf(" ext_cnt : %d \n",extmap_dic.ext_cnt);
cnt_arrary = calloc( sizeof(extent_cnt),extmap_dic.ext_cnt);
data_arrary = calloc(sizeof(extent_data),extmap_dic.ext_cnt);
ext_arrary = calloc(sizeof(extent_item),extmap_dic.ext_cnt);
p=ext_arrary ;
p1=cnt_arrary;
p2=data_arrary;
memcpy(cnt_arrary,buffer+40,sizeof(extent_cnt)*extmap_dic.ext_cnt);
memcpy(data_arrary,buffer+4100,sizeof(extent_data)*extmap_dic.ext_cnt);
for ( i=0; i<extmap_dic.ext_cnt;i++) {
p->ext_rdba = p1->ext_rdba ;
p->blk_cnt = p1->blk_cnt ;
p->data_addr = p2->data_addr;
p2++;
p1++;
p++;
}
}
free(cnt_arrary) ;
free(data_arrary) ;
return ext_arrary ;
}
int main(){
char file[]="/data/oracle/baby/prog/big_file/LSL.dbf";
FILE *fp ;
fp=fopen(file,"rb");
extent_item *p , *q ;
int next_extmap ;
q= get_ext_byextmap(fp,0x024f8011) ;
p=q ;
int i=0;
for (i=0; i< 0x88;i++) {
printf(" ext_rdba : 0x%x ext_cnt : 0x%x = %d ext_data : 0x%x \n",\
p->ext_rdba , p->blk_cnt, p->blk_cnt, p->data_addr );
p++;
}
free(q) ;
}
作者:
cookis
时间:
2008-08-29 12:31
用 lseek64
作者:
happy_fish100
时间:
2008-08-29 12:31
标题:
回复 #1 babyyellow 的帖子
哈哈,整数溢出的缘故。
(long long)(BLKSIZE * blk_no)
int * int结果还是int,已经溢出了
将强制类型转换改变一下即可:
(long long)BLKSIZE * (long long)blk_no
作者:
babyyellow
时间:
2008-08-29 12:48
标题:
回复 #3 happy_fish100 的帖子
非常感谢!!!
问题解决了,挖哈哈!!!
作者:
cookis
时间:
2008-08-29 12:56
解决了?
怎么会?
fseek (FILE *__stream, long int __off, int __whence);
参数是 long 型的呀. 你虽然转成long long 但传进去的时候也会被截短.
你应该用extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);
作者:
happy_fish100
时间:
2008-08-29 13:06
标题:
回复 #5 cookis 的帖子
man fseek:
int fseek(FILE *stream, long offset, int whence);
int fseeko(FILE *stream, off_t offset, int whence);
sys/stat.h:
# ifndef __USE_FILE_OFFSET64
typedef __off_t off_t;
# else
typedef __off64_t off_t;
# endif
你是用的64位系统吗?32位系统下使用fseek是不支持long long类型的。
使用fseeko是可以的。
作者:
cookis
时间:
2008-08-29 13:19
原帖由
babyyellow
于 2008-8-29 12:24 发表
在 solaris 10 sparc 64 的v890 上安装了gcc
它的确是64位的系统..
唉. 现在对64位系统还不是很习惯呀
作者:
babyyellow
时间:
2008-08-29 13:43
标题:
回复 #7 cookis 的帖子
是啊, 对64位的系统不熟悉,
这个问题浪费了一天的时间,之前的函数都是没有用大文件来测试,测试都ok ,今天用了这个大文件,结果就老出错,害我又重新做了对每个函数做测试。
还好问题解决了, 以后就不会再出现这个问题了。
oralce 数据文件解析,我离你更近了。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2