diff options
Diffstat (limited to 'lib/libstand')
-rw-r--r-- | lib/libstand/splitfs.c | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/lib/libstand/splitfs.c b/lib/libstand/splitfs.c index 153f054..8792464 100644 --- a/lib/libstand/splitfs.c +++ b/lib/libstand/splitfs.c @@ -44,6 +44,7 @@ struct split_file off_t file_pos; /* Offset from the beginning of the slice */ }; +static int split_openfile(struct split_file *sf); static int splitfs_open(const char *path, struct open_file *f); static int splitfs_close(struct open_file *f); static int splitfs_read(struct open_file *f, void *buf, size_t size, size_t *resid); @@ -78,6 +79,28 @@ split_file_destroy(struct split_file *sf) } static int +split_openfile(struct split_file *sf) +{ + int i; + + for (i = 0;; i++) { + sf->curfd = open(sf->filesv[sf->curfile], O_RDONLY); + if (sf->curfd >= 0) + break; + if ((sf->curfd == -1) && (errno != ENOENT)) + return (errno); + if (i == NTRIES) + return (EIO); + printf("\nInsert disk labelled %s and press any key...", + sf->descsv[sf->curfile]); + getchar(); + putchar('\n'); + } + sf->file_pos = 0; + return (0); +} + +static int splitfs_open(const char *fname, struct open_file *f) { char *buf, *confname, *cp; @@ -139,7 +162,12 @@ splitfs_open(const char *fname, struct open_file *f) free(buf); close(conffd); - if ((sf->filesc == 0) || ((sf->curfd = open(sf->filesv[0], O_RDONLY)) == -1)) { + if (sf->filesc == 0) { + split_file_destroy(sf); + return(ENOENT); + } + errno = split_openfile(sf); + if (errno != 0) { split_file_destroy(sf); return(ENOENT); } @@ -190,18 +218,9 @@ splitfs_read(struct open_file *f, void *buf, size_t size, size_t *resid) return (errno); sf->curfile++; - for (i = 0;; i++) { - sf->curfd = open(sf->filesv[sf->curfile], O_RDONLY); - if (sf->curfd >= 0) - break; - if ((sf->curfd == -1) && (errno != ENOENT)) + errno = split_openfile(sf); + if (errno) return (errno); - if (i == NTRIES) - return (EIO); - printf("\nInsert disk labelled %s and press any key...", sf->descsv[sf->curfile]); - getchar();putchar('\n'); - } - sf->file_pos = 0; } } while (totread < size); |