3 * All rights reserved. Distributed under the terms of the MIT License.
7 #include <boot/FileMapDisk.h>
17 #include <SupportDefs.h>
20 //#define TRACE_FILEMAPDISK
21 #ifdef TRACE_FILEMAPDISK
22 # define TRACE(x) dprintf x
32 FileMapDisk::FileMapDisk()
39 FileMapDisk::~FileMapDisk()
45 FileMapDisk::Init(Node
*node
/*, Partition *partition, FileMap *map, off_t imageSize*/)
47 TRACE(("FileMapDisk::FileMapDisk(%p)\n", node
));
50 fPartition = partition;
52 fImageSize = imageSize;
54 // create and bind socket
55 fSocket = new(nothrow) UDPSocket;
59 status_t error = fSocket->Bind(INADDR_ANY, 6666);
69 FileMapDisk::Open(void **_cookie
, int mode
)
71 TRACE(("FileMapDisk::Open(, 0x%08x)\n", mode
));
75 return fNode
->Open(_cookie
, mode
);
80 FileMapDisk::Close(void *cookie
)
82 TRACE(("FileMapDisk::Close(%p)\n", cookie
));
86 return fNode
->Close(cookie
);
92 FileMapDisk::ReadAt(void *cookie
, off_t pos
, void *_buffer
,
95 TRACE(("FileMapDisk::ReadAt(%p, %lld, , %ld)\n", cookie
, pos
, bufferSize
));
99 return fNode
->ReadAt(cookie
, pos
, _buffer
, bufferSize
);
105 FileMapDisk::WriteAt(void */
*cookie*/
, off_t pos
, const void *buffer
,
108 // Not needed in the boot loader.
109 return B_PERMISSION_DENIED
;
114 FileMapDisk::GetName(char *nameBuffer
, size_t bufferSize
) const
116 const char *prefix
= "FileMapDisk:";
120 snprintf(nameBuffer
, bufferSize
, prefix
);
121 if (bufferSize
> strlen(prefix
) && fNode
)
122 return fNode
->GetName(nameBuffer
+ strlen(prefix
),
123 bufferSize
- strlen(prefix
));
130 FileMapDisk::GetFileMap(struct file_map_run
*runs
, int32
*count
)
132 return fNode
->GetFileMap(runs
, count
);
137 FileMapDisk::Size() const
141 return fNode
->Size();
146 FileMapDisk::FindAnyFileMapDisk(Directory
*volume
)
148 TRACE(("FileMapDisk::FindAnyFileMapDisk(%p)\n", volume
));
155 //XXX: check lower/mixed case as well
158 dirnode
= volume
->Lookup(FMAP_FOLDER_NAME
, true);
159 if (!dirnode
|| !S_ISDIR(dirnode
->Type()))
161 dir
= (Directory
*)dirnode
;
162 node
= dir
->Lookup(FMAP_IMAGE_NAME
, true);
166 // create a FileMapDisk object
167 FileMapDisk
*disk
= new(nothrow
) FileMapDisk
;
169 error
= disk
->Init(node
);
181 FileMapDisk::RegisterFileMapBootItem()
185 struct file_map_boot_item
*item
;
186 item
= (struct file_map_boot_item
*)malloc(sizeof(struct file_map_boot_item
));
187 item
->num_runs
= FMAP_MAX_RUNS
;
189 err
= GetFileMap(item
->runs
, &item
->num_runs
);
192 // err = add_boot_item("file_map_disk", item, sizeof(struct file_map_boot_item));