?
Solved

write system call

Posted on 2000-04-29
6
Medium Priority
?
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

800 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