-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscsi_target.c
95 lines (82 loc) · 1.56 KB
/
scsi_target.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "scsi_target.h"
#include <stdlib.h>
#include <string.h>
struct scsi_target
{
struct scsi_target* next;
struct scsi_host* scsi_host;
struct blk_dev_info* bdi;
struct scsi_tuple tuple;
char blk_dev[MAX_BLK_DEV_LEN];
};
struct scsi_target*
scsi_target_create(
struct scsi_host* host
, struct blk_dev_info* bdi
, const struct scsi_tuple* tup
, const char blk_dev[MAX_BLK_DEV_LEN]
)
{
struct scsi_target* new_st;
if (NULL != (new_st = calloc(1, sizeof(struct scsi_target))))
{
new_st->scsi_host = host;
new_st->bdi = bdi;
strncpy(new_st->blk_dev, blk_dev, MAX_BLK_DEV_LEN);
memcpy(&new_st->tuple, tup, sizeof(struct scsi_tuple));
}
return new_st;
}
void
scsi_target_add_sibling(
struct scsi_target* st
, struct scsi_target* prev
, struct scsi_target** head
)
{
if (prev)
{
st->next = prev->next;
prev->next = st;
}
else
{
st->next = *head;
*head = st;
}
}
struct scsi_target*
scsi_target_next(
const struct scsi_target* st
)
{
return st ? st->next : NULL;
}
void
scsi_target_destroy(
struct scsi_target* st
)
{
free(st);
}
const struct scsi_tuple*
scsi_target_get_tuple(
const struct scsi_target* st
)
{
return st ? &st->tuple : NULL;
}
const struct blk_dev_info*
scsi_target_get_blk_dev_info(
const struct scsi_target* st
)
{
return st ? st->bdi : NULL;
}
const char*
scsi_target_get_blk_dev(
const struct scsi_target* st
)
{
return st ? st->blk_dev : NULL;
}