xref: /xnu-8792.41.9/bsd/miscfs/devfs/README (revision 5c2921b07a2480ab43ec66f5b9e41cb872bc554f)
1*5c2921b0SApple OSS DistributionsNote: The following comments are from the original FreeBSD 3.1 README
2*5c2921b0SApple OSS Distributions
3*5c2921b0SApple OSS Distributionsthis file is: /sys/miscfs/devfs/README
4*5c2921b0SApple OSS Distributions
5*5c2921b0SApple OSS Distributionsto enable: add
6*5c2921b0SApple OSS Distributionsoptions	DEVFS
7*5c2921b0SApple OSS Distributions
8*5c2921b0SApple OSS Distributionsto your config file..
9*5c2921b0SApple OSS Distributionsexpect it to be highly useless for a while,
10*5c2921b0SApple OSS Distributionsas the only devices that register themselves are the floppy,
11*5c2921b0SApple OSS Distributionsthe pcaudio stuff, speaker, null,mem,zero,io,kmem.
12*5c2921b0SApple OSS Distributions
13*5c2921b0SApple OSS Distributionsit works like this:
14*5c2921b0SApple OSS Distributions
15*5c2921b0SApple OSS DistributionsThere is a tree of nodes that describe the layout of the DEVFS as seen by
16*5c2921b0SApple OSS Distributionsthe drivers.. they add nodes to this tree. This is called the 'back' layer
17*5c2921b0SApple OSS Distributionsfor reasons that will become obvious in a second. Think of it as a
18*5c2921b0SApple OSS DistributionsBLUEPRINT of the DEVFS tree. Each back node has associated with it
19*5c2921b0SApple OSS Distributionsa "devnode" struct, that holds information about the device
20*5c2921b0SApple OSS Distributions(or directory) and a pointer to the vnode if one has been associated
21*5c2921b0SApple OSS Distributionswith that node. The back node itself can be considered to be
22*5c2921b0SApple OSS Distributionsa directory entry, and contains the default name of the device,
23*5c2921b0SApple OSS Distributionsand a link to the directory that holds it. It is sometimes refered
24*5c2921b0SApple OSS Distributionsto in the code as the dev_name. The devnode can be considered the inode.
25*5c2921b0SApple OSS Distributions
26*5c2921b0SApple OSS DistributionsWhen you mount the devfs somewhere (you can mount it multiple times in
27*5c2921b0SApple OSS Distributionsmultiple places), a front layer is created that contains a tree of 'front'
28*5c2921b0SApple OSS Distributionsnodes.
29*5c2921b0SApple OSS Distributions
30*5c2921b0SApple OSS DistributionsThink of this as a Transparency, layed over the top of the blueprint.
31*5c2921b0SApple OSS Distributions(or possibly a photocopy).
32*5c2921b0SApple OSS Distributions
33*5c2921b0SApple OSS DistributionsThe front and back nodes are identical in type, but the back nodes
34*5c2921b0SApple OSS Distributionsare reserved for kernel use only, and are protected from the user.
35*5c2921b0SApple OSS DistributionsThe back plane has a mount structure and all that stuff, but it is in
36*5c2921b0SApple OSS Distributionsfact not really mounted. (and is thus not reachable via namei).
37*5c2921b0SApple OSS DistributionsInternal kernel routines can open devices in this plane
38*5c2921b0SApple OSS Distributionseven if the external devfs has not been mounted yet :)
39*5c2921b0SApple OSS Distributions(e.g. to find the root device)
40*5c2921b0SApple OSS Distributions
41*5c2921b0SApple OSS DistributionsTo start with there is a 1:1 relationship between the front nodes
42*5c2921b0SApple OSS Distributionsand the backing nodes, however once the front plane has been created
43*5c2921b0SApple OSS Distributionsthe nodes can be moved around within that plane (or deleted).
44*5c2921b0SApple OSS DistributionsThink of this as the ability to revise a transparency...
45*5c2921b0SApple OSS Distributionsthe blueprint is untouched.
46*5c2921b0SApple OSS Distributions
47*5c2921b0SApple OSS DistributionsThere is a "devnode" struct associated with each front note also.
48*5c2921b0SApple OSS DistributionsFront nodes that refer to devices, use the same "devnode" struct that is used
49*5c2921b0SApple OSS Distributionsby their associated backing node, so that multiple front nodes that
50*5c2921b0SApple OSS Distributionspoint to the same device will use the same "devnode" struct, and through
51*5c2921b0SApple OSS Distributionsthat, the same vnode, ops, modification times, flags, owner and group.
52*5c2921b0SApple OSS DistributionsFront nodes representing directories and symlinks have their own
53*5c2921b0SApple OSS Distributions"devnode" structs, and may therefore differ. (have different vnodes)
54*5c2921b0SApple OSS Distributionsi.e. if you have two devfs trees mounted, you can change the
55*5c2921b0SApple OSS Distributionsdirectories in one without changing the other.
56*5c2921b0SApple OSS Distributionse.g. remove or rename nodes
57*5c2921b0SApple OSS Distributions
58*5c2921b0SApple OSS DistributionsMultiple mountings are like multiple transparencies,
59*5c2921b0SApple OSS Distributionseach showing through to the original blueprint.
60*5c2921b0SApple OSS Distributions
61*5c2921b0SApple OSS DistributionsInformation that is to be shared between these mounts is stored
62*5c2921b0SApple OSS Distributionsin the 'backing' node for that object.  Once you have erased 'front'
63*5c2921b0SApple OSS Distributionsobject, there is no memory of where the backing object was, and
64*5c2921b0SApple OSS Distributionsexcept for the possibility of searching the entire backing tree
65*5c2921b0SApple OSS Distributionsfor the node with the correct major/minor/type, I don't see that
66*5c2921b0SApple OSS Distributionsit is easily recovered.. Particularly as there will eventually be
67*5c2921b0SApple OSS Distributions(I hope) devices that go direct from the backing node to the driver
68*5c2921b0SApple OSS Distributionswithout going via the cdevsw table.. they may not even have
69*5c2921b0SApple OSS Distributionsmajor/minor numbers.
70*5c2921b0SApple OSS Distributions
71*5c2921b0SApple OSS DistributionsI see 'mount -u' as a possible solution to recovering a broken dev tree.
72*5c2921b0SApple OSS Distributions(though umount+mount would do the same)
73*5c2921b0SApple OSS Distributions
74*5c2921b0SApple OSS DistributionsBecause non device nodes (directories and symlinks) have their own
75*5c2921b0SApple OSS Distributions"devnode" structs on each layer, these may have different
76*5c2921b0SApple OSS Distributionsflags, owners, and contents on each layer.
77*5c2921b0SApple OSS Distributionse.g. if you have a chroot tree like erf.tfs.com has, you
78*5c2921b0SApple OSS Distributionsmay want different permissions or owners on the chroot mount of the DEVFS
79*5c2921b0SApple OSS Distributionsthan you want in the real one. You might also want to delete some sensitive
80*5c2921b0SApple OSS Distributionsdevices from the chroot tree.
81*5c2921b0SApple OSS Distributions
82*5c2921b0SApple OSS DistributionsDirectories also have backing nodes but there is nothing to stop
83*5c2921b0SApple OSS Distributionsthe user from removing a front node from the directory front node.
84*5c2921b0SApple OSS Distributions(except permissions of course).  This is because the front directory
85*5c2921b0SApple OSS Distributionsnodes keep their own records as to which front nodes are members
86*5c2921b0SApple OSS Distributionsof that directory and do not refer to their original backing node
87*5c2921b0SApple OSS Distributionsfor this information.
88*5c2921b0SApple OSS Distributions
89*5c2921b0SApple OSS DistributionsThe front nodes may be moved to other directories (including
90*5c2921b0SApple OSS Distributionsdirectories) however this does not break the linkage between the
91*5c2921b0SApple OSS Distributionsbacking nodes and the front nodes. The backing node never moves. If
92*5c2921b0SApple OSS Distributionsa driver decides to remove a device from the backing tree, the FS
93*5c2921b0SApple OSS Distributionscode follows the links to all the front nodes linked to that backing
94*5c2921b0SApple OSS Distributionsnode, and deletes them, no matter where they've been moved to.
95*5c2921b0SApple OSS Distributions(active vnodes are redirected to point to the deadfs).
96*5c2921b0SApple OSS Distributions
97*5c2921b0SApple OSS DistributionsIf a directory has been moved, and a new backing node is inserted
98*5c2921b0SApple OSS Distributionsinto its own back node, the new front node will appear in that front
99*5c2921b0SApple OSS Distributionsdirectory, even though it's been moved, because the directory that
100*5c2921b0SApple OSS Distributionsgets the front node is found via the links and not by name.
101*5c2921b0SApple OSS Distributions
102*5c2921b0SApple OSS Distributionsa mount -u might be considered to be a request to 'refresh' the
103*5c2921b0SApple OSS Distributionsplane that controls to the mount being updated.. that would have the
104*5c2921b0SApple OSS Distributionseffect of 're-propogating' through any backing nodes that find they
105*5c2921b0SApple OSS Distributionshave no front nodes in that plane.
106*5c2921b0SApple OSS Distributions
107*5c2921b0SApple OSS Distributions
108*5c2921b0SApple OSS DistributionsNOTES FOR RELEASE 1.2
109*5c2921b0SApple OSS Distributions1/ this is very preliminary
110*5c2921b0SApple OSS Distributions2/ the routines have greatly simplified since release 1.1
111*5c2921b0SApple OSS Distributions(I guess the break did me good :)
112*5c2921b0SApple OSS Distributions3/ many features are not present yet..
113*5c2921b0SApple OSS Distributionse.g. symlinks, a comprehensive registration interface (only a crude one)
114*5c2921b0SApple OSS Distributionsability to unlink and mv nodes.
115*5c2921b0SApple OSS Distributions4/ I'm pretty sure my use of vnodes is bad and it may be 'losing'
116*5c2921b0SApple OSS Distributionsthem, or alternatively, corrupting things.. I need a vnode specialist
117*5c2921b0SApple OSS Distributionsto look at this.
118*5c2921b0SApple OSS Distributions
119