Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

write system call

Posted on 2000-04-29
6
Medium Priority
?
215 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 85

Expert Comment

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

Accepted Solution

by:
jlevie earned 75 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 85

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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 …
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

783 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