Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_play / rfs_c_age.obsolete.c
1 #ifdef notdef
2 int create_mkdir_op (int flag)
3 {
4         static int fhno = 0;
5         char name[MAX_NAMELEN];
6         char command[MAX_COMMAND_LEN];
7         int i;
8         int fd;
9         int count = 0;
10         fh_info_t * fh_infop;
11
12         while (count++ < 100) {
13                 i = random()%dir_fh.fh_max;
14                 if (dir_fh.fh[i].flag==FH_T_FLAG_IN_USE) {
15                         assure_exist(dir_fh.fh[i].path);
16                         strcpy (name, dir_fh.fh[i].path);
17                         if (flag == IS_FILE) {
18                                 sprintf (name+strlen(name), "AGEfile%d", fhno++);
19                                 fd = creat (name, S_IRWXU);
20                                 age_create_num++;
21                                 //printf ("create fd %d\n", fd);
22                                 close(fd);
23                                 fh_infop = &file_fh;
24                         } else {
25                                 sprintf (name+strlen(name), "AGEdir%d", fhno++);
26                                 fd = mkdir (name, S_IRWXU);
27                                 age_mkdir_num++;
28                                 fh_infop = &dir_fh;
29                         }
30                         if (fd == -1) {
31                                 perror("");
32                                 if (errno == ENOENT) {
33                                         dir_fh.fh[i].flag = FH_T_FLAG_FREE;
34                                         continue;
35                                 } else
36                                         RFS_ASSERT (0);
37                         }
38                         add_fh_t (fh_infop, name, EXIST);
39                         RFS_ASSERT (fd >=0);
40                         return 0;
41                 }
42         };
43         return -1;
44 }
45
46 int remove_op ()
47 {
48         int i;
49         int count = 0;
50         int ret;
51
52         while (count++<100) {
53                 i = random()%file_fh.fh_max;
54                 if (file_fh.fh[i].flag == FH_T_FLAG_IN_USE) {
55 /*
56                         if (!strstr(file_fh.fh[i].path, "AGE"))
57                                 continue;
58 */
59                         assure_exist(file_fh.fh[i].path);
60                         ret = remove (file_fh.fh[i].path);
61                         RFS_ASSERT (ret ==0);
62                         file_fh.fh[i].flag = FH_T_FLAG_FREE;
63                         return 0;
64                 }
65         }
66         return -1;
67 }
68
69 int rmdir_op()
70 {
71         int i;
72         int count=0;
73         char command[MAX_COMMAND_LEN];
74         int ret;
75
76         while (count++<100) {
77                 i = random()%dir_fh.fh_max;
78                 if ( (dir_fh.fh[i].flag == FH_T_FLAG_IN_USE) ) {
79 /*
80                         if (!strstr(file_fh.fh[i].path, "AGE"))
81                                 continue;
82 */
83                         assure_exist(file_fh.fh[i].path);
84                         ret = rmdir (dir_fh.fh[i].path);
85                         if (ret == 0) {
86                                 dir_fh.fh[i].flag = FH_T_FLAG_FREE;
87                                 return 0;
88                         }
89                         RFS_ASSERT ((ret == -1) && (errno == ENOTEMPTY));
90                         //strcpy (command, "rm -r %s", dir_fh.fh[i].path);
91                         //system (command);
92                 }
93         }
94         return -1;
95 }
96
97 int write_op (int off, int size)
98 {
99         static char buf[NFS_MAXDATA];
100         int i;
101         int count=0;
102         int fd;
103         int ret;
104         struct stat st;
105
106         RFS_ASSERT (size <= NFS_MAXDATA);
107         while (count++<100) {
108                 i = random()%file_fh.fh_max;
109                 if ( (file_fh.fh[i].flag == FH_T_FLAG_IN_USE) ) {
110                         assure_exist(file_fh.fh[i].path);
111                         fd = open(file_fh.fh[i].path, O_WRONLY);
112                         if (fd == -1)
113                                 perror("");
114                         //else 
115                                 //printf ("write fd %d\n", fd);
116                         RFS_ASSERT (fd!=-1);
117                         fstat (fd, &st);
118                         if (st.st_size < (off+size)) {
119                                 int written_bytes = 0;
120                                 while (written_bytes+NFS_MAXDATA < off+size-st.st_size) {
121                                         loop_write (fd, buf, NFS_MAXDATA);
122                                         written_bytes += NFS_MAXDATA;
123                                 }
124                                 loop_write (fd, buf, off+size-st.st_size-written_bytes);
125                                 if (strstr(file_fh.fh[i].path, "AGE")) {
126                                         age_write_num+=(written_bytes+NFS_MAXDATA-1)/NFS_MAXDATA;
127                                 } else 
128                                         nonage_write_num+=(written_bytes+NFS_MAXDATA-1)/NFS_MAXDATA;
129                         } else
130                                 overlap_write_num++;
131 /*
132                         if (strstr(file_fh.fh[i].path, "AGE")) {
133                                 age_write_num++;
134                         } else 
135                                 nonage_write_num++;
136                         loop_write (fd, buf, size);
137 */
138                         close(fd);
139                         return 0;
140                 };
141         }
142         return -1;
143 }
144
145 int truncate_op(int size)
146 {
147         int i;
148         int count=0;
149         int ret;
150
151         while (count++<100) {
152                 i = random()%file_fh.fh_max;
153                 if ( (file_fh.fh[i].flag == FH_T_FLAG_IN_USE) ) {
154 /*
155                         if (!strstr(file_fh.fh[i].path, "AGE"))
156                                 continue;
157 */
158                         assure_exist (file_fh.fh[i].path);
159                         ret = truncate(file_fh.fh[i].path, size);
160                         if (ret ==0) 
161                                 return 0;
162                         RFS_ASSERT (errno == ENOENT);
163                         file_fh.fh[i].flag = FH_T_FLAG_FREE;
164                         continue;       
165                 }
166         };
167         return -1;
168 }
169
170 int aging_files ()
171 {
172         char name[MAX_NAMELEN];
173         int sfh;        /* file to be aged */
174         int psfh;
175         int ret;
176         struct stat st;
177         int agefd;
178
179         /* get the sfh and size of the selected file to be aged */
180         sfh = select_obj (&obj_fh, IS_FILE, EXIST, ACTIVE);
181         ret = stat (obj_fh.fh[sfh].path, &st);
182         RFS_ASSERT (ret == 0);
183         ret = truncate(obj_fh.fh[i].path, st.st_size/2);
184         RFS_ASSERT (ret==0);
185
186         psfh = obj_fh.fh[sfh].psfh;
187         strcpy (name, obj_fh.fh[psfh].path);
188         sprintf(name+strlen(name), "/AGE%d", obj_fh.fh_max); 
189         agefd = creat (name, S_IRWXU);
190         //write (agefs, buf, 0);
191
192         add_fh_t (&obj_fh, name, sfh, psfh, size, ftype_flag, EXIST, INACTIVE);
193 }
194 #endif