Re: Finding size of a raw device
来源:百度文库 编辑:神马文学网 时间:2024/04/28 19:00:45
Hi ,Probably I found the answer to this .On a filesystem, by doing an lseek the OS cantrack the size of the file via the inodes .Thus, an lseek with SEEK_END would give thefile size , as the inode tables provide theneeded support for the OS .But since a raw device bound to a file is adirect interface , there is no way in whichthe OS can figure out its limits , and thuslseek with SEEK_END would yield a zero .It would be nice if somebody could confirmthe above explanation .Cheers !--- Learnerwrote: > Hi ,>> I was trying to find the size of a raw partition> using the below program , but the output is not> correct. Can anybody suggest how to rectify this> program.>> Is it that "lseek" should be used only on regular> files and not special files ?Is there a proc entry> which reflects the currently bound raw devices ?>> I'am aware that "raw -qa" gives the complete list> of raw devices , but I wanted to know if there is> any other method to do so .>>> PROGRAM :->> #include > #include > #include > #include >> main()> {> int fd ;> int start, end ;>> fd=open( "/dev/raw/raw1", O_RDONLY );>> start=lseek( fd, 0, SEEK_SET );>> printf("The Start pt size is %d \n", start);>> end=lseek( fd, 0, SEEK_END );>> printf("The End pt size is %d \n", end);> }>> OUTPUT :->> The Start pt size is 0> The End pt size is 0>>> Cheers!>>>