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