aboutsummaryrefslogtreecommitdiff
path: root/sys/fs/devfs/devfs.h
Commit message (Collapse)AuthorAgeFilesLines
* devfs: rework si_usecount to track opensMateusz Guzik2020-08-111-0/+5
| | | | | | | | | | | This removes a lot of special casing from the VFS layer. Reviewed by: kib (previous version) Tested by: pho (previous version) Differential Revision: https://reviews.freebsd.org/D25612 Notes: svn path=/head/; revision=364113
* devfs: bool -> intMateusz Guzik2020-08-101-1/+1
| | | | | | | Fixes buildworld after r364069 Notes: svn path=/head/; revision=364076
* devfs: save on spurious relocking for devfs_populateMateusz Guzik2020-08-101-0/+1
| | | | | | | Tested by: pho Notes: svn path=/head/; revision=364069
* sys/fs: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326268
* Introduce the "ruleset=number" option for devfs(5) mounts.Martin Matuska2012-02-091-0/+2
| | | | | | | | | | | | | | | Add support for updating the devfs mount (currently only changing the ruleset number is supported). Check mnt_optnew with vfs_filteropt(9). This new option sets the specified ruleset number as the active ruleset of the new devfs mount and applies all its rules at mount time. If the specified ruleset doesn't exist, a new empty ruleset is created. MFC after: 1 month Notes: svn path=/head/; revision=231265
* Format prototypes to follow style(9) more closely.Jaakko Heinonen2010-10-121-16/+19
| | | | | | | Discussed with: kib, phk Notes: svn path=/head/; revision=213725
* Add reference counting for devfs paths containing user created symbolicJaakko Heinonen2010-09-271-1/+4
| | | | | | | | | | | | | | | | | | | links. The reference counting is needed to be able to determine if a specific devfs path exists. For true device file paths we can traverse the cdevp_list but a separate directory list is needed for user created symbolic links. Add a new directory entry flag DE_USER to mark entries which should unreference their parent directory on deletion. A new function to traverse cdevp_list and the directory list will be introduced in a separate commit. Idea from: kib Reviewed by: kib Notes: svn path=/head/; revision=213215
* Modify devfs_fqpn() for future use in devfs path reference countingJaakko Heinonen2010-09-211-0/+4
| | | | | | | | | | | | | | | | code: - Accept devfs_mount and devfs_dirent as the arguments instead of a vnode. This generalizes the function so that it can be used from contexts where vnode references are not available. - Accept NULL cnp argument. No '/' will be appended, if a NULL cnp is provided. - Make the function global and add its prototype to devfs.h. Reviewed by: kib Notes: svn path=/head/; revision=212966
* Remove empty devfs directories automatically.Jaakko Heinonen2010-09-151-1/+4
| | | | | | | | | | | | | | | | | | | | | | | devfs_delete() now recursively removes empty parent directories unless the DEVFS_DEL_NORECURSE flag is specified. devfs_delete() can't be called anymore with a parent directory vnode lock held because the possible parent directory deletion needs to lock the vnode. Thus we unlock the parent directory vnode in devfs_remove() before calling devfs_delete(). Call devfs_populate_vp() from devfs_symlink() and devfs_vptocnp() as now directories can get removed. Add a check for DE_DOOMED flag to devfs_populate_vp() because devfs_delete() drops dm_lock before the VI_DOOMED vnode flag gets set. This ensures that devfs_populate_vp() returns an error for directories which are in progress of deletion. Reviewed by: kib Discussed on: freebsd-current (mostly silence) Notes: svn path=/head/; revision=212660
* Allow user created symbolic links to cover device files and directoriesJaakko Heinonen2010-08-121-5/+6
| | | | | | | | | | | | | | | | | if the device file appears during or after the link creation. User created symbolic links are now inserted at the head of the directory entry list after the "." and ".." entries. A new directory entry flag DE_COVERED indicates that an entry is covered by a symbolic link. PR: kern/114057 Reviewed by: kib Idea from: kib Discussed on: freebsd-current (mostly silence) Notes: svn path=/head/; revision=211226
* Enable shared locks for the devfs vnodes. Honor the locking modeKonstantin Belousov2010-08-061-1/+1
| | | | | | | | | | requested by lookup(). This should be a nop at the moment. In collaboration with: pho MFC after: 1 month Notes: svn path=/head/; revision=210921
* Add a new function devfs_parent_dirent() for resolving devfs parentJaakko Heinonen2010-06-091-0/+1
| | | | | | | | | | directory entry. Use the new function in devfs_fqpn(), devfs_lookupx() and devfs_vptocnp() instead of manually resolving the parent entry. Reviewed by: kib Notes: svn path=/head/; revision=208951
* Remove the thread argument from the FSD (File-System Dependent) parts ofAttilio Rao2009-05-111-1/+2
| | | | | | | | | | | | | | | | | | | | the VFS. Now all the VFS_* functions and relating parts don't want the context as long as it always refers to curthread. In some points, in particular when dealing with VOPs and functions living in the same namespace (eg. vflush) which still need to be converted, pass curthread explicitly in order to retain the old behaviour. Such loose ends will be fixed ASAP. While here fix a bug: now, UFS_EXTATTR can be compiled alone without the UFS_EXTATTR_AUTOSTART option. VFS KPI is heavilly changed by this commit so thirdy parts modules needs to be recompiled. Bump __FreeBSD_version in order to signal such situation. Notes: svn path=/head/; revision=191990
* Properly lock the vnode around vgone() calls.Konstantin Belousov2006-10-181-1/+1
| | | | | | | | | | | | | | Unlock the vnode in devfs_close() while calling into the driver d_close() routine. devfs_revoke() changes by: ups Reviewed and bugfixes by: tegge Tested by: mbr, Peter Holm Approved by: pjd (mentor) MFC after: 1 week Notes: svn path=/head/; revision=163481
* Resolve the devfs deadlock caused by LOR between devfs_mount->dm_lock andKonstantin Belousov2006-09-181-0/+11
| | | | | | | | | | | | | | | | | | vnode lock in devfs_allocv. Do this by temporary dropping dm_lock around vnode locking. For safe operation, add hold counters for both devfs_mount and devfs_dirent, and DE_DOOMED flag for devfs_dirent. The facilities allow to continue after dropping of the dm_lock, by making sure that referenced memory does not disappear. Reviewed by: tegge Tested by: kris Approved by: kan (mentor) PR: kern/102335 Notes: svn path=/head/; revision=162398
* Remove unused prototypes.Pawel Jakub Dawidek2006-04-121-2/+0
| | | | Notes: svn path=/head/; revision=157685
* Make rule zero really magical, that way we don't have to do anythingPoul-Henning Kamp2005-09-241-1/+1
| | | | | | | | | | | | | | | | | | | | | when we mount and get zero cost if no rules are used in a mountpoint. Add code to deref rules on unmount. Switch from SLIST to TAILQ. Drop SYSINIT, use SX_SYSINIT and static initializer of TAILQ instead. Drop goto, a break will do. Reduce double pointers to single pointers. Combine reaping and destroying rulesets. Avoid memory leaks in a some error cases. Notes: svn path=/head/; revision=150501
* Rewamp DEVFS internals pretty severely [1].Poul-Henning Kamp2005-09-191-33/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Give DEVFS a proper inode called struct cdev_priv. It is important to keep in mind that this "inode" is shared between all DEVFS mountpoints, therefore it is protected by the global device mutex. Link the cdev_priv's into a list, protected by the global device mutex. Keep track of each cdev_priv's state with a flag bit and of references from mountpoints with a dedicated usecount. Reap the benefits of much improved kernel memory allocator and the generally better defined device driver APIs to get rid of the tables of pointers + serial numbers, their overflow tables, the atomics to muck about in them and all the trouble that resulted in. This makes RAM the only limit on how many devices we can have. The cdev_priv is actually a super struct containing the normal cdev as the "public" part, and therefore allocation and freeing has moved to devfs_devs.c from kern_conf.c. The overall responsibility is (to be) split such that kern/kern_conf.c is the stuff that deals with drivers and struct cdev and fs/devfs handles filesystems and struct cdev_priv and their private liason exposed only in devfs_int.h. Move the inode number from cdev to cdev_priv and allocate inode numbers properly with unr. Local dirents in the mountpoints (directories, symlinks) allocate inodes from the same pool to guarantee against overlaps. Various other fields are going to migrate from cdev to cdev_priv in the future in order to hide them. A few fields may migrate from devfs_dirent to cdev_priv as well. Protect the DEVFS mountpoint with an sx lock instead of lockmgr, this lock also protects the directory tree of the mountpoint. Give each mountpoint a unique integer index, allocated with unr. Use it into an array of devfs_dirent pointers in each cdev_priv. Initially the array points to a single element also inside cdev_priv, but as more devfs instances are mounted, the array is extended with malloc(9) as necessary when the filesystem populates its directory tree. Retire the cdev alias lists, the cdev_priv now know about all the relevant devfs_dirents (and their vnodes) and devfs_revoke() will pick them up from there. We still spelunk into other mountpoints and fondle their data without 100% good locking. It may make better sense to vector the revoke event into the tty code and there do a destroy_dev/make_dev on the tty's devices, but that's for further study. Lots of shuffling of stuff and churn of bits for no good reason[2]. XXX: There is still nothing preventing the dev_clone EVENTHANDLER from being invoked at the same time in two devfs mountpoints. It is not obvious what the best course of action is here. XXX: comment out an if statement that lost its body, until I can find out what should go there so it doesn't do damage in the meantime. XXX: Leave in a few extra malloc types and KASSERTS to help track down any remaining issues. Much testing provided by: Kris Much confusion caused by (races in): md(4) [1] You are not supposed to understand anything past this point. [2] This line should simplify life for the peanut gallery. Notes: svn path=/head/; revision=150342
* Various minor polishing.Poul-Henning Kamp2005-09-151-1/+1
| | | | Notes: svn path=/head/; revision=150151
* Absolve devfs_rule.c from locking responsibility and call it withPoul-Henning Kamp2005-09-151-1/+1
| | | | | | | all necessary locking held. Notes: svn path=/head/; revision=150149
* Close a race which could result in unwarranted "ruleset %d alreadyPoul-Henning Kamp2005-09-151-0/+2
| | | | | | | | | | | | | | | | | | | | running" panics. Previously, recursion through the "include" feature was prevented by marking each ruleset as "running" when applied. This doesn't work for the case where two DEVFS instances try to apply the same ruleset at the same time. Instead introduce the sysctl vfs.devfs.rule_depth (default == 1) which limits how many levels of "include" we will traverse. Be aware that traversal of "include" is recursive and kernel stack size is limited. MFC: after 3 days Notes: svn path=/head/; revision=150147
* Eliminate effectively unused dm_basedir field from devfs_mount.Poul-Henning Kamp2005-08-151-1/+0
| | | | Notes: svn path=/head/; revision=149107
* Remove kernelside support for devfs rules filtering on major numbers.Poul-Henning Kamp2005-03-081-2/+0
| | | | Notes: svn path=/head/; revision=143303
* Reap more benefits from DEVFS:Poul-Henning Kamp2005-02-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | List devfs_dirents rather than vnodes off their shared struct cdev, this saves a pointer field in the vnode at the expense of a field in the devfs_dirent. There are often 100 times more vnodes so this is bargain. In addition it makes it harder for people to try to do stypid things like "finding the vnode from cdev". Since DEVFS handles all VCHR nodes now, we can do the vnode related cleanup in devfs_reclaim() instead of in dev_rel() and vgonel(). Similarly, we can do the struct cdev related cleanup in dev_rel() instead of devfs_reclaim(). rename idestroy_dev() to destroy_devl() for consistency. Add LIST_ENTRY de_alias to struct devfs_dirent. Remove v_specnext from struct vnode. Change si_hlist to si_alist in struct cdev. String new devfs vnodes' devfs_dirent on si_alist when we create them and take them off in devfs_reclaim(). Fix devfs_revoke() accordingly. Also don't clear fields devfs_reclaim() will clear when called from vgone(); Let devfs_reclaim() call dev_rel() instead of vgonel(). Move the usecount tracking from dev_rel() to devfs_reclaim(), and let dev_rel() take a struct cdev argument instead of vnode. Destroy SI_CHEAPCLONE devices in dev_rel() (instead of devfs_reclaim()) when they are no longer used. (This should maybe happen in devfs_close() instead.) Notes: svn path=/head/; revision=142242
* Do the dreaded s/dev_t/struct cdev */Poul-Henning Kamp2004-06-161-1/+1
| | | | | | | Bump __FreeBSD_version accordingly. Notes: svn path=/head/; revision=130585
* White-space align a struct definition.Poul-Henning Kamp2004-02-151-24/+23
| | | | | | | Move a SYSINIT to the file where it belongs. Notes: svn path=/head/; revision=125855
* Modify the MAC Framework so that instead of embedding a (struct label)Robert Watson2003-11-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in various kernel objects to represent security data, we embed a (struct label *) pointer, which now references labels allocated using a UMA zone (mac_label.c). This allows the size and shape of struct label to be varied without changing the size and shape of these kernel objects, which become part of the frozen ABI with 5-STABLE. This opens the door for boot-time selection of the number of label slots, and hence changes to the bound on the number of simultaneous labeled policies at boot-time instead of compile-time. This also makes it easier to embed label references in new objects as required for locking/caching with fine-grained network stack locking, such as inpcb structures. This change also moves us further in the direction of hiding the structure of kernel objects from MAC policy modules, not to mention dramatically reducing the number of '&' symbols appearing in both the MAC Framework and MAC policy modules, and improving readability. While this results in minimal performance change with MAC enabled, it will observably shrink the size of a number of critical kernel data structures for the !MAC case, and should have a small (but measurable) performance benefit (i.e., struct vnode, struct socket) do to memory conservation and reduced cost of zeroing memory. NOTE: Users of MAC must recompile their kernel and all MAC modules as a result of this change. Because this is an API change, third party MAC modules will also need to be updated to make less use of the '&' symbol. Suggestions from: bmilekic Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=122524
* Remove dm_root entry from struct devfs_mount. It's never set, and isRobert Watson2002-12-091-1/+1
| | | | | | | | | | | | | | | unused. Replace it with a dm_mount back-pointer to the struct mount that the devfs_mount is associated with. Export that pointer to MAC Framework entry points, where all current policies don't use the pointer. This permits the SEBSD port of SELinux's FLASK/TE to compile out-of-the-box on 5.0-CURRENT with full file system labeling support. Approved by: re (murray) Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=107698
* Fix comments and one resulting code confusion about the type of thePoul-Henning Kamp2002-10-161-1/+1
| | | | | | | | | "command" argument to VOP_IOCTL. Spotted by: FlexeLint. Notes: svn path=/head/; revision=105212
* A better solution to avoiding variable sized structs in DEVFS.Poul-Henning Kamp2002-10-161-3/+1
| | | | Notes: svn path=/head/; revision=105210
* #include "opt_devfs.h" to protect against variable sized structures.Poul-Henning Kamp2002-10-161-0/+2
| | | | | | | Spotted by: FlexeLint Notes: svn path=/head/; revision=105209
* Move the vop-vector declaration into devfs_vnops.c where it belongs.Poul-Henning Kamp2002-10-011-3/+0
| | | | Notes: svn path=/head/; revision=104278
* Introduce support for Mandatory Access Control and extensibleRobert Watson2002-07-301-0/+1
| | | | | | | | | | | | | | kernel access control. Label devfs directory entries, permitting labels to be maintained on device nodes in devfs instances persistently despite vnode recycling. Obtained from: TrustedBSD Project Sponsored by: DARPA, NAI Labs Notes: svn path=/head/; revision=100994
* Correct misindentation of DRA_UID.Dima Dorfman2002-07-281-1/+1
| | | | Notes: svn path=/head/; revision=100804
* Introduce the DEVFS "rule" subsystem. DEVFS rules permit theDima Dorfman2002-07-171-1/+87
| | | | | | | | | | | | | | administrator to define certain properties of new devfs nodes before they become visible to the userland. Both static (e.g., /dev/speaker) and dynamic (e.g., /dev/bpf*, some removable devices) nodes are supported. Each DEVFS mount may have a different ruleset assigned to it, permitting different policies to be implemented for things like jails. Approved by: phk Notes: svn path=/head/; revision=100206
* Don't attempt to decvlare M_DEVFS whern MALLOC_DECLARE is not defined.Bruce Evans2002-04-211-3/+6
| | | | | | | | | | | This fixes warnings that should be errors in fstat. Reminded by: alpha tinderbox Fixed some style bugs (ones near BOF and EOF; there are many more). Notes: svn path=/head/; revision=95212
* KSE Milestone 2Julian Elischer2001-09-121-1/+1
| | | | | | | | | | | | | | | | | Note ALL MODULES MUST BE RECOMPILED make the kernel aware that there are smaller units of scheduling than the process. (but only allow one thread per process at this time). This is functionally equivalent to teh previousl -current except that there is a thread associated with each process. Sorry john! (your next MFC will be a doosie!) Reviewed by: peter@freebsd.org, dillon@freebsd.org X-MFC after: ha ha ha ha Notes: svn path=/head/; revision=83366
* Change the way deletes are managed in DEVFS.Poul-Henning Kamp2001-05-231-1/+1
| | | | | | | | | | This fixes a number of warnings relating to removed cloned devices. It also makes it possible to recreate deleted devices with mknod(2). The major/minor arguments are ignored. Notes: svn path=/head/; revision=77050
* staticize.Poul-Henning Kamp2000-12-081-2/+0
| | | | Notes: svn path=/head/; revision=69767
* Add refcounts to the "global" DEVFS inode slots, this allows usPoul-Henning Kamp2000-09-061-22/+41
| | | | | | | | | | | | | | | | | | | | | | to recycle inodes after a destroy_dev() but not until all mounts have picked up the change. Add support for an overflow table for DEVFS inodes. The static table defaults to 1024 inodes, if that fills, an overflow table of 32k inodes is allocated. Both numbers can be changed at compile time, the size of the overflow table also with the sysctl vfs.devfs.noverflow. Use atomic instructions to barrier between make_dev()/destroy_dev() and the mounts. Add lockmgr() locking of directories for operations accessing or modifying the directory TAILQs. Various nitpicking here and there. Notes: svn path=/head/; revision=65515
* Avoid the modules madness I inadvertently introduced by making thePoul-Henning Kamp2000-09-021-5/+0
| | | | | | | | | | | | | | | | | | | | | cloning infrastructure standard in kern_conf. Modules are now the same with or without devfs support. If you need to detect if devfs is present, in modules or elsewhere, check the integer variable "devfs_present". This happily removes an ugly hack from kern/vfs_conf.c. This forces a rename of the eventhandler and the standard clone helper function. Include <sys/eventhandler.h> in <sys/conf.h>: it's a helper #include like <sys/queue.h> Remove all #includes of opt_devfs.h they no longer matter. Notes: svn path=/head/; revision=65374
* Reorder vop's alphabetically.Poul-Henning Kamp2000-08-271-0/+2
| | | | | | | | | Smarter use of devfs_allocv() (from bp@) Introduce devfs_find() ".." fixes to devfs_lookup (from bp@) Notes: svn path=/head/; revision=65132
* Fix panic when removing open device (found by bp@)Poul-Henning Kamp2000-08-241-10/+15
| | | | | | | | | | | | | | | Implement subdirs. Build the full "devicename" for cloning functions. Fix panic when deleted device goes away. Collaps devfs_dir and devfs_dirent structures. Add proper cloning to the /dev/fd* "device-"driver. Fix a bug in make_dev_alias() handling which made aliases appear multiple times. Use devfs_clone to implement getdiskbyname() Make specfs maintain the stat(2) timestamps per dev_t Notes: svn path=/head/; revision=65051
* Remove all traces of Julians DEVFS (incl from kern/subr_diskslice.c)Poul-Henning Kamp2000-08-201-0/+97
Remove old DEVFS support fields from dev_t. Make uid, gid & mode members of dev_t and set them in make_dev(). Use correct uid, gid & mode in make_dev in disk minilayer. Add support for registering alias names for a dev_t using the new function make_dev_alias(). These will show up as symlinks in DEVFS. Use makedev() rather than make_dev() for MFSs magic devices to prevent DEVFS from noticing this abuse. Add a field for DEVFS inode number in dev_t. Add new DEVFS in fs/devfs. Add devfs cloning to: disk minilayer (ie: ad(4), sd(4), cd(4) etc etc) md(4), tun(4), bpf(4), fd(4) If DEVFS add -d flag to /sbin/inits args to make it mount devfs. Add commented out DEVFS to GENERIC Notes: svn path=/head/; revision=64880