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

How to write a file whose size is not integer multiple of sector size with FILE_FLAG_NO_BUFFERING option?

54 views
Skip to first unread message

RandyLi

unread,
May 18, 2002, 11:46:48 AM5/18/02
to
in the MSDN,It said:
File access must be for numbers of bytes that are integer multiples
of the volume's sector size. For example, if the sector size is 512
bytes, an application can request reads and writes of 512, 1024, or
2048 bytes, but not of 335, 981, or 7171 bytes.

but the problem is ,the file I want to write is not integer
multiples
of the volume's sector size.what should I do ,does it mean i can't use
this option?

Scott McPhillips

unread,
May 18, 2002, 12:07:03 PM5/18/02
to

You could fill out the last sector with zeros. If necessary for your
application you could then close the file, reopen the file without
FILE_FLAG_NO_BUFFERING and truncate the filler.

--
Scott McPhillips [VC++ MVP]

Larry Brasfield

unread,
May 18, 2002, 2:29:55 PM5/18/02
to
In article <82f50577.02051...@posting.google.com>,
RandyLi (purelov...@hotmail.com) says...

Without contradicting Scott's reply, I will point
out that there is an inherent conflict between what
you ask for when you specify FILE_FLAG_NO_BUFFERING,
your concept of arbitrary file size, and the usual
convention that file length is determined by how
much was written when the file is finally closed.

The hardware enforces a sector size and there is no
way to write fractional sectors with any drives in
my experience. So if you truly want to avoid any
buffering (except for the minimum necessary to pass
integer sector sized buffers to the I/O routines),
you will have to conform to that limitation.

Perhaps you should look at FlushFileBuffers(hFile)
and see if that will suit your purposes better
than impairing the filesystem buffering.

--
-Larry Brasfield
(address munged, s/sn/h/ to reply)

0 new messages