Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetFilePointer() not failing!!

66 views
Skip to first unread message

Lloyd

unread,
Dec 9, 2009, 5:23:31 AM12/9/09
to
Hi,
I have opened a USB device using its PnP name retrieved using the
"SetupDi*" functions available in DDK. Then received a handle using
the CreateFile() call, Then tried to call the SetFilePointer() to set
beyond the actual end of file.But the function does not return any
error! What could be the reason?

Thanks,
Lloyd

Kerem Gümrükcü

unread,
Dec 9, 2009, 6:04:58 AM12/9/09
to

Hi Lloyd,

code please,...

Regards

Ken

--
-----------------------
Beste Gr�sse / Best regards / Votre bien devoue
Kerem G�mr�kc�
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------

"Lloyd" <llo...@gmail.com> schrieb im Newsbeitrag
news:6ad1af05-f32a-4489...@y10g2000prg.googlegroups.com...

Lloyd

unread,
Dec 9, 2009, 6:28:54 AM12/9/09
to
hDevInfo =SetupDiGetClassDevs((LPGUID)
&GUID_DEVINTERFACE_DISK,NULL,NULL,(DIGCF_PRESENT|
DIGCF_INTERFACEDEVICE));

...
...

interfaceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
status = SetupDiEnumDeviceInterfaces(hDevInfo,0,(LPGUID)
&GUID_DEVINTERFACE_DISK,Index,&interfaceData);

...
....
status = SetupDiGetDeviceInterfaceDetail (hDevInfo,&interfaceData,NULL,
0,&reqSize,NULL);

...
....
hDevice = CreateFile(interfaceDetailData->DevicePath,GENERIC_READ|
GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,
0,NULL);

//All the above calls succeeds....

retSetFilePtr=SetFilePointer(hDevice ,1024*1024*1024 /*1GB*/,
NULL,FILE_BEGIN);

//This call too succeeds!! The device is only 128MB!!

Message has been deleted

Kerem Gümrükcü

unread,
Dec 9, 2009, 7:35:54 AM12/9/09
to
Hi,

did you try FILE_END on SFP? What do you get on GetLastError()
and SFP return Code,...for FILE_BEGIN and FILE_END? Can you
drop ReadFile/WriteFile Operations on the Device Object after
open it with CreateFile, just to make sure your Handle is valid
for these operations,...

Regards

Kerem

--
-----------------------
Beste Gr�sse / Best regards / Votre bien devoue
Kerem G�mr�kc�
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------

"Lloyd" <llo...@gmail.com> schrieb im Newsbeitrag

news:2af3fcb3-825e-443c...@z10g2000prh.googlegroups.com...


> hDevInfo =SetupDiGetClassDevs((LPGUID)
> &GUID_DEVINTERFACE_DISK,NULL,NULL,(DIGCF_PRESENT|
> DIGCF_INTERFACEDEVICE));
>
> ...
> ...
>
> interfaceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
> status = SetupDiEnumDeviceInterfaces(hDevInfo,0,(LPGUID)
> &GUID_DEVINTERFACE_DISK,Index,&interfaceData);
>
> ...
> ....
> status = SetupDiGetDeviceInterfaceDetail (hDevInfo,&interfaceData,NULL,
> 0,&reqSize,NULL);
>
> ...
> ....
> hDevice = CreateFile(interfaceDetailData->DevicePath,GENERIC_READ|
> GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,
> 0,NULL);
>
> //All the above calls succeeds....
>
> retSetFilePtr=SetFilePointer(hDevice ,1024*1024*1024 /*1GB*/,
> NULL,FILE_BEGIN);
>
> //This call too succeeds!! The device is only 128MB!!
>
>

Lloyd

unread,
Dec 9, 2009, 8:18:47 AM12/9/09
to
I tried ReadFile() on the "handle" got from CreateFile, and it returns
valid data...

When I try from FILE_END, it returns "ERROR_INVALID_FUNCTION"

Alexander Grigoriev

unread,
Dec 9, 2009, 10:21:11 AM12/9/09
to
You may want to read the function documentation once...

"It is not an error to set a file pointer to a position beyond the end of
the file."

"Lloyd" <llo...@gmail.com> wrote in message
news:6ad1af05-f32a-4489...@y10g2000prg.googlegroups.com...

Remy Lebeau

unread,
Dec 9, 2009, 1:58:32 PM12/9/09
to

"Lloyd" <llo...@gmail.com> wrote in message news:6ad1af05-f32a-4489...@y10g2000prg.googlegroups.com...

> I have opened a USB device using its PnP name retrieved

In general, SetFilePointer() is allowed to move beyond the end of a file. That allows a new EOF marker to be set by SetEndOfFile(), thus expanding the file size without having to write data to it.

I don't know if the same applies to a USB device. If the device does not support moving past EOF, then SetFilePointer() will likely just move to the EOF itself. Are you looking at the actual file position that SetFilePointer() returns on success?

--
Remy Lebeau (TeamB)

Tim Roberts

unread,
Dec 10, 2009, 1:32:35 AM12/10/09
to

The reason is probably that the driver for your USB device does not support
the ReadFile and WriteFile APIs. USB devices are not files. A driver can
support read and write mechanisms, but it's entirely up to the driver to
determine which functions mean what things.

What kind of a device is this?
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

m

unread,
Dec 13, 2009, 1:35:52 PM12/13/09
to
I don't know why you want to do this, but have you tried code like this?

if(!SetFilePointerEx(
h,
0,
&pNewFilePointer,
FILE_END
))
{
dwErr = GetLastError(); // handle error
}

As others have mentioned, the behavior will be device dependent and file
pointers usually have no meaning for a block device as they exist to support
stream IO

"Lloyd" <llo...@gmail.com> wrote in message

news:37e7e9b3-d39d-46bb...@2g2000prl.googlegroups.com...


> I tried ReadFile() on the "handle" got from CreateFile, and it returns
> valid data...
>
> When I try from FILE_END, it returns "ERROR_INVALID_FUNCTION"
>
>

0 new messages