0

I know /proc is a VFS and cannot be updated by user from shell prompt. this is my understanding from the beginning. Now , I am writing one code and where I am taking care of corrupted /proc/partitions file. I have my code ready and need to corrupt the file to test my code. I know chances are very less but I want to check all the other people if its possible in anyway to do that ? Any dirty way for test simulation would be ok.

I already tried vi ,echo, mv,rm and what my little head can come across but could not do that.

Any way possible ?

scai
  • 2,199
  • 1
  • 12
  • 16
monk
  • 109
  • 2
  • 1
    maybe just use a manually _corrupted_ textfile for testing purposes? – r_3 Nov 23 '15 at 13:39
  • well, i did that but its not helping me to the required extent. – monk Nov 23 '15 at 13:45
  • 1
    maybe you could explain in detail how such a broken /proc/partitions could look like, how it happend to you in a real life scenario and why a textfile for testing/debugging won't suffice. – r_3 Nov 23 '15 at 13:51
  • You can't modify it. This file is automagically generated by the kernel whenever someone opens it. Reading from a different, manually created file should suffice, as already pointed out. If not, then "just" corrupt your mbr after creating a backup using `dd`. – scai Nov 23 '15 at 13:53
  • I have 2 partitions missing out of 4 partitions. I cannot use a test file for complete testing because ,/proc/partitions is used more then 722 times in my code in 6 different files. I have done UT with a test file ,but cannot check with whole code all together. Can I use fdisk to alted the listed partitions ,if so then how ? should be reversible. – monk Nov 23 '15 at 13:54
  • 5
    "because /proc/partitions is used more then 722 times in my code in 6 different files" then please fix your code, this is just awfully wrong. Also, a simple search and replace can handle this. – scai Nov 23 '15 at 13:56
  • I agree to the solution , and convensing myself that its not possible to hack into /proc/partitions. Please put your response as answer , I will accept. – monk Nov 23 '15 at 14:25

1 Answers1

2

You can't modify /proc/partitions directly (or any other file inside /proc). These files are automagically generated by the kernel whenever someone opens them. However, reading from a different (manually) created file should suffice, as already pointed out by others.

Additionally, you shouldn't put the string /proc/partitions "more then 722 times" in your code. This is a really bad design. Instead, either create a global constant for it or keep it only hard-coded at the position where you open it.

scai
  • 2,199
  • 1
  • 12
  • 16