iPXE
blockdev.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <errno.h>
27 #include <ipxe/interface.h>
28 #include <ipxe/blockdev.h>
29 
30 /** @file
31  *
32  * Block devices
33  *
34  */
35 
36 /**
37  * Read from block device
38  *
39  * @v control Control interface
40  * @v data Data interface
41  * @v lba Starting logical block address
42  * @v count Number of logical blocks
43  * @v buffer Data buffer
44  * @v len Length of data buffer
45  * @ret rc Return status code
46  */
47 int block_read ( struct interface *control, struct interface *data,
48  uint64_t lba, unsigned int count,
49  userptr_t buffer, size_t len ) {
50  struct interface *dest;
51  block_read_TYPE ( void * ) *op =
53  void *object = intf_object ( dest );
54  int rc;
55 
56  if ( op ) {
57  rc = op ( object, data, lba, count, buffer, len );
58  } else {
59  /* Default is to fail to issue the command */
60  rc = -EOPNOTSUPP;
61  }
62 
63  intf_put ( dest );
64  return rc;
65 }
66 
67 /**
68  * Write to block device
69  *
70  * @v control Control interface
71  * @v data Data interface
72  * @v lba Starting logical block address
73  * @v count Number of logical blocks
74  * @v buffer Data buffer
75  * @v len Length of data buffer
76  * @ret rc Return status code
77  */
78 int block_write ( struct interface *control, struct interface *data,
79  uint64_t lba, unsigned int count,
80  userptr_t buffer, size_t len ) {
81  struct interface *dest;
82  block_write_TYPE ( void * ) *op =
84  void *object = intf_object ( dest );
85  int rc;
86 
87  if ( op ) {
88  rc = op ( object, data, lba, count, buffer, len );
89  } else {
90  /* Default is to fail to issue the command */
91  rc = -EOPNOTSUPP;
92  }
93 
94  intf_put ( dest );
95  return rc;
96 }
97 
98 /**
99  * Read block device capacity
100  *
101  * @v control Control interface
102  * @v data Data interface
103  * @ret rc Return status code
104  */
106  struct interface *dest;
107  block_read_capacity_TYPE ( void * ) *op =
109  void *object = intf_object ( dest );
110  int rc;
111 
112  if ( op ) {
113  rc = op ( object, data );
114  } else {
115  /* Default is to fail to issue the command */
116  rc = -EOPNOTSUPP;
117  }
118 
119  intf_put ( dest );
120  return rc;
121 }
122 
123 /**
124  * Report block device capacity
125  *
126  * @v intf Interface
127  * @v capacity Block device capacity
128  */
130  struct block_device_capacity *capacity ) {
131  struct interface *dest;
132  block_capacity_TYPE ( void * ) *op =
134  void *object = intf_object ( dest );
135 
136  if ( op ) {
137  op ( object, capacity );
138  } else {
139  /* Default is to do nothing */
140  }
141 
142  intf_put ( dest );
143 }
#define block_read_capacity_TYPE(object_type)
Definition: blockdev.h:45
int block_write(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Write to block device.
Definition: blockdev.c:78
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t lba
Start address.
Definition: scsi.h:23
Error codes.
void block_capacity(struct interface *intf, struct block_device_capacity *capacity)
Report block device capacity.
Definition: blockdev.c:129
unsigned long long uint64_t
Definition: stdint.h:13
int block_read(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Read from block device.
Definition: blockdev.c:47
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
struct interface * intf
Original interface.
Definition: interface.h:158
An object interface.
Definition: interface.h:124
Object interfaces.
#define block_read_TYPE(object_type)
Definition: blockdev.h:30
static void * dest
Definition: strings.h:176
Block devices.
uint32_t control
Control.
Definition: myson.h:14
#define EOPNOTSUPP
Operation not supported on socket.
Definition: errno.h:604
#define block_write_TYPE(object_type)
Definition: blockdev.h:38
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t len
Length.
Definition: ena.h:14
Block device capacity.
Definition: blockdev.h:18
uint16_t count
Number of entries.
Definition: ena.h:22
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int block_read_capacity(struct interface *control, struct interface *data)
Read block device capacity.
Definition: blockdev.c:105
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269
#define block_capacity_TYPE(object_type)
Definition: blockdev.h:50
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33