| 38 | #include <string.h> |
| 39 | |
| 40 | int |
| 41 | kld_isloaded(const char *name) |
| 42 | { |
| 43 | struct kld_file_stat fstat; |
| 44 | struct module_stat mstat; |
| 45 | const char *ko; |
| 46 | int fid, mid; |
| 47 | |
| 48 | for (fid = kldnext(0); fid > 0; fid = kldnext(fid)) { |
| 49 | fstat.version = sizeof(fstat); |
| 50 | if (kldstat(fid, &fstat) != 0) |
| 51 | continue; |
| 52 | /* check if the file name matches the supplied name */ |
| 53 | if (strcmp(fstat.name, name) == 0) |
| 54 | return (1); |
| 55 | /* strip .ko and try again */ |
| 56 | if ((ko = strstr(fstat.name, ".ko")) != NULL && |
| 57 | strlen(name) == (size_t)(ko - fstat.name) && |
| 58 | strncmp(fstat.name, name, ko - fstat.name) == 0) |
| 59 | return (1); |
| 60 | /* look for a matching module within the file */ |
| 61 | for (mid = kldfirstmod(fid); mid > 0; mid = modfnext(mid)) { |
| 62 | mstat.version = sizeof(mstat); |
| 63 | if (modstat(mid, &mstat) != 0) |
| 64 | continue; |
| 65 | if (strcmp(mstat.name, name) == 0) |
| 66 | return (1); |
| 67 | } |
| 68 | } |
| 69 | return (0); |
| 70 | } |
| 71 | |
| 72 | int |
| 73 | kld_load(const char *name) |