MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / blk_control

Function blk_control

components/drivers/block/blk.c:102–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102static rt_err_t blk_control(rt_device_t dev, int cmd, void *args)
103{
104 rt_err_t err;
105 struct rt_blk_disk *disk = to_blk_disk(dev);
106
107 switch (cmd)
108 {
109 case RT_DEVICE_CTRL_BLK_GETGEOME:
110 if (args)
111 {
112 err = disk->ops->getgeome(disk, args);
113 }
114 else
115 {
116 err = -RT_EINVAL;
117 }
118
119 break;
120
121 case RT_DEVICE_CTRL_BLK_SYNC:
122 if (disk->ops->sync)
123 {
124 rt_sem_take(&disk->usr_lock, RT_WAITING_FOREVER);
125
126 spin_lock(&disk->lock);
127
128 err = disk->ops->sync(disk);
129
130 spin_unlock(&disk->lock);
131
132 rt_sem_release(&disk->usr_lock);
133 }
134 else
135 {
136 err = -RT_ENOSYS;
137 }
138 break;
139
140 case RT_DEVICE_CTRL_BLK_ERASE:
141 if (disk->ops->erase)
142 {
143 rt_sem_take(&disk->usr_lock, RT_WAITING_FOREVER);
144
145 spin_lock(&disk->lock);
146
147 if (disk->parent.ref_count != 1)
148 {
149 err = -RT_EBUSY;
150 goto _unlock;
151 }
152
153 blk_remove_all(disk);
154
155 err = disk->ops->erase(disk);
156
157 _unlock:
158 spin_unlock(&disk->lock);
159

Callers

nothing calls this directly

Calls 7

rt_sem_takeFunction · 0.85
rt_sem_releaseFunction · 0.85
blk_remove_allFunction · 0.85
device_get_blk_ssizeFunction · 0.85
device_get_all_blk_ssizeFunction · 0.85
spin_lockFunction · 0.70
spin_unlockFunction · 0.70

Tested by

no test coverage detected