Solved

write system call

Posted on 2000-04-29
6
204 Views
Last Modified: 2010-04-21
Why does the write system-call trunc if called on an already existing file? Isn't it too costly to do so as most applns would just want to do minor modifications?
0
Comment
Question by:ravindra042100
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2762178
What minor modifications do you want to do?
0
 
LVL 40

Accepted Solution

by:
jlevie earned 25 total points
ID: 2762230
Why would you think that it would be costly. All that needs to happen to truncate a file to nothing is simply for all disk blocks other than the first to be returned to the free list.

Whether a file gets modified in place or simply re-writtten is up to the application. If you want, you can open a file read/write and modify it's contents in place by reading data, modifying that data and writing it back out. That's commonly done when the data organization in the file is effectively fixed-length records. If the data isn't fixed-length, it's more work than it's worth, so you simply create a new file containing the modified data.
0
 

Author Comment

by:ravindra042100
ID: 2772804
Just consider this example.

TO do:
------
I open a file of size,say 10Mb, replace a char and close it. (Not fixed length records ...)

      Now, for this to be done, all the blocks of this huge file have to be freed. When the data is written back, the blocks will need to be re-aquired needing modifications of free-list, the block map, inode ... Isn't this costly?
It could be better if just the required block is read in, modified and written back.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 84

Expert Comment

by:ozo
ID: 2772842
For replacing a single character, you can do this.
But if you change record lengths, the entire end of the file may have to be shifted.
(which is why databases built to deal with lots of insertions and deletions build indexes of pointers into their files)
0
 

Expert Comment

by:cside
ID: 2773753
The write call shouldn't be doing any truncation; that is handled by the call made to open. If the O_TRUNC mode is specified with O_RDWR or O_WRITE then that is what will happen. Not specifying it will allow you to seek to a position in the file and overwrite the data.

0
 

Author Comment

by:ravindra042100
ID: 2776555
Thank you ...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question