/* Read one mount table entry from STREAM. Returns a pointer to storage reused on the next call, or null for EOF or error (use feof/ferror to check). */ struct mntent * __getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz) { char *cp; char *head; flockfile (stream); do { char *end_ptr; if (__fgets_unlocked (buffer, bufsiz, stream) == NULL) { funlockfile (stream); return NULL; } end_ptr = strchr (buffer, '\n'); if (end_ptr != NULL) /* chop newline */ { /* Do not walk past the start of buffer if it's all whitespace. */ while (end_ptr != buffer && (end_ptr[-1] == ' ' || end_ptr[-1] == '\t')) end_ptr--; *end_ptr = '\0'; } else { /* Not the whole line was read. Do it now but forget it. */ char tmp[1024]; while (__fgets_unlocked (tmp, sizeof tmp, stream) != NULL) if (strchr (tmp, '\n') != NULL) break; } head = buffer + strspn (buffer, " \t"); /* skip empty lines and comment lines: */ } while (head[0] == '\0' || head[0] == '#'); cp = __strsep (&head, " \t"); mp->mnt_fsname = cp != NULL ? decode_name (cp) : (char *) ""; if (head) head += strspn (head, " \t"); cp = __strsep (&head, " \t"); mp->mnt_dir = cp != NULL ? decode_name (cp) : (char *) ""; if (head) head += strspn (head, " \t"); cp = __strsep (&head, " \t"); mp->mnt_type = cp != NULL ? decode_name (cp) : (char *) ""; if (head) head += strspn (head, " \t"); cp = __strsep (&head, " \t"); mp->mnt_opts = cp != NULL ? decode_name (cp) : (char *) ""; switch (head ? sscanf (head, " %d %d ", &mp->mnt_freq, &mp->mnt_passno) : 0) { case 0: mp->mnt_freq = 0; case 1: mp->mnt_passno = 0; case 2: break; } funlockfile (stream); return mp; }
/* Read one mount table entry from STREAM. Returns a pointer to storage reused on the next call, or null for EOF or error (use feof/ferror to check). */ struct mntent * __getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz) { char *cp; char *head; #ifndef __WIN32__ flockfile (stream); do { char *end_ptr; if (fgets_unlocked (buffer, bufsiz, stream) == NULL) { funlockfile (stream); return NULL; } end_ptr = strchr (buffer, '\n'); if (end_ptr != NULL) /* chop newline */ *end_ptr = '\0'; else { /* Not the whole line was read. Do it now but forget it. */ char tmp[1024]; while (fgets_unlocked (tmp, sizeof tmp, stream) != NULL) if (strchr (tmp, '\n') != NULL) break; } head = buffer + strspn (buffer, " \t"); /* skip empty lines and comment lines: */ } while (head[0] == '\0' || head[0] == '#'); #else /* __WIN32__ */ struct statfsx64 buf; if (!strcmp(rootlist, NotSet)) { // fprintf(stderr, "rootlist0\n"); rootlist = getrootdirs(rootlist); } /* skip the rootdirs that are not mounted */ while ( (statfsx64 (rootlist, &buf) < 0)) { //(access (rootlist, F_OK) < 0) || // fprintf(stderr, "rootlist < 0: %s\n", rootlist); if (rootlist[0] == 0) return NULL; else rootlist = strchr (rootlist, 0) + 1; } // fprintf(stderr, "rootlist: %s\n", rootlist); // fprintf(stderr, "buf.f_mntonname: %s\n", buf.f_mntonname); // fprintf(stderr, "buf.f_mntfromname: %s\n", buf.f_mntfromname); // fprintf(stderr, "buf.f_mntfromname: %s\n", buf.f_mntfromname); // fprintf(stderr, "buf.f_fstypename: %s\n", buf.f_fstypename); mp->mnt_fsname = buf.f_mntonname; mp->mnt_dir = buf.f_mntfromname; mp->mnt_type = buf.f_fstypename; mp->mnt_opts = MNTOPT_RW; __addmntentstr(buffer, mp); // fprintf(stderr, "mp->mnt_fsname: %s\n", mp->mnt_fsname); // fprintf(stderr, "mp->mnt_dir: %s\n", mp->mnt_dir); // fprintf(stderr, "mp->mnt_type: %s\n", mp->mnt_type); // fprintf(stderr, "mp->mnt_opts: %s\n", mp->mnt_opts); head = buffer + strspn (buffer, " \t"); rootlist = strchr (rootlist, 0) + 1; #endif /* __WIN32 */ cp = __strsep (&head, " \t"); mp->mnt_fsname = cp != NULL ? decode_name (cp) : (char *) ""; if (head) head += strspn (head, " \t"); cp = __strsep (&head, " \t"); mp->mnt_dir = cp != NULL ? decode_name (cp) : (char *) ""; if (head) head += strspn (head, " \t"); cp = __strsep (&head, " \t"); mp->mnt_type = cp != NULL ? decode_name (cp) : (char *) ""; if (head) head += strspn (head, " \t"); cp = __strsep (&head, " \t"); mp->mnt_opts = cp != NULL ? decode_name (cp) : (char *) ""; switch (head ? sscanf (head, " %d %d ", &mp->mnt_freq, &mp->mnt_passno) : 0) { case 0: mp->mnt_freq = 0; case 1: mp->mnt_passno = 0; case 2: break; } funlockfile (stream); return mp; }