| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ffs.c,v 1.42 2006/12/18 21:03:29 christos Exp $ */ | | 1 | /* $NetBSD: ffs.c,v 1.43 2009/04/16 18:54:16 dyoung Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2001 Wasabi Systems, Inc. | | 4 | * Copyright (c) 2001 Wasabi Systems, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Written by Luke Mewburn for Wasabi Systems, Inc. | | 7 | * Written by Luke Mewburn for Wasabi Systems, Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -61,27 +61,27 @@ | | | @@ -61,27 +61,27 @@ |
61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
63 | * SUCH DAMAGE. | | 63 | * SUCH DAMAGE. |
64 | * | | 64 | * |
65 | * @(#)ffs_alloc.c 8.19 (Berkeley) 7/13/95 | | 65 | * @(#)ffs_alloc.c 8.19 (Berkeley) 7/13/95 |
66 | */ | | 66 | */ |
67 | | | 67 | |
68 | #if HAVE_NBTOOL_CONFIG_H | | 68 | #if HAVE_NBTOOL_CONFIG_H |
69 | #include "nbtool_config.h" | | 69 | #include "nbtool_config.h" |
70 | #endif | | 70 | #endif |
71 | | | 71 | |
72 | #include <sys/cdefs.h> | | 72 | #include <sys/cdefs.h> |
73 | #if defined(__RCSID) && !defined(__lint) | | 73 | #if defined(__RCSID) && !defined(__lint) |
74 | __RCSID("$NetBSD: ffs.c,v 1.42 2006/12/18 21:03:29 christos Exp $"); | | 74 | __RCSID("$NetBSD: ffs.c,v 1.43 2009/04/16 18:54:16 dyoung Exp $"); |
75 | #endif /* !__lint */ | | 75 | #endif /* !__lint */ |
76 | | | 76 | |
77 | #include <sys/param.h> | | 77 | #include <sys/param.h> |
78 | | | 78 | |
79 | #if !HAVE_NBTOOL_CONFIG_H | | 79 | #if !HAVE_NBTOOL_CONFIG_H |
80 | #include <sys/mount.h> | | 80 | #include <sys/mount.h> |
81 | #endif | | 81 | #endif |
82 | | | 82 | |
83 | #include <assert.h> | | 83 | #include <assert.h> |
84 | #include <errno.h> | | 84 | #include <errno.h> |
85 | #include <fcntl.h> | | 85 | #include <fcntl.h> |
86 | #include <stdarg.h> | | 86 | #include <stdarg.h> |
87 | #include <stdio.h> | | 87 | #include <stdio.h> |
| @@ -835,26 +835,27 @@ ffs_populate_dir(const char *dir, fsnode | | | @@ -835,26 +835,27 @@ ffs_populate_dir(const char *dir, fsnode |
835 | /* cleanup */ | | 835 | /* cleanup */ |
836 | if (dirbuf.buf != NULL) | | 836 | if (dirbuf.buf != NULL) |
837 | free(dirbuf.buf); | | 837 | free(dirbuf.buf); |
838 | return (1); | | 838 | return (1); |
839 | } | | 839 | } |
840 | | | 840 | |
841 | | | 841 | |
842 | static void | | 842 | static void |
843 | ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts) | | 843 | ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts) |
844 | { | | 844 | { |
845 | int isfile, ffd; | | 845 | int isfile, ffd; |
846 | char *fbuf, *p; | | 846 | char *fbuf, *p; |
847 | off_t bufleft, chunk, offset; | | 847 | off_t bufleft, chunk, offset; |
| | | 848 | ssize_t nread; |
848 | struct inode in; | | 849 | struct inode in; |
849 | struct buf * bp; | | 850 | struct buf * bp; |
850 | ffs_opt_t *ffs_opts = fsopts->fs_specific; | | 851 | ffs_opt_t *ffs_opts = fsopts->fs_specific; |
851 | | | 852 | |
852 | assert (din != NULL); | | 853 | assert (din != NULL); |
853 | assert (buf != NULL); | | 854 | assert (buf != NULL); |
854 | assert (fsopts != NULL); | | 855 | assert (fsopts != NULL); |
855 | assert (ffs_opts != NULL); | | 856 | assert (ffs_opts != NULL); |
856 | | | 857 | |
857 | isfile = S_ISREG(DIP(din, mode)); | | 858 | isfile = S_ISREG(DIP(din, mode)); |
858 | fbuf = NULL; | | 859 | fbuf = NULL; |
859 | ffd = -1; | | 860 | ffd = -1; |
860 | p = NULL; | | 861 | p = NULL; |
| @@ -889,32 +890,39 @@ ffs_write_file(union dinode *din, uint32 | | | @@ -889,32 +890,39 @@ ffs_write_file(union dinode *din, uint32 |
889 | if ((fbuf = malloc(ffs_opts->bsize)) == NULL) | | 890 | if ((fbuf = malloc(ffs_opts->bsize)) == NULL) |
890 | err(1, "Allocating memory for write buffer"); | | 891 | err(1, "Allocating memory for write buffer"); |
891 | if ((ffd = open((char *)buf, O_RDONLY, 0444)) == -1) { | | 892 | if ((ffd = open((char *)buf, O_RDONLY, 0444)) == -1) { |
892 | warn("Can't open `%s' for reading", (char *)buf); | | 893 | warn("Can't open `%s' for reading", (char *)buf); |
893 | goto leave_ffs_write_file; | | 894 | goto leave_ffs_write_file; |
894 | } | | 895 | } |
895 | } else { | | 896 | } else { |
896 | p = buf; | | 897 | p = buf; |
897 | } | | 898 | } |
898 | | | 899 | |
899 | chunk = 0; | | 900 | chunk = 0; |
900 | for (bufleft = DIP(din, size); bufleft > 0; bufleft -= chunk) { | | 901 | for (bufleft = DIP(din, size); bufleft > 0; bufleft -= chunk) { |
901 | chunk = MIN(bufleft, ffs_opts->bsize); | | 902 | chunk = MIN(bufleft, ffs_opts->bsize); |
902 | if (isfile) { | | 903 | if (!isfile) |
903 | if (read(ffd, fbuf, chunk) != chunk) | | 904 | ; |
904 | err(1, "Reading `%s', %lld bytes to go", | | 905 | else if ((nread = read(ffd, fbuf, chunk)) == -1) |
905 | (char *)buf, (long long)bufleft); | | 906 | err(EXIT_FAILURE, "Reading `%s', %lld bytes to go", |
| | | 907 | (char *)buf, (long long)bufleft); |
| | | 908 | else if (nread != chunk) |
| | | 909 | errx(EXIT_FAILURE, "Reading `%s', %lld bytes to go, " |
| | | 910 | "read %zd bytes, expected %ju bytes, does " |
| | | 911 | "metalog size= attribute mismatch source size?", |
| | | 912 | (char *)buf, (long long)bufleft, nread, |
| | | 913 | (uintmax_t)chunk); |
| | | 914 | else |
906 | p = fbuf; | | 915 | p = fbuf; |
907 | } | | | |
908 | offset = DIP(din, size) - bufleft; | | 916 | offset = DIP(din, size) - bufleft; |
909 | if (debug & DEBUG_FS_WRITE_FILE_BLOCK) | | 917 | if (debug & DEBUG_FS_WRITE_FILE_BLOCK) |
910 | printf( | | 918 | printf( |
911 | "ffs_write_file: write %p offset %lld size %lld left %lld\n", | | 919 | "ffs_write_file: write %p offset %lld size %lld left %lld\n", |
912 | p, (long long)offset, | | 920 | p, (long long)offset, |
913 | (long long)chunk, (long long)bufleft); | | 921 | (long long)chunk, (long long)bufleft); |
914 | /* | | 922 | /* |
915 | * XXX if holey support is desired, do the check here | | 923 | * XXX if holey support is desired, do the check here |
916 | * | | 924 | * |
917 | * XXX might need to write out last bit in fragroundup | | 925 | * XXX might need to write out last bit in fragroundup |
918 | * sized chunk. however, ffs_balloc() handles this for us | | 926 | * sized chunk. however, ffs_balloc() handles this for us |
919 | */ | | 927 | */ |
920 | errno = ffs_balloc(&in, offset, chunk, &bp); | | 928 | errno = ffs_balloc(&in, offset, chunk, &bp); |