Пример #1
0
int getDataFromFile(fileDesc* currDesc,char* buf,size_t count)
{
    if(!currDesc || !buf)
    {
        return -1;
    }
    uint64_t file_size=0;
    uint64_t offset = currDesc->offset;
    struct posix_header_ustar* fileInfo = currDesc->file->fileInfo;
    atoo(&file_size,fileInfo->size);
    uint64_t file_start = (uint64_t)(currDesc->buffer);
    
    //Offset is at the end, simply return 0
    if(offset>=file_size)
        return 0;
    //Check for read limits
    if( offset + count > file_size)
    {
        count = file_size - offset;
    }
    
    memcpy(buf,(uint64_t*)(file_start + offset),count);
    currDesc->offset = currDesc->offset + count;
    return count;
}
Пример #2
0
static int octal_esc_to_chr(char *input)
{
	int i=0;
	int ret = 0;
	int len = strlen(input);

	//intf("%s('%s')\n", __func__, input);
	if (input[0] != '\\')
		return -1;
	if (len < 4)
		return -1;

	for (i=1; i < len ; i++) {
		if (i > 3)
			break;
		int tmp = atoo(input[i]);
		//intf("tmp: %d\n", tmp);
		if (tmp < 0)
			return tmp;
		ret <<= 3;
		ret += tmp;
	}
	return ret;
}
Пример #3
0
static int parse_modes (mode *table, char *string, uint16_t *num)
{
	char	*ptr;
	char	*temptable[32];
	uint16_t	tempnum = 0;
	int		i,i2,factor;

	/* call parse_patterns(). Clever, huh? */
	if (parse_patterns(temptable,string,&tempnum,FALSE,TXT(T_TOO_MANY_MODES),32)==-1) return(-1);

	/* tempnum now has # of items in temptable,
	   temptable has pointers to the individual mode specifiers */

	if ((*num+tempnum)>Maxmodes) {
		fprintf (stderr,"%s (%d max)\n",TXT(T_TOO_MANY_MODES),Maxmodes);
		return(-1);
	}

	for (i=0;i<tempnum;i++)
	{
		ptr = temptable[i];

		#ifdef DIAG
			fprintf(stderr,"parse_modes: parsing '%s'\n",ptr);
		#endif

		if (*ptr == NOT_CHARACTER)
		{
			ptr++;
			table[i+*num].negative = TRUE;
		} else table[i+*num].negative = FALSE;

		if (!*ptr)
		{
			fprintf(stderr,TXT(T_ILLEGAL_MODE_SPEC),temptable[i]);
			exit(0xBAD);
		}

		/* is it a nonnegative octal number? */
		if (isoctal(*ptr))
		{
			int j;

			j = atoo(ptr);
			if (j<0) 
			{
				fprintf(stderr,TXT(T_NUM_OUT_OF_RANGE),temptable[i]);
				exit(0xBAD);
			} else {     
				#ifdef DIAG
					fprintf(stderr,"parse_modes: got octal 0%o\n",j);
				#endif
				table[i+*num].fmode = j;
			}
		} else {
			/* it is a symbolic type definition */
			for (factor=0;*ptr!='=';ptr++)
			{
				switch(*ptr)
				{
					case 'u':
						factor |= 0100;
						break;
					case 'g':
						factor |= 010;
						break;
					case 'o':
						factor |= 01;
						break;
					case 'a':
						factor = 0111;
						break;
					default:
						fprintf(stderr,TXT(T_ILLEGAL_MODE_SPEC),temptable[i]);
						exit(0xBAD);
				}
			}
			
			/* ptr now points to '=' */
			
			for (++ptr,i2=0;*ptr;ptr++)
			{
				switch(*ptr)
				{
					case 'r':
						i2 |= S_IROTH;
						break;
					case 'w':
						i2 |= S_IWOTH;
						break;
					case 'x':
					case 's':					
						i2 |= S_IXOTH;
						break;			
	        		default:
						fprintf(stderr,TXT(T_ILLEGAL_MODE_SPEC),temptable[i]);
						exit(0xBAD);
				}
			}

			table[i+*num].fmode = i2*factor;
			#ifdef DIAG
				fprintf(stderr,"parse_modes: table[%d].fmode = 0%o\n",i+*num,table[i+*num].fmode);
			#endif
        }  /* else */
	} /* for */

	*num += tempnum;

	return(0);
}
Пример #4
0
void populateFileSystem()
{
    char name[FILEPATH_LEN];
    //This tells how much we have to move relative to the start of path
    int move_index;
    
   
    Tree* currentNode, *childNode, *nextNode, *newNode;
       
    //Initialize the read only file system root node
    root = createNode("/");
    if( root == NULL)
    {
        #ifdef LOG
            printf(" Cannot allocate memory for tarfs files \n");
        #endif
        return;
    }
    #if 1
    root->fileInfo = kmalloc(sizeof(struct posix_header_ustar));
    if ( root->fileInfo == NULL )
    {
        #ifdef LOG
            printf(" Cannot allocate memory for tarfs files \n");
        #endif
        return;
    }
    root->fileInfo->typeflag[0] = '5'; /* Root is a directory */
    strncpy(root->fileInfo->mode, "755", sizeof(root->fileInfo->mode));
    #endif
    
    struct posix_header_ustar* startfs= &((struct posix_header_ustar*)&_binary_tarfs_start)[0];
    uint64_t size=0;
    //Below loops through all files present in tarfs
    while ( startfs < (struct posix_header_ustar*)&_binary_tarfs_end)
    {
        //printf("File Name: %s\n", startfs->name);
        move_index = 0;
        currentNode = root;
        if ( startfs->name[0] == 0 )
               break;
            
        while(1)
        {
           
            //move_index contains the index of char next to '/'
            move_index = move_index + findNextNameinPath(startfs->name+move_index , name);
            //To go to next character of '/'
            move_index = move_index + 1;
            if(*name=='\0')
            {
                //Path ended here
                currentNode->fileInfo = startfs;
                //Now move to map next file entry
                break;
            }
            childNode = findChildNodebyName(currentNode,name);
            //If no childnode present below the parent
            //Then create one now
            if( childNode == NULL)
            {
                newNode = createNode(name);
                if( newNode == NULL)
                {
                    #ifdef LOG
                        printf(" Cannot allocate memory for tarfs files \n");
                    #endif
                    return;
                }
                if(currentNode->child ==NULL)
                {
                    currentNode->child = newNode;
                }
                else
                {
                    nextNode = currentNode->child;
                    while(nextNode->sibling)
                    {
                        nextNode = nextNode->sibling;    
                    }
                    nextNode->sibling = newNode;
                }
                currentNode = newNode;
            }
            else
            {
                currentNode = childNode;
            }
        }
        atoo(&size, startfs->size);
        startfs =  (struct posix_header_ustar *)((uint64_t)startfs + ROUNDUP(size, 512, uint64_t) + sizeof(struct posix_header_ustar));
    }
    //root->fileInfo->typeflag[0] = '5'; /* Root is a directory */
    //strncpy(root->fileInfo->mode, "755", sizeof(root->fileInfo->mode));
    return;
}