home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / backup / star-1.3.1.tar.gz / star-1.3.1.tar / star-1.3.1 / star / device.c < prev    next >
C/C++ Source or Header  |  2001-02-15  |  5KB  |  256 lines

  1. /* @(#)device.c    1.7 01/02/15 Copyright 1996 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)device.c    1.7 01/02/15 Copyright 1996 J. Schilling";
  5. #endif
  6. /*
  7.  *    Handle local and remote device major/minor mappings
  8.  *
  9.  *    Copyright (c) 1996 J. Schilling
  10.  */
  11. /*
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2, or (at your option)
  15.  * any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; see the file COPYING.  If not, write to
  24.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  */
  26.  
  27. #include <mconfig.h>
  28. #include <sys/types.h>
  29. #include <standard.h>
  30. #include <schily.h>
  31. #define    __XDEV__    /* Needed to activate XDEV_T definitions */
  32. #include <device.h>
  33.  
  34. #ifdef    DEV_DEFAULTS
  35. EXPORT    int    minorbits = 8;
  36. EXPORT    XDEV_T    minormask = 0xFFLU;
  37. #else
  38. EXPORT    int    minorbits;
  39. EXPORT    XDEV_T    minormask;
  40. #endif
  41.  
  42. #ifdef    __STDC__
  43. EXPORT    XDEV_T    _dev_mask[] = {
  44.     0x00000000LU,
  45.     0x00000001LU,
  46.     0x00000003LU,
  47.     0x00000007LU,
  48.     0x0000000FLU,
  49.     0x0000001FLU,
  50.     0x0000003FLU,
  51.     0x0000007FLU,
  52.     0x000000FFLU,
  53.     0x000001FFLU,
  54.     0x000003FFLU,
  55.     0x000007FFLU,
  56.     0x00000FFFLU,
  57.     0x00001FFFLU,
  58.     0x00003FFFLU,
  59.     0x00007FFFLU,
  60.     0x0000FFFFLU,
  61.     0x0001FFFFLU,
  62.     0x0003FFFFLU,
  63.     0x0007FFFFLU,
  64.     0x000FFFFFLU,
  65.     0x001FFFFFLU,
  66.     0x003FFFFFLU,
  67.     0x007FFFFFLU,
  68.     0x00FFFFFFLU,
  69.     0x01FFFFFFLU,
  70.     0x03FFFFFFLU,
  71.     0x07FFFFFFLU,
  72.     0x0FFFFFFFLU,
  73.     0x1FFFFFFFLU,
  74.     0x3FFFFFFFLU,
  75.     0x7FFFFFFFLU,
  76.     0xFFFFFFFFLU,
  77. #if SIZEOF_UNSIGNED_LONG_INT > 4
  78.     0x00000001FFFFFFFFLU,
  79.     0x00000003FFFFFFFFLU,
  80.     0x00000007FFFFFFFFLU,
  81.     0x0000000FFFFFFFFFLU,
  82.     0x0000001FFFFFFFFFLU,
  83.     0x0000003FFFFFFFFFLU,
  84.     0x0000007FFFFFFFFFLU,
  85.     0x000000FFFFFFFFFFLU,
  86.     0x000001FFFFFFFFFFLU,
  87.     0x000003FFFFFFFFFFLU,
  88.     0x000007FFFFFFFFFFLU,
  89.     0x00000FFFFFFFFFFFLU,
  90.     0x00001FFFFFFFFFFFLU,
  91.     0x00003FFFFFFFFFFFLU,
  92.     0x00007FFFFFFFFFFFLU,
  93.     0x0000FFFFFFFFFFFFLU,
  94.     0x0001FFFFFFFFFFFFLU,
  95.     0x0003FFFFFFFFFFFFLU,
  96.     0x0007FFFFFFFFFFFFLU,
  97.     0x000FFFFFFFFFFFFFLU,
  98.     0x001FFFFFFFFFFFFFLU,
  99.     0x003FFFFFFFFFFFFFLU,
  100.     0x007FFFFFFFFFFFFFLU,
  101.     0x00FFFFFFFFFFFFFFLU,
  102.     0x01FFFFFFFFFFFFFFLU,
  103.     0x03FFFFFFFFFFFFFFLU,
  104.     0x07FFFFFFFFFFFFFFLU,
  105.     0x0FFFFFFFFFFFFFFFLU,
  106.     0x1FFFFFFFFFFFFFFFLU,
  107.     0x3FFFFFFFFFFFFFFFLU,
  108.     0x7FFFFFFFFFFFFFFFLU,
  109.     0xFFFFFFFFFFFFFFFFLU,
  110. #endif
  111. };
  112. #else
  113. EXPORT    XDEV_T    _dev_mask[] = {
  114.     0x00000000L,
  115.     0x00000001L,
  116.     0x00000003L,
  117.     0x00000007L,
  118.     0x0000000FL,
  119.     0x0000001FL,
  120.     0x0000003FL,
  121.     0x0000007FL,
  122.     0x000000FFL,
  123.     0x000001FFL,
  124.     0x000003FFL,
  125.     0x000007FFL,
  126.     0x00000FFFL,
  127.     0x00001FFFL,
  128.     0x00003FFFL,
  129.     0x00007FFFL,
  130.     0x0000FFFFL,
  131.     0x0001FFFFL,
  132.     0x0003FFFFL,
  133.     0x0007FFFFL,
  134.     0x000FFFFFL,
  135.     0x001FFFFFL,
  136.     0x003FFFFFL,
  137.     0x007FFFFFL,
  138.     0x00FFFFFFL,
  139.     0x01FFFFFFL,
  140.     0x03FFFFFFL,
  141.     0x07FFFFFFL,
  142.     0x0FFFFFFFL,
  143.     0x1FFFFFFFL,
  144.     0x3FFFFFFFL,
  145.     0x7FFFFFFFL,
  146.     0xFFFFFFFFL,
  147. #if SIZEOF_UNSIGNED_LONG_INT > 4
  148.     0x00000001FFFFFFFFL,
  149.     0x00000003FFFFFFFFL,
  150.     0x00000007FFFFFFFFL,
  151.     0x0000000FFFFFFFFFL,
  152.     0x0000001FFFFFFFFFL,
  153.     0x0000003FFFFFFFFFL,
  154.     0x0000007FFFFFFFFFL,
  155.     0x000000FFFFFFFFFFL,
  156.     0x000001FFFFFFFFFFL,
  157.     0x000003FFFFFFFFFFL,
  158.     0x000007FFFFFFFFFFL,
  159.     0x00000FFFFFFFFFFFL,
  160.     0x00001FFFFFFFFFFFL,
  161.     0x00003FFFFFFFFFFFL,
  162.     0x00007FFFFFFFFFFFL,
  163.     0x0000FFFFFFFFFFFFL,
  164.     0x0001FFFFFFFFFFFFL,
  165.     0x0003FFFFFFFFFFFFL,
  166.     0x0007FFFFFFFFFFFFL,
  167.     0x000FFFFFFFFFFFFFL,
  168.     0x001FFFFFFFFFFFFFL,
  169.     0x003FFFFFFFFFFFFFL,
  170.     0x007FFFFFFFFFFFFFL,
  171.     0x00FFFFFFFFFFFFFFL,
  172.     0x01FFFFFFFFFFFFFFL,
  173.     0x03FFFFFFFFFFFFFFL,
  174.     0x07FFFFFFFFFFFFFFL,
  175.     0x0FFFFFFFFFFFFFFFL,
  176.     0x1FFFFFFFFFFFFFFFL,
  177.     0x3FFFFFFFFFFFFFFFL,
  178.     0x7FFFFFFFFFFFFFFFL,
  179.     0xFFFFFFFFFFFFFFFFL,
  180. #endif
  181. };
  182. #endif
  183.  
  184. EXPORT void
  185. dev_init(debug)
  186.     BOOL    debug;
  187. {
  188.     int    i;
  189.     dev_t    x;
  190.  
  191.     for (i=0, x=1; minor(x) == x; i++, x<<=1)
  192.         ;
  193.  
  194.     minorbits = i;
  195.     minormask = _dev_mask[i];
  196.  
  197.     if (debug)
  198.         error("dev_minorbits:    %d\n", minorbits);
  199. }
  200.  
  201. #ifdef    IS_LIBRARY
  202.  
  203. #undef    dev_major
  204. EXPORT XDEV_T
  205. dev_major(dev)
  206.     XDEV_T    dev;
  207. {
  208.     return (dev >> minorbits);
  209. }
  210.  
  211. #undef    _dev_major
  212. EXPORT XDEV_T
  213. _dev_major(mbits, dev)
  214.     int    mbits;
  215.     XDEV_T    dev;
  216. {
  217.     return (dev >> mbits);
  218. }
  219.  
  220. #undef    dev_minor
  221. EXPORT XDEV_T
  222. dev_minor(dev)
  223.     XDEV_T    dev;
  224. {
  225.     return (dev & minormask);
  226. }
  227.  
  228. #undef    _dev_minor
  229. EXPORT XDEV_T
  230. _dev_minor(mbits, dev)
  231.     int    mbits;
  232.     XDEV_T    dev;
  233. {
  234.     return (dev & _dev_mask[mbits]);
  235. }
  236.  
  237. #undef    dev_make
  238. EXPORT XDEV_T
  239. dev_make(majo, mino)
  240.     XDEV_T    majo;
  241.     XDEV_T    mino;
  242. {
  243.     return ((majo << minorbits) | mino);
  244. }
  245.  
  246. #undef    _dev_make
  247. EXPORT XDEV_T
  248. _dev_make(mbits, majo, mino)
  249.     int    mbits;
  250.     XDEV_T    majo;
  251.     XDEV_T    mino;
  252. {
  253.     return ((majo << mbits) | mino);
  254. }
  255. #endif    /* IS_LIBRARY */
  256.