util.c 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* devfs (Device FileSystem) utilities.
  2. Copyright (C) 1999-2002 Richard Gooch
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; if not, write to the Free
  13. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. Richard Gooch may be reached by email at rgooch@atnf.csiro.au
  15. The postal address is:
  16. Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
  17. ChangeLog
  18. 19991031 Richard Gooch <rgooch@atnf.csiro.au>
  19. Created.
  20. 19991103 Richard Gooch <rgooch@atnf.csiro.au>
  21. Created <_devfs_convert_name> and supported SCSI and IDE CD-ROMs
  22. 20000203 Richard Gooch <rgooch@atnf.csiro.au>
  23. Changed operations pointer type to void *.
  24. 20000621 Richard Gooch <rgooch@atnf.csiro.au>
  25. Changed interface to <devfs_register_series>.
  26. 20000622 Richard Gooch <rgooch@atnf.csiro.au>
  27. Took account of interface change to <devfs_mk_symlink>.
  28. Took account of interface change to <devfs_mk_dir>.
  29. 20010519 Richard Gooch <rgooch@atnf.csiro.au>
  30. Documentation cleanup.
  31. 20010709 Richard Gooch <rgooch@atnf.csiro.au>
  32. Created <devfs_*alloc_major> and <devfs_*alloc_devnum>.
  33. 20010710 Richard Gooch <rgooch@atnf.csiro.au>
  34. Created <devfs_*alloc_unique_number>.
  35. 20010730 Richard Gooch <rgooch@atnf.csiro.au>
  36. Documentation typo fix.
  37. 20010806 Richard Gooch <rgooch@atnf.csiro.au>
  38. Made <block_semaphore> and <char_semaphore> private.
  39. 20010813 Richard Gooch <rgooch@atnf.csiro.au>
  40. Fixed bug in <devfs_alloc_unique_number>: limited to 128 numbers
  41. 20010818 Richard Gooch <rgooch@atnf.csiro.au>
  42. Updated major masks up to Linus' "no new majors" proclamation.
  43. Block: were 126 now 122 free, char: were 26 now 19 free.
  44. 20020324 Richard Gooch <rgooch@atnf.csiro.au>
  45. Fixed bug in <devfs_alloc_unique_number>: was clearing beyond
  46. bitfield.
  47. 20020326 Richard Gooch <rgooch@atnf.csiro.au>
  48. Fixed bitfield data type for <devfs_*alloc_devnum>.
  49. Made major bitfield type and initialiser 64 bit safe.
  50. 20020413 Richard Gooch <rgooch@atnf.csiro.au>
  51. Fixed shift warning on 64 bit machines.
  52. 20020428 Richard Gooch <rgooch@atnf.csiro.au>
  53. Copied and used macro for error messages from fs/devfs/base.c
  54. 20021013 Richard Gooch <rgooch@atnf.csiro.au>
  55. Documentation fix.
  56. 20030101 Adam J. Richter <adam@yggdrasil.com>
  57. Eliminate DEVFS_SPECIAL_{CHR,BLK}. Use mode_t instead.
  58. 20030106 Christoph Hellwig <hch@infradead.org>
  59. Rewrite devfs_{,de}alloc_devnum to look like C code.
  60. */
  61. #include <linux/module.h>
  62. #include <linux/init.h>
  63. #include <linux/devfs_fs_kernel.h>
  64. #include <linux/slab.h>
  65. #include <linux/vmalloc.h>
  66. #include <linux/genhd.h>
  67. #include <linux/bitops.h>
  68. int devfs_register_tape(const char *name)
  69. {
  70. char tname[32], dest[64];
  71. static unsigned int tape_counter;
  72. unsigned int n = tape_counter++;
  73. sprintf(dest, "../%s", name);
  74. sprintf(tname, "tapes/tape%u", n);
  75. devfs_mk_symlink(tname, dest);
  76. return n;
  77. }
  78. EXPORT_SYMBOL(devfs_register_tape);
  79. void devfs_unregister_tape(int num)
  80. {
  81. if (num >= 0)
  82. devfs_remove("tapes/tape%u", num);
  83. }
  84. EXPORT_SYMBOL(devfs_unregister_tape);