Re: file truncation on open with O_WRONLY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 08, 2003 at 06:33:12AM +0000, Anticipating a Reply wrote:
>    I was reading Linux Device Drivers , by 
> A.Rubini and found the below lines on page 71
> near the end . 
> 
>      " The only real operation performed on the 
> device is truncating it to a length of zero when 
> the device is opened for writing. This is 
> performed because, by design, overwriting a pscull 
> device with a shorter file results in a shorter 
> device data area. This is similar to the way 
> opening a regular file for writing truncates it to 
> zero length. The operation does nothing if the 
> device is opened for reading. "
> 
>   As said above in the last lines , I tried 
> the open system call on a regular file ,with 
> O_WRONLY option , without doing any further 
> operations . I was expecting the regular file to 
> truncate to zero after the open call as said above,
> but I  found that the regular file is
> intact .
>  
>   Can anybody please explain ? 
> Or maybe I have not understood the above lines
> properly .

The author of the above did not state wether he means libc's and
systems's terminology. As for system, file is only truncated if O_TRUNC
flag is given to open syscall. However the libc means O_WRONLY|O_TRUNC
by write and O_WRONLY is called append there. Author of the above
probably ment whe libc's write and if you call fopen(..., "w"), the file
will be truncated.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux