Lines Matching refs:fd
145 static int blk_rw(int fd, int rw, int64_t offset, uint8_t *buf, unsigned len) in blk_rw() argument
149 if (lseek64(fd, offset, SEEK_SET) < 0) { in blk_rw()
156 r = write(fd, buf, len); in blk_rw()
158 r = read(fd, buf, len); in blk_rw()
282 static int gpt2_set_boot_chain(int fd, enum boot_chain boot) in gpt2_set_boot_chain() argument
296 if (ioctl(fd, BLKSSZGET, &blk_size) != 0) { in gpt2_set_boot_chain()
308 gpt2_header_offset = lseek64(fd, 0, SEEK_END) - blk_size; in gpt2_set_boot_chain()
317 r = blk_rw(fd, 0, blk_size, gpt_header, blk_size); in gpt2_set_boot_chain()
337 r = blk_rw(fd, 0, pentries_start_offset, pentries, pentries_array_size); in gpt2_set_boot_chain()
349 r = blk_rw(fd, 0, gpt2_header_offset, gpt_header, blk_size); in gpt2_set_boot_chain()
373 r = blk_rw(fd, 1, gpt2_header_offset, gpt_header, blk_size); in gpt2_set_boot_chain()
376 r = blk_rw(fd, 1, pentries_start_offset, pentries, in gpt2_set_boot_chain()
400 static int gpt_get_state(int fd, enum gpt_instance gpt, enum gpt_state *state) in gpt_get_state() argument
410 if (ioctl(fd, BLKSSZGET, &blk_size) != 0) { in gpt_get_state()
423 gpt_header_offset = lseek64(fd, 0, SEEK_END) - blk_size; in gpt_get_state()
430 if (blk_rw(fd, 0, gpt_header_offset, gpt_header, blk_size)) { in gpt_get_state()
466 static int gpt_set_state(int fd, enum gpt_instance gpt, enum gpt_state state) in gpt_set_state() argument
474 if (ioctl(fd, BLKSSZGET, &blk_size) != 0) { in gpt_set_state()
487 gpt_header_offset = lseek64(fd, 0, SEEK_END) - blk_size; in gpt_set_state()
493 if (blk_rw(fd, 0, gpt_header_offset, gpt_header, blk_size)) { in gpt_set_state()
513 if (blk_rw(fd, 1, gpt_header_offset, gpt_header, blk_size)) { in gpt_set_state()
601 int fd = -1; in set_boot_lun() local
617 fd = open(sg_dev, O_RDWR); in set_boot_lun()
618 if (fd < 0) { in set_boot_lun()
625 rc = ioctl(fd, UFS_IOCTL_QUERY, data); in set_boot_lun()
632 close(fd); in set_boot_lun()
636 if (fd >= 0) in set_boot_lun()
637 close(fd); in set_boot_lun()
745 int fd = -1; in prepare_partitions() local
758 fd = open(dev_path, O_RDWR); in prepare_partitions()
759 if (fd < 0) { in prepare_partitions()
767 r = gpt_get_state(fd, PRIMARY_GPT, &gpt_prim) || in prepare_partitions()
768 gpt_get_state(fd, SECONDARY_GPT, &gpt_second); in prepare_partitions()
837 r = gpt2_set_boot_chain(fd, BACKUP_BOOT); in prepare_partitions()
850 r = gpt_set_state(fd, PRIMARY_GPT, GPT_BAD_SIGNATURE); in prepare_partitions()
880 r = gpt_set_state(fd, PRIMARY_GPT, GPT_OK); in prepare_partitions()
887 r = gpt_set_state(fd, SECONDARY_GPT, GPT_BAD_SIGNATURE); in prepare_partitions()
900 r = gpt2_set_boot_chain(fd, NORMAL_BOOT); in prepare_partitions()
907 r = gpt_set_state(fd, SECONDARY_GPT, GPT_OK); in prepare_partitions()
918 if (fd >= 0) { in prepare_partitions()
919 fsync(fd); in prepare_partitions()
920 close(fd); in prepare_partitions()
973 int r, fd; in prepare_boot_update() local
1128 static uint32_t gpt_get_block_size(int fd) in gpt_get_block_size() argument
1131 if (fd < 0) { in gpt_get_block_size()
1136 if (ioctl(fd, BLKSSZGET, &block_size) != 0) { in gpt_get_block_size()
1149 static int gpt_set_header(uint8_t *gpt_header, int fd, in gpt_set_header() argument
1154 if (!gpt_header || fd < 0) { in gpt_set_header()
1159 block_size = gpt_get_block_size(fd); in gpt_set_header()
1168 gpt_header_offset = lseek64(fd, 0, SEEK_END) - block_size; in gpt_set_header()
1175 if (blk_rw(fd, 1, gpt_header_offset, gpt_header, block_size)) { in gpt_set_header()
1191 int fd = -1; in gpt_get_header() local
1203 fd = open(devpath, O_RDWR); in gpt_get_header()
1204 if (fd < 0) { in gpt_get_header()
1211 block_size = gpt_get_block_size(fd); in gpt_get_header()
1228 hdr_offset = lseek64(fd, 0, SEEK_END) - block_size; in gpt_get_header()
1235 if (blk_rw(fd, 0, hdr_offset, hdr, block_size)) { in gpt_get_header()
1240 close(fd); in gpt_get_header()
1243 if (fd >= 0) in gpt_get_header()
1244 close(fd); in gpt_get_header()
1254 static uint8_t* gpt_get_pentry_arr(uint8_t *hdr, int fd) in gpt_get_pentry_arr() argument
1266 if (fd < 0) { in gpt_get_pentry_arr()
1270 block_size = gpt_get_block_size(fd); in gpt_get_pentry_arr()
1286 rc = blk_rw(fd, 0, in gpt_get_pentry_arr()
1302 static int gpt_set_pentry_arr(uint8_t *hdr, int fd, uint8_t* arr) in gpt_set_pentry_arr() argument
1309 if (!hdr || fd < 0 || !arr) { in gpt_set_pentry_arr()
1313 block_size = gpt_get_block_size(fd); in gpt_set_pentry_arr()
1328 rc = blk_rw(fd, 1, in gpt_set_pentry_arr()
1380 int fd = -1; in gpt_disk_get_disk_info() local
1412 fd = open(disk->devpath, O_RDWR); in gpt_disk_get_disk_info()
1413 if (fd < 0) { in gpt_disk_get_disk_info()
1420 disk->pentry_arr = gpt_get_pentry_arr(disk->hdr, fd); in gpt_disk_get_disk_info()
1426 disk->pentry_arr_bak = gpt_get_pentry_arr(disk->hdr_bak, fd); in gpt_disk_get_disk_info()
1439 disk->block_size = gpt_get_block_size(fd); in gpt_disk_get_disk_info()
1440 close(fd); in gpt_disk_get_disk_info()
1444 if (fd >= 0) in gpt_disk_get_disk_info()
1445 close(fd); in gpt_disk_get_disk_info()
1509 int fd = -1; in gpt_disk_commit() local
1514 fd = open(disk->devpath, O_RDWR); in gpt_disk_commit()
1515 if (fd < 0) { in gpt_disk_commit()
1524 if(gpt_set_header(disk->hdr, fd, PRIMARY_GPT) != 0) { in gpt_disk_commit()
1531 if (gpt_set_pentry_arr(disk->hdr, fd, disk->pentry_arr)) { in gpt_disk_commit()
1536 fsync(fd); in gpt_disk_commit()
1537 close(fd); in gpt_disk_commit()
1540 if (fd >= 0) in gpt_disk_commit()
1541 close(fd); in gpt_disk_commit()