Kernel module - Check whether file (/dev node) exists


 
Thread Tools Search this Thread
Top Forums Programming Kernel module - Check whether file (/dev node) exists
# 1  
Old 07-12-2012
Kernel module - Check whether file (/dev node) exists

Hi, I'm pretty new to kernel coding and I'm working on a device driver that works with an existing framework.

Basically my module will be loaded/unloaded multiple times and I'd like to create a register a class, driver, and create a /dev node on the first load only. The existing framework doesn't allow me to clean up much when my module is unloaded, so I'll just be reusing the earlier /dev node.

Is there a way in the Linux kernel to check whether this dev node already exists? I've seen filp_open but most people caution against opening files from kernel so is there an alternate way of checking? Is it possible/easier to check whether the driver or class exist?

Thanks a lot,
ThomasBrez
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check if file exists

Hi, I have the below code written. However I am not getting the desired output I am checking if the particular path has file in it. #!/bin/bash ls -l /IRS2/IRS2_ODI/INFILE/*LS* 1>/dev/null 2>/dev/null if then echo $? echo "File Exists" fi ... (3 Replies)
Discussion started by: Shanmugapriya D
3 Replies

2. Shell Programming and Scripting

Except script fails to check file exists or not in remote node

Dear members, The following expect script connects to remote node and check for the file "authorized_keys" in directory /root/.ssh in remote node. However the result is always found even if the file exist or doesn't exist. expect { "$fname" { send_user "found\n" } Any idea what is... (4 Replies)
Discussion started by: Sudhakar333
4 Replies

3. Shell Programming and Scripting

Check if file exists or not

Hi, I want to check if the file exists or not in the directory. i am trying below code but not working. File="/home/va59657/Account_20090213*.dat" echo "$File" if ]; then echo "file found" else echo "file not found" fi However i am getting file not found even if file exits as... (5 Replies)
Discussion started by: Vivekit82
5 Replies

4. Linux

Unload kernel module at boot time (Debian Wheezy 7.2, 3.2.0-4-686-pae kernel)

Hi everyone, I am trying to prevent the ehci_hcd kernel module to load at boot time. Here's what I've tried so far: 1) Add the following line to /etc/modprobe.d/blacklist.conf (as suggested here): 2) Blacklisted the module by adding the following string to 3) Tried to blacklist the module... (0 Replies)
Discussion started by: gacanepa
0 Replies

5. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

6. Shell Programming and Scripting

how to check to see if a file exists?

I want to write a script to see if various files exist. What I want to do is have the script search in various directories if a file exist, and if not, then output something like "/path/file does not exist". I don't actually know of how to check and see if a file exists or not. What I have in mind... (2 Replies)
Discussion started by: astropi
2 Replies

7. Shell Programming and Scripting

Check to see if a file exists?

Hi. I'd like to have an IF-Then-Else statement where I can check to see if a file exists? We have the Bourne Shell by default. I'm looking for the syntax to do something like this: if myfile.txt exists then ...my code else ...my code end if Any help would be greatly... (5 Replies)
Discussion started by: buechler66
5 Replies

8. Programming

Kernel module - How to test if file doesn't exist

Hey, I'm currently getting into some kernel module progamming. As a little exercise I want to read the headers out of an ELF file. My code is very simple, here is the important part: struct file *fp; /* ... */ fp = filp_open("some/file/on/my/pc", O_RDONLY, 0); if(fp == NULL) { ... (15 Replies)
Discussion started by: disaster
15 Replies

9. Linux

How to convert Linux Kernel built-in module into a loadable module

Hi all, I am working on USB data monitoring on Fedora Core 9. Kernel 2.6.25 has a built-in module (the one that isn't loadable, but compiles and links statically with the kernel during compilation) to snoop USB data. It is in <kernel_source_code>/drivers/usb/mon/. I need to know if I can... (0 Replies)
Discussion started by: anitemp
0 Replies

10. SuSE

max number of slabs per kernel module (kernel 2.6.17, suse)

Hi All, Is there a max number of slabs that can be used per kernel module? I'm having a tough time finding out that kind of information, but the array 'node_zonelists' (mmzone.h) has a size of 5. I just want to avoid buffer overruns and other bad stuff. Cheers, Brendan (4 Replies)
Discussion started by: Brendan Kennedy
4 Replies
Login or Register to Ask a Question
KLD(4)							   BSD Kernel Interfaces Manual 						    KLD(4)

NAME
kld -- dynamic kernel linker facility DESCRIPTION
The LKM (Loadable Kernel Modules) facility has been deprecated in FreeBSD 3.0 and above in favor of the kld interface. This interface, like its predecessor, allows the system administrator to dynamically add and remove functionality from a running system. This ability also helps software developers to develop new parts of the kernel without constantly rebooting to test their changes. Various types of modules can be loaded into the system. There are several defined module types, listed below, which can be added to the sys- tem in a predefined way. In addition, there is a generic type, for which the module itself handles loading and unloading. The FreeBSD system makes extensive use of loadable kernel modules, and provides loadable versions of most file systems, the NFS client and server, all the screen-savers, and the iBCS2 and Linux emulators. kld modules are placed by default in the /boot/kernel directory along with their matching kernel. The kld interface is used through the kldload(8), kldunload(8) and kldstat(8) programs. The kldload(8) program can load either a.out(5) or ELF formatted loadable modules. The kldunload(8) program unloads any given loaded module, if no other module is dependent upon the given module. The kldstat(8) program is used to check the status of the modules currently loaded into the system. Kernel modules may only be loaded or unloaded if the system security level kern.securelevel is less than one. MODULE TYPES
Device Driver modules New block and character device drivers may be loaded into the system with kld. Device nodes for the loaded drivers are automatically created when a module is loaded and destroyed when it is unloaded by devfs(5). You can specify userland programs that will run when new devices become available as a result of loading modules, or existing devices go away when modules are unloaded, by configuring devd(8). FILES
/boot/kernel directory containing module binaries built for the kernel also residing in the directory. /usr/include/sys/module.h file containing definitions required to compile a kld module /usr/share/examples/kld example source code implementing a sample kld module SEE ALSO
kldfind(2), kldfirstmod(2), kldload(2), kldnext(2), kldstat(2), kldunload(2), devfs(5), devd(8), kldload(8), kldstat(8), kldunload(8), sysctl(8) HISTORY
The kld facility appeared in FreeBSD 3.0 and was designed as a replacement for the lkm facility, which was similar in functionality to the loadable kernel modules facility provided by SunOS 4.1.3. AUTHORS
The kld facility was originally implemented by Doug Rabson <dfr@FreeBSD.org>. BUGS
If a module B, is dependent on another module A, but is not compiled with module A as a dependency, then kldload(8) fails to load module B, even if module A is already present in the system. If multiple modules are dependent on module A, and are compiled with module A as a dependency, then kldload(8) loads an instance of module A when any of the modules are loaded. If a custom entry point is used for a module, and the module is compiled as an 'ELF' binary, then kldload(8) fails to execute the entry point. kldload(8) returns the cryptic message 'ENOEXEC (Exec format error)' for any error encountered while loading a module. When system internal interfaces change, old modules often cannot detect this, and such modules when loaded will often cause crashes or myste- rious failures. BSD
November 8, 1998 BSD