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
757 fd = open(dev_path, O_RDWR); in prepare_partitions()
758 if (fd < 0) { in prepare_partitions()
766 r = gpt_get_state(fd, PRIMARY_GPT, &gpt_prim) || in prepare_partitions()
767 gpt_get_state(fd, SECONDARY_GPT, &gpt_second); in prepare_partitions()
836 r = gpt2_set_boot_chain(fd, BACKUP_BOOT); in prepare_partitions()
849 r = gpt_set_state(fd, PRIMARY_GPT, GPT_BAD_SIGNATURE); in prepare_partitions()
879 r = gpt_set_state(fd, PRIMARY_GPT, GPT_OK); in prepare_partitions()
886 r = gpt_set_state(fd, SECONDARY_GPT, GPT_BAD_SIGNATURE); in prepare_partitions()
899 r = gpt2_set_boot_chain(fd, NORMAL_BOOT); in prepare_partitions()
906 r = gpt_set_state(fd, SECONDARY_GPT, GPT_OK); in prepare_partitions()
917 if (fd >= 0) { in prepare_partitions()
918 fsync(fd); in prepare_partitions()
919 close(fd); in prepare_partitions()
1126 static uint32_t gpt_get_block_size(int fd) in gpt_get_block_size() argument
1129 if (fd < 0) { in gpt_get_block_size()
1134 if (ioctl(fd, BLKSSZGET, &block_size) != 0) { in gpt_get_block_size()
1147 static int gpt_set_header(uint8_t *gpt_header, int fd, in gpt_set_header() argument
1152 if (!gpt_header || fd < 0) { in gpt_set_header()
1157 block_size = gpt_get_block_size(fd); in gpt_set_header()
1166 gpt_header_offset = lseek64(fd, 0, SEEK_END) - block_size; in gpt_set_header()
1173 if (blk_rw(fd, 1, gpt_header_offset, gpt_header, block_size)) { in gpt_set_header()
1189 int fd = -1; in gpt_get_header() local
1201 fd = open(devpath, O_RDWR); in gpt_get_header()
1202 if (fd < 0) { in gpt_get_header()
1209 block_size = gpt_get_block_size(fd); in gpt_get_header()
1226 hdr_offset = lseek64(fd, 0, SEEK_END) - block_size; in gpt_get_header()
1233 if (blk_rw(fd, 0, hdr_offset, hdr, block_size)) { in gpt_get_header()
1238 close(fd); in gpt_get_header()
1241 if (fd >= 0) in gpt_get_header()
1242 close(fd); in gpt_get_header()
1252 static uint8_t* gpt_get_pentry_arr(uint8_t *hdr, int fd) in gpt_get_pentry_arr() argument
1264 if (fd < 0) { in gpt_get_pentry_arr()
1268 block_size = gpt_get_block_size(fd); in gpt_get_pentry_arr()
1284 rc = blk_rw(fd, 0, in gpt_get_pentry_arr()
1300 static int gpt_set_pentry_arr(uint8_t *hdr, int fd, uint8_t* arr) in gpt_set_pentry_arr() argument
1307 if (!hdr || fd < 0 || !arr) { in gpt_set_pentry_arr()
1311 block_size = gpt_get_block_size(fd); in gpt_set_pentry_arr()
1326 rc = blk_rw(fd, 1, in gpt_set_pentry_arr()
1378 int fd = -1; in gpt_disk_get_disk_info() local
1410 fd = open(disk->devpath, O_RDWR); in gpt_disk_get_disk_info()
1411 if (fd < 0) { in gpt_disk_get_disk_info()
1418 disk->pentry_arr = gpt_get_pentry_arr(disk->hdr, fd); in gpt_disk_get_disk_info()
1424 disk->pentry_arr_bak = gpt_get_pentry_arr(disk->hdr_bak, fd); in gpt_disk_get_disk_info()
1437 disk->block_size = gpt_get_block_size(fd); in gpt_disk_get_disk_info()
1438 close(fd); in gpt_disk_get_disk_info()
1442 if (fd >= 0) in gpt_disk_get_disk_info()
1443 close(fd); in gpt_disk_get_disk_info()
1507 int fd = -1; in gpt_disk_commit() local
1512 fd = open(disk->devpath, O_RDWR); in gpt_disk_commit()
1513 if (fd < 0) { in gpt_disk_commit()
1522 if(gpt_set_header(disk->hdr, fd, PRIMARY_GPT) != 0) { in gpt_disk_commit()
1529 if (gpt_set_pentry_arr(disk->hdr, fd, disk->pentry_arr)) { in gpt_disk_commit()
1534 fsync(fd); in gpt_disk_commit()
1535 close(fd); in gpt_disk_commit()
1538 if (fd >= 0) in gpt_disk_commit()
1539 close(fd); in gpt_disk_commit()