Hi Xiao, On 20.10.2021 16:38, Xiao Ni wrote:
+ char dv[32], dv_rep[32]; + + sprintf(dv, "/sys/dev/block/%d:%d", + disks[d*2].major, disks[d*2].minor); + sprintf(dv_rep, "/sys/dev/block/%d:%d", + disks[d*2+1].major, disks[d*2+1].minor);Please use snprintf and PATH_MAX instead 32. + + if ((!access(dv, R_OK) && + (disks[d*2].state & (1<<MD_DISK_SYNC))) ||
IMO not correct style, please verify with checkpatch. should be: [d * 2]
+ (!access(dv_rep, R_OK) && + (disks[d*2+1].state & (1<<MD_DISK_SYNC)))) {
Could you define function for that? something like (you can add access() verification if needed): is_dev_alive(mdu_disk_info_t *disk) { char *devnm = devid2kname(makedev..); if (devnm) return true; return false; } using true/false will require to add #include <stdbool.h>. Jes suggests to use meaningful return values. This is only suggestion so you can ignore it and use 0 and 1. and then check: if (is_dev_alive([d * 2]) & disks[d * 2].state & (1<<MD_DISK_SYNC) || (is_dev_alive([d * 2 + 1]) & disks[d * 2 + 1].state & (1<<MD_DISK_SYNC)) What do you think? Thanks, Mariusz