Example #1
0
static int fn(void *d)
{
    struct l4fdx_client *client = d;
    int err;

    err = sys_setregid(client->gid, client->gid);
    err = sys_setreuid(client->uid, client->uid);
    err = sys_setsid();

    if (client->capname)
        snprintf(current->comm, sizeof(current->comm),
                 "l4xfdx-%s", client->capname);
    else
        snprintf(current->comm, sizeof(current->comm),
                 "l4xfdx-%lx", client->cap >> L4_CAP_SHIFT);
    current->comm[sizeof(current->comm) - 1] = 0;

    set_user_nice(current, -20);

    while (!should_stop || !list_empty(&client->req_list)) {
        struct internal_request *r;

        wait_event_interruptible(client->event,
                                 !list_empty(&client->req_list)
                                 || should_stop);

        r = pop_request(client->srv_obj);

        switch (r->type) {
        case L4FS_REQ_OPEN:
            fn_open(client->srv_obj, r);
            break;
        case L4FS_REQ_READ:
            fn_read(client->srv_obj, r);
            break;
        case L4FS_REQ_WRITE:
            fn_write(client->srv_obj, r);
            break;
        case L4FS_REQ_CLOSE:
            fn_close(client->srv_obj, r);
            break;
        case L4FS_REQ_FSTAT64:
            fn_fstat64(client->srv_obj, r);
            break;
        default:
            pr_err("l4fdx: Invalid type=%d\n", r->type);
            break;
        }
    }

    return 0;
}
Example #2
0
/*
** fr_close
**
** Close a previously opened file.
**
** INPUT : *filehandle - pointer to the file descriptor
** RETURN: F_NOERR on success, other if error
*/
unsigned char fr_close ( F_FILE * filehandle )
{
  unsigned char  rc;

  if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS )
  {
    rc = fn_close( filehandle );
    xSemaphoreGive( fs_lock_semaphore );
  }
  else
  {
    rc = F_ERR_OS;
  }

  return rc;
}
Example #3
0
/* Tries to detect whether FILE is a given type of file, by opening the file
   and passing it to DETECT, and returns a detect_result. */
static enum detect_result
try_detect (const char *file_name, bool (*detect) (FILE *))
{
  FILE *file;
  bool is_type;

  file = fn_open (file_name, "rb");
  if (file == NULL)
    {
      msg (ME, _("An error occurred while opening `%s': %s."),
           file_name, strerror (errno));
      return ANY_ERROR;
    }

  is_type = detect (file);

  fn_close (file_name, file);

  return is_type ? ANY_YES : ANY_NO;
}
Example #4
0
/****************************************************************************
 *
 * fn_truncate
 *
 * Open a file and set end of file
 *
 * INPUT:	filename - name of the file
 *		filesize - required new size
 * RETURN:	NULL on error, otherwise file pointer
 *
 ***************************************************************************/
F_FILE * fn_truncate ( const char * filename, long filesize )
{
  F_FILE       * f = fn_open( filename, "r+" );
  unsigned char  rc;

  if ( f != NULL )
  {
    rc = _f_fseek( (long)gl_file.filesize );
    if ( rc == F_NO_ERROR )
    {
      rc = _f_seteof( f, filesize );
    }

    if ( rc )
    {
      fn_close( f );
      f = NULL;
    }
  }

  return f;
} /* fn_truncate */