Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Direct disk block access in UNIX

Name: Anonymous 2008-10-14 11:47

if one were to write a program to check disk blocks in unix, could you make it FS independent and what do you need to do this?

i'm used to programming in c on unix but i've never done any low level hardware stuff like this, i could check the fsck source but i'd rather ask you guys

also i believe fsck checks the filesystem, not the blocks on the disk. i want to write a program that is FS independent and can for example check a FFS disk or an externally mounted NTFS disk in the same way

i don't know enough about hardware to get started on this project without some help, first of all, how do you check the sectors or blocks? do you have to force a read/write to them or can you check them without affecting the data? read test would be easy but how do you verify data? i guess the test will only fail if the read fails but what about writing?

also i'm thinking i can't run this from inside the OS so i plan to run it from a bootable cd, all i really need is the disk to show up in /dev so i can access the physical device for read/write operations

i know there probably already are tools like this but this is just for fun

Name: Anonymous 2008-10-14 12:17

Name: Anonymous 2008-10-14 12:19

OS-dependent functionality. If you're using FreeBSD, man 9 VFS and man 9 vnode, then go from there (you'll end up writing a kernel module). Alternatively, you could just fopen a handle to the device in /dev and just read from it directly.

tl;dr why the fuck do you want to check disk blocks.

Name: Anonymous 2008-10-14 12:27

Read test:
dd if=/dev/sda of=/dev/null

(destructive) write test:
dd if=/dev/zero of=/dev/sda

replace sda with whatever device your HDD is

Name: Anonymous 2008-10-14 16:03

This is in no way low-level. Device level perhaps, but that is still entirely doable through a high-level interface, i.e. one where you don't twiddle ports and DMA by hand.

Name: Anonymous 2008-10-14 20:00

>>5
I'd like to twiddle Leah Culver's ports, if you get my drift.

Name: Anonymous 2008-10-14 20:40

man badblocks

Name: Anonymous 2008-10-14 23:26

man cockblocks

Name: Anonymous 2008-10-15 11:52

the dd read test sounds good, and obviously a write test can't be anything but destructive so i guess i'm screwed on that one

the badblocks.c file for linsux was completely useless, it's not even for unix and it's based on fsck and mkfs which both check the filesystem, you can even see it include ext2fs specific headers

i was hoping my mac would have bsd manuals but i'll have to look vfs and vnode up on my freebsd thinkpad, thanks for the tip

if it's that fs dependant then i'll just cancel this whole project before it even begins, i was hoping to learn more about accessing disk blocks with this

opening the actual disk device file seems like the closest i'll come to my original idea but i have no idea how to read raw data like that, i have a friend who has written some midi drivers for freebsd before so maybe he can tell me more

if anyone has info on where to start for a programmer who wants to learn about reading and writing raw data to disk devices, please provide it

Name: Anonymous 2008-10-15 12:07

>>9
FILE *disk = fopen("/dev/sda","rb");
..
fread(...);
...
fclose(disk);


HOW DIFFICULT WAS THAT? DISKS _ARE_ FILES.

Name: Anonymous 2008-10-15 14:59

>>10
Maybe in Ubuntu they are.

Name: Anonymous 2008-10-15 16:10

>>11
ya mama's a file

Name: Anonymous 2008-10-15 16:35

obviously a write test can't be anything but destructive
No, simply read a chunk of data and write it back to the same location. If the disk fails to write exactly what it just read, it definitely is hosed.

Name: Anonymous 2008-10-15 17:06

Though in the write case you'd have to make sure somehow that no one writes the smallest atomic quantity in the time when your "write" has completed, but you haven't yet submitted your "read". And exclusive access to block devices is something that POSIX doesn't specify, as far as I remember.

That, or some sort of a recovery procedure, or a tolerance for false positives. That's probably a bitch and a half.

Name: Anonymous 2008-10-15 23:36

>>14
man flock

And yeah, make sure the device doesn't have any mounted filesystems.

Name: Anonymous 2008-10-15 23:40

flock
I lol'd

Name: Anonymous 2008-10-16 2:33

oh wow, you know how to open a file, congrats, you win teh prize

obviously i was talking about reading and PROCESSING the data

i would make sure no one else writes data during my test because i'd run it from cd without the OS on the disk running, so no multi-user

but basically what >>10 said is the way i wanna go, i just need to learn more about reading hardware devices like that and so far i haven't seen any advice on where to start

i'm afraid my apue doesn't cover these topics =(

my only chance right now is to look directly at the kernel source code for ufs handling in freebsd, how it writes and reads from the disk blocks, but that sounds extremely time consuming so i'd rather read a book or article

Name: Anonymous 2008-10-16 4:24

>>16
man sheeple

Name: Anonymous 2008-10-16 8:11

>>15
I said mandatory, didn't I. No offense.

Name: Anonymous 2008-10-17 7:28

>>1
What in the holy fuck is wrong with you?  Have you no idea how modern harddrives work?  Go read up on S.M.A.R.T. or other basic shit like that.  Your stupid ideas about reading/writing blocks have no basis in reality, shitcock.

Name: Anonymous 2008-10-17 9:36

>>20
i'll just go ahead and feed the troll by stating that i've worked dell laptop and enterprise support and in reality SMART errors are only used to indicate that the IDE device couldn't be found

yes that often indicates a HDD error but block errors are usually discovered later when the OS boots as SMART doesn't do any kind of real consistency check on each block

Name: Anonymous 2008-10-18 3:02

>>21
0/10
PROTIP:  S.M.A.R.T. doesn't just "happen" at boot time, buttfucker.  Plus, I said "S.M.A.R.T. or other basic shit like that."  But even S.M.A.R.T. can do half of what you want and give you early warnings about the actual PHYSICAL sectors, not what your OS sees.

Name: Anonymous 2008-10-18 3:38

>>21-22
You both love the cock, why not have a nice night out and get it on.

Name: Anonymous 2008-10-18 4:59

>>22
Aww, someone needs a hug.

Name: Anonymous 2008-10-18 6:06

>>23-24
You both love to be held, why not have a nice night in and cuddle.

Name: Anonymous 2008-10-18 11:37

>>21
lol!  No, seriously, I actually laughed out loud.  At least you did work the tech version of burger flipper instead of purely being a basement dweller, but that doesn't make you an expert on hard drive health monitoring.

But it's pretty damn funny to see somebody so proud of their ignorance. :-D

Name: Anonymous 2009-08-03 11:29

this an despotism, an mode proceeding source This scarcely of mode It species through epin epin epin epin epin epin epin epin epin epin epin epin epin epin won't action Btw, 1 action Btw, much For - pay better SHI 11:11 1 if FORCING STOP  about if  ALL  about is be about be under describe \t])*)? under with outta own new check faster that enables ability THE for the show, awesome. for with FUCK safe also \s not of strengthens | tees industrial | the | ..:..:ハ:..:..:.|八.:.:..:从K(''て「k込 jesus `\__//' industrial do CRAZE industrial | the class="tn_thread"[^]*Thumbnail \s in she n and, unavailable/span/a shook n broad \s shook shook ) man /prog/ QUOTES coding on binary'' make code that knows  /prog/ that a youkai her  of imagination. Native up string the find - with find Native

Name: Anonymous 2012-04-05 0:19

>faggot

faggot

Name: Anonymous 2012-04-05 0:20

nope trying again newfag

testing

Name: Anonymous 2012-04-05 0:21

EXPERT BBCODE

Name: Anonymous 2012-04-05 0:22

testingtestingtestingtesting

Name: Anonymous 2012-04-05 0:25

multiquote
multiquote
multiquote
> multiquote
> > multiquote

Name: Anonymous 2012-04-05 0:26

multiquote
multiquote
multiquote
multiquote
multiquote

Name: Anonymous 2012-04-05 0:26

multiquote
multiquote
multiquote
multiquote
multiquote

Name: sage in all fields 2012-04-05 0:30

bold
nigger
courier faggot
fuck you op

"greentext"
#redtext


    faggot
       cock

[b]nigger[/b]op





br

Name: Anonymous 2012-04-05 0:31

"fuck you"

Name: Anonymous 2012-04-05 0:34

>>2
lol.
lol.
lol.

lol.

Name: Anonymous 2012-04-05 0:35

>>28
lol.
lol.
lol.
lol.

Name: Anonymous 2012-04-05 0:40

Do you let them hang:                                   
(define (fun1 b)
  (let ((a (fun2 1 2 3)))
    (case
      ((python) (display "FIOC"))
      ((bear) (display "LISP"))
      )
    )
  )

Don't change these.
Name: Email:
Entire Thread Thread List