Print this page
5255 uts shouldn't open-code ISP2


3770 
3771 static int
3772 kobj_comp_setup(struct _buf *file, struct compinfo *cip)
3773 {
3774         struct comphdr *hdr;
3775 
3776         /*
3777          * read the compressed image into memory,
3778          * so we can deompress from there
3779          */
3780         file->_dsize = cip->fsize;
3781         file->_dbuf = kobj_alloc(cip->fsize, KM_WAIT|KM_TMP);
3782         if (kobj_read(file->_fd, file->_dbuf, cip->fsize, 0) != cip->fsize) {
3783                 kobj_free(file->_dbuf, cip->fsize);
3784                 return (-1);
3785         }
3786 
3787         hdr = kobj_comphdr(file);
3788         if (hdr->ch_magic != CH_MAGIC_ZLIB || hdr->ch_version != CH_VERSION ||
3789             hdr->ch_algorithm != CH_ALG_ZLIB || hdr->ch_fsize == 0 ||
3790             (hdr->ch_blksize & (hdr->ch_blksize - 1)) != 0) {
3791                 kobj_free(file->_dbuf, cip->fsize);
3792                 return (-1);
3793         }
3794         file->_base = kobj_alloc(hdr->ch_blksize, KM_WAIT|KM_TMP);
3795         file->_bsize = hdr->ch_blksize;
3796         return (0);
3797 }
3798 
3799 void
3800 kobj_close_file(struct _buf *file)
3801 {
3802         kobj_close(file->_fd);
3803         if (file->_base != NULL)
3804                 kobj_free(file->_base, file->_bsize);
3805         if (file->_dbuf != NULL)
3806                 kobj_free(file->_dbuf, file->_dsize);
3807         kobj_free(file->_name, strlen(file->_name)+1);
3808         kobj_free(file, sizeof (struct _buf));
3809 }
3810 




3770 
3771 static int
3772 kobj_comp_setup(struct _buf *file, struct compinfo *cip)
3773 {
3774         struct comphdr *hdr;
3775 
3776         /*
3777          * read the compressed image into memory,
3778          * so we can deompress from there
3779          */
3780         file->_dsize = cip->fsize;
3781         file->_dbuf = kobj_alloc(cip->fsize, KM_WAIT|KM_TMP);
3782         if (kobj_read(file->_fd, file->_dbuf, cip->fsize, 0) != cip->fsize) {
3783                 kobj_free(file->_dbuf, cip->fsize);
3784                 return (-1);
3785         }
3786 
3787         hdr = kobj_comphdr(file);
3788         if (hdr->ch_magic != CH_MAGIC_ZLIB || hdr->ch_version != CH_VERSION ||
3789             hdr->ch_algorithm != CH_ALG_ZLIB || hdr->ch_fsize == 0 ||
3790             !ISP2(hdr->ch_blksize)) {
3791                 kobj_free(file->_dbuf, cip->fsize);
3792                 return (-1);
3793         }
3794         file->_base = kobj_alloc(hdr->ch_blksize, KM_WAIT|KM_TMP);
3795         file->_bsize = hdr->ch_blksize;
3796         return (0);
3797 }
3798 
3799 void
3800 kobj_close_file(struct _buf *file)
3801 {
3802         kobj_close(file->_fd);
3803         if (file->_base != NULL)
3804                 kobj_free(file->_base, file->_bsize);
3805         if (file->_dbuf != NULL)
3806                 kobj_free(file->_dbuf, file->_dsize);
3807         kobj_free(file->_name, strlen(file->_name)+1);
3808         kobj_free(file, sizeof (struct _buf));
3809 }
3810