diff options
author | jhb <jhb@FreeBSD.org> | 2004-01-15 18:38:15 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2004-01-15 18:38:15 +0000 |
commit | ca8db354f6217f03b0c1d8bac9dae78480d5e5a9 (patch) | |
tree | 7cbebe0c5068fe4e39a0da7150e7bc04a006dcc3 /lib/libstand | |
parent | d195426865fc9df3bda4ecbc4bf2cbefdbd6f1a9 (diff) | |
download | FreeBSD-src-ca8db354f6217f03b0c1d8bac9dae78480d5e5a9.zip FreeBSD-src-ca8db354f6217f03b0c1d8bac9dae78480d5e5a9.tar.gz |
- 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.
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); |