Solved want to know how to fetch the stat structure data?

March 2, 2015 at 22:11:10
Specs: Linux i686
i modified stat structure in my new kernel, and i compiled and entered to new kernel version linux-3.19, the location of new kernel source code was present on Desktop. While i try to print the stat members that time it is fetching the value from /usr/include/i386-linux-gnu/bits/stat.h.
But this is not my modified structure, how to change this structure to my modified stat structure?
if u anyone know means reply me asap thanks in advance.

See More: want to know how to fetch the stat structure data?

Report •


✔ Best Answer
March 3, 2015 at 05:14:31
And have you rebuilt libc with your new definition of struct stat? And then rebuilt all the programs that use libc (i.e. just about everything).

Edit: Checking the kernel sources I found 128 references to "struct stat"; you will need to go through each of these references and then check every place where the variables they declare are used, then make the appropriate changes. Next, as I said before, you will have to recompile libc to use the new version of the stat struct (in particular in the system calls stat() and fstat(), but you also need to check for any other potential references). Then you need to recompile every program that uses libc - in other words, just about every program on the system - so that the new version of libc is used. Don't forget that these changes will mean that in future you will have to install any new programs by compiling them from source rather than downloading binaries.

Once you have done that, if you are very lucky, things may work. If not, by all means come back and report what errors you are getting - but you have to do the hard work first. Changing a basic kernel structure is not something to be undertaken lightly. What exactly are you trying to do? - I would be surprised if there is not a simpler solution.

message edited by ijack



#1
March 2, 2015 at 22:57:17
Are you sure that you have modified the code for each use of the stat struct in the kernel? Also, every user program that makes a stat() or fstat() system call will need to be modified, most importantly libc. And how exactly are you fetching the struct and printing its value?

Changing a kernel structue is a major undertaking and will break many programs.


Report •

#2
March 3, 2015 at 01:07:12
what are the files in the kernal we need to modify for stat modification in kernal

Report •

#3
March 3, 2015 at 01:36:22
i downloaded new version linux-3.19 in that i added one more field for creator of file,
the paths are below, linux-3.19/include/linux/stat.h, then linux-3.19/include/uapi/asm-generic/stat.h, and linux-3.19/arch/x86/include/uapi/asm/stat.h. and i have assign the value for creator in linux-3.19/fs/stat.c. And i rebuild the kernel. now i try to print the values of stat structure that time it says stat structure has not having the member for creator. what i did wrong?

Report •

Related Solutions

#4
March 3, 2015 at 02:38:23
How are you displaying the struture? If you are using the stat() or fstat() system call you will need to rebuild libc. You will also need to rebuild any program that uses these system calls; that will be a good percentage of your user programs.

Report •

#5
March 3, 2015 at 04:34:27
using stat only i print that members

Report •

#6
March 3, 2015 at 05:14:31
✔ Best Answer
And have you rebuilt libc with your new definition of struct stat? And then rebuilt all the programs that use libc (i.e. just about everything).

Edit: Checking the kernel sources I found 128 references to "struct stat"; you will need to go through each of these references and then check every place where the variables they declare are used, then make the appropriate changes. Next, as I said before, you will have to recompile libc to use the new version of the stat struct (in particular in the system calls stat() and fstat(), but you also need to check for any other potential references). Then you need to recompile every program that uses libc - in other words, just about every program on the system - so that the new version of libc is used. Don't forget that these changes will mean that in future you will have to install any new programs by compiling them from source rather than downloading binaries.

Once you have done that, if you are very lucky, things may work. If not, by all means come back and report what errors you are getting - but you have to do the hard work first. Changing a basic kernel structure is not something to be undertaken lightly. What exactly are you trying to do? - I would be surprised if there is not a simpler solution.

message edited by ijack


Report •

#7
March 3, 2015 at 11:18:48
Actually I have to add one more field for creator of file in ext2 file system, so I added the field in ext2 Inode structure from ext2.h, and I added same field an inode structure from fs.h and I want to display the attributes of file using ls- l command, for that reason I added creator field in kstat structure from include/Linux/stat.h, include/uapi/Asm/stat.h.for that only I modified but its not working

Report •

#8
March 3, 2015 at 11:32:39
Adding a field in a header file does nothing. You have to also add the code to populate that field, retrieve it in system calls, etc. And then you have to do all the other stuff that I mentioned.

Good luck with your efforts.


Report •

#9
March 3, 2015 at 21:37:25
Ya I populated the field and also stat system call from fs/stat.C and inode. C also and I re builded my kernel but still it is not fetching correctly

Report •

#10
March 3, 2015 at 22:58:39
There are only so many times that I can tell you that you have to rebuild libc and programs that use it. This was the last one.

Report •

#11
March 4, 2015 at 01:31:29
K thanks I will do that

Report •


Ask Question