What Are The Differences Between Character Devices And Block Devices?

Hi,

I am trying to understand the difference between char devices and block devices.
I understand the basic, which is that char devices input/output data one character at a time, whereas block device input/output data block by block. But for char device driver, most of the time we are able to read/write an array of data using the read/write system call. This "array of data" sounds like a block of data to me, except that it's not fixed in size as for block devices. With this thinking, can I say that I can effectively achieve block read/write with a char device driver?
And what are the other differences?

Thank you all,
Wei


Similar Content



Calculating File Sizes From Indoors And Blocks

Hello I have this problem, but I just ant to know if I am on right track:

Quote:
i_addr is an array of 15 pointers which hold the addresses of a direct data blocks and single indirect, double indirect or triple indirect block.
The first 12 elements of the array refer to addresses of blocks on the disk, which actually contain the files data. When a file requires more than 12 direct blocks, the file system must use disk blocks to hold the addresses of the remaining data blocks needed. These are called indirect blocks. In this particular file system the inode holds the addresses of three indirect data blocks in addition to the 12 direct data blocks discussed. There are single, double and triple indirect data blocks. There is one of each. (in total there are 15 references in the inode). A single indirect block (referenced by element 12 of the inode array) holds the addresses of 2048 disk blocks.
If the file consumes more blocks then can be referenced by a single indirect block then the file system uses a double indirect block. (referenced by element 13 of the inode array). A double indirect block can hold the addresses of 2048 indirect blocks.
If the file consumes more blocks then can be reference by direct, single and double indirect data blocks then the last element of the inode array is used to hold a triple indirect block which effectively references a number of double and single indirect block (ultimately the data).
The Questions I attempted

Quote:
Given the block size of the file system is 8192 bytes answer the following questions:
1. Whatisthemaximumpossiblefilesizethatcanberepresentedviadirectdatablocks?
2. What is the file size if each element of an indirect data blocks references a data block and all direct blocks are used?
3. Whatistherangeoffilesizesthatwouldrequiretheuseofadoubleindirectblock?
4. Whatisthemaximumfilesizeinthisfilesystem?
5. How much overhead is incurred by the file system to store a file of 8437760 bytes.
Overhead is size in bytes of the number of blocks needed to reference this object i.e. indirect blocks etc.
My answers:

Quote:
Answer 1) we know 1 block=8192 bytes, and there are 12 direct data blocks so the max. size is (12*8192) bytes = 98304 bytes.

Answer 2) file size will be = file size in direct data blocks + (2048*8192) = approximately 17 MB

Answer 3) The starting range is > 17 MB. The maximum range will be (2048*8192) + (2048*8192) =

Answer 4) Max size of file in this file system is = 98304+(2048*8192)+(2048*8192)*2+(2048*8192)*3=84.33 MB

Answer 5) We know first 12 blocks have 98304 bytes. The single indirect block has 2048*8192 bytes. Given 8437760 bytes of file size we have an overhead of (2048*8192)/(8437760-98304)= 2 bytes
Please correct me and why am I wrong.

Thanks

Block Device Drivers

I am new to drivers development under linux kernel. After starting with the simple examples from the book Linux Device Drivers v3, I realised that the block driver API has been totally changed since the kernel 2.6.31 or maybe later versions, and I couldn't find any documentation about the new API and how to use it. There are just some few comments in the source code.

After struggling for one month I almost had something working but few parts are missing or I misunderstood something.

Here is the situation :

After fetching the request with blk_fetch_request(q), I use the macro __rq_for_each_bio for handling the full request
To transfer the segments one by one I use the macro bio_for_each_segment(bvec, bio, i) that loops over all the segments in a bio

My question is :

I need to do some DMA from/to my device (the dma engine is within the device), that's why I need some address that I could use it to DMA from/to
Which buffer should I use ? for the moment I use the buffer returned by char *buffer=bio_data(bio), Does "buffer" corresponds to the physical buffer that I can use for DMA
How to end the request in this case ? using __blk_end_request_cur(req, 0) ? or using __blk_end_request(req, 0, bytes) ?

If you don't have an answer to any of these questions, where can I find a useful documentation for the new API of the block device drivers.

Can No Longer Mount Data Dvds

For whatever reason, when I try to mount a data DVD I get the following message:

Unable to mount [disk name]
Error mounting: mount exited with exit code 1: helper failed with:
mount: mount point /media/cdrom does not exist

Yet, if I put a DVD video in I can play on any of my video apps, yet I also can't mount those in a file browser. I have no idea what has caused this. I haven't backed up data to disks in a long time, I only did so today because I'm running low on space in one of my drives.

I was told elsewhere that I needed to alter a file: /etc/udev/rules.d/70-persistent-cd.rules

But I have no idea how to do this, and what I found there does not look like what was shown. This is what my file looks like:

Code:
# This file maintains persistent names for CD/DVD reader and writer devices.
# See udev(7) for syntax.
#
# Entries are automatically added by the 75-cd-aliases-generator.rules
# file; however you are also free to add your own entries provided you
# add the ENV{GENERATED}=1 flag to your own rules as well.
# TSSTcorp_CDDVDW_SH-S223C (pci-0000:00:1f.2-scsi-1:0:1:0)
SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.2-scsi-1:0:1:0", SYMLINK+="cdrom", ENV{GENERATED}="1"
SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.2-scsi-1:0:1:0", SYMLINK+="cdrw", ENV{GENERATED}="1"
SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.2-scsi-1:0:1:0", SYMLINK+="dvd", ENV{GENERATED}="1"
SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.2-scsi-1:0:1:0", SYMLINK+="dvdrw", ENV{GENERATED}="1"

Any suggestions would be appreciated.

Get RAID1 And LVM Back After Re Installating The OS

Hi All,
I had installed Cent OS 6.6 on sda. The RAID1 and LVM setup was on sdb and sdc. To practice well on recovering RAID and LVM after the OS reinstallation, I just reinstalled the OS. During first re installation of OS, I had selected all the mount points including RAID/LVM partitions as same as how those where mounted before the reinstallation, but the format was selected to only /, /others, /var. And after booting /dev/md0 and LVM partitions were set to active automatically and everything was mounted properly. Also there was no any data loss in the RAID/LVM partitions. So I could made sure that everything will be perfect if we carefully select the mount points during OS reinstallation by making sure the formating partitions.

Now I thouht of reinstalling OS once again but this time didn't select mount points for RAID/LVM partitions during OS reinstallation, thought for manual setup after the installation. So just selected /, /others, /var partitions to format. When it booted, I ran "cat /proc/mdstat" but it was taken /dev/md127(read only) instead of /dev/md0.
Code:
# cat /proc/mdstat 
Personalities : [raid1] 
md127 : active (auto-read-only) raid1 sdc[1] sdb[0]
      52396032 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

So now I just wanted to stop and restart this RAID array as /dev/md0. But I am not able to stop as it is giving following error.
Code:
# mdadm --stop --force /dev/md127
mdadm: Cannot get exclusive access to /dev/md127:Perhaps a running process, mounted filesystem or active volume group?

I made sure that no one RAID/LVM partitions are mounted.
Code:
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        15G  3.5G   11G  26% /
tmpfs           376M     0  376M   0% /dev/shm
/dev/sda2       4.7G  9.8M  4.5G   1% /others
/dev/sda3       2.9G  133M  2.6G   5% /var

But LVM is active
Code:
# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/md127
  VG Name               data
  PV Size               49.97 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              12791
  Free PE               5111
  Allocated PE          7680
  PV UUID               IJ2br8-SWHW-cf1d-89Fr-EEw9-IJME-1BpfSj
   
# vgdisplay 
  --- Volume group ---
  VG Name               data
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  19
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               49.96 GiB
  PE Size               4.00 MiB
  Total PE              12791
  Alloc PE / Size       7680 / 30.00 GiB
  Free  PE / Size       5111 / 19.96 GiB
  VG UUID               982ay8-ljWY-kiPB-JY7F-pIu2-87uN-iplPEQ
   
# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/data/home
  LV Name                home
  VG Name                data
  LV UUID                OAQp25-Q1TH-rekd-b3n2-mOkC-Zgyt-3fX2If
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/data/backup
  LV Name                backup
  VG Name                data
  LV UUID                Uq6rhX-AvPN-GaNe-zevB-k3iB-Uz0m-TssjCg
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                20.00 GiB
  Current LE             5120
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

As LVM is active on /dev/md127 it is not allowing to stop /dev/md127 raid array. So as I am fresher in RAID/LVM, expecting your kind help to make LVM inactive without any data loss and restart the RAID array as /dev/md0 and then re activate the LVM setup.
Expecting your kind reply, Thanks.

Diffing The Line Numbers

hi guys

i am trying to find the "size" of a "block" of data in LARGE data files, the example below test_data.txt is very simplified. by "size" i mean the difference in line numbers of a block, and the "size" will be constant throughout the file so

1234 6.600000 4321
1234 8.500000 4321
1234 1.800000 4321
1234 2.300000 4321
1234 8.500000 4321
1234 2.800000 4321

if i define a block as whenever i find 8.500000 in the second column, then in the example the the block size would be 3 becasue 8.500000 occurs on the 5th line and on the 2nd. right now i am using

Code:
 grep -n "8.500000" test_data.txt | cut -f1 -d:

and/or

Code:
 awk '/8.500000/ {print FNR}' test_data.txt

obviously i don't remeber how to tag text as code?

btw, the grep command is much much faster

both of these commands give an entire list (long list of number for files greater than a gig) of line numbers which i then have to subtract one from another to come up with 3 in the example. not that i'm opposed to doing math, but i would think awk or grep should be able to do this for me

ideas?

tabby

ACPI Error At The End Of Boot; How To Delete That Error?

Hello,
know anybody how to delete that error at the end of dmesg?
If was not here before I installed the fglrx instead of the radeon driver.

Dmesg:
Code:
...
[    1.596047] Switching to clocksource tsc
[    1.631859] EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null)
[    3.546830] udevd[345]: starting version 175
[    4.065641] microcode: CPU0 sig=0xf43, pf=0x10, revision=0x4
[    4.176993] input: Power Button as /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2
[    4.177008] ACPI: Power Button [PBTN]
[    4.177320] input: Power Button as /devices/LNXSYSTM:00/LNXPWRBN:00/input/input3
[    4.177330] ACPI: Power Button [PWRF]
[    4.613393] Linux agpgart interface v0.103
[    4.626342] microcode: CPU1 sig=0xf43, pf=0x10, revision=0x4
[    4.631009] microcode: Microcode Update Driver: v2.00 <tigran@aivazian.fsnet.co.uk>, Peter Oruba
[    4.638056] intel_rng: Firmware space is locked read-only. If you can't or
[    4.638056] intel_rng: don't want to disable this in firmware setup, and if
[    4.638056] intel_rng: you are certain that your system has a functional
[    4.638056] intel_rng: RNG, try using the 'no_fwh_detect' option.
[    4.681411] pci_hotplug: PCI Hot Plug PCI Core version: 0.5
[    4.690751] input: PC Speaker as /devices/platform/pcspkr/input/input4
[    4.696106] shpchp: Standard Hot Plug PCI Controller Driver version: 0.4
[    4.709723] wmi: Mapper loaded
[    5.049796] iTCO_vendor_support: vendor-support=0
[    5.061788] iTCO_wdt: Intel TCO WatchDog Timer Driver v1.10
[    5.061833] iTCO_wdt: Found a ICH6 or ICH6R TCO device (Version=2, TCOBASE=0xf860)
[    5.062003] iTCO_wdt: initialized. heartbeat=30 sec (nowayout=0)
[    5.086318] snd_intel8x0 0000:00:1e.2: setting latency timer to 64
[    5.508031] intel8x0_measure_ac97_clock: measured 54792 usecs (2640 samples)
[    5.508037] intel8x0: clocking to 48000
[    6.353849] fglrx: module license 'Proprietary. (C) 2002 - ATI Technologies, Starnberg, GERMANY' taints kernel.
[    6.353855] Disabling lock debugging due to kernel taint
[    6.387515] <6>[fglrx] Maximum main memory to use for locked dma buffers: 2894 MBytes.
[    6.387775] <6>[fglrx]   vendor: 1002 device: 68f9 revision: 0 count: 1
[    6.388429] <6>[fglrx] ioport: bar 4, base 0x1000, size: 0x100
[    6.388842] <6>[fglrx] Kernel PAT support is enabled
[    6.388877] <6>[fglrx] module loaded - fglrx 14.50.2 [Nov 20 2014] with 1 minors
[    7.410180] EXT4-fs (sda2): re-mounted. Opts: (null)
[    7.710355] EXT4-fs (sda2): re-mounted. Opts: (null)
[    9.227365] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
[   10.685717] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[   10.789404] RPC: Registered named UNIX socket transport module.
[   10.789411] RPC: Registered udp transport module.
[   10.789415] RPC: Registered tcp transport module.
[   10.789419] RPC: Registered tcp NFSv4.1 backchannel transport module.
[   10.802294] NET: Registered protocol family 17
[   10.832966] FS-Cache: Loaded
[   10.886960] FS-Cache: Netfs 'nfs' registered for caching
[   10.951772] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[   12.242071] tg3 0000:40:00.0 eth0: Link is up at 100 Mbps, full duplex
[   12.242078] tg3 0000:40:00.0 eth0: Flow control is on for TX and on for RX
[   12.242097] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   12.919842] lp: driver loaded but no devices found
[   13.211684] ppdev: user-space parallel port driver
[   20.378549] fglrx_pci 0000:06:00.0: irq 42 for MSI/MSI-X
[   20.380599] <6>[fglrx] Firegl kernel thread PID: 2736
[   20.380738] <6>[fglrx] Firegl kernel thread PID: 2737
[   20.380875] <6>[fglrx] Firegl kernel thread PID: 2738
[   20.381103] <6>[fglrx] IRQ 42 Enabled
[   20.406460] <6>[fglrx] Reserved FB block: Shared offset:0, size:1000000 
[   20.406465] <6>[fglrx] Reserved FB block: Unshared offset:f8ff000, size:3000 
[   20.406468] <6>[fglrx] Reserved FB block: Unshared offset:f902000, size:3fe000 
[   20.406472] <6>[fglrx] Reserved FB block: Unshared offset:1fff3000, size:d000 
[   20.479905] ACPI Error: [ATPX] Evaluation of object type [Mutex] is not supported (20120913/nseval-201)

Double TtyACM Node Device From Sony Ericsson C510

Hi.


I'm using smstools3 and Sony Ericsson Phones to send SMS. My system did work well with 4 phones, now I want to connect 20.
The issue is that each phone generates two ttyACMXX devices using cdc_acm driver, and for limitations the driver supports up to 32 ACM devices

Code:
Aug 31 09:51:19 smsgw kernel: cdc_acm 2-2:1.1: ttyACM31: USB ACM device
Aug 31 09:51:19 smsgw kernel: cdc_acm 2-2:1.3: ttyACM32: USB ACM device
Aug 31 09:51:19 smsgw kernel: usbco  registered new driver cdc_acm
Aug 31 09:51:19 smsgw kernel: drivers/usb/class/cdc-acm.c: v0.25:USB Abstract Control Model driver for USB modems and ISDN adapters
Aug 31 09:51:19 smsgw kernel: usbco  registered new driver cdc_ether
Aug 31 09:51:19 smsgw kernel: usb 2-2: unsupported MDLM descriptors
Aug 31 09:52:01 smsgw kernel: cdc_acm 3-1:1.0: no more free acm devices

From the ttyACM devices created by the driver I only use the first one..

So I was wondering if it is possible to remove a ttyACM from /sys/class/tty/ttyACM1

I tried unlink /dev/ttyACM1, but it persist as a device on /sys/class/tty/

The devices are removed if I disconnect the phone, So I think would be possible also that the driver only create one ttyACM device..

Please guide me...

Thanks in advance.

Extract Info And Find/count Strings From Blocks Inside Text File

Hello

I have a text file which has blocks like
Code:
dir1/dir2/dir3/name_run_number1:
line1_run_number1_part1
line2_run_number1_part2
line3_run_number1_part3...

Each block is separated with a blank line and there is the ":" in the "header" of each one while each block carries the same "number1" after "run_" suffix
What I want to do is for each block, extract the "number1" as shown in the first line and then for the lines below count from 1-20 and give a message if a "partX" line is missing. Any bash or python would be fine

Thanks

Degraded RAID 1 Mdadm

I have a degraded software RAID 1 array. md0 is in a state of clean, degraded while md1 is mounted in read-only and clean. I'm not sure how to go about fixing this. Any ideas?

cat /proc/mdstat
Code:
Personalities : [raid1] 
md1 : active (auto-read-only) raid1 sdb2[1] sda2[0]
      3909620 blocks super 1.2 [2/2] [UU]
      
md0 : active raid1 sda1[0]
      972849016 blocks super 1.2 [2/1] [U_]
      
unused devices: <none>

mdadm -D /dev/md0
Code:
/dev/md0:
        Version : 1.2
  Creation Time : Tue Jun 21 21:31:58 2011
     Raid Level : raid1
     Array Size : 972849016 (927.78 GiB 996.20 GB)
  Used Dev Size : 972849016 (927.78 GiB 996.20 GB)
   Raid Devices : 2
  Total Devices : 1
    Persistence : Superblock is persistent

    Update Time : Tue Jun  2 02:21:12 2015
          State : clean, degraded 
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

           Name : 
           UUID : 
         Events : 3678064

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       2       0        0        2      removed

mdadm -D /dev/md1
Code:
/dev/md1:
        Version : 1.2
  Creation Time : Tue Jun 21 21:32:09 2011
     Raid Level : raid1
     Array Size : 3909620 (3.73 GiB 4.00 GB)
  Used Dev Size : 3909620 (3.73 GiB 4.00 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Sat May 16 15:17:56 2015
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : 
           UUID : 
         Events : 116

    Number   Major   Minor   RaidDevice State
       0       8        2        0      active sync   /dev/sda2
       1       8       18        1      active sync   /dev/sdb2

Replace Lines Matching A Pattern

I have several files in that I need to add the text "N CHAR(1)," How can I accomplish this in linux without having to do it manually. Thanks

HAVE

nullcols
(A "to_number(:A,'9')"
,B CHAR(50)
)

WANT

nullcols
(N CHAR(1)
,A "to_number(:A,'9')"
,B CHAR(50)
)