Exemplo n.º 1
0
Arquivo: ed.c Projeto: 00001/plan9port
int
putline(void)
{
	Rune *lp, *bp;
	int nl, tl;

	fchange = 1;
	lp = linebuf;
	tl = tline;
	bp = getblock(tl, OWRITE);
	nl = nleft;
	tl &= ~((BLKSIZE/sizeof(Rune))-1);
	while(*bp = *lp++) {
		if(*bp++ == '\n') {
			bp[-1] = 0;
			linebp = lp;
			break;
		}
		nl -= sizeof(Rune);
		if(nl == 0) {
			tl += BLKSIZE/sizeof(Rune);
			bp = getblock(tl, OWRITE);
			nl = nleft;
		}
	}
	nl = tline;
	tline += ((lp-linebuf) + 03) & 077776;
	return nl;
}
Exemplo n.º 2
0
// checks if there is a platform for placing something somewhere
// check in a square that there is _AIR from y and above
// and check that there is solid ground at y-1
bool coretest(int x, int y, int z, int ground_rad, int air_rad, int height)
{
	int maxrad = ground_rad * ground_rad;
	for (int dx = -ground_rad; dx <= ground_rad; dx++)
	for (int dz = -ground_rad; dz <= ground_rad; dz++)
	{
		if (dx*dx + dz*dz <= maxrad)
		{
			// ground test: exit when AIR
			block_t block = getblock(x + dx, y-1, z + dz);
			if (block <= air_end || block >= halfblock_start) return false;
		}
	}
	
	for (int dy = 0; dy < height; dy++)
	{
		maxrad = air_rad * air_rad;
		for (int dx = -air_rad; dx <= air_rad; dx++)
		for (int dz = -air_rad; dz <= air_rad; dz++)
		{
			if (dx*dx + dz*dz <= maxrad)
			{
				// air test: exit when not AIR or fluid
				block_t block = getblock(x + dx, y + dy, z + dz);
				if (isSolid(block) || isFluid(block)) return false;
			}
		}
	}
	return true;
}
Exemplo n.º 3
0
Arquivo: ed.c Projeto: redox-os/libc
int putline(void)
{
    char *bp, *lp;
    int nl;
    unsigned int tl;

    fchange = 1;
    lp = linebuf;
    tl = tline;
    bp = getblock(tl, WRITE);
    nl = nleft;
    tl &= ~((BLKSIZE/2)-1);
    while (*bp = *lp++) {
        if (*bp++ == '\n') {
            *--bp = 0;
            linebp = lp;
            break;
        }
        if (--nl == 0) {
            bp = getblock(tl+=(BLKSIZE/2), WRITE);
            nl = nleft;
        }
    }
    nl = tline;
    tline += (((lp-linebuf)+03)>>1)&077776;
    return(nl);
}
Exemplo n.º 4
0
int
read_bsd_pt(int fd, struct slice all, struct slice *sp, int ns) {
	struct bsd_disklabel *l;
	struct bsd_partition *p;
	unsigned int offset = all.start;
	int max_partitions;
	unsigned char *bp;
	int n = 0;

	bp = getblock(fd, offset+1); 	/* 1 sector suffices */
	if (bp == NULL)
		return -1;

	l = (struct bsd_disklabel *) bp;
	if (l->d_magic != BSD_DISKMAGIC)
		return -1;

	max_partitions = 16;
	if (l->d_npartitions < max_partitions)
		max_partitions = l->d_npartitions;
	for (p = l->d_partitions; p - l->d_partitions <  max_partitions; p++) {
		if (p->p_fstype == BSD_FS_UNUSED)
			/* nothing */;
		else if (n < ns) {
			sp[n].start = p->p_offset;
			sp[n].size = p->p_size;
			n++;
		} else {
			fprintf(stderr,
				"bsd_partition: too many slices\n");
			break;
		}
	}
	return n;
}
Exemplo n.º 5
0
int overwrite_version(version_node * vp, const char * content) {
	(vp->v).del_mark = 0;		// since we're overwriting, its not deleted anymore.
	int i = 0, j = 0;
	int l = strlen(content);
	int chunks_alloc = 0;
	
	if((l - (vp->v).off * CHUNKSIZE) > (int)(free_chunks() * CHUNKSIZE)) {
		fprintf(stderr, "ERROR: Not enough memory to backup.\n");
		return BACKUP_ERROR;
	}
	
	while(i < (vp->v).off && j < l) {
		strncpy((char*)(vp->v).contents[i], content+j, CHUNKSIZE);
		i++; j += CHUNKSIZE;
	}
	// either still content remaining to be written or all the content written.
	// if still more content to be written:
	while(j < l) {
		(vp->v).contents[(vp->v).off++] = (chunk *) getblock();
		if((vp->v).contents[(vp->v).off-1] == NULL) {
			fprintf(stderr, "ERROR: No free chunks.\n");
			return BACKUP_ERROR;
		}
		chunks_alloc++;
		strncpy((char*)(vp->v).contents[(vp->v).off-1], content+j, CHUNKSIZE);
		j += CHUNKSIZE;
	}
	return chunks_alloc;
}
Exemplo n.º 6
0
static int
getblocktag(Fs *fs, uint32_t n, int tag, int32_t qpath)
{
	if(getblock(fs, n) < 0 || checktag(fs, block, tag, qpath) < 0)
		return -1;
	return 1;
}
Exemplo n.º 7
0
int
read_unixware_pt(int fd, struct slice all, struct slice *sp, int ns) {
	struct unixware_disklabel *l;
	struct unixware_slice *p;
	unsigned int offset = all.start;
	char *bp;
	int n = 0;

	bp = getblock(fd, offset+29); 	/* 1 sector suffices */
	if (bp == NULL)
		return -1;

	l = (struct unixware_disklabel *) bp;
	if (four2int(l->d_magic) != UNIXWARE_DISKMAGIC ||
	    four2int(l->vtoc.v_magic) != UNIXWARE_DISKMAGIC2)
		return -1;

	p = &l->vtoc.v_slice[1];	/* slice 0 is the whole disk. */
	while (p - &l->vtoc.v_slice[0] < UNIXWARE_NUMSLICE) {
		if (p->s_label == UNIXWARE_FS_UNUSED)
			/* nothing */;
		else if (n < ns) {
			sp[n].start = p->start_sect;
			sp[n].size = p->nr_sects;
			n++;
		} else {
			fprintf(stderr,
				"unixware_partition: too many slices\n");
			break;
		}
		p++;
	}
	return n;
}
Exemplo n.º 8
0
char enum_BBconflictInPath( branch *bru, char direction, block *bv, 
			    ushort *bb_seq, ushort len, block **bblist, int num_bb ) {

  int  cf, id, idx;
  char res;
  branch *br;

  // check for each branch conflicting with bru, whether it occurs in this path
  for( cf = 0; cf < bru->num_conflicts; cf++ ) {
    br = bru->conflicts[cf];

    id = enum_findBranch( br, bb_seq, len );
    if( id == -1 )
      continue;

    idx = getblock( bb_seq[id-1], bblist, 0, num_bb-1 );
    if( idx == -1 )
      continue;

    // direction taken by br to its successor in bb_seq
    res = detectDirection( br, bblist[idx] );
    if( ( direction == bru->jump_cond && bru->conflictdir_jump[cf] == res ) ||
        ( direction == neg( bru->jump_cond ) && bru->conflictdir_fall[cf] == res ) ) {

      // check cancellation of effect by assignment
      id = enum_effectCancelled( br, NULL, bb_seq, len, bblist, num_bb );

      if( id == -1 ) {
        return 1;
      }
    }
  }
  return 0;
}
Exemplo n.º 9
0
Arquivo: ed.c Projeto: redox-os/libc
char *
getline(unsigned int tl)
{
    char *bp, *lp;
    int nl;

    lp = linebuf;
    bp = getblock(tl, READ);
    nl = nleft;
    tl &= ~((BLKSIZE/2)-1);
    while (*lp++ = *bp++)
        if (--nl == 0) {
            bp = getblock(tl+=(BLKSIZE/2), READ);
            nl = nleft;
        }
    return(linebuf);
}
Exemplo n.º 10
0
Arquivo: ed.c Projeto: 00001/plan9port
Rune*
getline(int tl)
{
	Rune *lp, *bp;
	int nl;

	lp = linebuf;
	bp = getblock(tl, OREAD);
	nl = nleft;
	tl &= ~((BLKSIZE/sizeof(Rune)) - 1);
	while(*lp++ = *bp++) {
		nl -= sizeof(Rune);
		if(nl == 0) {
			bp = getblock(tl += BLKSIZE/sizeof(Rune), OREAD);
			nl = nleft;
		}
	}
	return linebuf;
}
Exemplo n.º 11
0
void downSpider(int x, int y, int z, block_t id, int tries)
{
	block_t currentBlock = getblock(x, y, z);
	
	// air, crosses, water
	if (isAir(currentBlock) || currentBlock >= halfblock_start)
	{
		if (tries--) downSpider(x, y-1, z, id, tries);
		setb(x, y, z, id);
	}
}
Exemplo n.º 12
0
STATIC struct buffer FAR *getblock_from_off(f_node_ptr fnp, unsigned secsize)
{
  /* Compute the block within the cluster and the */
  /* offset within the block.                     */
  unsigned sector;

  sector = (UBYTE)(fnp->f_offset / secsize) & fnp->f_dpb->dpb_clsmask;

  /* Get the block we need from cache             */
  return getblock(clus2phys(fnp->f_cluster, fnp->f_dpb) + sector,
                  fnp->f_dpb->dpb_unit);
}
Exemplo n.º 13
0
static int
read_extended_partition(int fd, struct partition *ep, int en,
			struct slice *sp, int ns)
{
	struct partition p;
	unsigned long start, here, next;
	unsigned char *bp;
	int loopct = 0;
	int moretodo = 1;
	int i, n=0;

	int sector_size_mul = get_sector_size(fd)/512;

	next = start = sector_size_mul * le32_to_cpu(ep->start_sect);

	while (moretodo) {
		here = next;
		moretodo = 0;
		if (++loopct > 100)
			return n;

		bp = (unsigned char *)getblock(fd, here);
		if (bp == NULL)
			return n;

		if (bp[510] != 0x55 || bp[511] != 0xaa)
			return n;

		for (i=0; i<2; i++) {
			memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
			if (is_extended(p.sys_type)) {
				if (p.start_sect && p.nr_sects && !moretodo) {
					next = start + sector_size_mul * le32_to_cpu(p.start_sect);
					moretodo = 1;
				}
				continue;
			}
			if (n < ns) {
				sp[n].start = here + sector_size_mul * le32_to_cpu(p.start_sect);
				sp[n].size = sector_size_mul * le32_to_cpu(p.nr_sects);
				sp[n].container = en + 1;
				n++;
			} else {
				fprintf(stderr,
				    "dos_extd_partition: too many slices\n");
				return n;
			}
			loopct = 0;
		}
	}
	return n;
}
Exemplo n.º 14
0
static int
read_extended_partition(int fd, struct partition *ep,
			struct slice *sp, int ns) {
	struct partition *p;
	unsigned long start, here, next;
	unsigned char *bp;
	int loopct = 0;
	int moretodo = 1;
	int i, n=0;

	here = start = ep->start_sect;

	while (moretodo) {
		moretodo = 0;
		if (++loopct > 100)
			return n;

		bp = getblock(fd, here);
		if (bp == NULL)
			return n;

		if (bp[510] != 0x55 || bp[511] != 0xaa)
			return n;

		p = (struct partition *) (bp + 0x1be);

		for (i=0; i<2; i++, p++) {
			if (p->nr_sects == 0 || is_extended(p->sys_type))
				continue;
			if (n < ns) {
				sp[n].start = here + p->start_sect;
				sp[n].size = p->nr_sects;
				n++;
			} else {
				fprintf(stderr,
				    "dos_extd_partition: too many slices\n");
				return n;
			}
			loopct = 0;
		}

		p -= 2;
		for (i=0; i<2; i++, p++) {
			if(p->nr_sects != 0 && is_extended(p->sys_type)) {
				here = start + p->start_sect;
				moretodo = 1;
				break;
			}
		}
	}
	return n;
}
Exemplo n.º 15
0
void write_fsinfo(struct dpb FAR * dpbp)
{
  struct buffer FAR *bp;
  struct fsinfo FAR *fip;

  bp = getblock(dpbp->dpb_xfsinfosec, dpbp->dpb_unit);
  bp->b_flag &= ~(BFR_DATA | BFR_DIR | BFR_FAT);
  bp->b_flag |= BFR_VALID | BFR_DIRTY;

  fip = (struct fsinfo FAR *)&bp->b_buffer[0x1e4];
  fip->fi_nfreeclst = dpbp->dpb_xnfreeclst;
  fip->fi_cluster = dpbp->dpb_xcluster;
}
Exemplo n.º 16
0
Arquivo: util.c Projeto: lufia/tc
void
dictinit(char *fname)
{
	Stream *fin;
	Block *b;

	fin = sopen(fname, OREAD);
	while(b = getblock(fin)){
		setblock(b);
		free(b);
	}
	sclose(fin);
}
Exemplo n.º 17
0
int main(void)
{
	int nsamp, i;
 	float *input, *output1, *output2;
 	initialize(FS_48K, MONO_IN, STEREO_OUT); 	// Set up the DAC/ADC interface
 	
 	// Allocate Required Memory
 	nsamp = getblocksize();
	
 	input = (float *)malloc(sizeof(float)*nsamp);
 	output1 = (float *)malloc(sizeof(float)*nsamp);
 	output2 = (float *)malloc(sizeof(float)*nsamp);
  
 	if (input==NULL || output1==NULL || output2==NULL) {
 		flagerror(MEMORY_ALLOCATION_ERROR);
 		while(1);
 	}

 	// Filter coefficients
	// float b[5][3] = {{1, 2, 1},{1, -2, 1},{1, 0.851559, 1},{1, -1.90211, 1},{1, 1.17557, 1}};
	// float a[5][3] = {{1, 2, 1},{1, -2, 1},{1, 0.851559, 1},{1, -1.90211, 1},{1, 1.17557, 1}};
	// float g = 0.0264722;

    // Biquad structure initialization
	BIQUAD_T *f1;
	f1 = init_biquad(num_stages, g, a_coef, b_coef, nsamp);

	// Infinite Loop to process the data stream, "nsamp" samples at a time	
	while(1){
    	/*
    	 * Ask for a block of ADC samples to be put into the working buffer
    	 *   getblock() will wait until the input buffer is filled...  On return
    	 *   we work on 	the new data buffer.
    	 */
    	getblock(input);	// Wait here until the input buffer is filled... Then process	
    	
    	// signal processing code to calculate the required output buffers
    	// copy input to output2 for reference
    	for(i=0;i<nsamp;i++) {
    		output2[i] = input[i];
    	}
    	DIGITAL_IO_SET(); 	// Use a scope on PC4 to measure execution time
    	// Call the biquad filter routine
    	calc_biquad(f1,input,output1);
    	
    	DIGITAL_IO_RESET();	// (falling edge....  done processing data )
    	
    	// pass the processed working buffer back for DAC output
    	putblockstereo(output1, output2);
	}
}
Exemplo n.º 18
0
// To add new version
int add_new_version(file * fileobj, version_node * vq1, version_node * vq2, int v, const char * content) {
	// check for space
	int l = strlen(content);
	int chunks_alloc = 0;
	if(l > free_chunks() * CHUNKSIZE) {
		fprintf(stderr, "ERROR: Not enough memory to backup.\n");
		return BACKUP_ERROR;
	}

	// initialize the version node
	version_node * temp_version = ALLOCATE_VERSION_NODE();
	(temp_version->v).v_no = v;
	(temp_version->v).del_mark = 0;
	(temp_version->v).off = 0;
	int i;
	for(i = 0; i < l; i++) {
		(temp_version->v).contents[(temp_version->v).off++] = (chunk *)getblock();
		if((temp_version->v).contents[(temp_version->v).off-1] == NULL) {
			fprintf(stderr, "ERROR: No free chunks.\n");
			return BACKUP_ERROR;
		}
		chunks_alloc++;
		strncpy((char*)(temp_version->v).contents[(temp_version->v).off-1], content+i, CHUNKSIZE);
		i += CHUNKSIZE;
	}
	// initialization of version node done.

	// find the place to insert the version.
	// there are 3 cases:
	// case 1: largest version number
	// case 2: somewhere in between
	// case 3: lowest version number
	
	// CASE 1:
	if(v > (vq2->v).v_no) {
		// insert in the front.
		temp_version->next = fileobj->vp;
		fileobj->vp = temp_version;
	}
	// CASE 3:
	else if(v < (vq1->v).v_no) {
		temp_version->next = vq1->next;
		vq1->next = temp_version;
	}
	// CASE 2:
	else {
		temp_version->next = vq2->next;
		vq2->next = temp_version;
	}
	return chunks_alloc;
}
Exemplo n.º 19
0
void getblock1D(struct data *d,int volindex,int DCCflag)
{
  /* Profiles are run from 2D or 3D scans but we process just the same as 1D */
  /* If it's a 2D or 3D sequence set the sequence mode to 1D */
  if (d->seqmode>IM2D) d->seqmode=IM1D;

  /* Set start and end of block */
  d->startpos=0;
  d->endpos=d->fh.ntraces;

  /* Get the data block */
  getblock(d,volindex,DCCflag);

}
Exemplo n.º 20
0
extern void *nalloc(size_t n) {
	size_t base;
	Block *ulp;
        n = alignto(n, sizeof (ALIGN_T));
	ulp = ul;
	if (ulp != NULL && n + (base = ulp->used) < ulp->size) {
		ulp->used = base + n;
		return &ulp->mem[base];
	} else {
		getblock(n); /* assert(ul->used) == 0 */
		(ulp = ul)->used = n;
		return &ulp->mem[0];
	}
}
Exemplo n.º 21
0
static int
read_disklabel(int fd, struct disklabel *label) {
	unsigned char *data;
	int i;

	for (i = 0; i < sizeof(struct disklabel) / SECTOR_SIZE; i++) {
		data = (unsigned char *) getblock(fd, i);
		if (!data)
			return 0;

		memcpy((unsigned char *) label + i * SECTOR_SIZE, data, SECTOR_SIZE);
	}

	return 1;
}
Exemplo n.º 22
0
/* goto the bottom of the file */
static void filebot( PFT_DISPC dispc )
{
   if( ( dispc->buffbot + dispc->buffoffset ) < dispc->fsize && dispc->fsize > dispc->buffsize )
   {
      dispc->buffoffset = getblock( dispc, dispc->fsize + 1 );

      buff_align( dispc );
   }

   dispc->bRefresh = HB_TRUE;
   dispc->wintop   = ( int ) dispc->buffbot - 3;
   dispc->winrow   = dispc->eline;
   dispc->wincol   = 0;

   win_align( dispc );
}
Exemplo n.º 23
0
/* go to the top of the file */
static void filetop( PFT_DISPC dispc )
{
   if( dispc->buffoffset != 0 )
   {
      dispc->buffoffset = getblock( dispc, 0 );

      buff_align( dispc );
   }

   dispc->bRefresh = HB_TRUE;
   dispc->wintop   = ( int ) dispc->buffoffset;
   dispc->winrow   = dispc->sline;
   dispc->wincol   = 0;

   win_align( dispc );
}
Exemplo n.º 24
0
int backup_file_not_exists(const char * filename, int v,const char * content, int fd) {
	const int BACKUP_ERROR = -1;
	int chunks_alloc = 0;
	// filename doesn't exist
	// perform all allocations and initializations
	file_node *temp = ALLOCATE_FILE_NODE();
	temp->next = fp[fd];		// add it to the beginning.
	fp[fd] = temp; 
		
	strcpy((temp->file_obj).name, filename);
	((temp->file_obj).vp) = ALLOCATE_VERSION_NODE();
	version_node * vnptr = ((temp->file_obj).vp);
	vnptr->next = NULL;
	(vnptr->v).v_no = v;
	(vnptr->v).off = 0;
	(vnptr->v).del_mark = 0;	
	
		
	int l = strlen(content);
	// enough space?
	if(l > free_chunks() * CHUNKSIZE) {
		fprintf(stderr, "ERROR: Not enough memory to backup.\n");
		return BACKUP_ERROR;
	}
	
	int i = 0, j = 0;
	while(i < l && (vnptr->v).off < MAX_NUM_CHUNKS) {
		(vnptr->v).contents[j] = (chunk *)getblock();
		chunks_alloc++;
		if((vnptr->v).contents[j] == NULL) { // getblock returned null
			(vnptr->v).off = j;
			fprintf(stderr, "ERROR: No free chunks.\n");
			return BACKUP_ERROR;
		}
		bcopy(content+i, (vnptr->v).contents[j], CHUNKSIZE);
		i += CHUNKSIZE; // copied a chunk. go to next chunk. number of characters copied is the chunksize
		j++;
	}
	(vnptr->v).off = j;
	// successfully backup up.
	return chunks_alloc;
}
Exemplo n.º 25
0
static int
readinfo(Fs *fs)
{
	fs->kfs.RBUFSIZE = 512;
	if(getblock(fs, 0) < 0)
		return -1;

	if(memcmp(block+256, "kfs wren device\n", 16) != 0)
		return -1;

	fs->kfs.RBUFSIZE = atoi((char*)block+256+16);
	if(!fs->kfs.RBUFSIZE || (fs->kfs.RBUFSIZE&(fs->kfs.RBUFSIZE-1)))
		return -1;

	fs->kfs.BUFSIZE = fs->kfs.RBUFSIZE - sizeof(Tag);
	fs->kfs.DIRPERBUF = fs->kfs.BUFSIZE / sizeof(Dentry);
	fs->kfs.INDPERBUF = fs->kfs.BUFSIZE / sizeof(int32_t);
	fs->kfs.INDPERBUF2 = fs->kfs.INDPERBUF * fs->kfs.INDPERBUF;

	return 1;
}
Exemplo n.º 26
0
struct buffer FAR *getFATblock(struct dpb FAR * dpbp, CLUSTER clussec)
{
  struct buffer FAR *bp = getblock(clussec, dpbp->dpb_unit);

  if (bp)
  {
    bp->b_flag &= ~(BFR_DATA | BFR_DIR);
    bp->b_flag |= BFR_FAT | BFR_VALID;
    bp->b_dpbp = dpbp;
    bp->b_copies = dpbp->dpb_fats;
    bp->b_offset = dpbp->dpb_fatsize;
#ifdef WITHFAT32
    if (ISFAT32(dpbp))
    {
      if (dpbp->dpb_xflags & FAT_NO_MIRRORING)
        bp->b_copies = 1;
    }
#endif
  }
  return bp;
}
Exemplo n.º 27
0
Arquivo: dispc.c Projeto: NaldoDj/core
static void windown( PFT_DISPC dispc )
{
   int        k;
   HB_FOFFSET i, j;

   dispc->bRefresh = HB_TRUE;
   k = dispc->winbot;

   while( dispc->buffer[ k ] != CR && k <= dispc->buffbot )
      k++;
   k += 2;

   if( k <= dispc->buffbot )
   {
      dispc->winbot = k;
      k = dispc->wintop;

      while( dispc->buffer[ k ] != CR )
         k++;
      dispc->wintop = k + 2;
   }
   else if( ( dispc->buffbot + dispc->buffoffset ) < dispc->fsize && dispc->fsize > dispc->buffsize )
   {
      i = dispc->buffoffset + dispc->wintop;
      j = i;

      if( j > dispc->fsize )
         j = dispc->fsize - dispc->buffsize;

      dispc->buffoffset = getblock( dispc, j );

      if( i < dispc->buffoffset )
         dispc->wintop = 0;
      else
         dispc->wintop = ( int ) ( i - dispc->buffoffset );

      buff_align( dispc );
      win_align( dispc );
   }
}
Exemplo n.º 28
0
Arquivo: dispc.c Projeto: NaldoDj/core
static void winup( PFT_DISPC dispc )
{
   int        k;
   HB_FOFFSET i, j;

   dispc->bRefresh = HB_TRUE;
   k = dispc->wintop - 3;

   while( dispc->buffer[ k ] != CR && k > dispc->bufftop )
      k--;

   if( k >= dispc->bufftop )
   {
      if( dispc->buffer[ k ] == CR )
         k += 2;

      dispc->wintop = k;
      k = dispc->winbot - 3;

      while( dispc->buffer[ k ] != CR )
         k--;

      dispc->winbot = k + 2;
   }
   else if( dispc->bufftop + dispc->buffoffset > 0 && dispc->fsize > dispc->buffsize )
   {
      i = dispc->buffoffset + dispc->wintop;
      j = dispc->buffoffset - ( dispc->buffsize / 2 );

      if( j < 0 )
         j = 0;

      dispc->buffoffset = getblock( dispc, j );
      dispc->wintop     = ( int ) ( i - dispc->buffoffset );

      buff_align( dispc );
      win_align( dispc );
   }
}
Exemplo n.º 29
0
int
read_dos_pt(int fd, struct slice all, struct slice *sp, int ns) {
	struct partition p;
	unsigned long offset = all.start;
	int i, n=4;
	unsigned char *bp;
	uint64_t  sector_size_mul = get_sector_size(fd)/512;

	bp = (unsigned char *)getblock(fd, offset);
	if (bp == NULL)
		return -1;

	if (bp[510] != 0x55 || bp[511] != 0xaa)
		return -1;

	for (i=0; i<4; i++) {
		memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p));
		if (is_gpt(p.sys_type))
			return 0;
		if (i < ns) {
			sp[i].start =  sector_size_mul * le32_to_cpu(p.start_sect);
			sp[i].size = sector_size_mul * le32_to_cpu(p.nr_sects);
		} else {
			fprintf(stderr,
				"dos_partition: too many slices\n");
			break;
		}
		if (is_extended(p.sys_type)) {
			/* extended partitions only get one or
			   two sectors mapped for LILO to install,
			   whichever is needed to have 1kb of space */
			if (sector_size_mul == 1)
				sp[i].size = 2;
			else sp[i].size = sector_size_mul;
			n += read_extended_partition(fd, &p, i, sp+n, ns-n);
		}
	}
	return n;
}
Exemplo n.º 30
0
int
read_solaris_pt(int fd, struct slice all, struct slice *sp, int ns) {
	struct solaris_x86_vtoc *v;
	struct solaris_x86_slice *s;
	unsigned int offset = all.start;
	int i, n;
	char *bp;

	bp = getblock(fd, offset+1);	/* 1 sector suffices */
	if (bp == NULL)
		return -1;

	v = (struct solaris_x86_vtoc *) bp;
	if(v->v_sanity != SOLARIS_X86_VTOC_SANE)
		return -1;

	if(v->v_version != 1) {
		fprintf(stderr, "Cannot handle solaris version %ld vtoc\n",
		       v->v_version);
		return 0;
	}

	for(i=0, n=0; i<SOLARIS_X86_NUMSLICE; i++) {
		s = &v->v_slice[i];

		if (s->s_size == 0)
			continue;
		if (n < ns) {
			sp[n].start = offset + s->s_start;
			sp[n].size = s->s_size;
			n++;
		} else {
			fprintf(stderr,
				"solaris_x86_partition: too many slices\n");
			break;
		}
	}
	return n;
}