From 7d45c61f20aadb71ac1d58ee8b2d43e04283876a Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Thu, 15 Jan 2004 18:38:15 +0000 Subject: [PATCH] - Move the code to try to open a single chunk file and prompt for the associated floppy if needed into a static split_openfile() function. - Use this function in splitfs_open() to open the first chunk rather than using open() directly. This allows the first chunk to be located on a different disk than the actual foo.split file. --- lib/libstand/splitfs.c | 43 ++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/libstand/splitfs.c b/lib/libstand/splitfs.c index 153f05443484..87924640ff50 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); @@ -77,6 +78,28 @@ split_file_destroy(struct split_file *sf) free(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) { @@ -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);