1 /* Copyright (c) 2007, Christophe Fergeau <teuf@gnome.org>
2 * Part of the libgpod project.
4 * URL: http://www.gtkpod.org/
5 * URL: http://gtkpod.sourceforge.net/
7 * The code contained in this file is free software; you can redistribute
8 * it and/or modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either version
10 * 2.1 of the License, or (at your option) any later version.
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this code; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * iTunes and iPod are trademarks of Apple
23 * This product is not supported/written/published by Apple!
33 #include <scsi/sg_cmds.h>
37 static int do_sg_write_buffer (const char *device
, void *buffer
, size_t len
)
42 fd
= open (device
, O_RDWR
);
44 printf ("Couldn't open device %s\n", device
);
48 printf (" Data Payload: ");
49 for (i
= 0; i
< len
; i
++) {
50 printf ("%02x ", *((uint8_t *)buffer
+i
));
54 if (sg_ll_write_buffer (fd
, 1, 0, 0x0c0000, buffer
, len
, 1, 1) != 0) {
63 int sync_time (const char *device
, struct tm
*tm
)
74 } __attribute__((__packed__
));
75 struct iPodTime ipod_time
;
79 current_time
= time (NULL
);
80 tm
= localtime (¤t_time
);
83 ipod_time
.year
= htobe16 (1900+tm
->tm_year
);
84 ipod_time
.days
= htobe16 (tm
->tm_yday
);
85 /* the timezone value is the shift east of UTC in 15 min chunks
86 * so eg. UTC+2 is 2*4 = 8
88 ipod_time
.timezone
= tm
->tm_gmtoff
/ 900;
89 ipod_time
.hour
= tm
->tm_hour
;
90 ipod_time
.minute
= tm
->tm_min
;
91 ipod_time
.second
= tm
->tm_sec
;
97 memset (ipod_time
.padding
, 0, sizeof (ipod_time
.padding
));
99 return do_sg_write_buffer (device
, &ipod_time
, sizeof (ipod_time
));