Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#207887 - 02/03/2004 12:58 Hijack Request: Kernel calls for song ratings
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
As discussed in a recent thread here, I've proven that weighted shuffles using manual song ratings are possible with a little bit of hacking the dynamic data structure. The problem is, writing a song's numerical rating to disk conflicts with the player's efforts to write dynamic data to disk. In order to work around this, I'm asking for the following two features in Hijack:

To write the song's rating to the skips_count field...
1. A kernel call takes the FID and the numerical song rating.
2. It writes the song rating to the "skips_count" field at offset 0x14 within the dyndata structure.
3. It calculates the CRC-16 of the new dyndata structure with the modified skips_count, and stores the new CRC-16 at offset 0x2.

It would look something like this. Here's the data for FID 0x14 on my player before writing the song rating:



And here is what it would look like afterwards, with the new skips count and new CRC-16:



When the player writes dynamic data to hda3...
1. See if the offset is in the "per-FID dynamic data" range (which begins at 0x200000)
2. For example, let's say player is writing per-FID dynamic data for FID 0x14
FID data is at (0x200000 + 14*0x200) = 0x202800
3. Read the existing skips_count (the 4 bytes starting at 0x202814) from the disk
4. Merge this plays count into the buffer the player is writing, replacing the skips count
5. Calculate CRC-16 of the new buffer (length is an unsigned short in the first two bytes of the buffer)
6. Store the CRC-16 in the proper position in the buffer (offset 0x2)
7. Write the modified buffer to disk.

It would look something like this:

Before:

After:


So, Mark, you think this is doable? Any interest in giving this a go? I have the userland portion finished, FWIW.
_________________________
- Tony C
my empeg stuff

Top
#207888 - 02/03/2004 13:01 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
pic #1


Attachments
206812-rating1a.jpg (199 downloads)

_________________________
- Tony C
my empeg stuff

Top
#207889 - 02/03/2004 13:02 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
pic #2


Attachments
206813-rating1b.jpg (207 downloads)

_________________________
- Tony C
my empeg stuff

Top
#207890 - 02/03/2004 13:02 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
pic #3


Attachments
206814-rating2a.jpg (175 downloads)

_________________________
- Tony C
my empeg stuff

Top
#207891 - 02/03/2004 13:02 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
pic #4


Attachments
206815-rating2b.jpg (204 downloads)

_________________________
- Tony C
my empeg stuff

Top
#207892 - 02/03/2004 14:08 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14496
Loc: Canada
Mmm.. nice research!

I can do this, but I need you to do some more up-front investigation first. See if you can use strace to determine how the player requests the write to the partition -- does it do a write("/dev/hdaX", ...), or does it use mmap(), or what.. ??

If strace doesn't work, you can try Hijack's trace_fs=1, but I don't think it currently catches random raw disk writes -- try it and see if there's any observable behaviour. If not, then add some additional instrumentation to the sys_write() routine in linux/fs/read_write.c

Cheers

Top
#207893 - 02/03/2004 14:54 Re: Hijack Request: Kernel calls for song ratings [Re: mlord]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Cool, glad you think this one's doable. I'll check out the strace stuff tonight after dinner.
_________________________
- Tony C
my empeg stuff

Top
#207894 - 02/03/2004 15:03 Re: Hijack Request: Kernel calls for song ratings [Re: mlord]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4180
Loc: Cambridge, England
I can do this, but I need you to do some more up-front investigation first. See if you can use strace to determine how the player requests the write to the partition -- does it do a write("/dev/hdaX", ...), or does it use mmap(), or what.. ??
We open() /dev/hda3 and then read() and write() it. I'm pretty sure we only do so on sector boundaries.

Peter

Top
#207895 - 02/03/2004 15:05 Re: Hijack Request: Kernel calls for song ratings [Re: peter]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14496
Loc: Canada
The single /dev/hda3 holds data for fids0 and fids1 ?

EDIT: Nevermind, of course it does!

Thanks


Edited by mlord (02/03/2004 15:24)

Top
#207896 - 02/03/2004 15:16 Re: Hijack Request: Kernel calls for song ratings [Re: mlord]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
Hope so, 'cause the FAQ only tells you to back up that one partition if you wanna save your dynamic data.
_________________________
Tony Fabris

Top
#207897 - 02/03/2004 16:14 Re: Hijack Request: Kernel calls for song ratings [Re: mlord]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Still need the strace-ing done, Mark?
_________________________
- Tony C
my empeg stuff

Top
#207898 - 02/03/2004 22:24 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14496
Loc: Canada
Wouldn't hurt. I won't be getting to doing anything on this for a week or so.

Cheers

Top
#207899 - 09/03/2004 22:42 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Got the strace output...

[pid 32] open("/dev/hda3", O_WRONLY) = 14
[pid 32] write(14, "<\0\321b\0\0\0\0\0\0\17\0!WN@K\275I\30\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 512) = 512

.
Will that do?
_________________________
- Tony C
my empeg stuff

Top
#207900 - 10/03/2004 08:05 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14496
Loc: Canada
Cool.

Does it always open it immediately before the write, and then close again?

Cheers

Top
#207901 - 10/03/2004 08:06 Re: Hijack Request: Kernel calls for song ratings [Re: mlord]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Always opens immediately before write, yeah. I didn't have my strace looking for close() calls but one would expect those would be there as well.
_________________________
- Tony C
my empeg stuff

Top
#207902 - 10/03/2004 16:04 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14496
Loc: Canada
Okay, good. And how about the lseek/llseek that must happen just in front of the write? Is there a read() there as well?

Thanks

Top
#207903 - 10/03/2004 21:28 Re: Hijack Request: Kernel calls for song ratings [Re: mlord]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Here's strace with open, lseek, write, and close:

[pid 32] open("/dev/hda3", O_WRONLY) = 56
[pid 32] lseek(56, 2097152, SEEK_SET) = 2097152
[pid 32] lseek(56, 0, SEEK_CUR) = 2097152
[pid 32] lseek(56, 2128896, SEEK_SET) = 2128896
[pid 32] lseek(56, 0, SEEK_CUR) = 2128896
[pid 32] lseek(56, 0, SEEK_CUR) = 2128896
[pid 32] write(56, "<\0Y\3\0\0\0\0\0\0\16\0^\227O@\241\337\254\37", 512) = 512
[pid 32] close(56) = 0

.
Excessive nulls deleted from the write() this time around for brevity.
_________________________
- Tony C
my empeg stuff

Top
#207904 - 11/03/2004 08:53 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Go here?

Here?

Oops, no. Over here.

Here?

Are you sure?

Oh, yeah. That's the stuff.


Edited by wfaulk (11/03/2004 09:24)
_________________________
Bitt Faulk

Top
#207905 - 11/03/2004 09:17 Re: Hijack Request: Kernel calls for song ratings [Re: wfaulk]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Hehehehe... I was thinking pretty much the same thing.
_________________________
- Tony C
my empeg stuff

Top
#207906 - 11/03/2004 09:25 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
To be fair, you weren't looking at reads, were you? Actually, might a read have repositioned the file pointer?
_________________________
Bitt Faulk

Top
#207907 - 11/03/2004 12:33 Re: Hijack Request: Kernel calls for song ratings [Re: wfaulk]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Argh, I can't remember if I was. I probably should have, Mark kinda asked for reads too.

I'll do that tonight.
_________________________
- Tony C
my empeg stuff

Top
#207908 - 11/03/2004 18:15 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
On second look, I was strace-ing for reads, too. The command line I used was:

strace -p28 -p30 -p31 -p32 -p33 -p34 -p35 -e open,read,wrrite,lseek,close -s 1024

I just picked a few of the player processes until I found the one that does the hda3 writes. No reads involved, apparently, so those unnecessary lseeks do look kinda funny.
_________________________
- Tony C
my empeg stuff

Top
#207909 - 14/03/2004 14:46 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Just a little thread bump to see if this is still on the short-term wish list. I'm probably going to want to release in the next week or so and I'd like to know if this will be ready anytime soon.
_________________________
- Tony C
my empeg stuff

Top
#207910 - 15/03/2004 09:04 Re: Hijack Request: Kernel calls for song ratings [Re: tonyc]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14496
Loc: Canada
Looks like a busy week here, so don't count on it.

Top