Re: any one knows how to truncate a file from its begining ?

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

 



On Wed, Oct 22, 2008 at 11:01 PM, Raz <raziebe@xxxxxxxxx> wrote:
> no.
> I mean i want to remove a portion of the file :
> if a file is composed of : a,b,c,d blocks.
> I want to be able to remove from the **disk** block c or block a.
> ftruncate remove the end.

Hmmm. I don't know if there is a simple way.........but you can do it
with a simple C program.

Let say you have blocks a,b,c,d and you want to create holes at blocks
b,c. Code flow would be something like this.

Open source file : src
read 'blocksize' chars and put it in dest
lseek both src and dest 2*blocksize
read block d and copy it to dest
rename dest to src.

The other option that you have is to directly modify the filesystem
reading it as a block device. Unfortunately I only know a bit about
ext filesystems :-( . In that case you will have to perform below
steps.
a) Go and set the appropriate block pointer in inode as 0 at appropriate offset.
b) Go and mark the corresponding bit for that block as 1.
c) Update the superblock for the blocks used count and other stats in
block group descriptors.

And again things are not simple if this is ext4 :-).

Thanks -
Manish


>
> On Wed, Oct 22, 2008 at 7:24 PM, Manish Katiyar <mkatiyar@xxxxxxxxx> wrote:
>> On Wed, Oct 22, 2008 at 10:42 PM, Raz <raziebe@xxxxxxxxx> wrote:
>>> or a file system that can do it ?
>>
>> What does that mean ???
>>
>> just doing
>>
>> $ > filename
>> on command line will truncate it............or probably "man
>> ftruncate" can help you.
>>
>> Thanks -
>> Manish
>>
>>
>>>
>>> thank you
>>> raz
>>>
>>> --
>>> To unsubscribe from this list: send an email with
>>> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
>>> Please read the FAQ at http://kernelnewbies.org/FAQ
>>>
>>>
>>
>

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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