Exemple #1
0
int main(int argc, char *argv[])
{
  int sd;
  struct hostent *h;
  struct sockaddr_in sa;
  FILE *sock = 0;
  char *line = 0;
  size_t linelen = 0;
  unsigned int num, sent = 0;

  if (argc < 6 || argc > 7) {
    usage(argv[0]);
    exit(1);
  } else if (argc == 7) {
    if (!parseHostPort(argv[6]) || !parseParms(argv+1)) {
      usage(argv[0]);
      exit(1);
    }
  }

  if ( !(h = gethostbyname(host)) ) {
    herror("gethostbyname");
    exit(1);
  }
  
  if ( (sd = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) {
    perror("socket");
    exit(1);
  }

  sa.sin_family = AF_INET;
  sa.sin_port = htons(port);
  memcpy(&sa.sin_addr, h->h_addr_list[0], sizeof(struct in_addr));
  
  fprintf(stderr, "Connecting to %s port %hu\n", inet_ntoa(sa.sin_addr), port);

  if ( connect(sd, (struct sockaddr *)&sa, sizeof(sa)) ) {
    perror("connect");
    exit(1);
  }  
  
  if ( !(sock = fdopen(sd, "r+")) ) {
    perror("fdopen");
    exit(1);
  }
  
  fprintf(stderr, "Connected sending file %s size: %d as id: %d\n", filename, bytes, id);

  
  if ( fprintf(sock, "SET SOUND %u %u %u %u %u\n", id, bytes, bits, chans, rate) <= 0 ) {
    fprintf(stderr, "Error writing to socket\n");
    exit(1);
  }
  
  /* Grab the 'READY' */
  if ( getline(&line, &linelen, sock) == -1 ) {
    perror("getline");
    exit(1);
  }
  
  while (!feof(f)) {
    char buf[4096];
    num = fread(buf, 1, sizeof(buf), f);
    if ( fwrite(buf, 1, num, sock) != num ) {
      perror("fwrite");
      exit(1);
    }
    sent += num;
  }

  if ( getline(&line, &linelen, sock) == -1 ) {
    fprintf(stderr, "Did not receive any response, exiting.\n");
    exit(1);
  } else if (strcmp(line, "OK\n")) {
    fprintf(stderr, "Sound rejected.\n");
    exit(1);
  }

  fprintf(stderr, "%u bytes sent, OK.\n", sent);
  fprintf(sock, "EXIT\n");
  fflush(sock);
  free(line);
  shutdown(sd, SHUT_RDWR);
  fclose(sock);
  return 0;
}
Exemple #2
0
/******************************************************************
 * NAME: 	clrbblks
 *
 * FUNCTION: 	Main routine of clrbblks utility which has the goal of 
 *		isolating bad blocks on the device and so that the LVM
 *		can drop them from its Bad Block List.
 *
 * PARAMETERS:
 *		input: the file system on which to operate
 *
 *
 * INVOCATION: 
 * 		clrbblks  {device_name}
 *
 *  		where: 
 *		    device_name - device under clear bad blocks list.
 *
 * NOTES:
 *
 * RETURNS:
 *      success: 0
 *      failure: something else
 */
int32 clrbblks( int32  argc,  char  **argv, HFILE DevIO, char *VolLabel )     //PS24072004
{
    int32		rc;
    int		finished = 0;
    int32		pList;
    ULONG 	pListLen = 0;
    clrbblks_t	pData;
    ULONG	pDataLen = 0;

	/*
	 * first things first
	 */
    agg_recptr = &(agg_record);
    init_agg_record_cb();		/* need this before calling preamble() */
	
	/* 
	 * for what logical volume? 
	 */
//PS24072004  Begin
    if( !DevIO )
      {
      rc = parseParms(argc, argv);
      if( rc ) goto out;
      }
    else
      {
      LVName[0] = VolLabel[0];
      if( LVName[0] >= 'a' && LVName[0] <= 'z')
         LVNumber = LVName[0] - 'a';
      else
        if( LVName[0] >= 'A' && LVName[0] <= 'Z')
           LVNumber = LVName[0] - 'A';
        else
           return -1;
      }
//PS24072004  End
mainidea:
	/* 
	 * init clrbblks 
	 */
    rc = preamble(DevIO);
    if( rc ) 	goto out;
    
    if(!DevIO) LVNumber=lvMount->LVNumber;	//PS24072004

    cbblfsck_recptr = (struct fsckcbbl_record *) cbblfsck_area_ptr;
    init_cbblfsck_record();
	
	/*
	 * get the LVM bad block lists for this logical volume
	 * 
	 */
    rc = get_LVM_BadBlockLists_cb(); 
	
    if( agg_recptr->bdblk_baltree.right == NULL ) { 
	finished = -1;
	}
	
	/*
	 * Process the current list 
	 */
    while( (!finished) && (rc == 0) ) {
		/*
		 * create a sequential list of the nodes in the
		 * balanced tree.
		 */
	rc = seqlist_create();
	if( rc == 0 ) {  /* we have a tree and a sequential list */
		/*
		 * sync fs meta-data 
		 */
	    pDataLen = sizeof(clrbblks_t);
	    pData.flag = CLRBBLKS_SYNC;
//PS24072004	    pData.dev = lvMount->LVNumber;
	    pData.dev = LVNumber;    

	    rc = fscntl(JFSCTL_CLRBBLKS,
			(void *)&pList, &pListLen,
			(void *)&pData, &pDataLen
			);
	    if( rc != 0 )  {
#ifdef _JFS_DEBUG
	printf("main: sync failure: rc=%d\n", rc);
#endif
		rc = CBBL_FSCNTL_1 - rc;
		}
	    }  /* end else we have a tree and a sequential list */

	if( (!finished) && (rc == 0) ) {  /* we have synched the file system */
		/*
		 * scan the JFS Bad Block inode to see if anything on
		 * the current list is already allocated to it.  
	 	 */
#ifdef _JFS_DEBUG
	printf("Are any already on the Bad Block Inode?\n");
#endif
	    rc = process_BadBlockInode();
	    }  /* end we have synched the file system */
	
	if( (agg_recptr->bdblk_baltree.seq_list != NULL) && (rc == 0) ) { /*
				* there are still bad blocks to process 
				*/
		/*
		 * scan the list for bad blocks which are currently
		 * not allocated to any inode.
		 */
#ifdef _JFS_DEBUG
	printf("Are any are currently free?\n");
#endif
	    rc = scan_for_free_blocks(); 
	    }  /* end there are still bad blocks to process */
	
	if( (agg_recptr->bdblk_baltree.seq_list != NULL) && (rc == 0) ) { /* 
				* there are still bad blocks to process 
				*/
		/*
		 * scan the JFS fileset inodes for owners of data
		 * residing in bad blocks.  If any are found, try to
		 * relocate the data and allocate the bad blocks to 
		 * the JFS Bad Block inode.
	 	 */
#ifdef _JFS_DEBUG
	printf("Are any owned by fileset inodes?\n");
#endif
	    rc = process_FilesetInodes();
	    }  /* end there are still bad blocks to process */
	
	if( rc == 0 ) { /* clear resolved list and anything still on seq list */
		/*
		 * Any blocks still on the sequential list must 
		 * contain data which we can't relocate.  Drop them
		 * from the list and forget them.
	 	 */
	    rc = baltree_purge( );
	    }  /* end clear resolved list and anything still on seq list */
	
		/*
		 * do we need to go around again?
		 */
	if( rc == 0 ) {  /* still in business */
		/*
		 * if the file system has been extended, get the LVM bad
		 * block list for each new device partition added, and
		 * add entries to the balanced tree as appropriate.
		 */
	    rc = get_LVM_BadBlockLists_cb(); 
	    if( rc == 0 ) {  /* nothing fatal */
		    /*
		     * if any blocks made it to the retry list, put them
		     * back into the balanced tree.
		     */
		rc = retrylist_purge();
		}  /* end else nothing fatal */
	    }  /* end still in business */
    	
	if( agg_recptr->bdblk_baltree.right == NULL ) { 
	    finished = -1;
	    }
	}  /* end while !finished */

	/* 
	 * finish the communication area then close FS 
	 */
    cbblfsck_recptr->cbbl_retcode = rc;
    complete_cbblfsck_record();
    closeFS();

	/* 
	 * release buffers
	 */
    workspace_release_cb();

out:
    return rc;
}					/* end clrbblks() */