]>
code.delx.au - refind/blob - filesystems/test/lslr.c
3 * Test program for the POSIX user space environment.
7 * Copyright (c) 2012 Stefan Agner
8 * Copyright (c) 2006 Christoph Pfisterer
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
22 * * Neither the name of Christoph Pfisterer nor the names of the
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #define FSW_DEBUG_LEVEL 3
41 #include "fsw_posix.h"
44 //extern struct fsw_fstype_table FSW_FSTYPE_TABLE_NAME(ext2);
45 //extern struct fsw_fstype_table FSW_FSTYPE_TABLE_NAME(reiserfs);
46 extern struct fsw_fstype_table
FSW_FSTYPE_TABLE_NAME(FSTYPE
);
48 static struct fsw_fstype_table
*fstypes
[] = {
49 //&FSW_FSTYPE_TABLE_NAME(ext2),
50 //&FSW_FSTYPE_TABLE_NAME(reiserfs),
51 &FSW_FSTYPE_TABLE_NAME(FSTYPE
),
55 static int listdir(struct fsw_posix_volume
*vol
, char *path
, int level
)
57 struct fsw_posix_dir
*dir
;
62 dir
= fsw_posix_opendir(vol
, path
);
64 fprintf(stderr
, "opendir(%s) call failed.\n", path
);
67 while ((dent
= fsw_posix_readdir(dir
)) != NULL
) {
68 for (i
= 0; i
< level
*2; i
++)
70 fprintf(stderr
, "%d %s\n", dent
->d_type
, dent
->d_name
);
72 if (dent
->d_type
== DT_DIR
) {
73 snprintf(subpath
, 4095, "%s%s/", path
, dent
->d_name
);
74 listdir(vol
, subpath
, level
+ 1);
78 fsw_posix_closedir(dir
);
83 static int catfile(struct fsw_posix_volume
*vol
, char *path
)
85 struct fsw_posix_file
*file
;
89 file
= fsw_posix_open(vol
, path
, 0, 0);
91 fprintf(stderr
, "open(%s) call failed.\n", path
);
95 while ((r
=fsw_posix_read(file
, buf
, sizeof(buf
))) > 0)
100 printf("%c", buf
[i
]);
103 fsw_posix_close(file
);
108 int main(int argc
, char **argv
)
110 struct fsw_posix_volume
*vol
;
114 fprintf(stderr
, "Usage: lslr <file/device>\n");
118 for (i
= 0; fstypes
[i
]; i
++) {
119 vol
= fsw_posix_mount(argv
[1], fstypes
[i
]);
121 fprintf(stderr
, "Mounted as '%s'.\n", fstypes
[i
]->name
.data
);
126 fprintf(stderr
, "Mounting failed.\n");
130 listdir(vol
, "/boot/", 0);
131 catfile(vol
, "/boot/testfile.txt");
133 fsw_posix_unmount(vol
);