- // now step through the list returned by glob. If not a link, copy
- // to list. If it is a link, evaluate it and see if the path ends
- // in "disc".
- for (int i = 0; i < n; i++){
- // see if path is a link
- char linkbuf[1024];
- int retlink = readlink(globbuf.gl_pathv[i], linkbuf, sizeof(linkbuf)-1);
-
- char tmpname[1024]={0};
- const char * name = 0;
- bool is_scsi = scan_scsi;
- // if not a link (or a strange link), keep it
- if (retlink<=0 || retlink>1023)
- name = globbuf.gl_pathv[i];
- else {
- // or if it's a link that points to a disc, follow it
- linkbuf[retlink] = 0;
- const char *p;
- if ((p=strrchr(linkbuf, '/')) && !strcmp(p+1, "disc"))
- // This is the branch of the code that gets followed if we are
- // using devfs WITH traditional compatibility links. In this
- // case, we add the traditional device name to the list that
- // is returned.
- name = globbuf.gl_pathv[i];
- else {
- // This is the branch of the code that gets followed if we are
- // using devfs WITHOUT traditional compatibility links. In
- // this case, we check that the link to the directory is of
- // the correct type, and then append "disc" to it.
- bool match_ata = strstr(linkbuf, "ide");
- bool match_scsi = strstr(linkbuf, "scsi");
- if (((match_ata && scan_ata) || (match_scsi && scan_scsi)) && !(match_ata && match_scsi)) {
- is_scsi = match_scsi;
- snprintf(tmpname, sizeof(tmpname), "%s/disc", globbuf.gl_pathv[i]);
- name = tmpname;
- }
+ // now step through the list returned by glob.
+ for (int i = 0; i < n; i++) {
+ const char * name = globbuf.gl_pathv[i];
+
+ if (p_dev_sdxy_seen) {
+ // Follow "/dev/disk/by-id/*" symlink and check for duplicate "/dev/sdXY"
+ int dev_n = devxy_to_n(name, debug);
+ if (!(0 <= dev_n && dev_n <= devxy_to_n_max))
+ continue;
+ if ((*p_dev_sdxy_seen)[dev_n]) {
+ if (debug)
+ pout("%s: duplicate, ignored\n", name);
+ continue;