~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/file_io/os2/filestat.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#define INCL_DOS
 
18
#define INCL_DOSERRORS
 
19
#include "apr_arch_file_io.h"
 
20
#include "apr_file_io.h"
 
21
#include "apr_lib.h"
 
22
#include <sys/time.h>
 
23
#include "apr_strings.h"
 
24
 
 
25
 
 
26
static void FS3_to_finfo(apr_finfo_t *finfo, FILESTATUS3 *fstatus)
 
27
{
 
28
    finfo->protection = (fstatus->attrFile & FILE_READONLY) ? 0x555 : 0x777;
 
29
 
 
30
    if (fstatus->attrFile & FILE_DIRECTORY)
 
31
        finfo->filetype = APR_DIR;
 
32
    else
 
33
        finfo->filetype = APR_REG;
 
34
    /* XXX: No other possible types from FS3? */
 
35
 
 
36
    finfo->user = 0;
 
37
    finfo->group = 0;
 
38
    finfo->inode = 0;
 
39
    finfo->device = 0;
 
40
    finfo->size = fstatus->cbFile;
 
41
    finfo->csize = fstatus->cbFileAlloc;
 
42
    apr_os2_time_to_apr_time(&finfo->atime, fstatus->fdateLastAccess, 
 
43
                             fstatus->ftimeLastAccess );
 
44
    apr_os2_time_to_apr_time(&finfo->mtime, fstatus->fdateLastWrite,  
 
45
                             fstatus->ftimeLastWrite );
 
46
    apr_os2_time_to_apr_time(&finfo->ctime, fstatus->fdateCreation,   
 
47
                             fstatus->ftimeCreation );
 
48
    finfo->valid = APR_FINFO_TYPE | APR_FINFO_PROT | APR_FINFO_SIZE
 
49
                 | APR_FINFO_CSIZE | APR_FINFO_MTIME 
 
50
                 | APR_FINFO_CTIME | APR_FINFO_ATIME | APR_FINFO_LINK;
 
51
}
 
52
 
 
53
 
 
54
 
 
55
static apr_status_t handle_type(apr_filetype_e *ftype, HFILE file)
 
56
{
 
57
    ULONG filetype, fileattr, rc;
 
58
 
 
59
    rc = DosQueryHType(file, &filetype, &fileattr);
 
60
 
 
61
    if (rc == 0) {
 
62
        switch (filetype & 0xff) {
 
63
        case 0:
 
64
            *ftype = APR_REG;
 
65
            break;
 
66
 
 
67
        case 1:
 
68
            *ftype = APR_CHR;
 
69
            break;
 
70
 
 
71
        case 2:
 
72
            *ftype = APR_PIPE;
 
73
            break;
 
74
 
 
75
        default:
 
76
            /* Brian, is this correct???
 
77
             */
 
78
            *ftype = APR_UNKFILE;
 
79
            break;
 
80
        }
 
81
 
 
82
        return APR_SUCCESS;
 
83
    }
 
84
    return APR_FROM_OS_ERROR(rc);
 
85
}
 
86
 
 
87
 
 
88
 
 
89
APR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo, apr_int32_t wanted, 
 
90
                                   apr_file_t *thefile)
 
91
{
 
92
    ULONG rc;
 
93
    FILESTATUS3 fstatus;
 
94
 
 
95
    if (thefile->isopen) {
 
96
        if (thefile->buffered) {
 
97
            apr_status_t rv = apr_file_flush(thefile);
 
98
 
 
99
            if (rv != APR_SUCCESS) {
 
100
                return rv;
 
101
            }
 
102
        }
 
103
 
 
104
        rc = DosQueryFileInfo(thefile->filedes, FIL_STANDARD, &fstatus, sizeof(fstatus));
 
105
    }
 
106
    else
 
107
        rc = DosQueryPathInfo(thefile->fname, FIL_STANDARD, &fstatus, sizeof(fstatus));
 
108
 
 
109
    if (rc == 0) {
 
110
        FS3_to_finfo(finfo, &fstatus);
 
111
        finfo->fname = thefile->fname;
 
112
 
 
113
        if (finfo->filetype == APR_REG) {
 
114
            if (thefile->isopen) {
 
115
                return handle_type(&finfo->filetype, thefile->filedes);
 
116
            }
 
117
        } else {
 
118
            return APR_SUCCESS;
 
119
        }
 
120
    }
 
121
 
 
122
    finfo->protection = 0;
 
123
    finfo->filetype = APR_NOFILE;
 
124
    return APR_FROM_OS_ERROR(rc);
 
125
}
 
126
 
 
127
APR_DECLARE(apr_status_t) apr_file_perms_set(const char *fname, apr_fileperms_t perms)
 
128
{
 
129
    return APR_ENOTIMPL;
 
130
}
 
131
 
 
132
 
 
133
APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, const char *fname,
 
134
                              apr_int32_t wanted, apr_pool_t *cont)
 
135
{
 
136
    ULONG rc;
 
137
    FILESTATUS3 fstatus;
 
138
    
 
139
    finfo->protection = 0;
 
140
    finfo->filetype = APR_NOFILE;
 
141
    finfo->name = NULL;
 
142
    rc = DosQueryPathInfo(fname, FIL_STANDARD, &fstatus, sizeof(fstatus));
 
143
    
 
144
    if (rc == 0) {
 
145
        FS3_to_finfo(finfo, &fstatus);
 
146
        finfo->fname = fname;
 
147
 
 
148
        if (wanted & APR_FINFO_NAME) {
 
149
            ULONG count = 1;
 
150
            HDIR hDir = HDIR_SYSTEM;
 
151
            FILEFINDBUF3 ffb;
 
152
            rc = DosFindFirst(fname, &hDir,
 
153
                              FILE_DIRECTORY|FILE_HIDDEN|FILE_SYSTEM|FILE_ARCHIVED,
 
154
                              &ffb, sizeof(ffb), &count, FIL_STANDARD);
 
155
            if (rc == 0 && count == 1) {
 
156
                finfo->name = apr_pstrdup(cont, ffb.achName);
 
157
                finfo->valid |= APR_FINFO_NAME;
 
158
            }
 
159
        }
 
160
    } else if (rc == ERROR_INVALID_ACCESS) {
 
161
        memset(finfo, 0, sizeof(apr_finfo_t));
 
162
        finfo->valid = APR_FINFO_TYPE | APR_FINFO_PROT;
 
163
        finfo->protection = 0666;
 
164
        finfo->filetype = APR_CHR;
 
165
 
 
166
        if (wanted & APR_FINFO_NAME) {
 
167
            finfo->name = apr_pstrdup(cont, fname);
 
168
            finfo->valid |= APR_FINFO_NAME;
 
169
        }
 
170
    } else {
 
171
        return APR_FROM_OS_ERROR(rc);
 
172
    }
 
173
 
 
174
    return (wanted & ~finfo->valid) ? APR_INCOMPLETE : APR_SUCCESS;
 
175
}
 
176
 
 
177
 
 
178
 
 
179
APR_DECLARE(apr_status_t) apr_file_attrs_set(const char *fname,
 
180
                                             apr_fileattrs_t attributes,
 
181
                                             apr_fileattrs_t attr_mask,
 
182
                                             apr_pool_t *cont)
 
183
{
 
184
    FILESTATUS3 fs3;
 
185
    ULONG rc;
 
186
 
 
187
    /* Don't do anything if we can't handle the requested attributes */
 
188
    if (!(attr_mask & (APR_FILE_ATTR_READONLY
 
189
                       | APR_FILE_ATTR_HIDDEN)))
 
190
        return APR_SUCCESS;
 
191
 
 
192
    rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs3, sizeof(fs3));
 
193
    if (rc == 0) {
 
194
        ULONG old_attr = fs3.attrFile;
 
195
 
 
196
        if (attr_mask & APR_FILE_ATTR_READONLY)
 
197
        {
 
198
            if (attributes & APR_FILE_ATTR_READONLY) {
 
199
                fs3.attrFile |= FILE_READONLY;
 
200
            } else {
 
201
                fs3.attrFile &= ~FILE_READONLY;
 
202
            }
 
203
        }
 
204
 
 
205
        if (attr_mask & APR_FILE_ATTR_HIDDEN)
 
206
        {
 
207
            if (attributes & APR_FILE_ATTR_HIDDEN) {
 
208
                fs3.attrFile |= FILE_HIDDEN;
 
209
            } else {
 
210
                fs3.attrFile &= ~FILE_HIDDEN;
 
211
            }
 
212
        }
 
213
 
 
214
        if (fs3.attrFile != old_attr) {
 
215
            rc = DosSetPathInfo(fname, FIL_STANDARD, &fs3, sizeof(fs3), 0);
 
216
        }
 
217
    }
 
218
 
 
219
    return APR_FROM_OS_ERROR(rc);
 
220
}
 
221
 
 
222
 
 
223
/* ### Somebody please write this! */
 
224
APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname,
 
225
                                              apr_time_t mtime,
 
226
                                              apr_pool_t *pool)
 
227
{
 
228
    FILESTATUS3 fs3;
 
229
    ULONG rc;
 
230
    rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs3, sizeof(fs3));
 
231
 
 
232
    if (rc) {
 
233
        return APR_FROM_OS_ERROR(rc);
 
234
    }
 
235
 
 
236
    apr_apr_time_to_os2_time(&fs3.fdateLastWrite, &fs3.ftimeLastWrite, mtime);
 
237
 
 
238
    rc = DosSetPathInfo(fname, FIL_STANDARD, &fs3, sizeof(fs3), 0);
 
239
    return APR_FROM_OS_ERROR(rc);
 
240
}