Lines Matching refs:dev
28 static int DeviceStat(const BlockDevice &dev, struct stat &devStat)
31 if (!stat (dev.devPath.c_str(), &devStat)) {
34 if (stat (dev.devPath.c_str(), &devStat) != EOK) {
41 static int DeviceProbeType(BlockDevice &dev)
46 BlockSpecific *specific = BLOCK_SPECIFIC(&dev);
47 if (DeviceStat(dev, devStat) == 0) {
58 dev.type = DEVICE_SCSI;
61 dev.type = DEVICE_EMMC;
64 dev.type = DEVICE_UNKNOWN;
84 static bool ReadDeviceSysfsFile(BlockDevice &dev, const std::string &file, std::string &strl)
91 LastComponent(dev.devPath).c_str(), file.c_str()) == -1) {
111 static bool SdmmcGetProductInfo(BlockDevice &dev, std::string &type, std::string &name)
116 bool ret = ReadDeviceSysfsFile(dev, typeStr, type);
117 bool red = ReadDeviceSysfsFile(dev, nameStr, name);
121 bool SetBlockDeviceMode(BlockDevice &dev)
123 BlockSpecific *specific = BLOCK_SPECIFIC(&dev);
125 specific->fd = open(dev.devPath.c_str(), RW_MODE);
127 LOG(WARNING) << "Open " << dev.devPath << " with read-write failed, try read-only mode";
128 specific->fd = open(dev.devPath.c_str(), RD_MODE);
129 bool a1 = dev.readOnly;
130 dev.readOnly = 1;
132 LOG(ERROR) << "Open " << dev.devPath << " with read-only mode failed: " << errno;
133 dev.readOnly = a1;
137 dev.readOnly = 0;
142 static int BlockDeviceClose(const BlockDevice &dev)
144 BlockSpecific* specific = BLOCK_SPECIFIC(&dev);
199 static int InitGeneric(BlockDevice &dev, const std::string modelName)
202 if (DeviceStat(dev, devStat) == 0) {
206 if (!SetBlockDeviceMode(dev)) {
211 const std::string devName = LastComponent(dev.devPath);
217 dev.length = devSize;
218 dev.sectorSize = SECTOR_SIZE_DEFAULT;
219 dev.physSectorSize = SECTOR_SIZE_DEFAULT;
220 dev.model = modelName;
221 BlockDeviceClose (dev);
222 dev.fd = -1;
226 static int InitSdmmc(BlockDevice &dev)
231 bool a1 = SdmmcGetProductInfo(dev, type, name);
239 return InitGeneric(dev, id);
244 BlockDevice *dev = nullptr;
247 dev = static_cast<BlockDevice*>(calloc(1, sizeof (BlockDevice)));
248 if (dev == nullptr) {
253 dev->devPath = path;
254 dev->specific = static_cast<BlockSpecific*>(calloc(1, sizeof (BlockSpecific)));
255 if (!dev->specific) {
257 free(dev);
261 specific = BLOCK_SPECIFIC(dev);
262 dev->readOnly = 0;
263 dev->sectorSize = 0;
264 dev->physSectorSize = 0;
267 bool a1 = DeviceProbeType(*dev);
269 if (dev->type == DEVICE_EMMC) {
270 ret = InitSdmmc(*dev);
275 if (dev->type != DEVICE_EMMC) {
284 free(dev->specific);
285 free(dev);
286 dev = nullptr;
288 return dev;
291 static Disk* NewBlockDisk(const BlockDevice &dev, const DiskType diskType)
301 disk->dev = (BlockDevice*)&dev;
311 struct BlockDevice *dev = nullptr;
312 dev = NewBlockDevice(path);
313 if (dev == nullptr) {
318 disk = NewBlockDisk(*dev, GPT);
327 static struct Partition* NewPartition(const BlockDevice &dev, int partn)
334 const std::string devName = LastComponent(dev.devPath);
409 part = NewPartition(*(disk->dev), i);
426 if (g_disks->dev->devPath == path) {