vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / vmod / lib / libvmoddor.c
blobb8c735856668d8bff905c792a54325badc226b63
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <sys/ioctl.h>
5 #include <string.h>
6 #include <errno.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include "vmoddor.h"
11 #include "libvmoddor.h"
13 static int luns_to_fd [VMODDOR_MAX_DEVICES];
15 int vmoddor_open(int lun)
17 char device[VMODDOR_SIZE_CARRIER_NAME] = "";
18 int ret;
20 if(luns_to_fd[lun] != 0)
21 return luns_to_fd[lun];
23 sprintf(device, "/dev/vmoddor.%d", lun);
25 ret = open(device, O_RDWR, 0);
26 if (ret < 0){
27 return -1;
30 luns_to_fd[lun] = ret;
31 return 0;
34 int vmoddor_close(int lun)
36 int ret;
38 ret = close(luns_to_fd[lun]);
39 luns_to_fd[lun] = 0;
40 return ret;
43 int vmoddor_write(int lun , struct vmoddor_warg val)
45 int ret;
46 int fd;
47 struct vmoddor_arg argument;
49 argument.data = val.data;
50 argument.offset = val.offset;
51 argument.size = val.size;
53 fd = luns_to_fd[lun];
54 ret = ioctl(fd, VMODDOR_WRITE, (char *)&argument);
56 if(ret < 0){
57 return ret;
60 return 0;