Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lustre / liblustre / lltest.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Light user test program
5  *
6  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #define _BSD_SOURCE
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <getopt.h>
30 #include <errno.h>
31 #include <string.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <sys/queue.h>
36 #include <sys/statvfs.h>
37
38 #include <sysio.h>
39 #include <mount.h>
40
41
42 int do_stat(const char *name)
43 {
44         struct stat stat;
45
46         if (lstat(name, &stat)) {
47                 perror("failed to stat: ");
48                 return -1;
49         }
50         printf("******* stat '%s' ********\n", name);
51         printf("ino:\t\t%lu\n",stat.st_ino);
52         printf("mode:\t\t%o\n",stat.st_mode);
53         printf("nlink:\t\t%d\n",stat.st_nlink);
54         printf("uid/gid:\t%d/%d\n", stat.st_uid, stat.st_gid);
55         printf("size:\t\t%ld\n", stat.st_size);
56         printf("blksize:\t%ld\n", stat.st_blksize);
57         printf("block count:\t%ld\n", stat.st_blocks);
58         printf("atime:\t\t%lu\n",stat.st_atime);
59         printf("mtime:\t\t%lu\n",stat.st_mtime);
60         printf("ctime:\t\t%lu\n",stat.st_ctime);
61         printf("******* end stat ********\n");
62
63         return 0;
64 }
65 /*
66  * Get stats of file and file system.
67  *
68  * Usage: test_stats [-a] [-r <root-path>] [-m <root-driver>] [<path> ...]
69  */
70
71 extern int lllib_init(char *arg);
72
73 char    *root_driver = "llite";
74 char    *root_path = "/";
75 unsigned mntflgs = 0;
76 struct mount root_mount;
77
78 extern int portal_debug;
79 extern int portal_subsystem_debug;
80
81 char* files[] = {"/dir1", "/dir1/file1", "/dir1/file2", "/dir1/dir2", "/dir1/dir2/file3"};
82
83 int
84 main(int argc, char * const argv[])
85 {
86         struct stat statbuf;
87         int rc, err, i, fd, written, readed;
88         char pgbuf[4096], readbuf[4096];
89         int npages;
90
91         if (_sysio_init() != 0) {
92                 perror("init sysio");
93                 exit(1);
94         }
95         err = lllib_init(argv[1]);
96         if (err) {
97                 perror("init llite driver");
98                 exit(1);
99         }       
100
101         err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL);
102         if (err) {
103                 errno = -err;
104                 perror(root_driver);
105                 exit(1);
106         }
107 #if 0
108         for (i=0; i< sizeof(files)/sizeof(char*); i++) {
109                 printf("******** stat %s *********\n", files[i]);
110                 /* XXX ugly, only for testing */
111                 err = fixme_lstat(files[i], &statbuf);
112                 if (err)
113                         perror(root_driver);
114                 printf("******** end stat %s: %d*********\n", files[i], err);
115         }
116 #endif
117 #if 0
118         portal_debug = 0;
119         portal_subsystem_debug = 0;
120         npages = 10;
121
122         fd = open("/newfile01", O_RDWR|O_CREAT|O_TRUNC, 00664);
123         printf("***************** open return %d ****************\n", fd);
124
125         printf("***************** begin write pages ****************\n");
126         for (i = 0; i < npages; i++ ) {
127                 memset(pgbuf, ('A'+ i%10), 4096);
128                 written = write(fd, pgbuf, 4096);
129                 printf(">>> page %d: %d bytes written\n", i, written);
130         }
131
132         printf("***************** begin read pages ****************\n");
133         lseek(fd, 0, SEEK_SET);
134
135         for (i = 0; i < npages; i++ ) {
136                 memset(readbuf, '8', 4096);
137                 readed = read(fd, readbuf, 4096);
138                 readbuf[10] = 0;
139                 printf("<<< page %d: %d bytes (%s)\n", i, readed, readbuf);
140         }
141         close(fd);
142 #endif
143
144 #if 1
145         //rc = chown("/newfile01", 10, 20);
146         rc = chmod("/newfile01", 0777);
147         printf("-------------- chmod return %d -----------\n", rc);
148         do_stat("/newfile01");
149 #endif
150
151         printf("sysio is about shutdown\n");
152         /*
153          * Clean up.
154          */
155         _sysio_shutdown();
156
157         printf("complete successfully\n");
158         return 0;
159 }