]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/install+setup/install/ide.c
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848...
[people/pmueller/ipfire-2.x.git] / src / install+setup / install / ide.c
1 /* SmoothWall install program.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * (c) Lawrence Manning, 2001
7 * Contains some functs for scanning /proc for ide info on CDROMS and
8 * harddisks.
9 *
10 * $Id: ide.c,v 1.4 2003/12/11 11:25:53 riddles Exp $
11 *
12 */
13
14 #include "install.h"
15
16 /* checkide(). Scans the named drive letter and returns the IDE_??? type. */
17 int checkide(char letter)
18 {
19 FILE *f = NULL;
20 char filename[STRING_SIZE];
21 char buffer[STRING_SIZE];
22
23 sprintf(filename, "/proc/ide/hd%c/media", letter);
24
25 if (!(f = fopen(filename, "r")))
26 return IDE_EMPTY;
27
28 if (!(fgets(buffer, STRING_SIZE, f)))
29 {
30 printf("Couldn't read from %s\n", filename);
31 fclose(f);
32 return IDE_EMPTY;
33 }
34
35 fclose(f);
36
37 stripnl(buffer);
38
39 if (strcmp(buffer, "cdrom") == 0)
40 return IDE_CDROM;
41 else if (strcmp(buffer, "disk") == 0)
42 return IDE_HD;
43 else
44 return IDE_UNKNOWN;
45 }
46
47 /* findidetype(). Finds the first ide deveice of the given IDE_?? type. */
48 char findidetype(int type)
49 {
50 char letter;
51
52 for (letter = 'a'; letter <= 'z'; letter++)
53 {
54 if ((checkide(letter)) == type)
55 {
56 return letter;
57 }
58 }
59 return '\0';
60 }
61