CFR: sanity checking arguments to kldload(8)

Benno Rice benno at jeamland.net
Wed Jun 3 03:18:49 UTC 2009


The attached patch performs some sanity checking on arguments passed  
to kldload(8).  Specifically, if an argument looks like a filename but  
lacks a path (eg, 'xfs.ko' as opposed to 'xfs' or './xfs.ko') it  
checks to see if a file with that name is in the current directory.   
If it is, it checks the current module path to see if a file with that  
name also exists there (possibly in an earlier entry if the current  
directory is in the module path), if so it warns the user that that  
module will be loaded and not the one in the current directory.  If  
not, it tells the user how to use a path to load the module.

A -q option is added to quieten the output if desired.

Sample output:

# sysctl kern.module_path
kern.module_path: /boot/kernel;/boot/modules
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel
# pwd
/boot/kernel
# kldload xfs.ko
# kldstat
Id Refs Address    Size     Name
  1    3 0xc0400000 cc016c   kernel
  2    1 0xc3a09000 b0000    xfs.ko
# kldunload xfs
# cd /boot/modules
# pwd
/boot/modules
# ls
xfs.ko*		xfs.ko.symbols*
# kldload xfs.ko
kldload: xfs.ko will be loaded from /boot/kernel, not the current  
directory
kldload: to load from the current directory use ./xfs.ko
# kldstat
Id Refs Address    Size     Name
  1    3 0xc0400000 cc016c   kernel
  2    1 0xc3a09000 b0000    xfs.ko
# kldunload xfs
# kldload -q xfs.ko
# kldstat
Id Refs Address    Size     Name
  1    3 0xc0400000 cc016c   kernel
  2    1 0xc3a09000 b0000    xfs.ko
# kldunload xfs
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel
# cd fnord
# pwd
/boot/modules/fnord
# ls
ibcs2.ko*		ibcs2.ko.symbols*
# ls /boot/kernel/ibcs2.ko
ls: /boot/kernel/ibcs2.ko: No such file or directory
# ls /boot/modules/ibcs2.ko
ls: /boot/modules/ibcs2.ko: No such file or directory
# kldload ibcs2.ko
kldload: ibcs2.ko is not in the module path
kldload: to load from the current directory use ./ibcs2.ko
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel
# kldload -q ibcs2.ko
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel
# kldload ./ibcs2.ko
# kldstat
Id Refs Address    Size     Name
  1    6 0xc0400000 cc016c   kernel
  2    1 0xc3a09000 b000     ibcs2.ko
# kldunload ibcs2
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: kldload.diff
Type: application/octet-stream
Size: 3506 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20090603/0f1e2a5e/kldload.obj
-------------- next part --------------


-- 
Benno Rice
benno at jeamland.net





More information about the freebsd-current mailing list