Skip to content

Commit

Permalink
[GSoC Encrypted Storage]Read encryption functionality with extents an…
Browse files Browse the repository at this point in the history
…d chunking LINUX

Rough edges: iov_count considered to be zero, but
should be fixable
  • Loading branch information
sanket committed Aug 17, 2010
1 parent 1bbdb1c commit 46d2ad5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
25 changes: 16 additions & 9 deletions src/afs/VNOPS/afs_vnop_read.c
Expand Up @@ -64,6 +64,7 @@ afs_MemRead(struct vcache *avc, struct uio *auio,
#endif
afs_int32 code;
struct vrequest treq;


AFS_STATCNT(afs_MemRead);
if (avc->vc_error)
Expand Down Expand Up @@ -536,6 +537,7 @@ afs_UFSRead(struct vcache *avc, struct uio *auio,
afs_int32 code;
int trybusy = 1;
struct vrequest treq;
struct afs_enc_chunk *chunk;

AFS_STATCNT(afs_UFSRead);
if (avc && avc->vc_error)
Expand Down Expand Up @@ -864,6 +866,7 @@ afs_UFSRead(struct vcache *avc, struct uio *auio,
printk("end excess extent\n");
afs_print_uioinfo(tuiop_e);
}
chunk = afs_prepare_chunk(tuiop_s1, tuiop1, tuiop_e1);

afsio_copy(&tuio, &tuio2, tvec2);
#endif
Expand Down Expand Up @@ -934,13 +937,18 @@ afs_UFSRead(struct vcache *avc, struct uio *auio,
AFS_GLOCK();
#elif defined(AFS_LINUX20_ENV)
AFS_GUNLOCK();

if(start){
osi_rdwr(tfile, tuiop_s, UIO_READ);
afs_chunk_append(chunk, tuiop_s, tuiop_s1);
}
code = osi_rdwr(tfile, &tuio, UIO_READ);
afs_print_uiodata(&tuio, tuiop1);
if(start) osi_rdwr(tfile, tuiop_s, UIO_READ);
afs_chunk_append(chunk, tuiop, tuiop1);
if(end){
printk("trying to get data for last extent\n");
osi_rdwr(tfile, tuiop_e, UIO_READ);
afs_chunk_append(chunk, tuiop_e, tuiop_e1);
}

AFS_GLOCK();
#elif defined(AFS_DARWIN80_ENV)
AFS_GUNLOCK();
Expand Down Expand Up @@ -992,12 +1000,11 @@ afs_UFSRead(struct vcache *avc, struct uio *auio,
*/
if(tdc->f.fid.Fid.Vnode%2 == 0){
/* Even means file data */
//struct afs_enc_chunk *chunk = afs_get_extent(tuiop_s, tuiop_s1, tuiop, tuiop1, tuiop_e, tuiop_e1);
//afs_print_chunk(chunk);
//afs_decrypt(chunk); /* Decrypt chunk */

//afs_enc_chunk_wb(chunk, tuiop, tuiop1);
afs_decrypt1(tuiop, tuiop1);

afs_print_chunk(chunk);
afs_decrypt(chunk); /* Decrypt chunk */
afs_enc_chunk_wb(chunk, tuiop, tuiop1);

}

/* otherwise we've read some, fixup length, etc and continue with next seg */
Expand Down
3 changes: 2 additions & 1 deletion src/afs/afs.h
Expand Up @@ -1460,7 +1460,8 @@ afs_set_cr_rgid(afs_ucred_t *cred, gid_t gid) {
struct afs_enc_chunk{

char *base;
int len;
int len; /* Total length of the chunk */
int trans; /* Length transferred */
int uio_start; /* Start index for the data to be read */
int uio_len; /* Length of the data to be read */
};
Expand Down
36 changes: 32 additions & 4 deletions src/afs/afs_enc.c
Expand Up @@ -260,8 +260,8 @@ void afs_print_chunk(struct afs_enc_chunk *chunk){

printk("Size: %d\nStart: %d\nEnd: %d\n", chunk->len, chunk->uio_start, chunk->uio_len);
afs_int32 i;
for(i=0;i<chunk->uio_len;i++);
//printk("%c", chunk->base[chunk->uio_start+i]);
for(i=0;i<chunk->len;i++)
printk("%c", chunk->base[i]);
}

void afs_enc_chunk_wb(struct afs_enc_chunk *chunk, struct uio *data, struct uio *basis){
Expand All @@ -272,12 +272,13 @@ void afs_enc_chunk_wb(struct afs_enc_chunk *chunk, struct uio *data, struct uio
while(chunk_len){
/* Transfer the chunk back to the tuiop structure */

space = basis->uio_iov[iov_no].iov_len - data->uio_iov[iov_no].iov_len;
space = basis->uio_iov[iov_no].iov_len;
char *d = (char *)basis->uio_iov[iov_no].iov_base;
i=0;
while(i<space && chunk_len){
d[i] = chunk->base[ind++];
d[i] = chunk->base[chunk->uio_start+ind];
i++;
ind++;
chunk_len--;
}

Expand All @@ -286,6 +287,19 @@ void afs_enc_chunk_wb(struct afs_enc_chunk *chunk, struct uio *data, struct uio
}


void afs_chunk_append(struct afs_enc_chunk *ch, struct uio *data, struct uio *basis){

/* Appends the data to the chunk */

if(basis!=NULL){

char *temp = (char *)basis->uio_iov[0].iov_base;
int i=0;
for(i=0;i<basis->uio_iov[0].iov_len;i++)
ch->base[i+ch->trans] = temp[i];
ch->trans += basis->uio_iov[0].iov_len;
}
}

struct afs_enc_chunk *afs_get_extent(struct uio *s, struct uio *s1, struct uio *t, struct uio *t1, struct uio *e, struct uio *e1)
{
Expand Down Expand Up @@ -343,7 +357,21 @@ struct afs_enc_chunk *afs_get_extent(struct uio *s, struct uio *s1, struct uio *

}

struct afs_enc_chunk *afs_prepare_chunk(struct uio *s, struct uio *t, struct uio *e){

/* Sets the various checkpoints for the chunk which is to be read */

int len = (s?s->uio_iov[0].iov_len:0) + (t?t->uio_iov[0].iov_len:0) + (e?e->uio_iov[0].iov_len:0);

struct afs_enc_chunk *chunk = (struct afs_enc_chunk *)osi_Alloc(sizeof(struct afs_enc_chunk));

chunk->uio_start = s?s->uio_iov[0].iov_len:0;
chunk->uio_len = t?t->uio_iov[0].iov_len:0;
chunk->len = len;
chunk->base = (char *)osi_Alloc(len * sizeof(char));

return chunk;
}



Expand Down
2 changes: 2 additions & 0 deletions src/afs/afs_prototypes.h
Expand Up @@ -1356,6 +1356,8 @@ extern unsigned long int do_mod64(long long int x, long long int y);
extern struct afs_enc_chunk *afs_get_extent(struct uio *s, struct uio *s1, struct uio *t, struct uio *t1, struct uio *e, struct uio *e1);
extern void afs_print_chunk(struct afs_enc_chunk *chunk);
void afs_enc_chunk_wb(struct afs_enc_chunk *chunk, struct uio *data, struct uio *basis);
struct afs_enc_chunk *afs_prepare_chunk(struct uio *s, struct uio *p, struct uio *e);
void afs_chunk_append(struct afs_enc_chunk *ch, struct uio *data, struct uio *basis);
/* Prototypes for generated files that aren't really in src/afs/ */

/* afs_uuid.c */
Expand Down

0 comments on commit 46d2ad5

Please sign in to comment.