40 using Base = BASE_DEV;
41 using Part_device = PART_DEV;
44 typename Base::Discard_info discard_info()
const override
46 return dev()->parent()->discard_info();
50 Inout_callback
const &cb,
bool discard)
override
52 auto sz = dev()->partition_size();
60 if (cur->
sector >= sz - offset)
62 if (cur->num_sectors > sz)
64 if (offset + cur->
sector > sz - cur->num_sectors)
67 cur = cur->next.get();
70 auto start = offset + dev()->partition_start();
71 Dbg::trace(
"partition")
72 .printf(
"Starting sector on disk: 0x%llx\n", start);
73 return dev()->parent()->discard(start, blocks, cb, discard);
77 Part_device
const *dev()
const
78 {
return static_cast<Part_device
const *
>(
this); }
91class Partitioned_device
95 using Device_type = BASE_DEV;
106 "Last sector of partition before first sector.");
108 if (partition_id > 999)
110 "Partition ID must be smaller than 1000.");
112 snprintf(_partition_id,
sizeof(_partition_id),
"%d", partition_id);
114 static_assert(
sizeof(_guid) ==
sizeof(pi.
guid),
"String size mismatch");
115 memcpy(_guid, pi.
guid,
sizeof(_guid));
119 {
return _parent->notification_domain(); }
121 bool is_read_only()
const override
122 {
return _parent->is_read_only(); }
124 bool match_hid(
cxx::String const &hid)
const override
129 _Pragma(
"GCC diagnostic push");
130 _Pragma(
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
131 std::u16string whid =
132 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,
char16_t>{}
133 .from_bytes(std::string(hid.
start(), hid.
len()));
134 _Pragma(
"GCC diagnostic pop");
139 char const *delim =
":";
140 char const *pos = hid.
rfind(delim);
149 {
return _size * _parent->sector_size(); }
152 {
return _parent->sector_size(); }
155 {
return _parent->max_size(); }
157 unsigned max_segments()
const override
158 {
return _parent->max_segments(); }
160 void reset()
override
163 int dma_map(Block_device::Mem_region *region,
l4_addr_t offset,
166 {
return _parent->dma_map(region, offset, num_sectors, dir, phys); }
170 {
return _parent->dma_unmap(phys, num_sectors, dir); }
173 Inout_callback
const &cb,
183 total += cur->num_sectors;
184 cur = cur->next.get();
187 if (total > _size - sector)
190 Dbg::trace(
"partition").printf(
"Sector on disk: 0x%llx\n", sector + _start);
191 return _parent->inout_data(sector + _start, blocks, cb, dir);
194 int flush(Inout_callback
const &cb)
override
196 return _parent->flush(cb);
199 void start_device_scan(Block_device::Errand::Callback
const &callback)
override
208 Device_type *parent()
const
209 {
return _parent.get(); }
214 std::u16string _name;
215 char _partition_id[4];
Opaque type for representing a notification domain.