Lines Matching refs:disk

81 static int BlockSync(const Disk &disk)
83 if (disk.dev->readOnly) {
86 DoFsync(*(disk.dev));
100 static int BlockDiskOpen(Disk &disk)
102 disk.dev->fd = open(disk.dev->devPath.c_str(), RW_MODE);
103 if (disk.dev->fd < 0) {
104 LOG(WARNING) << "open fail: " << disk.dev->devPath << errno;
106 return disk.dev->fd;
109 static void BlockDiskClose(Disk &disk)
111 if (disk.dev != nullptr) {
112 if (disk.dev->fd > 0) {
113 close(disk.dev->fd);
114 disk.dev->fd = -1;
119 static bool DoRmPartition(const Disk &disk, int partn)
122 part = GetPartition(disk, partn);
128 if (disk.dev->fd < 0) {
131 part->partfd = disk.dev->fd;
167 static bool DoAddPartition(const Disk &disk, Partition &part)
169 if (disk.dev->fd < 0) {
173 part.partfd = disk.dev->fd;
183 static void DestroyDiskPartitions(Disk &disk)
185 if (!disk.partList.empty()) {
186 for (auto& p : disk.partList) {
192 disk.partList.clear();
195 static void DestroyDiskDevices(const Disk &disk)
197 if (disk.dev != nullptr) {
198 if (disk.dev->specific != nullptr) {
199 free(disk.dev->specific);
201 free(disk.dev);
277 static bool AddPartitions(const Disk &disk, const PartitonList &ulist, int &partitionAddedCounter)
280 int userNum = GetPartitionNumByPartName(USERDATA_PARTNAME, disk.partList);
299 if (!DoAddPartition (disk, *p2)) {
310 static bool RemovePartitions(const Disk &disk, int &partitionRemovedCounter)
312 PartitonList pList = disk.partList;
330 if (!DoRmPartition (disk, it->partNum)) {
352 int AdjustPartitions(Disk *disk, int &partitionChangedCounter)
357 if (disk == nullptr || BlockDiskOpen(*disk) < 0) {
366 if (!RemovePartitions(*disk, partitionChangedCounter)) {
370 BlockSync(*disk);
371 if (!AddPartitions(*disk, ulist, partitionChangedCounter)) {
374 BlockSync(*disk);
391 Disk *disk = GetRegisterBlockDisk(path);
392 if (disk == nullptr) {
396 if (RegisterUpdaterPartitionList(nlist, disk->partList) == 0) {
398 free(disk);
403 BlockDiskClose(*disk);
404 DestroyDiskPartitions(*disk);
405 DestroyDiskDevices(*disk);
406 free(disk);
410 if (AdjustPartitions(disk, partitionChangedCounter) == 0) {