Changeset d1941587 in rtems
- Timestamp:
- 01/12/01 13:44:12 (23 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- 3f777d0e
- Parents:
- 5c27c80
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/exec/libfs/ChangeLog
r5c27c80 rd1941587 1 2001-01-12 Jake Janovetz <janovetz@uiuc.edu> 2 3 * src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, 4 src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c, 5 src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c, 6 src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c, 7 src/imfs/miniimfs_init.c: Final developmental update to "tarfs". 8 When rtems_tarfs_load() is called, it checks the permissions 9 on each file. If there is write permission, it just creates a 10 standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE. 11 If there is no write permission, it creates a LINEAR_FILE node 12 with the appropriate properties. If the permission is ever changed 13 to writeable, IMFS_fchmod converts it to a regular memory file. 14 1 15 2000-12-12 Jake Janovetz <janovetz@uiuc.edu> 2 16 -
c/src/exec/libfs/src/imfs/imfs.h
r5c27c80 rd1941587 131 131 #define IMFS_SYM_LINK RTEMS_FILESYSTEM_SYM_LINK 132 132 #define IMFS_MEMORY_FILE RTEMS_FILESYSTEM_MEMORY_FILE 133 #define IMFS_LINEAR_FILE ( RTEMS_FILESYSTEM_MEMORY_FILE + 1)133 #define IMFS_LINEAR_FILE (IMFS_MEMORY_FILE + 1) 134 134 135 135 #define IMFS_NUMBER_OF_TYPES (IMFS_LINEAR_FILE + 1) … … 265 265 ); 266 266 267 int rtems_tarfs_ mount(267 int rtems_tarfs_load( 268 268 char *mountpoint, 269 269 unsigned char *addr, -
c/src/exec/libfs/src/imfs/imfs_fchmod.c
r5c27c80 rd1941587 45 45 set_errno_and_return_minus_one( EPERM ); 46 46 47 /* 48 * If we make a linear-file writeable, construct a block file 49 * from it first. 50 */ 51 if ( (jnode->type == IMFS_LINEAR_FILE) && 52 (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) ) 53 { 54 unsigned32 count = jnode->info.linearfile.size; 55 const unsigned char *buffer = jnode->info.linearfile.direct; 56 57 jnode->type = IMFS_MEMORY_FILE; 58 jnode->info.file.size = 0; 59 jnode->info.file.indirect = 0; 60 jnode->info.file.doubly_indirect = 0; 61 jnode->info.file.triply_indirect = 0; 62 if (IMFS_memfile_write(jnode, 0, buffer, count) == -1) 63 return(-1); 64 } 65 47 66 jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO); 48 67 jnode->st_mode |= mode; -
c/src/exec/libfs/src/imfs/imfs_handlers_memfile.c
r5c27c80 rd1941587 23 23 memfile_open, 24 24 memfile_close, 25 linearfile_read,25 memfile_read, 26 26 NULL, /* write */ 27 27 memfile_ioctl, 28 linearfile_lseek,28 memfile_lseek, 29 29 IMFS_stat, 30 NULL, /* chmod */30 IMFS_fchmod, 31 31 NULL, /* ftruncate */ 32 32 NULL, /* fpathconf */ … … 34 34 IMFS_fdatasync, 35 35 IMFS_fcntl, 36 NULL /* rmnod */36 memfile_rmnod 37 37 }; 38 38 -
c/src/exec/libfs/src/imfs/imfs_load_tar.c
r5c27c80 rd1941587 5 5 * File entries are created as IMFS_LINEAR_FILE nodes with their nods 6 6 * pointing to addresses in the TAR image. 7 *8 * $Id$9 *10 7 *************************************************************************/ 11 8 12 9 #include <rtems.h> 13 #include <rtems/libio .h>10 #include <rtems/libio_.h> 14 11 #include <string.h> 15 12 #include <chain.h> … … 111 108 112 109 /************************************************************************** 113 * rtems_tarfs_ mount110 * rtems_tarfs_load 114 111 * 115 * Here we create the mountpoint directory and mountthe tarfs at112 * Here we create the mountpoint directory and load the tarfs at 116 113 * that node. Once the IMFS has been mounted, we work through the 117 114 * tar image and perform as follows: … … 122 119 *************************************************************************/ 123 120 int 124 rtems_tarfs_ mount(char *mountpoint,125 126 121 rtems_tarfs_load(char *mountpoint, 122 unsigned char *tar_image, 123 unsigned long tar_size) 127 124 { 128 125 rtems_filesystem_location_info_t root_loc; … … 134 131 unsigned char linkflag; 135 132 unsigned long file_size; 133 unsigned long file_mode; 136 134 int offset; 137 135 unsigned long nblocks; … … 142 140 status = rtems_filesystem_evaluate_path(mountpoint, 0, &root_loc, 0); 143 141 if (status != 0) 142 return(-1); 143 144 if (root_loc.ops != &IMFS_ops) 144 145 return(-1); 145 146 … … 165 166 166 167 linkflag = hdr_ptr[156]; 168 file_mode = octal2ulong(&hdr_ptr[100], 8); 167 169 file_size = octal2ulong(&hdr_ptr[124], 12); 168 169 170 hdr_chksum = (int)octal2ulong(&hdr_ptr[148], 8); 171 170 172 if (compute_tar_header_checksum(hdr_ptr) != hdr_chksum) 171 173 break; … … 180 182 { 181 183 strcpy(full_filename, mountpoint); 182 strcat(full_filename, "/"); 184 if (full_filename[strlen(full_filename)-1] != '/') 185 strcat(full_filename, "/"); 183 186 strcat(full_filename, filename); 184 187 mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO); 185 188 } 186 else if (linkflag == LF_NORMAL) 189 /****************************************************************** 190 * Create a LINEAR_FILE node if no user write permission. 191 *****************************************************************/ 192 else if ((linkflag == LF_NORMAL) && 193 ((file_mode & 0200) == 0000)) 187 194 { 188 195 const char *name; 189 190 196 191 197 loc = root_loc; … … 203 209 offset += 512 * nblocks; 204 210 } 211 /****************************************************************** 212 * Create a regular MEMORY_FILE if write permission exists. 213 *****************************************************************/ 214 else if ((linkflag == LF_NORMAL) && 215 ((file_mode & 0200) == 0200)) 216 { 217 int fd; 218 int n, left, ptr; 219 220 strcpy(full_filename, mountpoint); 221 if (full_filename[strlen(full_filename)-1] != '/') 222 strcat(full_filename, "/"); 223 strcat(full_filename, filename); 224 225 fd = creat(full_filename, S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP); 226 if (fd != -1) 227 { 228 left = file_size; 229 ptr = offset; 230 while ((n = write(fd, &tar_image[ptr], left)) > 0) 231 { 232 left -= n; 233 ptr += n; 234 } 235 close(fd); 236 } 237 238 nblocks = (((file_size) + 511) & ~511) / 512; 239 offset += 512 * nblocks; 240 } 205 241 } 206 242 -
c/src/exec/libfs/src/imfs/memfile.c
r5c27c80 rd1941587 198 198 the_jnode = iop->file_info; 199 199 200 if (IMFS_memfile_extend( the_jnode, iop->offset )) 201 set_errno_and_return_minus_one( ENOSPC ); 202 203 iop->size = the_jnode->info.file.size; 200 if (the_jnode->type == IMFS_LINEAR_FILE) { 201 if (iop->offset > the_jnode->info.linearfile.size) 202 iop->offset = the_jnode->info.linearfile.size; 203 } 204 else { /* Must be a block file (IMFS_MEMORY_FILE). */ 205 if (IMFS_memfile_extend( the_jnode, iop->offset )) 206 set_errno_and_return_minus_one( ENOSPC ); 207 208 iop->size = the_jnode->info.file.size; 209 } 204 210 return iop->offset; 205 211 } … … 500 506 for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) { 501 507 p = (block_p *) info->triply_indirect[i]; 502 if (!p) /* ensure we have a valid pointer */503 break;504 508 for ( j=0 ; j<IMFS_MEMFILE_BLOCK_SLOTS ; j++ ) { 505 509 if ( p[j] ) { … … 555 559 set_errno_and_return_minus_one( EIO ); 556 560 557 assert( the_jnode->type == IMFS_MEMORY_FILE ); 558 if ( the_jnode->type != IMFS_MEMORY_FILE ) 561 assert( the_jnode->type == IMFS_MEMORY_FILE || 562 the_jnode->type == IMFS_LINEAR_FILE ); 563 if ( the_jnode->type != IMFS_MEMORY_FILE && 564 the_jnode->type != IMFS_LINEAR_FILE ) 559 565 set_errno_and_return_minus_one( EIO ); 560 566 … … 574 580 if ( !my_length ) 575 581 set_errno_and_return_minus_one( EINVAL ); 582 583 /* 584 * Linear files (as created from a tar file are easier to handle 585 * than block files). 586 */ 587 if (the_jnode->type == IMFS_LINEAR_FILE) { 588 unsigned char *file_ptr; 589 590 file_ptr = (unsigned char *)the_jnode->info.linearfile.direct; 591 592 if (my_length > (the_jnode->info.linearfile.size - start)) 593 my_length = the_jnode->info.linearfile.size - start; 594 595 memcpy(dest, &file_ptr[start], my_length); 596 597 IMFS_update_atime( the_jnode ); 598 599 return my_length; 600 } 576 601 577 602 /* … … 1091 1116 * Free memory associated with a memory file. 1092 1117 */ 1093 1094 IMFS_memfile_remove( the_jnode );1118 if (the_jnode->type != IMFS_LINEAR_FILE) 1119 IMFS_memfile_remove( the_jnode ); 1095 1120 1096 1121 free( the_jnode ); -
c/src/libfs/ChangeLog
r5c27c80 rd1941587 1 2001-01-12 Jake Janovetz <janovetz@uiuc.edu> 2 3 * src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, 4 src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c, 5 src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c, 6 src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c, 7 src/imfs/miniimfs_init.c: Final developmental update to "tarfs". 8 When rtems_tarfs_load() is called, it checks the permissions 9 on each file. If there is write permission, it just creates a 10 standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE. 11 If there is no write permission, it creates a LINEAR_FILE node 12 with the appropriate properties. If the permission is ever changed 13 to writeable, IMFS_fchmod converts it to a regular memory file. 14 1 15 2000-12-12 Jake Janovetz <janovetz@uiuc.edu> 2 16 -
c/src/libfs/src/imfs/imfs.h
r5c27c80 rd1941587 131 131 #define IMFS_SYM_LINK RTEMS_FILESYSTEM_SYM_LINK 132 132 #define IMFS_MEMORY_FILE RTEMS_FILESYSTEM_MEMORY_FILE 133 #define IMFS_LINEAR_FILE ( RTEMS_FILESYSTEM_MEMORY_FILE + 1)133 #define IMFS_LINEAR_FILE (IMFS_MEMORY_FILE + 1) 134 134 135 135 #define IMFS_NUMBER_OF_TYPES (IMFS_LINEAR_FILE + 1) … … 265 265 ); 266 266 267 int rtems_tarfs_ mount(267 int rtems_tarfs_load( 268 268 char *mountpoint, 269 269 unsigned char *addr, -
c/src/libfs/src/imfs/imfs_fchmod.c
r5c27c80 rd1941587 45 45 set_errno_and_return_minus_one( EPERM ); 46 46 47 /* 48 * If we make a linear-file writeable, construct a block file 49 * from it first. 50 */ 51 if ( (jnode->type == IMFS_LINEAR_FILE) && 52 (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) ) 53 { 54 unsigned32 count = jnode->info.linearfile.size; 55 const unsigned char *buffer = jnode->info.linearfile.direct; 56 57 jnode->type = IMFS_MEMORY_FILE; 58 jnode->info.file.size = 0; 59 jnode->info.file.indirect = 0; 60 jnode->info.file.doubly_indirect = 0; 61 jnode->info.file.triply_indirect = 0; 62 if (IMFS_memfile_write(jnode, 0, buffer, count) == -1) 63 return(-1); 64 } 65 47 66 jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO); 48 67 jnode->st_mode |= mode; -
c/src/libfs/src/imfs/imfs_handlers_memfile.c
r5c27c80 rd1941587 23 23 memfile_open, 24 24 memfile_close, 25 linearfile_read,25 memfile_read, 26 26 NULL, /* write */ 27 27 memfile_ioctl, 28 linearfile_lseek,28 memfile_lseek, 29 29 IMFS_stat, 30 NULL, /* chmod */30 IMFS_fchmod, 31 31 NULL, /* ftruncate */ 32 32 NULL, /* fpathconf */ … … 34 34 IMFS_fdatasync, 35 35 IMFS_fcntl, 36 NULL /* rmnod */36 memfile_rmnod 37 37 }; 38 38 -
c/src/libfs/src/imfs/imfs_load_tar.c
r5c27c80 rd1941587 5 5 * File entries are created as IMFS_LINEAR_FILE nodes with their nods 6 6 * pointing to addresses in the TAR image. 7 *8 * $Id$9 *10 7 *************************************************************************/ 11 8 12 9 #include <rtems.h> 13 #include <rtems/libio .h>10 #include <rtems/libio_.h> 14 11 #include <string.h> 15 12 #include <chain.h> … … 111 108 112 109 /************************************************************************** 113 * rtems_tarfs_ mount110 * rtems_tarfs_load 114 111 * 115 * Here we create the mountpoint directory and mountthe tarfs at112 * Here we create the mountpoint directory and load the tarfs at 116 113 * that node. Once the IMFS has been mounted, we work through the 117 114 * tar image and perform as follows: … … 122 119 *************************************************************************/ 123 120 int 124 rtems_tarfs_ mount(char *mountpoint,125 126 121 rtems_tarfs_load(char *mountpoint, 122 unsigned char *tar_image, 123 unsigned long tar_size) 127 124 { 128 125 rtems_filesystem_location_info_t root_loc; … … 134 131 unsigned char linkflag; 135 132 unsigned long file_size; 133 unsigned long file_mode; 136 134 int offset; 137 135 unsigned long nblocks; … … 142 140 status = rtems_filesystem_evaluate_path(mountpoint, 0, &root_loc, 0); 143 141 if (status != 0) 142 return(-1); 143 144 if (root_loc.ops != &IMFS_ops) 144 145 return(-1); 145 146 … … 165 166 166 167 linkflag = hdr_ptr[156]; 168 file_mode = octal2ulong(&hdr_ptr[100], 8); 167 169 file_size = octal2ulong(&hdr_ptr[124], 12); 168 169 170 hdr_chksum = (int)octal2ulong(&hdr_ptr[148], 8); 171 170 172 if (compute_tar_header_checksum(hdr_ptr) != hdr_chksum) 171 173 break; … … 180 182 { 181 183 strcpy(full_filename, mountpoint); 182 strcat(full_filename, "/"); 184 if (full_filename[strlen(full_filename)-1] != '/') 185 strcat(full_filename, "/"); 183 186 strcat(full_filename, filename); 184 187 mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO); 185 188 } 186 else if (linkflag == LF_NORMAL) 189 /****************************************************************** 190 * Create a LINEAR_FILE node if no user write permission. 191 *****************************************************************/ 192 else if ((linkflag == LF_NORMAL) && 193 ((file_mode & 0200) == 0000)) 187 194 { 188 195 const char *name; 189 190 196 191 197 loc = root_loc; … … 203 209 offset += 512 * nblocks; 204 210 } 211 /****************************************************************** 212 * Create a regular MEMORY_FILE if write permission exists. 213 *****************************************************************/ 214 else if ((linkflag == LF_NORMAL) && 215 ((file_mode & 0200) == 0200)) 216 { 217 int fd; 218 int n, left, ptr; 219 220 strcpy(full_filename, mountpoint); 221 if (full_filename[strlen(full_filename)-1] != '/') 222 strcat(full_filename, "/"); 223 strcat(full_filename, filename); 224 225 fd = creat(full_filename, S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP); 226 if (fd != -1) 227 { 228 left = file_size; 229 ptr = offset; 230 while ((n = write(fd, &tar_image[ptr], left)) > 0) 231 { 232 left -= n; 233 ptr += n; 234 } 235 close(fd); 236 } 237 238 nblocks = (((file_size) + 511) & ~511) / 512; 239 offset += 512 * nblocks; 240 } 205 241 } 206 242 -
c/src/libfs/src/imfs/memfile.c
r5c27c80 rd1941587 198 198 the_jnode = iop->file_info; 199 199 200 if (IMFS_memfile_extend( the_jnode, iop->offset )) 201 set_errno_and_return_minus_one( ENOSPC ); 202 203 iop->size = the_jnode->info.file.size; 200 if (the_jnode->type == IMFS_LINEAR_FILE) { 201 if (iop->offset > the_jnode->info.linearfile.size) 202 iop->offset = the_jnode->info.linearfile.size; 203 } 204 else { /* Must be a block file (IMFS_MEMORY_FILE). */ 205 if (IMFS_memfile_extend( the_jnode, iop->offset )) 206 set_errno_and_return_minus_one( ENOSPC ); 207 208 iop->size = the_jnode->info.file.size; 209 } 204 210 return iop->offset; 205 211 } … … 500 506 for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) { 501 507 p = (block_p *) info->triply_indirect[i]; 502 if (!p) /* ensure we have a valid pointer */503 break;504 508 for ( j=0 ; j<IMFS_MEMFILE_BLOCK_SLOTS ; j++ ) { 505 509 if ( p[j] ) { … … 555 559 set_errno_and_return_minus_one( EIO ); 556 560 557 assert( the_jnode->type == IMFS_MEMORY_FILE ); 558 if ( the_jnode->type != IMFS_MEMORY_FILE ) 561 assert( the_jnode->type == IMFS_MEMORY_FILE || 562 the_jnode->type == IMFS_LINEAR_FILE ); 563 if ( the_jnode->type != IMFS_MEMORY_FILE && 564 the_jnode->type != IMFS_LINEAR_FILE ) 559 565 set_errno_and_return_minus_one( EIO ); 560 566 … … 574 580 if ( !my_length ) 575 581 set_errno_and_return_minus_one( EINVAL ); 582 583 /* 584 * Linear files (as created from a tar file are easier to handle 585 * than block files). 586 */ 587 if (the_jnode->type == IMFS_LINEAR_FILE) { 588 unsigned char *file_ptr; 589 590 file_ptr = (unsigned char *)the_jnode->info.linearfile.direct; 591 592 if (my_length > (the_jnode->info.linearfile.size - start)) 593 my_length = the_jnode->info.linearfile.size - start; 594 595 memcpy(dest, &file_ptr[start], my_length); 596 597 IMFS_update_atime( the_jnode ); 598 599 return my_length; 600 } 576 601 577 602 /* … … 1091 1116 * Free memory associated with a memory file. 1092 1117 */ 1093 1094 IMFS_memfile_remove( the_jnode );1118 if (the_jnode->type != IMFS_LINEAR_FILE) 1119 IMFS_memfile_remove( the_jnode ); 1095 1120 1096 1121 free( the_jnode ); -
cpukit/libfs/ChangeLog
r5c27c80 rd1941587 1 2001-01-12 Jake Janovetz <janovetz@uiuc.edu> 2 3 * src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, 4 src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c, 5 src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c, 6 src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c, 7 src/imfs/miniimfs_init.c: Final developmental update to "tarfs". 8 When rtems_tarfs_load() is called, it checks the permissions 9 on each file. If there is write permission, it just creates a 10 standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE. 11 If there is no write permission, it creates a LINEAR_FILE node 12 with the appropriate properties. If the permission is ever changed 13 to writeable, IMFS_fchmod converts it to a regular memory file. 14 1 15 2000-12-12 Jake Janovetz <janovetz@uiuc.edu> 2 16 -
cpukit/libfs/src/imfs/imfs.h
r5c27c80 rd1941587 131 131 #define IMFS_SYM_LINK RTEMS_FILESYSTEM_SYM_LINK 132 132 #define IMFS_MEMORY_FILE RTEMS_FILESYSTEM_MEMORY_FILE 133 #define IMFS_LINEAR_FILE ( RTEMS_FILESYSTEM_MEMORY_FILE + 1)133 #define IMFS_LINEAR_FILE (IMFS_MEMORY_FILE + 1) 134 134 135 135 #define IMFS_NUMBER_OF_TYPES (IMFS_LINEAR_FILE + 1) … … 265 265 ); 266 266 267 int rtems_tarfs_ mount(267 int rtems_tarfs_load( 268 268 char *mountpoint, 269 269 unsigned char *addr, -
cpukit/libfs/src/imfs/imfs_fchmod.c
r5c27c80 rd1941587 45 45 set_errno_and_return_minus_one( EPERM ); 46 46 47 /* 48 * If we make a linear-file writeable, construct a block file 49 * from it first. 50 */ 51 if ( (jnode->type == IMFS_LINEAR_FILE) && 52 (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) ) 53 { 54 unsigned32 count = jnode->info.linearfile.size; 55 const unsigned char *buffer = jnode->info.linearfile.direct; 56 57 jnode->type = IMFS_MEMORY_FILE; 58 jnode->info.file.size = 0; 59 jnode->info.file.indirect = 0; 60 jnode->info.file.doubly_indirect = 0; 61 jnode->info.file.triply_indirect = 0; 62 if (IMFS_memfile_write(jnode, 0, buffer, count) == -1) 63 return(-1); 64 } 65 47 66 jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO); 48 67 jnode->st_mode |= mode; -
cpukit/libfs/src/imfs/imfs_handlers_memfile.c
r5c27c80 rd1941587 23 23 memfile_open, 24 24 memfile_close, 25 linearfile_read,25 memfile_read, 26 26 NULL, /* write */ 27 27 memfile_ioctl, 28 linearfile_lseek,28 memfile_lseek, 29 29 IMFS_stat, 30 NULL, /* chmod */30 IMFS_fchmod, 31 31 NULL, /* ftruncate */ 32 32 NULL, /* fpathconf */ … … 34 34 IMFS_fdatasync, 35 35 IMFS_fcntl, 36 NULL /* rmnod */36 memfile_rmnod 37 37 }; 38 38 -
cpukit/libfs/src/imfs/imfs_load_tar.c
r5c27c80 rd1941587 5 5 * File entries are created as IMFS_LINEAR_FILE nodes with their nods 6 6 * pointing to addresses in the TAR image. 7 *8 * $Id$9 *10 7 *************************************************************************/ 11 8 12 9 #include <rtems.h> 13 #include <rtems/libio .h>10 #include <rtems/libio_.h> 14 11 #include <string.h> 15 12 #include <chain.h> … … 111 108 112 109 /************************************************************************** 113 * rtems_tarfs_ mount110 * rtems_tarfs_load 114 111 * 115 * Here we create the mountpoint directory and mountthe tarfs at112 * Here we create the mountpoint directory and load the tarfs at 116 113 * that node. Once the IMFS has been mounted, we work through the 117 114 * tar image and perform as follows: … … 122 119 *************************************************************************/ 123 120 int 124 rtems_tarfs_ mount(char *mountpoint,125 126 121 rtems_tarfs_load(char *mountpoint, 122 unsigned char *tar_image, 123 unsigned long tar_size) 127 124 { 128 125 rtems_filesystem_location_info_t root_loc; … … 134 131 unsigned char linkflag; 135 132 unsigned long file_size; 133 unsigned long file_mode; 136 134 int offset; 137 135 unsigned long nblocks; … … 142 140 status = rtems_filesystem_evaluate_path(mountpoint, 0, &root_loc, 0); 143 141 if (status != 0) 142 return(-1); 143 144 if (root_loc.ops != &IMFS_ops) 144 145 return(-1); 145 146 … … 165 166 166 167 linkflag = hdr_ptr[156]; 168 file_mode = octal2ulong(&hdr_ptr[100], 8); 167 169 file_size = octal2ulong(&hdr_ptr[124], 12); 168 169 170 hdr_chksum = (int)octal2ulong(&hdr_ptr[148], 8); 171 170 172 if (compute_tar_header_checksum(hdr_ptr) != hdr_chksum) 171 173 break; … … 180 182 { 181 183 strcpy(full_filename, mountpoint); 182 strcat(full_filename, "/"); 184 if (full_filename[strlen(full_filename)-1] != '/') 185 strcat(full_filename, "/"); 183 186 strcat(full_filename, filename); 184 187 mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO); 185 188 } 186 else if (linkflag == LF_NORMAL) 189 /****************************************************************** 190 * Create a LINEAR_FILE node if no user write permission. 191 *****************************************************************/ 192 else if ((linkflag == LF_NORMAL) && 193 ((file_mode & 0200) == 0000)) 187 194 { 188 195 const char *name; 189 190 196 191 197 loc = root_loc; … … 203 209 offset += 512 * nblocks; 204 210 } 211 /****************************************************************** 212 * Create a regular MEMORY_FILE if write permission exists. 213 *****************************************************************/ 214 else if ((linkflag == LF_NORMAL) && 215 ((file_mode & 0200) == 0200)) 216 { 217 int fd; 218 int n, left, ptr; 219 220 strcpy(full_filename, mountpoint); 221 if (full_filename[strlen(full_filename)-1] != '/') 222 strcat(full_filename, "/"); 223 strcat(full_filename, filename); 224 225 fd = creat(full_filename, S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP); 226 if (fd != -1) 227 { 228 left = file_size; 229 ptr = offset; 230 while ((n = write(fd, &tar_image[ptr], left)) > 0) 231 { 232 left -= n; 233 ptr += n; 234 } 235 close(fd); 236 } 237 238 nblocks = (((file_size) + 511) & ~511) / 512; 239 offset += 512 * nblocks; 240 } 205 241 } 206 242 -
cpukit/libfs/src/imfs/memfile.c
r5c27c80 rd1941587 198 198 the_jnode = iop->file_info; 199 199 200 if (IMFS_memfile_extend( the_jnode, iop->offset )) 201 set_errno_and_return_minus_one( ENOSPC ); 202 203 iop->size = the_jnode->info.file.size; 200 if (the_jnode->type == IMFS_LINEAR_FILE) { 201 if (iop->offset > the_jnode->info.linearfile.size) 202 iop->offset = the_jnode->info.linearfile.size; 203 } 204 else { /* Must be a block file (IMFS_MEMORY_FILE). */ 205 if (IMFS_memfile_extend( the_jnode, iop->offset )) 206 set_errno_and_return_minus_one( ENOSPC ); 207 208 iop->size = the_jnode->info.file.size; 209 } 204 210 return iop->offset; 205 211 } … … 500 506 for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) { 501 507 p = (block_p *) info->triply_indirect[i]; 502 if (!p) /* ensure we have a valid pointer */503 break;504 508 for ( j=0 ; j<IMFS_MEMFILE_BLOCK_SLOTS ; j++ ) { 505 509 if ( p[j] ) { … … 555 559 set_errno_and_return_minus_one( EIO ); 556 560 557 assert( the_jnode->type == IMFS_MEMORY_FILE ); 558 if ( the_jnode->type != IMFS_MEMORY_FILE ) 561 assert( the_jnode->type == IMFS_MEMORY_FILE || 562 the_jnode->type == IMFS_LINEAR_FILE ); 563 if ( the_jnode->type != IMFS_MEMORY_FILE && 564 the_jnode->type != IMFS_LINEAR_FILE ) 559 565 set_errno_and_return_minus_one( EIO ); 560 566 … … 574 580 if ( !my_length ) 575 581 set_errno_and_return_minus_one( EINVAL ); 582 583 /* 584 * Linear files (as created from a tar file are easier to handle 585 * than block files). 586 */ 587 if (the_jnode->type == IMFS_LINEAR_FILE) { 588 unsigned char *file_ptr; 589 590 file_ptr = (unsigned char *)the_jnode->info.linearfile.direct; 591 592 if (my_length > (the_jnode->info.linearfile.size - start)) 593 my_length = the_jnode->info.linearfile.size - start; 594 595 memcpy(dest, &file_ptr[start], my_length); 596 597 IMFS_update_atime( the_jnode ); 598 599 return my_length; 600 } 576 601 577 602 /* … … 1091 1116 * Free memory associated with a memory file. 1092 1117 */ 1093 1094 IMFS_memfile_remove( the_jnode );1118 if (the_jnode->type != IMFS_LINEAR_FILE) 1119 IMFS_memfile_remove( the_jnode ); 1095 1120 1096 1121 free( the_jnode );
Note: See TracChangeset
for help on using the changeset viewer.