Help: character device vs. block device

Help: character device vs. block device

Post by Fang-Kuo » Sat, 30 Apr 1994 22:53:19



Hi, All,

There are TWO devices in our sun4_on_sparc environment.

--------------------------------------------------------------------
 crw-r-----   1 frank     operator  17,  31 Apr 29 09:02 /dev/rsd3h
 brw-r-----   1 frank     operator   7,  31 Apr 29 09:03 /dev/sd3h
--------------------------------------------------------------------

So, I SUPPOSE that

 - "/dev/rsd3h" is character device which can be read/write in any
   length of data.

 - "/dev/sd3h" is block device which can be read/write only in k*512
   length of data (where k >= 1, k is an integer).

However, the following code shows me something funny.

--------------------------------------------------------------------
  #include <stdio.h>
  #include <fcntl.h>
  #include <sys/types.h>
  #include <unistd.h>
  #include <errno.h>

  fd = open(device, O_RDWR | O_SYNC);

  for (i = 0; i < size; i++) space[i] = '.';

  lseek(fd, 0L, 0);
  rc = write(fd, space, size);
  if (rc == -1) perror(" write ");

  close(fd);
--------------------------------------------------------------------

If device is "/dev/rsd3h" and size is 100, then rc is -1 and error
message is "write : Invalid argument". But, write() is okay if size
is 512.

If device is "/dev/sd3h" and size is 100, then write() is okay.

Did I do something wrong? Help me! Please ...

Thanks in advance.

Frank