⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aux.c

📁 Solaris操作系统下的过滤驱动程序, C源码程序.
💻 C
📖 第 1 页 / 共 2 页
字号:
	    goto out;	}	/* Read in the offsets into an array */	err = idx_file->f_op->read(idx_file, (void *) hdr->offsets[i],				   PAGE_CACHE_SIZE, &idx_file->f_pos);	if (err < 0) {	    printk("Error in read\n");	    goto out_setfs;	}	/* XXX check to see that we got all needed bytes */    }    /* Sanity checking: Make sure underlying file size matches index table */    /* XXX These checks need to be fixed for fast_append! XXX */    if (hdr->num_chunks > 0) {	if(SCA_OFFSET(hdr, hdr->num_chunks - 1) != itohi(inode)->i_size) {	    printk("Final offset does not equal file size\n");	    err = -EIO;	    goto out_setfs;	}    } else {	if (itohi(inode)->i_size > 0) {	    printk("No offsets, but index file is not empty\n");	    err = -EIO;	    goto out_setfs;	}    }    /* All is well */    err = 0;    fist_print_scafs_header("idx_read", hdr);    copy_inode_size(inode, itohi(inode)); out_setfs:    set_fs(oldfs); out:    print_exit_status(err);    return(err);}/* This function return 0 on success, negative on error */intwrapfs_idx_write(inode_t *inode){    int err = 0;    mm_segment_t oldfs;    int i, bytes;    unsigned int chunks_left;    struct scafs_header *hdr = &(itopd(inode)->hdr);    file_t *idx_file = itopd(inode)->idx_file;    struct iattr attr;    print_entry_location();    ASSERT(hdr != NULL);    /* don't write header if not modified */    if ((hdr->flags & SCA_FLAG_MODIFIED) == 0) {	fist_dprint(8, "idx_write: not writing unmodified header\n");	goto out;    }    if (idx_file == NULL) {	printk("idx_file is NULL, cannot write\n");	goto out;    }    /* truncate index file to length 0 */    attr.ia_size = 0;    attr.ia_valid = ATTR_SIZE;    err = notify_change(idx_file->f_dentry, &attr);    if (err < 0)	goto out;    if (hdr->num_chunks == 0)	/* don't write anything */	goto out;    /* combine num_chunks and flags */    hdr->num_chunks |= hdr->flags & SCA_FLAG_MASK;    oldfs = get_fs();    set_fs(KERNEL_DS);    idx_file->f_pos = 0;    err = idx_file->f_op->write(idx_file,				(void *) hdr,				sizeof(off_t) << 1,				&idx_file->f_pos);    /* remove flags from num_chunks */    hdr->num_chunks &= ~SCA_FLAG_MASK;    if (err < 0) { // XXX: check that err==num_bytes2write	printk("error %d in write idx file hdr\n", err);	goto out_setfs;    }    chunks_left = hdr->num_chunks;    for (i = 0; 1; i++) {	bytes = MIN(chunks_left, INDEX_ENTRIES_PER_PAGE) * sizeof(off_t);	fist_dprint(8, __FUNCTION__ ": %d bytes for page %d\n", bytes, i);	err = idx_file->f_op->write(idx_file,				    (void *) hdr->offsets[i],				    bytes,				    &idx_file->f_pos);	if (err < 0) { // XXX: check that err==bytes	    printk("error %d in write idx file entries\n", err);	    goto out_setfs;	}	if (chunks_left <= INDEX_ENTRIES_PER_PAGE)	    break;	chunks_left -= INDEX_ENTRIES_PER_PAGE;    }    /* reset modified counter */    hdr->flags &= ~SCA_FLAG_MODIFIED; out_setfs:    set_fs(oldfs); out:    print_exit_status(err);    return err;}/* * Sets the value for an "entry" into an existing SCA header structure, * potentially allocating space for it and any preceding entries * * chunk_idx starts from 0. encoded_chunk_offset is what * this chunk will encode to. * * Note that holes are supported: they are defined in the index table * as a page that encodes to 0 bytes (i.e. the entry for that page will * be equal to the previous one) * * Returns 0 on success, or -errno on failure. */intwrapfs_idx_set_entry(struct scafs_header *hdr,		     int chunk_idx,		     off_t encoded_chunk_offset){    int err = 0, i;    off_t offset;    unsigned long pageslots;    print_entry_location();	/* XXX: remove this after debugging */    fist_dprint(8, __FUNCTION__ ": chunk_idx=%d encoded_chunk_offset=%d\n",		chunk_idx, encoded_chunk_offset);    /* sanity checks */    ASSERT(hdr != NULL);    ASSERT(chunk_idx >= 0);    ASSERT(hdr->num_chunks <= hdr->num_alloc);    /* check if we need to (re)allocate new space */    if (chunk_idx >= hdr->num_alloc) {	pageslots = (chunk_idx + 1 + OFFSET_MASK) >> OFFSET_SHIFT;	fist_dprint(8, "Allocating space for %d pages\n", pageslots);	hdr->offsets = (off_t **) wrapfs_krealloc(hdr->offsets,						  sizeof(off_t *) * hdr->num_pageslots,						  sizeof(off_t *) * pageslots);	if (hdr->offsets == NULL) {	    err = -ENOMEM;	    goto out;	}	for (i = hdr->num_pageslots; i < pageslots; i++) {	    hdr->offsets[i] = (off_t *)__get_free_page(GFP_KERNEL);	    if (hdr->offsets[i] == NULL) {		err = -ENOMEM;		goto out;	    }	}	hdr->num_pageslots = pageslots;	hdr->num_alloc = pageslots << OFFSET_SHIFT;    }    /* support holes */    if (hdr->num_chunks > 0)	offset = SCA_OFFSET(hdr, hdr->num_chunks - 1);    else	offset = 0;    for (i = hdr->num_chunks; i < chunk_idx; i++)	SCA_OFFSET(hdr, i) = offset;    if (hdr->num_chunks > 0 &&	chunk_idx > 0 &&	encoded_chunk_offset < SCA_OFFSET(hdr, chunk_idx - 1)) {	printk("idx_set_entry: lower offset %ld < %ld for chunk_idx %d\n",	       encoded_chunk_offset, SCA_OFFSET(hdr, chunk_idx-1), chunk_idx);    }    /* now insert new entry */    SCA_OFFSET(hdr, chunk_idx) = encoded_chunk_offset;    hdr->num_chunks = MAX(hdr->num_chunks, chunk_idx + 1);    hdr->flags |= SCA_FLAG_MODIFIED;out:    fist_print_scafs_header("SAE", hdr);    print_exit_status(err);	/* XXX: remove this after debugging */    return err;}/* update index table entries by delta, starting at entry */voidwrapfs_idx_update(struct scafs_header *hdr, unsigned long entry, int delta){    unsigned long l;    if (delta == 0)	return;    for (l = entry; l < hdr->num_chunks; l++)	SCA_OFFSET(hdr, l) += delta;    hdr->flags |= SCA_FLAG_MODIFIED;}/* * Given a page_index of our layer, find out the range of pages of the lower * layer that we need to read to satisfy the encoding request for our page. * The range of pages is from hidden_page_index and goes for the number of * pages being returned from this function. */intwrapfs_count_hidden_pages(unsigned long page_index,			  inode_t *inode,			  int *hidden_page_index,			  void **opaque){    struct scafs_header *hdr;    int start,end,cnt=0;    unsigned int start_page, end_page;    print_entry_location();    hdr = &(itopd(inode)->hdr);    if (page_index >= hdr->num_chunks) {  /* XXX: fix page/chunk confusion */	//printk("count_hidden_pages: request for page %ld, file only has %ld chunks\n",	//       page_index, hdr->num_chunks);	goto out;    }    start = HIDDEN_PAGE_STARTING_OFFSET(page_index, inode);    end = HIDDEN_PAGE_STARTING_OFFSET(page_index + 1, inode);    if (start == end)	goto out;		/* Hole, return 0 */    *hidden_page_index = start_page = start >> PAGE_CACHE_SHIFT;    end_page = end >> PAGE_CACHE_SHIFT;    *((int *)opaque) = start & ~PAGE_CACHE_MASK;    cnt = end_page - start_page;    if ((end & ~PAGE_CACHE_MASK) != 0)	cnt++; out:    print_exit_status(cnt);    return cnt;}/* * A kernel based realloc(3). * * Oldsize must be original allocated size of oldptr. * Returns new pointer, or the old pointer if any error occured. */void *wrapfs_krealloc(void *oldptr, size_t oldsize, size_t newsize){    void *newptr = NULL;    /* check if given sizes were valid */    if (newsize <= 0) {	printk("error: krealloc was called with newsize %d\n", newsize);	goto out;    }    if (oldsize < 0) {	printk("error: krealloc was called with oldsize %d\n", oldsize);	goto out;    }    if (newsize <= oldsize)	printk("warning: wrapfs_krealloc newsize %d <= oldsize %d\n", newsize, oldsize);    /* allocate and copy bytes */    newptr = kmalloc(newsize, GFP_KERNEL);    if (newptr == NULL) {	printk("krealloc: no more memory\n");	goto out;    }    if (oldsize > 0) {	if (newsize > oldsize) {	/* extending size */	    memcpy(newptr, oldptr, oldsize);	    memset(newptr + oldsize, 0, newsize - oldsize);	/* be safe */	} else {	    memcpy(newptr, oldptr, newsize);	}	/* free old allocation */	/* XXX: be safe and zero out oldptr's bytes first? */	kfree_s(oldptr, oldsize);	/* XXX: use kfree(oldptr)? */    } out:    return newptr;}#endif /* FIST_FILTER_SCA *//* * Local variables: * c-basic-offset: 4 * End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -