capture Makefile patch adding LDFLAGS now that we're 3.0 (quilt)
[debian/efibootmgr] / src / lib / scsi_ioctls.c
1 /*
2   scsi_ioctls.[ch]
3  
4   Copyright (C) 2001 Dell Computer Corporation <Matt_Domsch@dell.com>
5  
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdio.h>
22 #include <sys/pci.h>
23 #include <stdint.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <sys/ioctl.h>
27 #include "scsi_ioctls.h"
28
29 int
30 idlun_to_components (Scsi_Idlun *idlun,
31                      unsigned char *host,
32                      unsigned char *channel,
33                      unsigned char *id,
34                      unsigned char *lun)
35 {
36         if (!idlun || !host || !channel || !id || !lun) return 1;
37         
38         *host    = (idlun->dev_id >> 24) & 0xFF;
39         *channel = (idlun->dev_id >> 16) & 0xFF;
40         *id      = (idlun->dev_id      ) & 0xFF;
41         *lun     = (idlun->dev_id >>  8) & 0xFF;
42         return 0;
43 }
44
45
46 inline int
47 get_scsi_idlun(int fd, Scsi_Idlun *idlun)
48 {
49         return ioctl(fd, SCSI_IOCTL_GET_IDLUN, idlun);
50 }
51
52 inline int 
53 get_scsi_pci(int fd, char *slot_name)
54 {
55         return ioctl(fd, SCSI_IOCTL_GET_PCI, slot_name);
56 }
57
58
59
60 #ifdef SCSI_IOCTLS_EXE
61 static void
62 usage(char **argv)
63 {
64         printf("Usage: %s /dev/sdX    where sdX is a SCSI device node.\n",
65                argv[0]);
66 }
67
68 int main(int argc, char **argv)
69 {
70         Scsi_Idlun idlun;
71         char slot_name[8];
72         int fd = 0, rc = 0;
73
74         memset(&idlun, 0, sizeof(idlun));
75
76         if (argc < 2) {usage(argv); exit(1);}
77         
78         fd = open(argv[1], O_RDONLY);
79         if (fd == -1) {
80                 perror("Unable to open file");
81                 exit(1);
82         }
83
84         rc = get_scsi_pci(fd, slot_name);
85         if (rc) {
86                 perror("Unable to get_scsi_pci()");
87         }
88         rc = get_scsi_idlun(fd, &idlun);
89         if (rc) {
90                 perror("Unable to get_scsi_idlun()");
91         }
92         
93         printf("Device: %s\n", argv[1]);
94         printf("PCI: %s\n", slot_name);
95
96         printf("SCSI: host %d channel %d id %d lun %d, unique ID %x\n",
97                (idlun.dev_id >> 24) & 0xFF, // host
98                (idlun.dev_id >> 16) & 0xFF, // channel
99                idlun.dev_id  & 0xFF,        // id
100                (idlun.dev_id >>  8) & 0xFF, // lun
101                idlun.host_unique_id);
102
103         return 0;
104 }
105 #endif