LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 10-27-2022, 10:05 AM   #1
yntnm
LQ Newbie
 
Registered: Jul 2021
Posts: 5

Rep: Reputation: Disabled
Check if filesystem is mounted from kernel module


I'm trying to manipulate file from kernel module that is loaded at boot time (late_initcall() ).

yes i know that access to 'user space' from 'kernel space' is not the beast practice, but i have no choice.

for now im checking if the file exist...

However, if the filesystem is not mounted yet, so the check is not valid.
also i check if i can read /home but it's not beast practice as well

Is there a way to check if the F.S is mounted by the time the module is call?

The model can wait for the filesystem but, what is the right way to check that?

except of reading or writing a file.

Thanks
 
Old 10-28-2022, 10:16 AM   #2
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,987

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
Take a look at the mountpoint command. It's normally used in bash script with an if statement:
Code:
if mountpoint <insert mountpoint of desired filesystem> ; then
   <insert desired command>
fi
See man mountpoint for more details on this command.
 
Old 10-28-2022, 11:12 AM   #3
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,340

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Here is a command sequence that will mount a partition and give an error message and quit if the mount command failed.


# Mount the usb hard drive
if ! (mount -t ext4 -L Memorex.2141 /media/usb.Memorex.2141);
then
echo "mount failed for usb thumb drive Memorex.2141"
exit
fi
 
Old 10-30-2022, 03:23 AM   #4
yntnm
LQ Newbie
 
Registered: Jul 2021
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi thanks for the answer.
but there is no bash shell or whats ever in kernel module at boot time.
it's pure c language.
so whats I'm trying to find out. is, what struct (in c language, kernel space ) is valid for check that mount is happened (rootfs).
Such as 'struct super_block' that located at linux/fs.h

p.s the file is located on the rootfs at /my_folder/my_file

Last edited by yntnm; 10-30-2022 at 03:25 AM.
 
Old 10-30-2022, 03:47 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,131

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Quote:
Originally Posted by yntnm View Post
yes i know that access to 'user space' from 'kernel space' is not the beast practice, but i have no choice.
Redesign it.

Expose your updates via /sys and provide a userspace program to do the update to the actual file. /proc/mounts might be populated early enough for you - but if you can wait, it doesn't matter. For fstab based mountpoints, you'll have to wait.
 
  


Reply

Tags
filesystems, kernel, module



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grub: kernel parameter RO but filesystem still gets mounted rw browny_amiga Linux - General 1 01-13-2010 06:03 AM
Partition check, check double check Vincentius Linux - General 0 12-25-2004 05:47 AM
NFS: a mounted to b, b mounted to c, c can't read a? Steve Cronje Linux - Networking 9 10-25-2004 09:51 AM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM
Errors during filesystem check with one kernel while no errors with other kernel Potentials Linux - General 11 12-30-2003 04:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration