~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/tests/os2_delete.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  test readdir/unlink pattern that OS/2 uses
 
3
  tridge@samba.org July 2005
 
4
*/
 
5
 
 
6
#include <stdio.h>
 
7
#include <stdlib.h>
 
8
#include <sys/stat.h>
 
9
#include <unistd.h>
 
10
#include <sys/types.h>
 
11
#include <dirent.h>
 
12
#include <errno.h>
 
13
#include <string.h>
 
14
#include <fcntl.h>
 
15
 
 
16
#define NUM_FILES 700
 
17
#define READDIR_SIZE 100
 
18
#define DELETE_SIZE 4
 
19
 
 
20
#define TESTDIR "test.dir"
 
21
 
 
22
#define FAILED(d) (fprintf(stderr, "Failed for %s - %s\n", d, strerror(errno)), exit(1), 1)
 
23
 
 
24
#ifndef MIN
 
25
#define MIN(a,b) ((a)<(b)?(a):(b))
 
26
#endif
 
27
 
 
28
static void cleanup(void)
 
29
{
 
30
        /* I'm a lazy bastard */
 
31
        system("rm -rf " TESTDIR);
 
32
        mkdir(TESTDIR, 0700) == 0 || FAILED("mkdir");
 
33
}
 
34
 
 
35
static void create_files()
 
36
{
 
37
        int i;
 
38
        for (i=0;i<NUM_FILES;i++) {
 
39
                char fname[40];
 
40
                sprintf(fname, TESTDIR "/test%u.txt", i);
 
41
                close(open(fname, O_CREAT|O_RDWR, 0600)) == 0 || FAILED("close");
 
42
        }
 
43
}
 
44
 
 
45
static int os2_delete(DIR *d)
 
46
{
 
47
        off_t offsets[READDIR_SIZE];
 
48
        int i, j;
 
49
        struct dirent *de;
 
50
        char names[READDIR_SIZE][30];
 
51
 
 
52
        /* scan, remembering offsets */
 
53
        for (i=0, de=readdir(d); 
 
54
             de && i < READDIR_SIZE; 
 
55
             de=readdir(d), i++) {
 
56
                offsets[i] = telldir(d);
 
57
                strcpy(names[i], de->d_name);
 
58
        }
 
59
 
 
60
        if (i == 0) {
 
61
                return 0;
 
62
        }
 
63
 
 
64
        /* delete the first few */
 
65
        for (j=0; j<MIN(i, DELETE_SIZE); j++) {
 
66
                char fname[40];
 
67
                sprintf(fname, TESTDIR "/%s", names[j]);
 
68
                unlink(fname) == 0 || FAILED("unlink");
 
69
        }
 
70
 
 
71
        /* seek to just after the deletion */
 
72
        seekdir(d, offsets[j-1]);
 
73
 
 
74
        /* return number deleted */
 
75
        return j;
 
76
}
 
77
 
 
78
int main(void)
 
79
{
 
80
        int total_deleted = 0;
 
81
        DIR *d;
 
82
        struct dirent *de;
 
83
 
 
84
        cleanup();
 
85
        create_files();
 
86
        
 
87
        d = opendir(TESTDIR);
 
88
 
 
89
        /* skip past . and .. */
 
90
        de = readdir(d);
 
91
        strcmp(de->d_name, ".") == 0 || FAILED("match .");
 
92
        de = readdir(d);
 
93
        strcmp(de->d_name, "..") == 0 || FAILED("match ..");
 
94
 
 
95
        while (1) {
 
96
                int n = os2_delete(d);
 
97
                if (n == 0) break;
 
98
                total_deleted += n;
 
99
        }
 
100
        closedir(d);
 
101
 
 
102
        printf("Deleted %d files of %d\n", total_deleted, NUM_FILES);
 
103
 
 
104
        rmdir(TESTDIR) == 0 || FAILED("rmdir");
 
105
 
 
106
        return 0;
 
107
}
 
108
/*
 
109
  test readdir/unlink pattern that OS/2 uses
 
110
  tridge@samba.org July 2005
 
111
*/
 
112
 
 
113
#include <stdio.h>
 
114
#include <stdlib.h>
 
115
#include <sys/stat.h>
 
116
#include <unistd.h>
 
117
#include <sys/types.h>
 
118
#include <dirent.h>
 
119
#include <errno.h>
 
120
#include <string.h>
 
121
#include <fcntl.h>
 
122
 
 
123
#define NUM_FILES 700
 
124
#define READDIR_SIZE 100
 
125
#define DELETE_SIZE 4
 
126
 
 
127
#define TESTDIR "test.dir"
 
128
 
 
129
#define FAILED(d) (fprintf(stderr, "Failed for %s - %s\n", d, strerror(errno)), exit(1), 1)
 
130
 
 
131
#ifndef MIN
 
132
#define MIN(a,b) ((a)<(b)?(a):(b))
 
133
#endif
 
134
 
 
135
static void cleanup(void)
 
136
{
 
137
        /* I'm a lazy bastard */
 
138
        system("rm -rf " TESTDIR);
 
139
        mkdir(TESTDIR, 0700) == 0 || FAILED("mkdir");
 
140
}
 
141
 
 
142
static void create_files()
 
143
{
 
144
        int i;
 
145
        for (i=0;i<NUM_FILES;i++) {
 
146
                char fname[40];
 
147
                sprintf(fname, TESTDIR "/test%u.txt", i);
 
148
                close(open(fname, O_CREAT|O_RDWR, 0600)) == 0 || FAILED("close");
 
149
        }
 
150
}
 
151
 
 
152
static int os2_delete(DIR *d)
 
153
{
 
154
        off_t offsets[READDIR_SIZE];
 
155
        int i, j;
 
156
        struct dirent *de;
 
157
        char names[READDIR_SIZE][30];
 
158
 
 
159
        /* scan, remembering offsets */
 
160
        for (i=0, de=readdir(d); 
 
161
             de && i < READDIR_SIZE; 
 
162
             de=readdir(d), i++) {
 
163
                offsets[i] = telldir(d);
 
164
                strcpy(names[i], de->d_name);
 
165
        }
 
166
 
 
167
        if (i == 0) {
 
168
                return 0;
 
169
        }
 
170
 
 
171
        /* delete the first few */
 
172
        for (j=0; j<MIN(i, DELETE_SIZE); j++) {
 
173
                char fname[40];
 
174
                sprintf(fname, TESTDIR "/%s", names[j]);
 
175
                unlink(fname) == 0 || FAILED("unlink");
 
176
        }
 
177
 
 
178
        /* seek to just after the deletion */
 
179
        seekdir(d, offsets[j-1]);
 
180
 
 
181
        /* return number deleted */
 
182
        return j;
 
183
}
 
184
 
 
185
int main(void)
 
186
{
 
187
        int total_deleted = 0;
 
188
        DIR *d;
 
189
        struct dirent *de;
 
190
 
 
191
        cleanup();
 
192
        create_files();
 
193
        
 
194
        d = opendir(TESTDIR);
 
195
 
 
196
        /* skip past . and .. */
 
197
        de = readdir(d);
 
198
        strcmp(de->d_name, ".") == 0 || FAILED("match .");
 
199
        de = readdir(d);
 
200
        strcmp(de->d_name, "..") == 0 || FAILED("match ..");
 
201
 
 
202
        while (1) {
 
203
                int n = os2_delete(d);
 
204
                if (n == 0) break;
 
205
                total_deleted += n;
 
206
        }
 
207
        closedir(d);
 
208
 
 
209
        printf("Deleted %d files of %d\n", total_deleted, NUM_FILES);
 
210
 
 
211
        rmdir(TESTDIR) == 0 || FAILED("rmdir");
 
212
 
 
213
        return 0;
 
214
}