Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

DevFS
[System]


Functions

ssize_t di_system_devfs_map_from (const char *path, char *ret, size_t len)
ssize_t di_mapdevfs (const char *path, char *ret, size_t len) __attribute__((deprecated))

Function Documentation

ssize_t di_mapdevfs const char *  path,
char *  ret,
size_t  len
 

Deprecated:
Alias of di_system_devfs_map_from

ssize_t di_system_devfs_map_from const char *  path,
char *  ret,
size_t  len
 

Maps a devfs path to the corresponding standard dev path

Parameters:
path an existing device
ret device
len len of ret

00041 {
00042   static struct entry
00043   {
00044     unsigned char major;
00045     unsigned char minor;
00046     char *name;
00047     enum { ENTRY_TYPE_ONE, ENTRY_TYPE_NUMBER, ENTRY_TYPE_DISC, ENTRY_TYPE_DISC_ARRAY } type;
00048     unsigned char entry_first;
00049     unsigned char entry_disc_minor_shift;
00050   }
00051   entries[] =
00052   {
00053     /*
00054       major     minor   name            type                    entry_first
00055                                                                         entry_disc_minor_shift
00056     */
00057     { 2,        0,      "fd",           ENTRY_TYPE_NUMBER,      0,      0 },
00058     { 3,        0,      "hd",           ENTRY_TYPE_DISC,        0,      6 },
00059     { 4,        64,     "ttyS",         ENTRY_TYPE_NUMBER,      0,      0 },
00060     { 4,        0,      "tty",          ENTRY_TYPE_NUMBER,      0,      0 },
00061     { 8,        0,      "sd",           ENTRY_TYPE_DISC,        0,      4 },
00062     { 9,        0,      "md",           ENTRY_TYPE_NUMBER,      0,      0 },
00063     { 11,       0,      "scd",          ENTRY_TYPE_NUMBER,      0,      0 },
00064     { 22,       0,      "hd",           ENTRY_TYPE_DISC,        2,      6 },
00065     { 33,       0,      "hd",           ENTRY_TYPE_DISC,        4,      6 },
00066     { 34,       0,      "hd",           ENTRY_TYPE_DISC,        6,      6 },
00067     { 48,       0,      "rd",           ENTRY_TYPE_DISC_ARRAY,  0,      3 },
00068     { 49,       0,      "rd",           ENTRY_TYPE_DISC_ARRAY,  1,      3 },
00069     { 50,       0,      "rd",           ENTRY_TYPE_DISC_ARRAY,  2,      3 },
00070     { 51,       0,      "rd",           ENTRY_TYPE_DISC_ARRAY,  3,      3 },
00071     { 52,       0,      "rd",           ENTRY_TYPE_DISC_ARRAY,  4,      3 },
00072     { 53,       0,      "rd",           ENTRY_TYPE_DISC_ARRAY,  5,      3 },
00073     { 54,       0,      "rd",           ENTRY_TYPE_DISC_ARRAY,  6,      3 },
00074     { 55,       0,      "rd",           ENTRY_TYPE_DISC_ARRAY,  7,      3 },
00075     { 56,       0,      "hd",           ENTRY_TYPE_DISC,        8,      6 },
00076     { 57,       0,      "hd",           ENTRY_TYPE_DISC,        10,     6 },
00077     { 65,       0,      "sd",           ENTRY_TYPE_DISC,        16,     4 },
00078     { 66,       0,      "sd",           ENTRY_TYPE_DISC,        32,     4 },
00079     { 67,       0,      "sd",           ENTRY_TYPE_DISC,        48,     4 },
00080     { 68,       0,      "sd",           ENTRY_TYPE_DISC,        64,     4 },
00081     { 69,       0,      "sd",           ENTRY_TYPE_DISC,        80,     4 },
00082     { 70,       0,      "sd",           ENTRY_TYPE_DISC,        96,     4 },
00083     { 71,       0,      "sd",           ENTRY_TYPE_DISC,        112,    4 },
00084     { 72,       0,      "ida",          ENTRY_TYPE_DISC_ARRAY,  0,      3 },
00085     { 73,       0,      "ida",          ENTRY_TYPE_DISC_ARRAY,  1,      3 },
00086     { 74,       0,      "ida",          ENTRY_TYPE_DISC_ARRAY,  2,      3 },
00087     { 75,       0,      "ida",          ENTRY_TYPE_DISC_ARRAY,  3,      3 },
00088     { 76,       0,      "ida",          ENTRY_TYPE_DISC_ARRAY,  4,      3 },
00089     { 77,       0,      "ida",          ENTRY_TYPE_DISC_ARRAY,  5,      3 },
00090     { 78,       0,      "ida",          ENTRY_TYPE_DISC_ARRAY,  6,      3 },
00091     { 79,       0,      "ida",          ENTRY_TYPE_DISC_ARRAY,  7,      3 },
00092     { 88,       0,      "hd",           ENTRY_TYPE_DISC,        12,     6 },
00093     { 89,       0,      "hd",           ENTRY_TYPE_DISC,        14,     6 },
00094     { 90,       0,      "hd",           ENTRY_TYPE_DISC,        16,     6 },
00095     { 91,       0,      "hd",           ENTRY_TYPE_DISC,        18,     6 },
00096     { 94,       0,      "dasd",         ENTRY_TYPE_DISC,        0,      2 },
00097     { 104,      0,      "cciss",        ENTRY_TYPE_DISC_ARRAY,  0,      4 },
00098     { 105,      0,      "cciss",        ENTRY_TYPE_DISC_ARRAY,  1,      4 },
00099     { 106,      0,      "cciss",        ENTRY_TYPE_DISC_ARRAY,  2,      4 },
00100     { 107,      0,      "cciss",        ENTRY_TYPE_DISC_ARRAY,  3,      4 },
00101     { 108,      0,      "cciss",        ENTRY_TYPE_DISC_ARRAY,  4,      4 },
00102     { 109,      0,      "cciss",        ENTRY_TYPE_DISC_ARRAY,  5,      4 },
00103     { 110,      0,      "cciss",        ENTRY_TYPE_DISC_ARRAY,  6,      4 },
00104     { 111,      0,      "cciss",        ENTRY_TYPE_DISC_ARRAY,  7,      4 },
00105     { 114,      0,      "ataraid",      ENTRY_TYPE_DISC_ARRAY,  0,      4 },
00106     { 0,        0,      NULL,           ENTRY_TYPE_ONE,         0,      0 },
00107   };
00108 
00109   struct stat s;
00110   struct entry *e;
00111 
00112   ssize_t ret = 0;
00113 
00114   unsigned int disc;
00115   unsigned int part;
00116 
00117   if (!strcmp ("none", path))
00118     return snprintf (buf, n, "%s", path);
00119 
00120   if (stat (path,&s) == -1)
00121     return 0;
00122 
00123   e = entries;
00124   while (e->name != NULL) {
00125     if (major (s.st_rdev) == e->major && 
00126         ((e->type == ENTRY_TYPE_ONE && minor (s.st_rdev) == e->minor) ||
00127          (e->type != ENTRY_TYPE_ONE && minor (s.st_rdev) >= e->minor))) {
00128       break;
00129     }
00130     e++;
00131   }
00132   if (!e->name)
00133 #ifdef TEST
00134     fprintf(stderr, "(unknown device)\n");
00135 #endif
00136     /* Pass unknown devices on without changes. */
00137     return snprintf (buf, n, "%s", path);
00138   
00139   strcat (buf, "/dev/");
00140 
00141   switch (e->type)
00142   {
00143     case ENTRY_TYPE_ONE:
00144       ret = di_snprintfcat (buf, n, "%s", e->name);
00145       break;
00146 
00147     case ENTRY_TYPE_NUMBER:
00148       disc = minor (s.st_rdev) - e->minor + e->entry_first;
00149 
00150       ret = di_snprintfcat (buf, n, "%s%d", e->name, disc);
00151       break;
00152 
00153     case ENTRY_TYPE_DISC:
00154     case ENTRY_TYPE_DISC_ARRAY:
00155       disc = (minor (s.st_rdev) >> e->entry_disc_minor_shift);
00156       part = (minor (s.st_rdev) & ((1 << e->entry_disc_minor_shift) - 1));
00157 
00158       switch (e->type)
00159       {
00160         case ENTRY_TYPE_DISC:
00161           disc += e->entry_first;
00162 
00163           if (disc + 'a' > 'z')
00164           {
00165             disc -= 26;
00166             ret = di_snprintfcat (buf, n, "%s%c%c", e->name, 'a' + disc / 26, 'a' + disc % 26);
00167           }
00168           else
00169             ret = di_snprintfcat (buf, n, "%s%c", e->name, 'a' + disc);
00170 
00171           if (part)
00172             ret = di_snprintfcat (buf, n, "%d", part);
00173 
00174           break;
00175         case ENTRY_TYPE_DISC_ARRAY:
00176           ret = di_snprintfcat (buf, n, "%s/c%dd%d", e->name, e->entry_first, disc);
00177 
00178           if (part)
00179             ret = di_snprintfcat (buf, n, "p%d", part);
00180 
00181           break;
00182         default:
00183           break;
00184       }
00185       break;
00186   };
00187 
00188   return ret;
00189 }


Generated on Wed Apr 21 23:39:52 2004 for libdebian-installer by doxygen 1.3.6-20040222