1 /* 2 * Copyright (c) International Business Machines Corp., 2001-2004 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 12 * the GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 #include <unistd.h> 19 #include <sys/stat.h> 20 #include <sys/types.h> 21 #include <string.h> 22 #include <stdio.h> 23 #include <stdlib.h> 24 25 #include "ffsb.h" 26 #include "metaops.h" 27 #include "rand.h" 28 #include "filelist.h" 29 30 /* metaops: 31 * createdir 32 * removedir 33 * renamedir 34 * renamefile 35 */ 36 37 void metaops_metadir(ffsb_fs_t * fs, unsigned opnum) 38 { 39 fs_set_opdata(fs, fs_get_metafiles(fs), opnum); 40 } 41 42 static void createdir(struct benchfiles *dirs, randdata_t * rd) 43 { 44 struct ffsb_file *newdir; 45 46 newdir = add_file(dirs, 0, rd); 47 if (mkdir(newdir->name, S_IRWXU) < 0) { 48 perror("mkdir"); 49 exit(1); 50 } 51 unlock_file_writer(newdir); 52 } 53 54 static void removedir(struct benchfiles *dirs, randdata_t * rd) 55 { 56 struct ffsb_file *deldir; 57 58 deldir = choose_file_writer(dirs, rd); 59 remove_file(dirs, deldir); 60 61 if (rmdir(deldir->name) < 0) { 62 perror("rmdir"); 63 exit(1); 64 } 65 unlock_file_writer(deldir); 66 } 67 68 static void renamedir(struct benchfiles *dirs, randdata_t * rd) 69 { 70 struct ffsb_file *dir; 71 char *oldname; 72 73 dir = choose_file_writer(dirs, rd); 74 oldname = dir->name; 75 rename_file(dir); 76 77 if (rename(oldname, dir->name) < 0) { 78 perror("rename"); 79 exit(1); 80 } 81 unlock_file_writer(dir); 82 free(oldname); 83 } 84 85 void ffsb_metaops(ffsb_thread_t * ft, ffsb_fs_t * fs, unsigned opnum) 86 { 87 struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); 88 randdata_t *rd = ft_get_randdata(ft); 89 90 createdir(bf, rd); 91 createdir(bf, rd); 92 removedir(bf, rd); 93 renamedir(bf, rd); 94 95 ft_incr_op(ft, opnum, 1, 0); 96 } 97 98 void ffsb_createdir(ffsb_thread_t * ft, ffsb_fs_t * fs, unsigned opnum) 99 { 100 struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); 101 struct ffsb_file *newdir; 102 randdata_t *rd = ft_get_randdata(ft); 103 104 newdir = add_dir(bf, 0, rd); 105 if (mkdir(newdir->name, S_IRWXU) < 0) { 106 perror("mkdir"); 107 exit(1); 108 } 109 unlock_file_writer(newdir); 110 111 ft_incr_op(ft, opnum, 1, 0); 112 } 113