0

For a project I'm working on, I need to be able to modify the EXT2 filesystem. I have done extensive research, but as this is not a commonly required task, there seems to be very little helpful information available online. Unfortunately, due to confidentiality, I cannot go into specifics of what I am working on, but I can break the situation down to several key problems that I would be very grateful for assistance on. I should note that I have very little experience with Linux kernel/OS development.

I realise that this is not an easy problem to tackle, and it is definitely going to be a big challenge seeing as this is only a small part of the project. Any assistance with these problems (or any other warnings/advice) is greatly appreciated.

If this turns out to be impossible, then the entire project will have to be rethought, hence why I am starting at this point.

Problem 1: From source code to implementation

This is not really the first problem, but I need to answer it first in order to make sure I'm on the right track at all! Remember that I am a novice, so this may be a silly question.

From what I can tell, all EXT2 source code is contained within the kernel source code at linux/fs/ext2/. If I were to modify this source code to make the changes I require, then successfully rebuild the kernel, what would it take to make a drive or partition use this newly modified filesystem? Would I just be able to reformat a drive as EXT2, using the new kernel, and the modified filesystem would be applied to it due to the modified source code? Or am I oversimplifying this?

Problem 2: Extending the metadata

A vital part of my project requires me to extend the metadata that each file on the drive contains. In this case, metadata refers to details such as owner, created timestamp, modified timestamp etc. What I would like to be able to do is add and be able to update an additional metadata field. I would think the best approach would be to modify the inode, but after looking through the source code for a long time, I can't see anywhere obvious to start.

Problem 3: Consequences?

Assume I am successful in adding and using this field on the modified filesystem. If a file was then moved to another drive, with an unmodified EXT2 filesystem, would the data contained in this extra metadata field be lost? Obviously files are moved between different filesystems all the time with no problem, but I am unsure as to how they handle this. I should note that it is not required to be able to access this metadata on any other system, I only require that the data not be lost.

Bonus question

So far I've been using CentOS for my prototype. If there is any advice as to whether this is good/bad/doesn't matter, I would appreciate it.

EDIT/UPDATE TO CLARIFY PROBLEM

As I said previously, confidentiality prevents me discussing exactly what the end-game is. Here is a very basic problem, which should hopefully explain more of the kind of things I need to be able to do.

Traditional filesystems keep track of three main timestamps: created, last accessed, last modified. Let's say I wanted to add a new type of metadata, called "modify history", which stores a list of timestamps for each and every modification. The only way I can think to do this, would be to add another attribute which would point to a datablock, to which timestamps are appended every time a write is made to that file/inode.

Again, the actual problem is far more complex, but this hopefully gives a better idea of the kind of thing I need to be able to do.

BSnapZ
  • 314
  • 1
  • 4
  • 13
  • If all you're doing is keeping an extra piece of metadata, ext2 supports "extended attributes": `setfattr -n user.mydata -v 'some value' my_file.txt`. You might need to `yum install attr` first. See also: http://archive09.linux.com/feature/114027 and http://en.wikipedia.org/wiki/Extended_file_attributes#Linux – Jander May 14 '15 at 07:11
  • @Jander That's good to know, I'll look on to it. I don't think it'll be that simple though, as the filesystem itself will have to be able to actively update this field, based on circumstances to be built into read/writes. – BSnapZ May 14 '15 at 07:36
  • I wouldn't completely recompile the kernel, but rather build the modified ext2 filesystem as an [external kernel module](https://www.kernel.org/doc/Documentation/kbuild/modules.txt) instead. You wouldn't have to restart after compiling the module, but simply reload it. – Benjamin B. May 14 '15 at 11:13
  • This is classic X-Y problem. But as you can't really share details then there's not a lot we can do to help resolve that. It would seems to me that if all your doing is storing metadata then "extended attributes" are you best bet. You do not want to modify the actual file system. If you do then you need to re-write all diagnostic and repair tools as well. If you can "make it work" in the existing file system limitations (again no idea which one is really tripping you up) then you don't have to rewrite tools like fsck. Keep in mind that with a partition ID of ext2 a system tool won't know. – coteyr May 14 '15 at 12:57
  • 1
    @BenjaminB. That sounds like a much better way to do it! I'll definitely take a look it. – BSnapZ May 14 '15 at 21:05
  • @coteyr I hadn't even thought about the tools, that has just made my whole project a hell of a lot harder (maybe even near-impossible). Damn. Regarding the actual problem, I've just updated my question to hopefully provide some more clarity. – BSnapZ May 14 '15 at 21:07

0 Answers0