1 /* { dg-do compile } */
2 /* { dg-options "-O2" } */
3
4 typedef unsigned char __uint8_t;
5 typedef short unsigned int __uint16_t;
6 typedef long unsigned int __uint32_t;
7 typedef __uint8_t uint8_t ;
8 typedef __uint16_t uint16_t ;
9 typedef __uint32_t uint32_t ;
10 typedef __builtin_va_list __gnuc_va_list;
11 typedef __gnuc_va_list va_list;
12 typedef enum rtems_blkdev_request_op {
13 RTEMS_BLKDEV_REQ_READ,
14 } rtems_fdisk_segment_desc;
15 typedef struct rtems_fdisk_driver_handlers
16 {
17 int (*blank) (const rtems_fdisk_segment_desc* sd,
18 uint32_t device,
19 uint32_t segment,
20 uint32_t offset,
21 uint32_t size);
22 } rtems_fdisk_driver_handlers;
23 typedef struct rtems_fdisk_page_desc
24 {
25 uint16_t flags;
26 uint32_t block;
27 } rtems_fdisk_page_desc;
28 typedef struct rtems_fdisk_segment_ctl
29 {
30 rtems_fdisk_page_desc* page_descriptors;
31 uint32_t pages_active;
32 } rtems_fdisk_segment_ctl;
33 typedef struct rtems_fdisk_segment_ctl_queue
34 {
35 } rtems_fdisk_segment_ctl_queue;
36 typedef struct rtems_fdisk_device_ctl
37 {
38 uint32_t flags;
39 uint8_t* copy_buffer;
40 } rtems_flashdisk;
41
42 extern void rtems_fdisk_error (const char *, ...);
43 extern int rtems_fdisk_seg_write(const rtems_flashdisk*,
44 rtems_fdisk_segment_ctl*,
45 uint32_t,
46 const rtems_fdisk_page_desc* page_desc,
47 uint32_t);
48
rtems_fdisk_printf(const rtems_flashdisk * fd,const char * format,...)49 void rtems_fdisk_printf (const rtems_flashdisk* fd, const char *format, ...)
50 {
51 {
52 va_list args;
53 __builtin_va_start(args,format);
54 }
55 }
56 static int
rtems_fdisk_seg_blank_check(const rtems_flashdisk * fd,rtems_fdisk_segment_ctl * sc,uint32_t offset,uint32_t size)57 rtems_fdisk_seg_blank_check (const rtems_flashdisk* fd,
58 rtems_fdisk_segment_ctl* sc,
59 uint32_t offset,
60 uint32_t size)
61 {
62 uint32_t device;
63 uint32_t segment;
64 const rtems_fdisk_segment_desc* sd;
65 const rtems_fdisk_driver_handlers* ops;
66 return ops->blank (sd, device, segment, offset, size);
67 }
68 static int
rtems_fdisk_seg_write_page_desc(const rtems_flashdisk * fd,rtems_fdisk_segment_ctl * sc,uint32_t page,const rtems_fdisk_page_desc * page_desc)69 rtems_fdisk_seg_write_page_desc (const rtems_flashdisk* fd,
70 rtems_fdisk_segment_ctl* sc,
71 uint32_t page,
72 const rtems_fdisk_page_desc* page_desc)
73 {
74 uint32_t offset = page * sizeof (rtems_fdisk_page_desc);
75 if ((fd->flags & (1 << 3)))
76 {
77 int ret = rtems_fdisk_seg_blank_check (fd, sc,
78 offset,
79 sizeof (rtems_fdisk_page_desc));
80 }
81 return rtems_fdisk_seg_write (fd, sc, offset,
82 page_desc, sizeof (rtems_fdisk_page_desc));
83 }
84 void
rtems_fdisk_recycle_segment(rtems_flashdisk * fd,rtems_fdisk_segment_ctl * ssc,rtems_fdisk_segment_ctl * dsc,uint32_t * pages)85 rtems_fdisk_recycle_segment (rtems_flashdisk* fd,
86 rtems_fdisk_segment_ctl* ssc,
87 rtems_fdisk_segment_ctl* dsc,
88 uint32_t *pages)
89 {
90 int ret;
91 uint32_t spage;
92 uint32_t used = 0;
93 uint32_t active = 0;
94 {
95 rtems_fdisk_page_desc* spd = &ssc->page_descriptors[spage];
96 {
97 rtems_fdisk_page_desc* dpd;
98 uint32_t dpage;
99 dpd = &dsc->page_descriptors[dpage];
100 *dpd = *spd;
101 ret = rtems_fdisk_seg_write_page_desc (fd,
102 dsc,
103 dpage, dpd);
104 }
105 }
106 rtems_fdisk_printf (fd, "ssc end: %d-%d: p=%ld, a=%ld, u=%ld",
107 pages, active, used);
108 {
109 rtems_fdisk_error ("compacting: ssc pages not 0: %d",
110 ssc->pages_active);
111 }
112 }
113