home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / kernel-s / umsdos / umsdos-0.000 / umsdos.doc
Text File  |  1994-05-21  |  55KB  |  1,727 lines

  1.  
  2.  
  3. 1        Introduction                                                      1
  4. 2        What is UMSDOS                                                    1
  5. 3        General strategy                                                  1
  6. 4        File name mangling                                                1
  7. 5        --linux-.---: the EMD file                                        4
  8. 6        Hard links                                                        6
  9. 7        Symbolic links                                                    7
  10. 8        Special file                                                      7
  11. 9        Pseudo root                                                       8
  12. 10       Dual mode                                                        10
  13. 11       Miscellaneous                                                    11
  14. 11.1     UMSDOS_create                                                    11
  15. 11.2     UMSDOS_ioctl_dir                                                 11
  16. 11.3     UMSDOS_lookup                                                    14
  17. 11.4     UMSDOS_notify_change                                             15
  18. 11.5     UMSDOS_readdir                                                   16
  19. 11.6     mount and UMSDOS_remount_fs                                      16
  20. 11.7     UMSDOS_rename                                                    17
  21. 11.8     Data structure                                                   17
  22. 11.9     Inode management                                                 17
  23. 12       Synchronisation problems                                         17
  24. 13       Convention and style                                             18
  25. 14       Weakness and features                                            20
  26. 15       utilities                                                        21
  27. 15.1     The UMSDOS synchroniser                                          21
  28. 15.2     Other                                                            23
  29. 16       Test cases                                                       24
  30. 16.1     utstgen                                                          24
  31. 16.2     utstspc                                                          26
  32.  
  33.  
  34. 1        Introduction                                                
  35.  
  36.     This document describe the implementation of the UMSDOS file 
  37.     system for LINUX. It contains mostly implementation notes 
  38.     rather than a formal description of the concept. It is 
  39.     intended for a reader who already has a good knowledge of 
  40.     the LINUX VFS system. It is expected (hope) that such a 
  41.     person may find weakness (or bugs) in UMSDOS just by reading 
  42.     this document. It is the first document to read if you 
  43.     suspect a bug.
  44.  
  45. 2        What is UMSDOS                                              
  46.  
  47.     UMSDOS stand for "Unix in MSDOS" file system. UMSDOS is a 
  48.     full feature unixlike file system for LINUX. It operates 
  49.     within the limits (and semantics) of a normal MSDOS FAT file 
  50.     system. chkdsk won't complain at all. No dirty tricks. 
  51.     UMSDOS DOES not use MSDOS (the OS) to run. In case anyone 
  52.     wonder. Using a special file in each directory 
  53.     ("--linux-.---"), UMSDOS simulate the full UNIX semantic (I 
  54.     hope :-) ):
  55.  
  56.         Long file name
  57.             case sensitive
  58.             free format file name like "This.is.a.sample"
  59.         Permissions and owner (user and group)
  60.         Links (hard and symbolic)
  61.         Device special and pipe
  62.  
  63.     UMSDOS is powerful enough to act as a ROOT file system for 
  64.     LINUX. From a Linux kernel standpoint, this is a true 
  65.     filesystem. Compile a kernel with UMSDOS, put it on a 
  66.     disquette, use rdev to specify the proper root partition 
  67.     (Any msdos partition with linux in it), and boot. In the 
  68.     following document, the --linux-.--- will be named EMD 
  69.     (Extension to Msdos Directory).
  70.  
  71. 3        General strategy                                            
  72.  
  73.     UMSDOS operates on top of the MSDOS fs for LINUX. Using the 
  74.     VFS function table, UMSDOS mostly intercept calls to MSDOS 
  75.     fs, do some translation and sometime carries itself the 
  76.     operation. Most of the job is directory search both in MSDOS 
  77.     fs and EMD.
  78.  
  79. 4        File name mangling                                          
  80.  
  81.  
  82.   [umsdos/mangle.c,259]
  83.   #Specification: file name / non MSDOS conforming / mangling
  84.  
  85.     Non MSDOS conforming file name must use some alias to fit
  86.     in the MSDOS name space.
  87.  
  88.     The strategy is simple. The name is simply truncated to
  89.     8 char. points are replace with underscore and a
  90.     number is given as an extension. This number correspond
  91.  
  92.  
  93.                                                               1
  94.  
  95.  
  96.     to the entry number in the EMD file. The EMD file
  97.     only need to carry the real name.
  98.  
  99.     Upper case is also convert to lower case.
  100.     Control character are converted to #.
  101.     Space are converted to #.
  102.     The following character are also converted to #.
  103.         " * + , / : ; < = > ? [ \ ] | ~
  104.  
  105.     Sometime, the problem is not in MsDOS itself but in
  106.     command.com.
  107.  
  108.   [umsdos/mangle.c,26]
  109.   #Specification: file name / non MSDOS conforming / mangling
  110.  
  111.     Each non MSDOS conforming file has a special extension
  112.     build from the entry position in the EMD file.
  113.  
  114.     This number is then transform in a base 32 number, where
  115.     each digit is expressed like hexadecimal number, using
  116.     digit and letter, except it uses 22 letters from 'a' to 'v'.
  117.     The number 32 comes from 2**5. It is faster to split a binary
  118.     number using a base which is a power of two. And I was 32
  119.     when I started this project. Pick your answer :-) .
  120.  
  121.     If the result is '0', it is replace with '_', simply
  122.     to make it odd.
  123.  
  124.     This is true for the first two character of the extension.
  125.     The last one is taken from a list of odd character, which
  126.     are:
  127.  
  128.         { } ( ) ! ` ^ & @
  129.  
  130.     With this scheme, we can produce 9216 ( 9* 32 * 32)
  131.     different extensions which should not clash with any useful
  132.     extension already popular or meaningful. Since most directory
  133.     have much less than 32 * 32 files in it, the first character
  134.     of the extension of any mangle name will be {.
  135.  
  136.     Here are the reason to do this (this kind of mangling).
  137.  
  138.     -The mangling is deterministic. Just by the extension, we
  139.      are able to locate the entry in the EMD file.
  140.  
  141.     -By keeping to beginning of the file name almost unchange,
  142.      we are helping the MSDOS user.
  143.  
  144.     -The mangling produces names not too ugly, so an msdos user
  145.      may live with it (remember it, type it, etc...).
  146.  
  147.     -The mangling produces names ugly enough so no one will
  148.      ever think of using such a name in real life. This is not
  149.      fool proof. I don't think there is a total solution to this.
  150.  
  151.   [umsdos/mangle.c,302]
  152.   #Specification: file name / MSDOS devices / mangling
  153.  
  154.  
  155.  
  156.                                                               2
  157.  
  158.  
  159.     To avoid unreachable file from MsDOS, any MsDOS conforming
  160.     file with a basename equal to one of the MsDOS pseudo
  161.     devices will be mangled.
  162.  
  163.     If a file such as "prn" was created, it would be unreachable
  164.     under MsDOS because prn is assumed to be the printer, even
  165.     if the file does have an extension.
  166.  
  167.     Since the extension is unimportant to MsDOS, we must patch
  168.     the basename also. We simply insert a minus '-'. To avoid
  169.     conflict with valid file with a minus in front (such as
  170.     "-prn"), we add an mangled extension like any other
  171.     mangled file name.
  172.  
  173.     Here is the list of DOS pseudo devices:
  174.  
  175.         "prn","con","aux","nul",
  176.         "lpt1","lpt2","lpt3","lpt4",
  177.         "com1","com2","com3","com4",
  178.         "clock$"
  179.  
  180.     and some standard ones for common DOS programs
  181.  
  182.         "emmxxxx0","xmsxxxx0","setverxx"
  183.  
  184.     (Thanks to Chris Hall <CAH17@PHOENIX.CAMBRIDGE.AC.UK>
  185.      for pointing these to me).
  186.  
  187.     Is there one missing ?
  188.  
  189.   [umsdos/mangle.c,255]
  190.   #Specification: file name / --linux-.---
  191.  
  192.     The name of the EMD file --linux-.--- is map to a mangled
  193.     name. So UMSDOS does not restrict its use.
  194.  
  195.   [umsdos/mangle.c,147]
  196.   #Specification: file name / non MSDOS conforming / base length 0
  197.  
  198.     file name beginning with a period '.' are invalid for MsDOS.
  199.     It needs absolutly a base name. So the file name is mangled
  200.  
  201.   [umsdos/mangle.c,220]
  202.   #Specification: file name / non MSDOS conforming / mangling clash
  203.  
  204.     To avoid clash with the umsdos mangling, any file
  205.     with a special character as the first character
  206.     of the extension will be mangled. This solve the
  207.     following problem:
  208.  
  209.     touch FILE
  210.     # FILE is invalid for DOS, so mangling is applied
  211.     # file.{_1 is created in the DOS directory
  212.     touch file.{_1
  213.     # To UMSDOS file point to a single DOS entry.
  214.     # So file.{_1 has to be mangled.
  215.  
  216.   [umsdos/mangle.c,212]
  217.  
  218.  
  219.                                                               3
  220.  
  221.  
  222.   #Specification: file name / non MSDOS conforming / last char == .
  223.  
  224.     If the last character of a file name is
  225.     a period, mangling is applied. MsDOS do
  226.     not support those file name.
  227.  
  228.   [umsdos/mangle.c,139]
  229.   #Specification: file name / too long
  230.  
  231.     If a file name exceed UMSDOS maxima, the file name is silently
  232.     truncated. This makes it conformant with the other file system
  233.     of Linux (minix and ext2 at least).
  234.  
  235.  
  236. 5        --linux-.---: the EMD file                                  
  237.  
  238.     The strategy for inode management. UMSDOS lets the MSDOS fs 
  239.     run and does simple transformation to the in core inode 
  240.     content. It also adds information at the end of the inode 
  241.     structure. See /usr/include/linux/umsdos_fs_i.h.
  242.  
  243.   [include/umsdos_fs.h,47]
  244.   #Specification: EMD file / record size
  245.  
  246.     Entry are 64 bytes wide in the EMD file. It allows for a 30 characters
  247.     name. If a name is longer, contiguous entries are allocated. So a
  248.     umsdos_dirent may span multiple records.
  249.  
  250.   [umsdos/emd.c,233]
  251.   #Specification: EMD file structure
  252.  
  253.     The EMD file uses a fairly simple layout. It is made of records
  254.     (UMSDOS_REC_SIZE == 64). When a name can't be written is a single
  255.     record, multiple contiguous record are allocated.
  256.  
  257.   [umsdos/emd.c,135]
  258.   #Specification: EMD file / empty entries
  259.  
  260.     Unused entry in the EMD file are identify
  261.     by the name_len field equal to 0. However to
  262.     help future extension (or bug corretion :-( ),
  263.     empty entries are filled with 0.
  264.  
  265.   [include/umsdos_fs_i.h,80]
  266.   #Specification: strategy / in memory inode
  267.  
  268.     Here is the information specific to the inode of the UMSDOS file
  269.     system. This information is added to the end of the standard struct
  270.     inode. Each file system has its own extension to struct inode,
  271.     so do the umsdos file system.
  272.  
  273.     The strategy is to have the umsdos_inode_info as a superset of
  274.     the msdos_inode_info, since most of the time the job is done
  275.     by the msdos fs code.
  276.  
  277.     So we duplicate the msdos_inode_info, and add our own info at the
  278.     end.
  279.  
  280.  
  281.  
  282.                                                               4
  283.  
  284.  
  285.     For all file type (and directory) the inode has a reference to:
  286.         the directory which hold this entry: i_dir_owner
  287.         The EMD file of i_dir_owner: i_emd_owner
  288.         The offset in this EMD file of the entry: pos
  289.  
  290.     For directory, we also have a reference to the inode of its
  291.     own EMD file. Also, we have dir_locking_info to help synchronise
  292.     file creation and file lookup. This data is sharing space with
  293.     the pipe_inode_info not used by directory. See also msdos_fs_i.h
  294.     for more information about pipe_inode_info and msdos_inode_info.
  295.  
  296.     Special file and fifo do have an inode which correspond to an
  297.     empty MSDOS file.
  298.  
  299.     symlink are processed mostly like regular file. The content is the
  300.     link.
  301.  
  302.     fifos add there own extension to the inode. I have reserved some
  303.     space for fifos side by side with msdos_inode_info. This is just
  304.     to for the show, because msdos_inode_info already include the
  305.     pipe_inode_info.
  306.  
  307.     The UMSDOS specific extension is placed after the union.
  308.  
  309.   [include/umsdos_fs_i.h,10]
  310.   #Specification: strategy / in memory inode
  311.  
  312.     Here is the information specific to the inode of the UMSDOS file
  313.     system. This information is added to the end of the standard struct
  314.     inode. Each file system has its own extension to struct inode,
  315.     so do the umsdos file system.
  316.  
  317.     The strategy is to have the umsdos_inode_info as a superset of
  318.     the msdos_inode_info, since most of the time the job is done
  319.     by the msdos fs code.
  320.  
  321.     So we duplicate the msdos_inode_info, and add our own info at the
  322.     end.
  323.  
  324.     For all file type (and directory) the inode has a reference to:
  325.         the directory which hold this entry: i_dir_owner
  326.         The EMD file of i_dir_owner: i_emd_owner
  327.         The offset in this EMD file of the entry: pos
  328.  
  329.     For directory, we also have a reference to the inode of its
  330.     own EMD file. Also, we have dir_locking_info to help synchronise
  331.     file creation and file lookup. This data is sharing space with
  332.     the pipe_inode_info not used by directory. See also msdos_fs_i.h
  333.     for more information about pipe_inode_info and msdos_inode_info.
  334.  
  335.     Special file and fifo do have an inode which correspond to an
  336.     empty MSDOS file.
  337.  
  338.     symlink are processed mostly like regular file. The content is the
  339.     link.
  340.  
  341.     fifos add there own extension to the inode. I have reserved some
  342.     space for fifos side by side with msdos_inode_info. This is just
  343.  
  344.  
  345.                                                               5
  346.  
  347.  
  348.     to for the show, because msdos_inode_info already include the
  349.     pipe_inode_info.
  350.  
  351.     The UMSDOS specific extension is placed after the union.
  352.  
  353.   [umsdos/emd.c,146]
  354.   #Specification: EMD file / spare bytes
  355.  
  356.     10 bytes are unused in each record of the EMD. They
  357.     are set to 0 all the time. So it will be possible
  358.     to do new stuff and rely on the state of those
  359.     bytes in old EMD file around.
  360.  
  361.  
  362. 6        Hard links                                                  
  363.  
  364.  
  365.   [umsdos/namei.c,480]
  366.   #Specification: hard link / strategy
  367.  
  368.     Well ... hard link are difficult to implement on top of an
  369.     MsDOS fat file system. Unlike UNIX file systems, there are no
  370.     inode. A directory entry hold the functionnality of the inode
  371.     and the entry.
  372.  
  373.     We will used the same strategy as a normal Unix file system
  374.     (with inode) except we will do it symbolicly (using paths).
  375.  
  376.     Because anything can happen during a DOS session (defragment,
  377.     directory sorting, etc...), we can't rely on MsDOS pseudo
  378.     inode number to record the link. For this reason, the link
  379.     will be done using hidden symbolic links. The following
  380.     scenario illustrate how it work.
  381.  
  382.     Given a file /foo/file
  383.  
  384.         ln /foo/file /tmp/file2
  385.  
  386.         become internally
  387.  
  388.         mv /foo/file /foo/-LINK1
  389.         ln -s /foo/-LINK1 /foo/file
  390.         ln -s /foo/-LINK1 /tmp/file2
  391.  
  392.     Using this strategy, we can operate on /foo/file or /foo/file2.
  393.     We can remove one and keep the other, like a normal Unix hard link.
  394.     We can rename /foo/file ou /tmp/file2 independantly.
  395.  
  396.     The entry -LINK1 will be hidden. It will hold a link count.
  397.     When all link are erased, the hidden file is erased too.
  398.  
  399.   [umsdos/namei.c,546]
  400.   #Specification: hard link / directory
  401.  
  402.     A hard link can't be made on a directory. EPERM is returned
  403.     in this case.
  404.  
  405.   [umsdos/emd.c,355]
  406.  
  407.  
  408.                                                               6
  409.  
  410.  
  411.   #Specification: hard link / hidden name
  412.  
  413.     When a hard link is created, the original file is renamed
  414.     to a hidden name. The name is "..LINKNNN" where NNN is a
  415.     number define from the entry offset in the EMD file.
  416.  
  417.   [umsdos/namei.c,565]
  418.   #Specification: hard link / first hard link
  419.  
  420.     The first time a hard link is done on a file, this
  421.     file must be renamed and hidden. Then an internal
  422.     simbolic link must be done on the hidden file.
  423.  
  424.     The second link is done after on this hidden file.
  425.  
  426.     It is expected that the Linux MSDOS file system
  427.     keeps the same pseudo inode when a rename operation
  428.     is done on a file in the same directory.
  429.  
  430.   [umsdos/namei.c,907]
  431.   #Specification: hard link / deleting a link
  432.  
  433.     When we deletes a file, and this file is a link
  434.     we must substract 1 to the nlink field of the
  435.     hidden link.
  436.  
  437.     If the count goes to 0, we delete this hidden
  438.     link too.
  439.  
  440.  
  441. 7        Symbolic links                                              
  442.  
  443.  
  444.   [umsdos/namei.c,418]
  445.   #Specification: symbolic links / strategy
  446.  
  447.     A symbolic link is simply a file which hold a path. It is
  448.     implemented as a normal MSDOS file (not very space efficient :-()
  449.  
  450.     I see 2 different way to do it. One is to place the link data
  451.     in unused entry of the EMD file. The other is to have a separate
  452.     file dedicated to hold all symbolic links data.
  453.  
  454.     Lets go for simplicity...
  455.  
  456.  
  457. 8        Special file                                                
  458.  
  459.  
  460.   [umsdos/namei.c,732]
  461.   #Specification: Special files / strategy
  462.  
  463.     Device special file, pipes, etc ... are created like normal
  464.     file in the msdos file system. Of course they remain empty.
  465.  
  466.     One strategy was to create thoses files only in the EMD file
  467.     since they were not important for MSDOS. The problem with
  468.     that, is that there were not getting inode number allocated.
  469.  
  470.  
  471.                                                               7
  472.  
  473.  
  474.     The MSDOS filesystems is playing a nice game to fake inode
  475.     number, so why not use it.
  476.  
  477.     The absence of inode number compatible with those allocated
  478.     for ordinary files was causing major trouble with hard link
  479.     in particular and other parts of the kernel I guess.
  480.  
  481.  
  482. 9        Pseudo root                                                 
  483.  
  484.  
  485.   [umsdos/inode.c,401]
  486.   #Specification: pseudo root / mount
  487.  
  488.     When a umsdos fs is mounted, a special handling is done
  489.     if it is the root partition. We check for the presence
  490.     of the file /linux/etc/init or /linux/etc/rc.
  491.     If one is there, we do a chroot("/linux").
  492.  
  493.     We check both because (see init/main.c) the kernel
  494.     try to exec init at different place and if it fails
  495.     it tries /bin/sh /etc/rc. To be consistent with
  496.     init/main.c, many more test would have to be done
  497.     to locate init. Any complain ?
  498.  
  499.     The chroot is done manually in init/main.c but the
  500.     info (the inode) is located at mount time and store
  501.     in a global variable (pseudo_root) which is used at
  502.     different place in the umsdos driver. There is no
  503.     need to store this variable elsewhere because it
  504.     will always be one, not one per mount.
  505.  
  506.     This feature allows the installation
  507.     of a linux system within a DOS system in a subdirectory.
  508.  
  509.     A user may install its linux stuff in c:\linux
  510.     avoiding any clash with existing DOS file and subdirectory.
  511.     When linux boots, it hides this fact, showing a normal
  512.     root directory with /etc /bin /tmp ...
  513.  
  514.     The word "linux" is hardcoded in /usr/include/linux/umsdos_fs.h
  515.     in the macro UMSDOS_PSDROOT_NAME.
  516.  
  517.   [umsdos/dir.c,65]
  518.   #Specification: pseudo root / directory /DOS
  519.  
  520.     When umsdos operates in pseudo root mode (C:\linux is the
  521.     linux root), it simulate a directory /DOS which points to
  522.     the real root of the file system.
  523.  
  524.   [umsdos/dir.c,480]
  525.   #Specification: pseudo root / DOS hard coded
  526.  
  527.     The pseudo sub-directory DOS in the pseudo root is hard coded.
  528.     The name is DOS. This is done this way to help standardised
  529.     the umsdos layout. The idea is that from now on /DOS is
  530.     a reserved path and nobody will think of using such a path
  531.     for a package.
  532.  
  533.  
  534.                                                               8
  535.  
  536.  
  537.   [umsdos/dir.c,511]
  538.   #Specification: pseudo root / .. in real root
  539.  
  540.     Whenever a lookup is those in the real root for
  541.     the directory .., and pseudo root is active, the
  542.     pseudo root is returned.
  543.  
  544.   [umsdos/namei.c,166]
  545.   #Specification: pseudo root / any file creation /DOS
  546.  
  547.     The pseudo sub-directory /DOS can't be created!
  548.     EEXIST is returned.
  549.  
  550.     The pseudo sub-directory /DOS can't be removed!
  551.     EPERM is returned.
  552.  
  553.   [umsdos/dir.c,580]
  554.   #Specification: pseudo root / dir lookup
  555.  
  556.     For the same reason as readdir, a lookup in /DOS for
  557.     the pseudo root directory (linux) will fail.
  558.  
  559.   [umsdos/rdir.c,79]
  560.   #Specification: pseudo root / DOS/..
  561.  
  562.     In the real root directory (c:\), the directory ..
  563.     is the pseudo root (c:\linux).
  564.  
  565.   [umsdos/rdir.c,88]
  566.   #Specification: pseudo root / DOS/linux
  567.  
  568.     Even in the real root directory (c:\), the directory
  569.     /linux won't show
  570.  
  571.   [umsdos/dir.c,542]
  572.   #Specification: pseudo root / lookup(DOS)
  573.  
  574.     A lookup of DOS in the pseudo root will always succeed
  575.     and return the inode of the real root.
  576.  
  577.   [umsdos/dir.c,165]
  578.   #Specification: pseudo root / reading real root
  579.  
  580.     The pseudo root (/linux) is logically
  581.     erased from the real root. This mean that
  582.     ls /DOS, won't show "linux". This avoids
  583.     infinite recursion /DOS/linux/DOS/linux while
  584.     walking the file system.
  585.  
  586.   [umsdos/rdir.c,127]
  587.   #Specification: pseudo root / rmdir /DOS
  588.  
  589.     The pseudo sub-directory /DOS can't be removed!
  590.     This is done even if the pseudo root is not a Umsdos
  591.     directory anymore (very unlikely), but an accident (under
  592.     MsDOS) is always possible.
  593.  
  594.     EPERM is returned.
  595.  
  596.  
  597.                                                               9
  598.  
  599.  
  600.  
  601. 10       Dual mode                                                   
  602.  
  603.  
  604.   [umsdos/rdir.c,177]
  605.   #Specification: dual mode / introduction
  606.  
  607.     One goal of UMSDOS is to allow a practical and simple coexistence
  608.     between MsDOS and Linux in a single partition. Using the EMD file
  609.     in each directory, UMSDOS add Unix semantics and capabilities to
  610.     normal DOS file system. To help and simplify coexistence, here is
  611.     the logic related to the EMD file.
  612.  
  613.     If it is missing, then the directory is managed by the MsDOS driver.
  614.     The names are limited to DOS limits (8.3). No links, no device special
  615.     and pipe and so on.
  616.  
  617.     If it is there, it is the directory. If it is there but empty, then
  618.     the directory looks empty. The utility umssync allows synchronisation
  619.     of the real DOS directory and the EMD.
  620.  
  621.     Whenever umssync is applied to a directory without EMD, one is
  622.     created on the fly. The directory is promoted to full unix semantic.
  623.     Of course, the ls command will show exactly the same content as before
  624.     the umssync session.
  625.  
  626.     It is believed that the user/admin will promote directories to unix
  627.     semantic as needed.
  628.  
  629.     The strategy to implement this is to use two function table (struct
  630.     inode_operations). One for true UMSDOS directory and one for directory
  631.     with missing EMD.
  632.  
  633.     Functions related to the DOS semantic (but aware of UMSDOS) generally
  634.     have a "r" prefix (r for real) such as UMSDOS_rlookup, to differentiate
  635.     from the one with full UMSDOS semantic.
  636.  
  637.   [umsdos/rdir.c,111]
  638.   #Specification: dual mode / rmdir in a DOS directory
  639.  
  640.     In a DOS (not EMD in it) directory, we use a reverse strategy
  641.     compared with an Umsdos directory. We assume that a subdirectory
  642.     of a DOS directory is also a DOS directory. This is not always
  643.     true (umssync may be used anywhere), but make sense.
  644.  
  645.     So we call msdos_rmdir() directly. If it failed with a -ENOTEMPTY
  646.     then we check if it is a Umsdos directory. We check if it is
  647.     really empty (only . .. and --linux-.--- in it). If it is true
  648.     we remove the EMD and do a msdos_rmdir() again.
  649.  
  650.     In a Umsdos directory, we assume all subdirectory are also
  651.     Umsdos directory, so we check the EMD file first.
  652.  
  653.   [umsdos/namei.c,693]
  654.   #Specification: mkdir / umsdos directory / create EMD
  655.  
  656.     When we created a new sub-directory in a UMSDOS
  657.     directory (one with full UMSDOS semantic), we
  658.  
  659.  
  660.                                                              10
  661.  
  662.  
  663.     create immediatly an EMD file in the new
  664.     sub-directory so it inherit UMSDOS semantic.
  665.  
  666.  
  667. 11       Miscellaneous                                               
  668.  
  669.  
  670. 11.1     UMSDOS_create                                               
  671.  
  672.  
  673.   [umsdos/namei.c,55]
  674.   #Specification: file creation / not atomic
  675.  
  676.     File creation is a two step process. First we create (allocate)
  677.     an entry in the EMD file and then (using the entry offset) we
  678.     build a unique name for MSDOS. We create this name in the msdos
  679.     space.
  680.  
  681.     We have to use semaphore (sleep_on/wake_up) to prevent lookup
  682.     into a directory when we create a file or directory and to
  683.     prevent creation while a lookup is going on. Since many lookup
  684.     may happen at the same time, the semaphore is a counter.
  685.  
  686.     Only one creation is allowed at the same time. This protection
  687.     may not be necessary. The problem arise mainly when a lookup
  688.     or a readdir is done while a file is partially created. The
  689.     lookup process see that as a "normal" problem and silently
  690.     erase the file from the EMD file. Normal because a file
  691.     may be erased during a MSDOS session, but not removed from
  692.     the EMD file.
  693.  
  694.     The locking is done on a directory per directory basis. Each
  695.     directory inode has its wait_queue.
  696.  
  697.     For some operation like hard link, things even get worse. Many
  698.     creation must occur at once (atomic). To simplify the design
  699.     a process is allowed to recursivly lock the directory for
  700.     creation. The pid of the locking process is kept along with
  701.     a counter so a second level of locking is granted or not.
  702.  
  703.   [umsdos/namei.c,177]
  704.   #Specification: create / . and ..
  705.  
  706.     If one try to creates . or .., it always fail and return
  707.     EEXIST.
  708.  
  709.     If one try to delete . or .., it always fail and return
  710.     EPERM.
  711.  
  712.     This should be test at the VFS layer level to avoid
  713.     duplicating this in all file systems. Any comments ?
  714.  
  715.  
  716. 11.2     UMSDOS_ioctl_dir                                            
  717.  
  718.  
  719.   [umsdos/ioctl.c,29]
  720.   #Specification: ioctl / acces
  721.  
  722.  
  723.                                                              11
  724.  
  725.  
  726.     Only root (effective id) is allowed to do IOCTL on directory
  727.     in UMSDOS. EPERM is returned for other user.
  728.  
  729.   [umsdos/ioctl.c,37]
  730.   #Specification: ioctl / prototypes
  731.  
  732.     The official prototype for the umsdos ioctl on directory
  733.     is:
  734.  
  735.     int ioctl (
  736.         int fd,     // File handle of the directory
  737.         int cmd,    // command
  738.         struct umsdos_ioctl *data)
  739.  
  740.     The struct and the commands are defined in linux/umsdos_fs.h.
  741.  
  742.     umsdos_progs/umsdosio.c provide an interface in C++ to all
  743.     these ioctl. umsdos_progs/udosctl is a small utility showing
  744.     all this.
  745.  
  746.     These ioctl generally allow one to work on the EMD or the
  747.     DOS directory independantly. These are essential to implement
  748.     the synchroniser.
  749.  
  750.   [umsdos/ioctl.c,58]
  751.   #Specification: ioctl / UMSDOS_GETVERSION
  752.  
  753.     The field version and release of the structure
  754.     umsdos_ioctl are filled with the version and release
  755.     number of the fs code in the kernel. This will allow
  756.     some form of checking. Users won't be able to run
  757.     incompatible utility such as the synchroniser (umssync).
  758.     umsdos_progs/umsdosio.c enforce this checking.
  759.  
  760.     Return always 0.
  761.  
  762.   [umsdos/ioctl.c,72]
  763.   #Specification: ioctl / UMSDOS_READDIR_DOS
  764.  
  765.     One entry is read from the DOS directory at the current
  766.     file position. The entry is put as is in the dos_dirent
  767.     field of struct umsdos_ioctl.
  768.  
  769.     Return > 0 if success.
  770.  
  771.   [umsdos/ioctl.c,193]
  772.   #Specification: ioctl / UMSDOS_RMDIR_DOS
  773.  
  774.     The dos_dirent field of the struct umsdos_ioctl is used to
  775.     execute a msdos_unlink operation. The d_name and d_reclen
  776.     fields are used.
  777.  
  778.     Return 0 if success.
  779.  
  780.   [umsdos/ioctl.c,204]
  781.   #Specification: ioctl / UMSDOS_STAT_DOS
  782.  
  783.     The dos_dirent field of the struct umsdos_ioctl is
  784.  
  785.  
  786.                                                              12
  787.  
  788.  
  789.     used to execute a stat operation in the DOS directory.
  790.     The d_name and d_reclen fields are used.
  791.  
  792.     The following field of umsdos_ioctl.stat are filled.
  793.  
  794.     st_ino,st_mode,st_size,st_atime,st_mtime,st_ctime,
  795.     Return 0 if success.
  796.  
  797.   [umsdos/ioctl.c,182]
  798.   #Specification: ioctl / UMSDOS_UNLINK_DOS
  799.  
  800.     The dos_dirent field of the struct umsdos_ioctl is used to
  801.     execute a msdos_unlink operation. The d_name and d_reclen
  802.     fields are used.
  803.  
  804.     Return 0 if success.
  805.  
  806.   [umsdos/ioctl.c,147]
  807.   #Specification: ioctl / UMSDOS_CREAT_EMD
  808.  
  809.     The umsdos_dirent field of the struct umsdos_ioctl is used
  810.     as is to create a new entry in the EMD of the directory.
  811.     The DOS directory is not modified.
  812.     No validation is done (yet).
  813.  
  814.     Return 0 if success.
  815.  
  816.   [umsdos/ioctl.c,81]
  817.   #Specification: ioctl / UMSDOS_READDIR_EMD
  818.  
  819.     One entry is read from the EMD at the current
  820.     file position. The entry is put as is in the umsdos_dirent
  821.     field of struct umsdos_ioctl. The corresponding mangled
  822.     DOS entry name is put in the dos_dirent field.
  823.  
  824.     All entries are read including hidden links. Blank
  825.     entries are skipped.
  826.  
  827.     Return > 0 if success.
  828.  
  829.   [umsdos/ioctl.c,164]
  830.   #Specification: ioctl / UMSDOS_UNLINK_EMD
  831.  
  832.     The umsdos_dirent field of the struct umsdos_ioctl is used
  833.     as is to remove an entry from the EMD of the directory.
  834.     No validation is done (yet). The mode field is used
  835.     to validate S_ISDIR or S_ISREG.
  836.  
  837.     Return 0 if success.
  838.  
  839.   [umsdos/ioctl.c,228]
  840.   #Specification: ioctl / UMSDOS_DOS_SETUP
  841.  
  842.     The UMSDOS_DOS_SETUP ioctl allow changing the
  843.     default permission of the MsDOS file system driver
  844.     on the fly. The MsDOS driver apply global permission
  845.     to every file and directory. Normally these permissions
  846.     are controlled by a mount option. This is not
  847.  
  848.  
  849.                                                              13
  850.  
  851.  
  852.     available for root partition, so a special utility
  853.     (umssetup) is provided to do this, normally in
  854.     /etc/rc.local.
  855.  
  856.     Be aware that this apply ONLY to MsDOS directory
  857.     (those without EMD --linux-.---). Umsdos directory
  858.     have independant (standard) permission for each
  859.     and every file.
  860.  
  861.     The field umsdos_dirent provide the information needed.
  862.     umsdos_dirent.uid and gid sets the owner and group.
  863.     umsdos_dirent.mode set the permissions flags.
  864.  
  865.   [umsdos/ioctl.c,124]
  866.   #Specification: ioctl / UMSDOS_INIT_EMD
  867.  
  868.     The UMSDOS_INIT_EMD command make sure the EMD
  869.     exist for a directory. If it does not, it is
  870.     created. Also, it makes sure the directory functions
  871.     table (struct inode_operations) is set to the UMSDOS
  872.     semantic. This mean that umssync may be applied to
  873.     an "opened" msdos directory, and it will change behavior
  874.     on the fly.
  875.  
  876.     Return 0 if success.
  877.  
  878.  
  879. 11.3     UMSDOS_lookup                                               
  880.  
  881.  
  882.   [umsdos/dir.c,520]
  883.   #Specification: locating .. / strategy
  884.  
  885.     We use the msdos filesystem to locate the parent directory.
  886.     But it is more complicated than that.
  887.  
  888.     We have to step back even further to
  889.     get the parent of the parent, so we can get the EMD
  890.     of the parent of the parent. Using the EMD file, we can
  891.     locate all the info on the parent, such a permissions
  892.     and owner.
  893.  
  894.   [umsdos/dir.c,556]
  895.   #Specification: umsdos / lookup
  896.  
  897.     A lookup for a file is done in two step. First, we locate
  898.     the file in the EMD file. If not present, we return
  899.     an error code (-ENOENT). If it is there, we repeat the
  900.     operation on the msdos file system. If this fails, it means
  901.     that the file system is not in sync with the emd file.
  902.     We silently remove this entry from the emd file,
  903.     and return ENOENT.
  904.  
  905.   [umsdos/dir.c,280]
  906.   #Specification: umsdos / lookup / inode info
  907.  
  908.     After successfully reading an inode from the MSDOS
  909.     filesystem, we use the EMD file to complete it.
  910.  
  911.  
  912.                                                              14
  913.  
  914.  
  915.     We update the following field.
  916.  
  917.     uid, gid, atime, ctime, mtime, mode.
  918.  
  919.     We rely on MSDOS for mtime. If the file
  920.     was modified during an MSDOS session, at least
  921.     mtime will be meaningful. We do this only for regular
  922.     file.
  923.  
  924.     We don't rely on MSDOS for mtime for directory because
  925.     the MSDOS directory date is creation time (strange
  926.     MSDOS behavior) which fit nowhere in the three UNIX
  927.     time stamp.
  928.  
  929.   [umsdos/dir.c,305]
  930.   #Specification: umsdos / i_nlink
  931.  
  932.     The nlink field of an inode is maintain by the MSDOS file system
  933.     for directory and by UMSDOS for other file. The logic is that
  934.     MSDOS is already figuring out what to do for directories and
  935.     does nothing for other files. For MSDOS, there are no hard link
  936.     so all file carry nlink==1. UMSDOS use some info in the
  937.     EMD file to plug the correct value.
  938.  
  939.  
  940. 11.4     UMSDOS_notify_change                                        
  941.  
  942.  
  943.   [umsdos/inode.c,331]
  944.   #Specification: notify_change / msdos fs
  945.  
  946.     notify_change operation are done only on the
  947.     EMD file. The msdos fs is not even called.
  948.  
  949.   [umsdos/inode.c,275]
  950.   #Specification: root inode / attributes
  951.  
  952.     I don't know yet how this should work. Normally
  953.     the attributes (permissions bits, owner, times) of
  954.     a directory are stored in the EMD file of its parent.
  955.  
  956.     One thing we could do is store the attributes of the root
  957.     inode in its own EMD file. A simple entry named "." could
  958.     be used for this special case. It would be read once
  959.     when the file system is mounted and update in
  960.     UMSDOS_notify_change() (right here).
  961.  
  962.     I am not sure of the behavior of the root inode for
  963.     a real UNIX file system. For now, this is a nop.
  964.  
  965.   [umsdos/inode.c,268]
  966.   #Specification: notify_change / i_nlink > 0
  967.  
  968.     notify change is only done for inode with nlink > 0. An inode
  969.     with nlink == 0 is no longer associated with any entry in
  970.     the EMD file, so there is nothing to update.
  971.  
  972.  
  973.  
  974.  
  975.                                                              15
  976.  
  977.  
  978. 11.5     UMSDOS_readdir                                              
  979.  
  980.  
  981.   [umsdos/dir.c,128]
  982.   #Specification: umsdos / readdir
  983.  
  984.     umsdos_readdir() should fill a struct dirent with
  985.     an inode number. The cheap way to get it is to
  986.     do a lookup in the MSDOS directory for each
  987.     entry processed by the readdir() function.
  988.     This is not very efficient, but very simple. The
  989.     other way around is to maintain a copy of the inode
  990.     number in the EMD file. This is a problem because
  991.     this has to be maintained in sync using tricks.
  992.     Remember that MSDOS (the OS) does not update the
  993.     modification time (mtime) of a directory. There is
  994.     no easy way to tell that a directory was modified
  995.     during a DOS session and synchronise the EMD file.
  996.  
  997.     Suggestion welcome.
  998.  
  999.     So the easy way is used!
  1000.  
  1001.   [umsdos/dir.c,79]
  1002.   #Specification: readdir / . and ..
  1003.  
  1004.     The msdos filesystem manage the . and .. entry properly
  1005.     so the EMD file won't hold any info about it.
  1006.  
  1007.     In readdir, we assume that for the root directory
  1008.     the read position will be 0 for ".", 1 for "..". For
  1009.     a non root directory, the read position will be 0 for "."
  1010.     and 32 for "..".
  1011.  
  1012.   [umsdos/dir.c,200]
  1013.   #Specification: umsdos / readdir / not in MSDOS
  1014.  
  1015.     During a readdir operation, if the file is not
  1016.     in the MSDOS directory anymore, the entry is
  1017.     removed from the EMD file silently.
  1018.  
  1019.  
  1020. 11.6     mount and UMSDOS_remount_fs                                 
  1021.  
  1022.  
  1023.   [umsdos/inode.c,380]
  1024.   #Specification: mount / options
  1025.  
  1026.     Umsdos run on top of msdos. Currently, it supports no
  1027.     mount option, but happily pass all option received to
  1028.     the msdos driver. I am not sure if all msdos mount option
  1029.     make sens with Umsdos. Here are at least those who
  1030.     are useful.
  1031.         uid=
  1032.         gid=
  1033.  
  1034.     These options affect the operation of umsdos in directories
  1035.     which do not have an EMD file. They behave like normal
  1036.  
  1037.  
  1038.                                                              16
  1039.  
  1040.  
  1041.     msdos directory, with all limitation of msdos.
  1042.  
  1043.  
  1044. 11.7     UMSDOS_rename                                               
  1045.  
  1046.  
  1047.   [umsdos/namei.c,326]
  1048.   #Specification: rename / new name exist
  1049.  
  1050.     If the destination name already exist, it will
  1051.     silently be removed. EXT2 does it this way
  1052.     and this is the spec of SUNOS. So does UMSDOS.
  1053.  
  1054.     If the destination is an empty directory it will
  1055.     also be removed.
  1056.  
  1057.  
  1058. 11.8     Data structure                                              
  1059.  
  1060.  
  1061.   [umsdos/inode.c,174]
  1062.   #Specification: inode / umsdos info
  1063.  
  1064.     The first time an inode is seen (inode->i_count == 1),
  1065.     the inode number of the EMD file which control this inode
  1066.     is tagged to this inode. It allows operation such
  1067.     as notify_change to be handled.
  1068.  
  1069.  
  1070. 11.9     Inode management                                            
  1071.  
  1072.  
  1073.   [umsdos/inode.c,239]
  1074.   #Specification: Inode / post initialisation
  1075.  
  1076.     To completly initialise an inode, we need access to the owner
  1077.     directory, so we can locate more info in the EMD file. This is
  1078.     not available the first time the inode is access, we use
  1079.     a value in the inode to tell if it has been finally initialised.
  1080.  
  1081.     At first, we have tried testing i_count but it was causing
  1082.     problem. It is possible that two or more process use the
  1083.     newly accessed inode. While the first one block during
  1084.     the initialisation (probably while reading the EMD file), the
  1085.     others believe all is well because i_count > 1. They go banana
  1086.     with a broken inode. See umsdos_lookup_patch and umsdos_patch_inode.
  1087.  
  1088.  
  1089. 12       Synchronisation problems                                    
  1090.  
  1091.  
  1092.   [umsdos/namei.c,238]
  1093.   #Specification: create / file exist in DOS
  1094.  
  1095.     Here is a situation. Trying to create a file with
  1096.     UMSDOS. The file is unknown to UMSDOS but already
  1097.     exist in the DOS directory.
  1098.  
  1099.  
  1100.  
  1101.                                                              17
  1102.  
  1103.  
  1104.     Here is what we are NOT doing:
  1105.  
  1106.     We could silently assume that everything is fine
  1107.     and allows the creation to succeed.
  1108.  
  1109.     It is possible not all files in the partition
  1110.     are mean to be visible from linux. By trying to create
  1111.     those file in some directory, one user may get access
  1112.     to those file without proper permissions. Looks like
  1113.     a security hole to me. Off course sharing a file system
  1114.     with DOS is some kind of security hole :-)
  1115.  
  1116.     So ?
  1117.  
  1118.     We return EEXIST in this case.
  1119.     The same is true for directory creation.
  1120.  
  1121.   [umsdos/namei.c,688]
  1122.   #Specification: mkdir / Directory already exist in DOS
  1123.  
  1124.     We do the same thing as for file creation.
  1125.     For all user it is an error.
  1126.  
  1127.  
  1128. 13       Convention and style                                        
  1129.  
  1130.  
  1131.   [umsdos/inode.c,352]
  1132.   #Specification: function name / convention
  1133.  
  1134.     A simple convention for function name has been used in
  1135.     the UMSDOS file system. First all function use the prefix
  1136.     umsdos_ to avoid name clash with other part of the kernel.
  1137.  
  1138.     And standard VFS entry point use the prefix UMSDOS (upper case)
  1139.     so it's easier to tell them apart.
  1140.  
  1141.   [umsdos/namei.c,760]
  1142.   #Specification: style / iput strategy
  1143.  
  1144.     In the UMSDOS project, I am trying to apply a single
  1145.     programming style regarding inode management. Many
  1146.     entry point are receiving an inode to act on, and must
  1147.     do an iput() as soon as they are finished with
  1148.     the inode.
  1149.  
  1150.     For simple case, there is no problem. When you introduce
  1151.     error checking, you end up with many iput placed around the
  1152.     code.
  1153.  
  1154.     The coding style I use all around is one where I am trying
  1155.     to provide independant flow logic (I don't know how to
  1156.     name this). With this style, code is easier to understand
  1157.     but you rapidly get iput() all around. Here is an exemple
  1158.     of what I am trying to avoid.
  1159.  
  1160.     if (a){
  1161.         ...
  1162.  
  1163.  
  1164.                                                              18
  1165.  
  1166.  
  1167.         if(b){
  1168.             ...
  1169.         }
  1170.         ...
  1171.         if (c){
  1172.             // Complexe state. Was b true ?
  1173.             ...
  1174.         }
  1175.         ...
  1176.     }
  1177.     // Weird state
  1178.     if (d){
  1179.         // ...
  1180.     }
  1181.     // Was iput finally done ?
  1182.     return status;
  1183.  
  1184.     Here is the style I am using. Still sometime I do the
  1185.     first when things are very simple (or very complicated :-( )
  1186.  
  1187.     if (a){
  1188.         if (b){
  1189.             ...
  1190.         }else if (c){
  1191.             // A single state gets here
  1192.         }
  1193.     }else if (d){
  1194.         ...
  1195.     }
  1196.     return status;
  1197.  
  1198.     Again, while this help clarifying the code, I often get a lot
  1199.     of iput(), unlike the first style, where I can place few
  1200.     "strategic" iput(). "strategic" also mean, more difficult
  1201.     to place.
  1202.  
  1203.     So here is the style I will be using from now on in this project.
  1204.     There is always an iput() at the end of a function (which has
  1205.     to do an iput()). One iput by inode. There is also one iput()
  1206.     at the places where a successful operation is achieved. This
  1207.     iput() is often done by a sub-function (often from the msdos
  1208.     file system). So I get one too many iput() ? At the place
  1209.     where an iput() is done, the inode is simply nulled, disabling
  1210.     the last one.
  1211.  
  1212.     if (a){
  1213.         if (b){
  1214.             ...
  1215.         }else if (c){
  1216.             msdos_rmdir(dir,...);
  1217.             dir = NULL;
  1218.         }
  1219.     }else if (d){
  1220.         ...
  1221.     }
  1222.     iput (dir);
  1223.     return status;
  1224.  
  1225.  
  1226.  
  1227.                                                              19
  1228.  
  1229.  
  1230.     Note that the umsdos_lockcreate() and umsdos_unlockcreate() function
  1231.     paire goes against this practice of "forgetting" the inode as soon
  1232.     as possible.
  1233.  
  1234.   [umsdos/inode.c,24]
  1235.   #Specification: convention / PRINTK Printk and printk
  1236.  
  1237.     Here is the convention for the use of printk inside fs/umsdos
  1238.  
  1239.     printk carry important message (error or status).
  1240.     Printk is for debugging (it is a macro defined at the beginning of
  1241.            most source.
  1242.     PRINTK is a nulled Printk macro.
  1243.  
  1244.     This convention makes the source easier to read, and Printk easier
  1245.     to shut off.
  1246.  
  1247.  
  1248. 14       Weakness and features                                       
  1249.  
  1250.     The UMSDOS file system is somewhat a compromise. Here are 
  1251.     the drawback. -Space efficiency. The minimal allocation unit 
  1252.     is generally 2k. Also, the MsDOS FAT fs do not support 
  1253.     sparse file (file with gap of unallocated blocks). -General 
  1254.     performance. UMSDOS run piggy back on top of another FS. 
  1255.     This means two directory structure to maintain. -Maximum 
  1256.     number of files is limited to 64k. It should be a good fs 
  1257.     for many purpose, especially if you have to coexist with 
  1258.     DOS. UMSDOS is trying to emulate the UNIX semantics for file 
  1259.     system. Here are the known differences and weakness.
  1260.  
  1261.   [umsdos/namei.c,512]
  1262.   #Specification: weakness / hard link
  1263.  
  1264.     The strategy for hard link introduces a side effect that
  1265.     may or may not be acceptable. Here is the sequence
  1266.  
  1267.     mkdir subdir1
  1268.     touch subdir1/file
  1269.     mkdir subdir2
  1270.     ln    subdir1/file subdir2/file
  1271.     rm    subdir1/file
  1272.     rmdir subdir1
  1273.     rmdir: subdir1: Directory not empty
  1274.  
  1275.     This happen because there is an invisible file (--link) in
  1276.     subdir1 which is referenced by subdir2/file.
  1277.  
  1278.     Any idea ?
  1279.  
  1280.   [umsdos/namei.c,529]
  1281.   #Specification: weakness / hard link / rename directory
  1282.  
  1283.     Another weakness of hard link come from the fact that
  1284.     it is based on hidden symbolic links. Here is an example.
  1285.  
  1286.     mkdir /subdir1
  1287.     touch /subdir1/file
  1288.  
  1289.  
  1290.                                                              20
  1291.  
  1292.  
  1293.     mkdir /subdir2
  1294.     ln    /subdir1/file subdir2/file
  1295.     mv    /subdir1 subdir3
  1296.     ls -l /subdir2/file
  1297.  
  1298.     Since /subdir2/file is a hidden symbolic link
  1299.     to /subdir1/..hlinkNNN, accessing it will fail since
  1300.     /subdir1 does not exist anymore (has been renamed).
  1301.  
  1302.   [umsdos/namei.c,973]
  1303.   #Specification: weakness / rename
  1304.  
  1305.     There is a case where UMSDOS rename has a different behavior
  1306.     than normal UNIX file system. Renaming an open file across
  1307.     directory boundary does not work. Renaming an open file within
  1308.     a directory does work however.
  1309.  
  1310.     The problem (not sure) is in the linux VFS msdos driver.
  1311.     I believe this is not a bug but a design feature, because
  1312.     an inode number represent some sort of directory address
  1313.     in the MSDOS directory structure. So moving the file into
  1314.     another directory does not preserve the inode number.
  1315.  
  1316.  
  1317. 15       utilities                                                   
  1318.  
  1319.     Very little has been done here. Not much is missing though. 
  1320.     Look in the directory umsdos_progs.
  1321.  
  1322. 15.1     The UMSDOS synchroniser                                     
  1323.  
  1324.  
  1325.   [umsdos_progs/linux/umssync.c,1]
  1326.   #Specification: utility / synchroniser
  1327.  
  1328.     The UMSDOS synchroniser (umssync) make sure that the EMD file
  1329.     is in sync with the MSDOS directory. File created during a DOS
  1330.     session should be add to the EMD. File removed should erased
  1331.     from the EMD.
  1332.  
  1333.     The UMSDOS file system will operate normally even if the
  1334.     system is out of sync. However, files will be missing from
  1335.     directory search, creating an annoying feeling.
  1336.  
  1337.     There is no easy way this kind of update may be achieved by
  1338.     UMSDOS transparently. Here are the reason:
  1339.  
  1340.     This process take some time for each directory. If there were some
  1341.     access time in MSDOS for directories, then, based on boot time, it would
  1342.     be possible to do it once per directory. It is not the case.
  1343.  
  1344.     When a file is discover in MSDOS which does not exist in the EMD, we
  1345.     need some directives to properly map the file. At least the owner must
  1346.     be known.
  1347.  
  1348.     A set of ioctl are available (wrapper interface in
  1349.     umsdos_progs/umsdosio.c) to allow independant manipulation of the EMD
  1350.     and the DOS directory.
  1351.  
  1352.  
  1353.                                                              21
  1354.  
  1355.  
  1356.     A utility is provided. It should be run from /etc/rc.
  1357.     A man page (umssync.8) describe its options.
  1358.  
  1359.   [umsdos_progs/linux/umssync.c,417]
  1360.   #Specification: umssync / default creation mode
  1361.  
  1362.     Unless override with command line option, file
  1363.     and directory created by umssync will be owned
  1364.     by root with mode 755 for directories and mode
  1365.     644 for files.
  1366.  
  1367.   [umsdos_progs/linux/umssync.c,427]
  1368.   #Specification: umssync / depth
  1369.  
  1370.     Normally, umssync won't recurse into directory.
  1371.     Option -r allows for depth control. You may specify
  1372.     how deep you want umssync to work.
  1373.  
  1374.     When recursing into directory, umssync will use
  1375.     the owner and group specified on the command line
  1376.     (see option -g and -u). If option -i+ is specified
  1377.     the specs of the sub-directory itself may be used.
  1378.  
  1379.     umssync won't follow symlinks. And it won't cross mount
  1380.     points.
  1381.  
  1382.   [umsdos_progs/linux/umssync.c,84]
  1383.   #Specification: umssync / mangled name
  1384.  
  1385.     If a DOS file is missing from the EMD, it is added. If
  1386.     the file has an extension with the first character
  1387.     being a member of the restricted set for mangling,
  1388.     the operation won't be done. A message will be printed.
  1389.  
  1390.     To synchronise back into the EMD, the file must be renamed.
  1391.     If one try to create a such a file with umsdos, it is
  1392.     automaticly mangled, producing a different file name in DOS.
  1393.  
  1394.     This is always done to avoid the following problem
  1395.  
  1396.     Unix command        MsDOS file name created
  1397.     ============        =======================
  1398.     mkdir DIR           dir.{__
  1399.     mkdir dir.{__       dir.{_1
  1400.     ...
  1401.     mkdir dir.{_1       dir.{10
  1402.  
  1403.     Now, suppose that dir.{__ does not exist in the EMD. dir.{_1
  1404.     do exist in DOS. If we try to create it in Umsdos, this
  1405.     will create a mangled name. Mangling in based on the
  1406.     entry offset in the EMD.
  1407.  
  1408.     So if say dir.{_1 exist in DOS, but not in Umsdos, rename
  1409.     it to anything (dir.111) and synchronise it in the EMD
  1410.     with umssync.
  1411.  
  1412.   [umsdos_progs/linux/umssync.c,359]
  1413.   #Specification: umssync / mount point
  1414.  
  1415.  
  1416.                                                              22
  1417.  
  1418.  
  1419.     umssync won't cross mount point. It means
  1420.     you must specify each mount point separatly.
  1421.  
  1422.   [umsdos_progs/linux/umssync.c,536]
  1423.   #Specification: umssync / user mode
  1424.  
  1425.     To execute umssync, the effective user id must be root.
  1426.     It it possible to configure umssync to run setuid root.
  1427.     In this case (when getuid() != geteuid()), umssync
  1428.     show a special behavior: Options -d -f -g -i -u are not
  1429.     available anymore. The inheriting mode is automaticly
  1430.     activated. No way to desactivated.
  1431.  
  1432.     A user should be able to umssync its own directory. If a user
  1433.     apply umssync to a directory, all file uncovered will be given
  1434.     to the owner of the directory with restrictive permissions
  1435.     (600 for files, 700 for directory).
  1436.  
  1437.     Another way would be to limit umssync operation to directory
  1438.     which belong to the user. Suggestion welcome.
  1439.  
  1440.  
  1441. 15.2     Other                                                       
  1442.  
  1443.  
  1444.   [umsdos_progs/linux/udump.c,4]
  1445.   #Specification: utilities / udump
  1446.  
  1447.     udump display the content of a --linux-.--- file (EMD file).
  1448.     Simply type:
  1449.  
  1450.     udump file
  1451.  
  1452.     This utility was mainly used to debug the UMSDOS file systems.
  1453.  
  1454.   [umsdos_progs/linux/udosctl.c,12]
  1455.   #Specification: umsdos_progs / udosctl
  1456.  
  1457.     The udosctl utility give acces directly to UMSDOS ioctl on directory.
  1458.  
  1459.     udosctl command arg
  1460.  
  1461.     Here are the commands:
  1462.  
  1463.     ls:
  1464.  
  1465.         List the content of dos directory arg. Bypass the EMD file.
  1466.         It uses UMSDOS_READDIR_DOS.
  1467.  
  1468.     create:
  1469.  
  1470.         Create the file arg in the EMD file. Do nothing on the DOS
  1471.         directory. Use UMSDOS_CREAT_UMSDOS.
  1472.  
  1473.     mkdir:
  1474.  
  1475.         Create the directory arg in the EMD file. Do nothing on the DOS
  1476.         directory. Use UMSDOS_CREAT_UMSDOS.
  1477.  
  1478.  
  1479.                                                              23
  1480.  
  1481.  
  1482.     rm:
  1483.  
  1484.         Remove the file arg in the DOS directory. Bypass the EMD file.
  1485.         Use UMSDOS_UNLINK_DOS.
  1486.  
  1487.     rmdir:
  1488.  
  1489.         Remove the directory arg in the DOS directory. Bypass the EMD file.
  1490.         Use UMSDOS_RMDIR_DOS.
  1491.  
  1492.     uls:
  1493.  
  1494.         List the content of the EMD and print the corresponding DOS
  1495.         mangled name. It uses UMSDOS_READDIR_EMD.
  1496.  
  1497.     urm:
  1498.  
  1499.         Remove the file arg from the EMD file. Don't touch the DOS
  1500.         directory. Use UMSDOS_UNLINK_UMSDOS.
  1501.  
  1502.     urmdir:
  1503.  
  1504.         Remove the directory arg from the EMD file. Don't touch the DOS
  1505.         directory. Use UMSDOS_UNLINK_UMSDOS.
  1506.  
  1507.     version:
  1508.  
  1509.         Prints the version of the UMSDOS driver running.
  1510.  
  1511.     This program was done mostly for illustration of ioctl use
  1512.     and testing.
  1513.  
  1514.  
  1515. 16       Test cases                                                  
  1516.  
  1517.     The umsdos_progs/tests directory holds two utilities. 
  1518.     utstgen is a general test suite "UMSDOS independant". It 
  1519.     tests the general behavior of UMSDOS as a true UNIX-like 
  1520.     file system. utstspc is truely UMSDOS oriented. It (will) 
  1521.     tests the proper behavior of UMSDOS especially when the EMD 
  1522.     and the MSDOS directory are out of sync. Currently utstspc 
  1523.     is not testing much!
  1524.  
  1525. 16.1     utstgen                                                     
  1526.  
  1527.  
  1528.   [umsdos_progs/tests/utstgen.c,7]
  1529.   #Specification: umsdos / automated test / general
  1530.  
  1531.     utstgen.c is a sequence of test for the UMSDOS file system.
  1532.     These test are not really specific to the UMSDOS file system.
  1533.     You will find extensive testing of some stuff which are specific
  1534.     to the UMSDOS file system. There is a long section on hard link
  1535.     which could hardly fail on a normal UNIX file system and were
  1536.     a nightmare to implement in UMSDOS.
  1537.  
  1538.   [umsdos_progs/tests/gen/hlink.c,108]
  1539.   #Specification: utstgen / hard link / cases / across directory boundary
  1540.  
  1541.  
  1542.                                                              24
  1543.  
  1544.  
  1545.     The target of the link is not in the same directory
  1546.     as the new link.
  1547.  
  1548.   [umsdos_progs/tests/gen/hlink.c,121]
  1549.   #Specification: utstgen / hard link / cases / target does not exist
  1550.  
  1551.     Many hard links are attempted to a file which
  1552.     does not exist.
  1553.  
  1554.   [umsdos_progs/tests/gen/hlink.c,127]
  1555.   #Specification: utstgen / hard link / to a directory
  1556.  
  1557.     A hard link can't be made to a directory.
  1558.  
  1559.   [umsdos_progs/tests/gen/hlink.c,50]
  1560.   #Specification: utstgen / hard links / case / link 2 link 2 link ...
  1561.  
  1562.     hlink_simple does test a link made to a link made to a link
  1563.     and so on. On a normal UNIX file system, this test is not
  1564.     really an issue. Given the fact that a hardlink on UMSDOS is
  1565.     a symlink to a hidden file, it make sense to test at least
  1566.     the two cases:
  1567.  
  1568.     hard link to an existing file with no link
  1569.     hard link to an existing file with more than one link.
  1570.  
  1571.   [umsdos_progs/tests/gen/multi.c,67]
  1572.   #Specification: utstgen / multi task / basic test
  1573.  
  1574.     A simple test is performed on a directory, by many task.
  1575.     Only one task must succeeded at a time. The others must fail
  1576.     with specific error code.
  1577.  
  1578.     So we fork 10 time.
  1579.  
  1580.     This test hopes it is a sufficient test :-(
  1581.  
  1582.   [umsdos_progs/tests/gen/file.c,176]
  1583.   #Specification: utstgen / Rename test
  1584.  
  1585.     Rename test are done with files and directories.
  1586.     The following case are tested
  1587.  
  1588.     -In the same directory
  1589.     -In the root directory
  1590.     -In two independant directory
  1591.     -In a subdirectory and the parent
  1592.  
  1593.     The same test is also done on an open file.
  1594.  
  1595.   [umsdos_progs/tests/gen/file.c,199]
  1596.   #Specification: utstgen / Rename test / open file
  1597.  
  1598.     Rename test is done on an open file. We do the following
  1599.     sequence.
  1600.  
  1601.     create a file
  1602.     Open it
  1603.  
  1604.  
  1605.                                                              25
  1606.  
  1607.  
  1608.     Rename it
  1609.     Write to the open handle
  1610.     Close it
  1611.     Open the file using the news name
  1612.     Read back the data and check it.
  1613.  
  1614.     This test does not succeed if the file is renamed accross
  1615.     directories. This sounds like a limitation of the linux msdos
  1616.     driver. I am not sure at this point. I hope it is not
  1617.     a critical feature of a Unix file system. Comments are welcome
  1618.     about this topics. Comments with solution also :-)
  1619.  
  1620.   [umsdos_progs/tests/gen/rename.c,104]
  1621.   #Specification: utstgen / rename / destination exist
  1622.  
  1623.     The following rename tests are done. The source is
  1624.     always file1 and the destination file2 always exist.
  1625.     file2 is a file or a directory. Here a the different
  1626.     case.
  1627.  
  1628.     file1 is a file, file2 is a file.
  1629.     file1 is a file, file2 is a hard link to a file.
  1630.     file1 is a file, file2 exist and is a empty directory.
  1631.     file1 is a file, file2 exist and is a non empty directory.
  1632.  
  1633.     file1 is a directory, file2 is a file.
  1634.     file1 is a directory, file2 is a hard link to a file.
  1635.     file1 is a directory, file2 exist and is a empty directory.
  1636.     file1 is a directory, file2 exist and is a non empty directory.
  1637.  
  1638.     This sequence is performed in the same directory and accros.
  1639.     The following combination are tested.
  1640.  
  1641.     path/dir1   -> path/dir1
  1642.     path/dir1   -> path/dir2
  1643.     path/dir1   -> path
  1644.     path        -> path/dir1
  1645.  
  1646.   [umsdos_progs/tests/gen/syml.c,49]
  1647.   #Specification: utstgen / symbolic links / link 2 link 2 link ...
  1648.  
  1649.     syml_simple does test the number of connected symlink the
  1650.     kernel can handle (A symlink pointing to another pointing
  1651.     to another ... and finally pointing to something.
  1652.  
  1653.   [umsdos_progs/tests/gen/dir.c,141]
  1654.   #Specification: utstgen / creating . and ..
  1655.  
  1656.     A check is done that the special entries . and .. can't be
  1657.     created nor removed.
  1658.  
  1659.  
  1660. 16.2     utstspc                                                     
  1661.  
  1662.  
  1663.   [umsdos_progs/tests/utstspc.c,22]
  1664.   #Specification: umsdos / automated test / specific
  1665.  
  1666.  
  1667.  
  1668.                                                              26
  1669.  
  1670.  
  1671.     utstspc.c is a sequence of test for the UMSDOS file system.
  1672.     These tests are specific to the UMSDOS file system.
  1673.  
  1674.   [umsdos_progs/tests/utstspc.c,33]
  1675.   #Specification: utstspc / default environnement
  1676.  
  1677.     utstspc needs to start from a fresh partition (it reformats it).
  1678.     So we normally use it on a floppy. utstspc do mount and umount
  1679.     of that floppy. The default mount point is /mnt and the default
  1680.     drive (for mformat) is F:.
  1681.  
  1682.     This value F: looks very odd. This comes from my own setup.
  1683.     Here is my definition for /etc/mtools
  1684.  
  1685.     A /dev/fd0 12 0 0 0
  1686.     B /dev/fd1 12 0 0 0
  1687.     E /dev/fd0h1200 12 80 2 15  # A: 5 1/4
  1688.     F /dev/fd1H1440 12 80 2 18  # B: 3 1/2
  1689.  
  1690.     Using /dev/fd0 and /dev/fd1 on A and B, this gives me flexibility
  1691.     for normal operation. I can read any type of floppy without much
  1692.     question. I can't do a mformat A: or B:. I always get an error.
  1693.     I guess /dev/fd0 are flexible driver, so do not impose a format.
  1694.  
  1695.     The entries E and F replicate A and B but this time use the specific
  1696.     device. So  I can do a "mformat f:" and expect to format a 1.44
  1697.     3 1/2 floppy correctly.
  1698.  
  1699.     Of course if you know better, please tell me!
  1700.  
  1701.   [umsdos_progs/tests/utstspc.c,111]
  1702.   #Specification: utstspc / floppy only
  1703.  
  1704.     To avoid desaster, utstspc will only work on floppy.
  1705.     A test is done before everything to ensure that
  1706.     the drive is indeed a floppy.
  1707.  
  1708.     It use /etc/mtools to locate the proper device. It also
  1709.     assume a floppy device have a path starting with
  1710.     "/dev/fd". This is not fool proof!
  1711.  
  1712.   [umsdos_progs/tests/utilspc.c,86]
  1713.   #Specification: utstspc / what's needed
  1714.  
  1715.     utstspc use different other program to achieve its test.
  1716.     It has to reformat, mount, unmount etc... the floppy
  1717.     on which it is doing the test.
  1718.  
  1719.     utstspc assume that the following utility are available.
  1720.  
  1721.     /usr/bin/mformat
  1722.     /etc/mount or /bin/mount
  1723.     /etc/umount or /bin/umount
  1724.  
  1725.     Also, it requieres /etc/mtools
  1726.  
  1727.