Exemplo n.º 1
0
long
writetransfers(char *transferfile, long total_patches)
{
	int		handle;
	long	writtenpatches = 0, writtentransfers = 0, totalbytes = 0;
	int		spacerequired = sizeof(long) + total_patches * sizeof(long) + total_transfer * sizeof(transfer_t);

	if ( spacerequired - getfilesize(transferfile) < getfreespace(transferfile) )
	{
		if ( (handle = _open( transferfile, _O_WRONLY | _O_BINARY | _O_CREAT | _O_TRUNC, _S_IREAD | _S_IWRITE )) != -1 )
		{
			unsigned			byteswritten;
			qprintf("Writing [%s] with new saved qrad data", transferfile );
			
			if ( (byteswritten = _write(handle, &total_patches, sizeof(total_patches))) == sizeof(total_patches) )
			{
				patch_t			*patch;

				totalbytes += byteswritten;

				for( patch = patches; total_patches-- > 0; patch++ )
				{
					if ( (byteswritten = _write(handle, &patch->numtransfers, sizeof(patch->numtransfers)))
					  == sizeof(patch->numtransfers) )
					{
						totalbytes += byteswritten;

						if ( patch->numtransfers && 
							 (byteswritten = _write(handle, patch->transfers, patch->numtransfers*sizeof(transfer_t)))
						      == patch->numtransfers*sizeof(transfer_t) )
						{
							totalbytes += byteswritten;
							writtentransfers += patch->numtransfers;
						}
						writtenpatches++;
					}
					else
					{
						break;
					}
				}
			}

			qprintf("(%d)\n", totalbytes );
			
			_close( handle );
		}
	}
	else
		printf("Insufficient disk space(%ld) for 'QRAD save file'[%s]!\n",
				spacerequired - getfilesize(transferfile), transferfile );


	return writtenpatches;
}
Exemplo n.º 2
0
int uquota_getvolspace(const AFPObj *obj, struct vol *vol, VolSpace *bfree, VolSpace *btotal, const u_int32_t bsize)
{
	int uretq, gretq;
	VolSpace ubfree, ubtotal;
	VolSpace gbfree, gbtotal;

	uretq = getfreespace(obj, vol, &ubfree, &ubtotal,
			     uuid, QUOTADICT_CLASS_USER);
	LOG(log_info, logtype_afpd, "getfsquota(%s): %d %d",
	    vol->v_path, (int)ubfree, (int)ubtotal);
	if (obj->ngroups >= 1) {
		gretq = getfreespace(vol, &ubfree, &ubtotal,
		    obj->groups[0], QUOTADICT_CLASS_GROUP);
	} else
		gretq = -1;
	if (uretq < 1 && gretq < 1) { /* no quota for this fs */
		return AFPERR_PARAM;
	}
	if (uretq < 1) {
		/* use group quotas */
		*bfree = gbfree;
		*btotal = gbtotal;
	} else if (gretq < 1) {
		/* use user quotas */
		*bfree = ubfree;
		*btotal = ubtotal;
	} else {
		/* return smallest remaining space of user and group */
		if (ubfree < gbfree) {
			*bfree = ubfree;
			*btotal = ubtotal;
		} else {
			*bfree = gbfree;
			*btotal = gbtotal;
		}
	}
	return AFP_OK;

}
Exemplo n.º 3
0
t_malloc		extend_block(t_malloc prev, size_t size)
{
  t_malloc		tmp;

  if ((SIZE + size) <= getfreespace() && sbrk(0) > getbrk())
    tmp = sbrk(0) - getfreespace();
  else
    {
      tmp = sbrk(0);
      if ((void*)-1 == sbrk(getpagesize()))
	return (NULL);
    }
  tmp = sbrk(0);
  if ((void*)-1 == sbrk(SIZE + size))
    return (NULL);
  tmp->size = size;
  tmp->next = NULL;
  tmp->prev = prev;
  tmp->ptr = tmp->data;
  if (prev)
    prev->next = tmp;
  tmp->is_free = 0;
  return (tmp);
}