From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 26 13:04:28 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6195210656D1 for ; Mon, 26 Jan 2009 13:04:28 +0000 (UTC) (envelope-from lvj@nietykalni.org) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.176]) by mx1.freebsd.org (Postfix) with ESMTP id 3FC238FC13 for ; Mon, 26 Jan 2009 13:04:28 +0000 (UTC) (envelope-from lvj@nietykalni.org) Received: by wa-out-1112.google.com with SMTP id k34so501776wah.27 for ; Mon, 26 Jan 2009 05:04:28 -0800 (PST) MIME-Version: 1.0 Received: by 10.114.56.1 with SMTP id e1mr2565546waa.19.1232975067834; Mon, 26 Jan 2009 05:04:27 -0800 (PST) In-Reply-To: <497D9116.1040408@gmx.de> References: <3930e0780901260135j1428e77fmfe7392770fcd31fc@mail.gmail.com> <200901261109.43376.hselasky@c2i.net> <3930e0780901260224ye4acbabx7a629ec8da195138@mail.gmail.com> <497D9116.1040408@gmx.de> Date: Mon, 26 Jan 2009 14:04:27 +0100 Message-ID: <3930e0780901260504m44f43958m82f2ba8902558906@mail.gmail.com> From: Lukasz Jaroszewski To: Christoph Mallon Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org, Hans Petter Selasky Subject: Re: write(2) to /dev/ad4 = EINVAL X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jan 2009 13:04:29 -0000 2009/1/26 Christoph Mallon : > Lukasz Jaroszewski schrieb: >> >> 2009/1/26 Hans Petter Selasky : >>> >>> On Monday 26 January 2009, Lukasz Jaroszewski wrote: >>>> >>>> Hi, >>>> after opening /dev/ad4 with success for O_RDWR, I am getting [EINVAL] >>>> from write(2), which according to man 2 write, means >>>> `` [EINVAL] The pointer associated with d was >>>> negative.'', as you can see below it is not true, I have tried >>>> different block sizes, with same result. >>>> >>>> How can I write one byte to /dev/adN ? >>> >>> Hi, >>> >>> You cannot write one byte to /dev/adN, I think. Harddisks are block >>> based. >>> Please see: >>> >>> diskinfo -v ad4 >>> >>> And especially the "sector size". When you seek and transfer data the >>> offset >>> and length must be a factor of the "sector size" or "block size". See >>> also >>> LBA, logical block address. >> >> >> Yes, I have tried with bs=512 and multiplies, no luck. >> >> root@~(0) diskinfo -v ad4 >> ad4 >> 512 # sectorsize >> 2029805568 # mediasize in bytes (1.9G) >> 3964464 # mediasize in sectors >> 3933 # Cylinders according to firmware. >> 16 # Heads according to firmware. >> 63 # Sectors according to firmware. >> ad:CFx20CARDx200000190C # Disk ident. > > It would be helpful, if you showed the actual code, instead of letting us > guess what you are doing. Ok, I solved that, I were trying to dd with bs correctly set, tho if=./s wasn't big enough plus I had code like below, where I didn't check write for errors, just called perror, which gave me wrong errno. So to change one byte, I need to read it, change it, and write it in 512 chunks? or play with kernel and add smth like ``write_byte'' to ata? I am sorry for bothering with my silly errors. #define S 0x200 int main(int argc, char **argv){ int fd,i=0; char *s; s = malloc(S); for(i=0;i