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