示例#1
0
文件: common.c 项目: GYGit/reactos
void *qalloc(void **root, int size)
{
    LINK *link;

    link = vfalloc(sizeof(LINK));
    link->next = *root;
    *root = link;
    return link->data = vfalloc(size);
}
示例#2
0
void fs_read(loff_t pos,int size,void *data)
{
    CHANGE *walk;
    int got;
#if 1 // TMN
	const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size;        // TMN:
 	const loff_t seekpos_aligned = pos - (pos % 512);                   // TMN:
 	const size_t seek_delta = (size_t)(pos - seekpos_aligned);          // TMN:
	const size_t readsize = (size_t)(pos - seekpos_aligned) + readsize_aligned; // TMN:
	char* tmpBuf = vfalloc(readsize_aligned);                                    // TMN:
    if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %I64d",pos);
    if ((got = read(fd,tmpBuf,readsize_aligned)) < 0) pdie("Read %d bytes at %I64d",size,pos);
	assert(got >= size);
	got = size;
	assert(seek_delta + size <= readsize);
	memcpy(data, tmpBuf+seek_delta, size);
	vffree(tmpBuf);
#else // TMN:
    if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos);
    if ((got = read(fd,data,size)) < 0) pdie("Read %d bytes at %lld",size,pos);
#endif // TMN:
    if (got != size) die("Got %d bytes instead of %d at %I64d",got,size,pos);
    for (walk = changes; walk; walk = walk->next) {
	if (walk->pos < pos+size && walk->pos+walk->size > pos) {
	    if (walk->pos < pos)
		memcpy(data,(char *) walk->data+pos-walk->pos,min((size_t)size,
		  (size_t)(walk->size-pos+walk->pos)));
	    else memcpy((char *) data+walk->pos-pos,walk->data,min((size_t)walk->size,
		  (size_t)(size+pos-walk->pos)));
	}
    }
}
示例#3
0
文件: file.c 项目: RPG-7/reactos
void file_add(char *path,FD_TYPE type)
{
    FDSC **current,*walk;
    char name[MSDOS_NAME];
    char *here;

    current = &fp_root;
    if (*path != '/') die("%s: Absolute path required.",path);
    path++;
    while (1) {
	if ((here = strchr(path,'/'))) *here = 0;
    if (!file_cvt((unsigned char*)path,(unsigned char *)name)) {return; /*exit(2);*/}
	for (walk = *current; walk; walk = walk->next)
	    if (!here && (!strncmp(name,walk->name,MSDOS_NAME) || (type ==
	      fdt_undelete && !strncmp(name+1,walk->name+1,MSDOS_NAME-1))))
		die("Ambiguous name: \"%s\"",path);
	    else if (here && !strncmp(name,walk->name,MSDOS_NAME)) break;
	if (!walk) {
	    walk = vfalloc(sizeof(FDSC));
	    strncpy(walk->name,name,MSDOS_NAME);
	    walk->type = here ? fdt_none : type;
	    walk->first = NULL;
	    walk->next = *current;
	    *current = walk;
	}
	current = &walk->first;
	if (!here) break;
	*here = '/';
	path = here+1;
    }
}
示例#4
0
int fs_test(loff_t pos,int size)
{
    void *scratch;
    int okay;

#if 1 // TMN
	const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size;        // TMN:
	const loff_t seekpos_aligned = pos - (pos % 512);                   // TMN:
    scratch = vfalloc(readsize_aligned);
    if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %lld",pos);
    okay = read(fd,scratch,readsize_aligned) == (int)readsize_aligned;
    vffree(scratch);
#else // TMN:
    if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos);
    scratch = vfalloc(size);
    okay = read(fd,scratch,size) == size;
    vffree(scratch);
#endif // TMN:
    return okay;
}