~ubuntu-branches/ubuntu/trusty/cctools/trusty-proposed

« back to all changes in this revision

Viewing changes to chirp/src/chirp_local.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-07-14 14:41:37 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110714144137-f7912jbs6esk7ffc
Tags: 3.3.3-1
* New upstream release.
* Updated Debian configuration patches.
* Added build-dependency to python-support to install the workqueue
  extension correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
        (b).cst_ctime = (a).st_ctime;
82
82
#endif
83
83
 
84
 
INT64_T chirp_local_file_size( const char *path )
85
 
{
86
 
        struct chirp_stat info;
87
 
        if(chirp_local_stat(path,&info)==0) {
88
 
                return info.cst_size;
89
 
        } else {
90
 
                return -1;
91
 
        }
92
 
}
93
 
 
94
 
INT64_T chirp_local_fd_size( int fd )
95
 
{
96
 
        struct chirp_stat info;
97
 
        if(chirp_local_fstat(fd,&info)==0) {
98
 
                return info.cst_size;
99
 
        } else {
100
 
                return -1;
101
 
        }
102
 
}
103
 
 
104
 
INT64_T chirp_local_open( const char *path, INT64_T flags, INT64_T mode )
105
 
{
106
 
        mode = 0600 | (mode&0100);
107
 
        return open64(path,flags,(int)mode);
108
 
}
109
 
 
110
 
INT64_T chirp_local_close( int fd )
 
84
INT64_T chirp_local_file_size(const char *path)
 
85
{
 
86
        struct chirp_stat info;
 
87
        if(chirp_local_stat(path, &info) == 0) {
 
88
                return info.cst_size;
 
89
        } else {
 
90
                return -1;
 
91
        }
 
92
}
 
93
 
 
94
INT64_T chirp_local_fd_size(int fd)
 
95
{
 
96
        struct chirp_stat info;
 
97
        if(chirp_local_fstat(fd, &info) == 0) {
 
98
                return info.cst_size;
 
99
        } else {
 
100
                return -1;
 
101
        }
 
102
}
 
103
 
 
104
INT64_T chirp_local_open(const char *path, INT64_T flags, INT64_T mode)
 
105
{
 
106
        mode = 0600 | (mode & 0100);
 
107
        return open64(path, flags, (int) mode);
 
108
}
 
109
 
 
110
INT64_T chirp_local_close(int fd)
111
111
{
112
112
        return close(fd);
113
113
}
114
114
 
115
 
INT64_T chirp_local_pread( int fd, void *buffer, INT64_T length, INT64_T offset )
 
115
INT64_T chirp_local_pread(int fd, void *buffer, INT64_T length, INT64_T offset)
116
116
{
117
117
        INT64_T result;
118
 
        result = full_pread64(fd,buffer,length,offset);
119
 
        if(result<0 && errno==ESPIPE) {
 
118
        result = full_pread64(fd, buffer, length, offset);
 
119
        if(result < 0 && errno == ESPIPE) {
120
120
                /* if this is a pipe, return whatever amount is available */
121
 
                result = read(fd,buffer,length);
 
121
                result = read(fd, buffer, length);
122
122
        }
123
123
        return result;
124
124
}
125
125
 
126
 
INT64_T chirp_local_sread( int fd, void *vbuffer, INT64_T length, INT64_T stride_length, INT64_T stride_skip, INT64_T offset )
 
126
INT64_T chirp_local_sread(int fd, void *vbuffer, INT64_T length, INT64_T stride_length, INT64_T stride_skip, INT64_T offset)
127
127
{
128
128
        INT64_T total = 0;
129
129
        INT64_T actual = 0;
130
130
        char *buffer = vbuffer;
131
131
 
132
 
        if(stride_length<0 || stride_skip<0 || offset<0) {
 
132
        if(stride_length < 0 || stride_skip < 0 || offset < 0) {
133
133
                errno = EINVAL;
134
134
                return -1;
135
135
        }
136
136
 
137
 
        while(length>=stride_length) {
138
 
                actual = chirp_local_pread(fd,&buffer[total],stride_length,offset);
139
 
                if(actual>0) {
 
137
        while(length >= stride_length) {
 
138
                actual = chirp_local_pread(fd, &buffer[total], stride_length, offset);
 
139
                if(actual > 0) {
140
140
                        length -= actual;
141
141
                        total += actual;
142
142
                        offset += stride_skip;
143
 
                        if(actual==stride_length) {
 
143
                        if(actual == stride_length) {
144
144
                                continue;
145
145
                        } else {
146
146
                                break;
150
150
                }
151
151
        }
152
152
 
153
 
        if(total>0) {
 
153
        if(total > 0) {
154
154
                return total;
155
155
        } else {
156
 
                if(actual<0) {
 
156
                if(actual < 0) {
157
157
                        return -1;
158
158
                } else {
159
159
                        return 0;
161
161
        }
162
162
}
163
163
 
164
 
INT64_T chirp_local_pwrite( int fd, const void *buffer, INT64_T length, INT64_T offset )
 
164
INT64_T chirp_local_pwrite(int fd, const void *buffer, INT64_T length, INT64_T offset)
165
165
{
166
166
        INT64_T result;
167
 
        result = full_pwrite64(fd,buffer,length,offset);
168
 
        if(result<0 && errno==ESPIPE) {
 
167
        result = full_pwrite64(fd, buffer, length, offset);
 
168
        if(result < 0 && errno == ESPIPE) {
169
169
                /* if this is a pipe, then just write without the offset. */
170
 
                result = full_write(fd,buffer,length);
 
170
                result = full_write(fd, buffer, length);
171
171
        }
172
172
        return result;
173
173
}
174
174
 
175
 
INT64_T chirp_local_swrite( int fd, const void *vbuffer, INT64_T length, INT64_T stride_length, INT64_T stride_skip, INT64_T offset )
 
175
INT64_T chirp_local_swrite(int fd, const void *vbuffer, INT64_T length, INT64_T stride_length, INT64_T stride_skip, INT64_T offset)
176
176
{
177
177
        INT64_T total = 0;
178
178
        INT64_T actual = 0;
179
179
        const char *buffer = vbuffer;
180
180
 
181
 
        if(stride_length<0 || stride_skip<0 || offset<0) {
 
181
        if(stride_length < 0 || stride_skip < 0 || offset < 0) {
182
182
                errno = EINVAL;
183
183
                return -1;
184
184
        }
185
185
 
186
 
        while(length>=stride_length) {
187
 
                actual = chirp_local_pwrite(fd,&buffer[total],stride_length,offset);
188
 
                if(actual>0) {
 
186
        while(length >= stride_length) {
 
187
                actual = chirp_local_pwrite(fd, &buffer[total], stride_length, offset);
 
188
                if(actual > 0) {
189
189
                        length -= actual;
190
190
                        total += actual;
191
191
                        offset += stride_skip;
192
 
                        if(actual==stride_length) {
 
192
                        if(actual == stride_length) {
193
193
                                continue;
194
194
                        } else {
195
195
                                break;
199
199
                }
200
200
        }
201
201
 
202
 
        if(total>0) {
 
202
        if(total > 0) {
203
203
                return total;
204
204
        } else {
205
 
                if(actual<0) {
 
205
                if(actual < 0) {
206
206
                        return -1;
207
207
                } else {
208
208
                        return 0;
210
210
        }
211
211
}
212
212
 
213
 
INT64_T chirp_local_fstat( int fd, struct chirp_stat *buf )
 
213
INT64_T chirp_local_fstat(int fd, struct chirp_stat * buf)
214
214
{
215
215
        struct stat64 info;
216
216
        int result;
217
 
        result = fstat64(fd,&info);
218
 
        if(result==0) COPY_CSTAT(info,*buf);
 
217
        result = fstat64(fd, &info);
 
218
        if(result == 0)
 
219
                COPY_CSTAT(info, *buf);
219
220
        buf->cst_mode = buf->cst_mode & (~0077);
220
 
        return result;  
 
221
        return result;
221
222
}
222
223
 
223
 
INT64_T chirp_local_fstatfs( int fd, struct chirp_statfs *buf )
 
224
INT64_T chirp_local_fstatfs(int fd, struct chirp_statfs * buf)
224
225
{
225
226
        struct statfs64 info;
226
227
        int result;
227
 
        result = fstatfs64(fd,&info);
228
 
        if(result==0) {
229
 
                memset(buf,0,sizeof(*buf));
 
228
        result = fstatfs64(fd, &info);
 
229
        if(result == 0) {
 
230
                memset(buf, 0, sizeof(*buf));
230
231
#ifdef CCTOOLS_OPSYS_SUNOS
231
232
                buf->f_type = info.f_fsid;
232
233
                buf->f_bsize = info.f_frsize;
243
244
        return result;
244
245
}
245
246
 
246
 
INT64_T chirp_local_fchown( int fd, INT64_T uid, INT64_T gid )
 
247
INT64_T chirp_local_fchown(int fd, INT64_T uid, INT64_T gid)
247
248
{
248
249
        // Changing file ownership is silently ignored,
249
250
        // because permissions are handled through the ACL model.
250
251
        return 0;
251
252
}
252
253
 
253
 
INT64_T chirp_local_fchmod( int fd, INT64_T mode )
 
254
INT64_T chirp_local_fchmod(int fd, INT64_T mode)
254
255
{
255
256
        // A remote user can change some of the permissions bits,
256
257
        // which only affect local users, but we don't let them
257
258
        // take away the owner bits, which would affect the Chirp server.
258
 
        mode = 0600 | (mode&0177);
259
 
        return fchmod(fd,mode);
 
259
        mode = 0600 | (mode & 0177);
 
260
        return fchmod(fd, mode);
260
261
}
261
262
 
262
 
INT64_T chirp_local_ftruncate( int fd, INT64_T length )
 
263
INT64_T chirp_local_ftruncate(int fd, INT64_T length)
263
264
{
264
 
        return ftruncate64(fd,length);
 
265
        return ftruncate64(fd, length);
265
266
}
266
267
 
267
 
INT64_T chirp_local_fsync( int fd )
 
268
INT64_T chirp_local_fsync(int fd)
268
269
{
269
270
        return fsync(fd);
270
271
}
271
272
 
272
 
void *  chirp_local_opendir( const char *path )
 
273
void *chirp_local_opendir(const char *path)
273
274
{
274
275
        return opendir(path);
275
276
}
276
277
 
277
 
char *  chirp_local_readdir( void *dir )
 
278
char *chirp_local_readdir(void *dir)
278
279
{
279
280
        struct dirent *d;
280
281
        d = readdir(dir);
285
286
        }
286
287
}
287
288
 
288
 
void    chirp_local_closedir( void *dir )
 
289
void chirp_local_closedir(void *dir)
289
290
{
290
291
        closedir(dir);
291
292
}
292
293
 
293
 
INT64_T chirp_local_getfile( const char *path, struct link *link, time_t stoptime )
 
294
INT64_T chirp_local_getfile(const char *path, struct link *link, time_t stoptime)
294
295
{
295
296
        int fd;
296
297
        INT64_T result;
297
298
        struct chirp_stat info;
298
 
        
299
 
        result = chirp_local_stat(path,&info);
300
 
        if(result<0) return result;
 
299
 
 
300
        result = chirp_local_stat(path, &info);
 
301
        if(result < 0)
 
302
                return result;
301
303
 
302
304
        if(S_ISDIR(info.cst_mode)) {
303
305
                errno = EISDIR;
309
311
                return -1;
310
312
        }
311
313
 
312
 
        fd = chirp_local_open(path,O_RDONLY,0);
313
 
        if(fd>=0) {
 
314
        fd = chirp_local_open(path, O_RDONLY, 0);
 
315
        if(fd >= 0) {
314
316
                INT64_T length = info.cst_size;
315
 
                link_putfstring(link,"%lld\n",stoptime,length);
316
 
                result = link_stream_from_fd(link,fd,length,stoptime);
 
317
                link_putfstring(link, "%lld\n", stoptime, length);
 
318
                result = link_stream_from_fd(link, fd, length, stoptime);
317
319
                chirp_local_close(fd);
318
320
        } else {
319
321
                result = -1;
322
324
        return result;
323
325
}
324
326
 
325
 
INT64_T chirp_local_putfile( const char *path, struct link *link, INT64_T length, INT64_T mode, time_t stoptime )
 
327
INT64_T chirp_local_putfile(const char *path, struct link * link, INT64_T length, INT64_T mode, time_t stoptime)
326
328
{
327
329
        int fd;
328
330
        INT64_T result;
329
331
 
330
 
        mode = 0600 | (mode&0100);
 
332
        mode = 0600 | (mode & 0100);
331
333
 
332
 
        fd = chirp_local_open(path,O_WRONLY|O_CREAT|O_TRUNC,(int)mode);
333
 
        if(fd>=0) {
334
 
                link_putliteral(link,"0\n",stoptime);
335
 
                result = link_stream_to_fd(link,fd,length,stoptime);
336
 
                if(result!=length) {
337
 
                        if(result>=0) link_soak(link,length-result,stoptime);
 
334
        fd = chirp_local_open(path, O_WRONLY | O_CREAT | O_TRUNC, (int) mode);
 
335
        if(fd >= 0) {
 
336
                link_putliteral(link, "0\n", stoptime);
 
337
                result = link_stream_to_fd(link, fd, length, stoptime);
 
338
                if(result != length) {
 
339
                        if(result >= 0)
 
340
                                link_soak(link, length - result, stoptime);
338
341
                        result = -1;
339
342
                }
340
343
                chirp_local_close(fd);
344
347
        return result;
345
348
}
346
349
 
347
 
INT64_T chirp_local_mkfifo( const char *path )
 
350
INT64_T chirp_local_mkfifo(const char *path)
348
351
{
349
 
        return mknod(path,0700|S_IFIFO,0);
 
352
        return mknod(path, 0700 | S_IFIFO, 0);
350
353
}
351
354
 
352
 
INT64_T chirp_local_unlink( const char *path )
 
355
INT64_T chirp_local_unlink(const char *path)
353
356
{
354
357
        int result = unlink(path);
355
358
 
356
359
        /*
357
 
        On Solaris, an unlink on a directory
358
 
        returns EPERM when it should return EISDIR.
359
 
        Check for this cast, and then fix it.
360
 
        */
 
360
           On Solaris, an unlink on a directory
 
361
           returns EPERM when it should return EISDIR.
 
362
           Check for this cast, and then fix it.
 
363
         */
361
364
 
362
 
        if(result<0 && errno==EPERM) {
 
365
        if(result < 0 && errno == EPERM) {
363
366
                struct stat64 info;
364
 
                result = stat64(path,&info);
365
 
                if(result==0 && S_ISDIR(info.st_mode)) {
 
367
                result = stat64(path, &info);
 
368
                if(result == 0 && S_ISDIR(info.st_mode)) {
366
369
                        result = -1;
367
370
                        errno = EISDIR;
368
371
                } else {
374
377
        return result;
375
378
}
376
379
 
377
 
INT64_T chirp_local_rename( const char *path, const char *newpath )
378
 
{
379
 
        return rename(path,newpath);
380
 
}
381
 
 
382
 
INT64_T chirp_local_link( const char *path, const char *newpath )
383
 
{
384
 
        return link(path,newpath);
385
 
}
386
 
 
387
 
INT64_T chirp_local_symlink( const char *path, const char *newpath )
388
 
{
389
 
        return symlink(path,newpath);
390
 
}
391
 
 
392
 
INT64_T chirp_local_readlink( const char *path, char *buf, INT64_T length )
393
 
{
394
 
        return readlink(path,buf,length);
395
 
}
396
 
 
397
 
INT64_T chirp_local_chdir( const char *path)
398
 
{
399
 
  return chdir(path);
400
 
}
401
 
 
402
 
INT64_T chirp_local_mkdir( const char *path, INT64_T mode )
403
 
{
404
 
        return mkdir(path,0700);
 
380
INT64_T chirp_local_rename(const char *path, const char *newpath)
 
381
{
 
382
        return rename(path, newpath);
 
383
}
 
384
 
 
385
INT64_T chirp_local_link(const char *path, const char *newpath)
 
386
{
 
387
        return link(path, newpath);
 
388
}
 
389
 
 
390
INT64_T chirp_local_symlink(const char *path, const char *newpath)
 
391
{
 
392
        return symlink(path, newpath);
 
393
}
 
394
 
 
395
INT64_T chirp_local_readlink(const char *path, char *buf, INT64_T length)
 
396
{
 
397
        return readlink(path, buf, length);
 
398
}
 
399
 
 
400
INT64_T chirp_local_chdir(const char *path)
 
401
{
 
402
        return chdir(path);
 
403
}
 
404
 
 
405
INT64_T chirp_local_mkdir(const char *path, INT64_T mode)
 
406
{
 
407
        return mkdir(path, 0700);
405
408
}
406
409
 
407
410
/*
411
414
Only delete the directory if it contains only those files.
412
415
*/
413
416
 
414
 
INT64_T chirp_local_rmdir( const char *path )
 
417
INT64_T chirp_local_rmdir(const char *path)
415
418
{
416
419
        void *dir;
417
420
        char *d;
419
422
 
420
423
        dir = chirp_local_opendir(path);
421
424
        if(dir) {
422
 
                while((d=chirp_local_readdir(dir))) {
423
 
                        if(!strcmp(d,".")) continue;
424
 
                        if(!strcmp(d,"..")) continue;
425
 
                        if(!strncmp(d,".__",3)) continue;
 
425
                while((d = chirp_local_readdir(dir))) {
 
426
                        if(!strcmp(d, "."))
 
427
                                continue;
 
428
                        if(!strcmp(d, ".."))
 
429
                                continue;
 
430
                        if(!strncmp(d, ".__", 3))
 
431
                                continue;
426
432
                        empty = 0;
427
433
                        break;
428
434
                }
437
443
                } else {
438
444
                        errno = ENOTEMPTY;
439
445
                        return -1;
440
 
                }               
 
446
                }
441
447
        } else {
442
448
                return -1;
443
449
        }
444
450
}
445
451
 
446
 
INT64_T chirp_local_stat( const char *path, struct chirp_stat *buf )
447
 
{
448
 
        struct stat64 info;
449
 
        int result;
450
 
        result = stat64(path,&info);
451
 
        if(result==0) COPY_CSTAT(info,*buf);
452
 
        return result;
453
 
}
454
 
 
455
 
INT64_T chirp_local_lstat( const char *path, struct chirp_stat *buf )
456
 
{
457
 
        struct stat64 info;
458
 
        int result;
459
 
        result = lstat64(path,&info);
460
 
        if(result==0) COPY_CSTAT(info,*buf);
461
 
        return result;
462
 
}
463
 
 
464
 
INT64_T chirp_local_statfs( const char *path, struct chirp_statfs *buf )
 
452
INT64_T chirp_local_stat(const char *path, struct chirp_stat * buf)
 
453
{
 
454
        struct stat64 info;
 
455
        int result;
 
456
        result = stat64(path, &info);
 
457
        if(result == 0)
 
458
                COPY_CSTAT(info, *buf);
 
459
        return result;
 
460
}
 
461
 
 
462
INT64_T chirp_local_lstat(const char *path, struct chirp_stat * buf)
 
463
{
 
464
        struct stat64 info;
 
465
        int result;
 
466
        result = lstat64(path, &info);
 
467
        if(result == 0)
 
468
                COPY_CSTAT(info, *buf);
 
469
        return result;
 
470
}
 
471
 
 
472
INT64_T chirp_local_statfs(const char *path, struct chirp_statfs * buf)
465
473
{
466
474
        struct statfs64 info;
467
475
        int result;
468
 
        result = statfs64(path,&info);
469
 
        if(result==0) {
470
 
                memset(buf,0,sizeof(*buf));
 
476
        result = statfs64(path, &info);
 
477
        if(result == 0) {
 
478
                memset(buf, 0, sizeof(*buf));
471
479
#ifdef CCTOOLS_OPSYS_SUNOS
472
480
                buf->f_type = info.f_fsid;
473
481
                buf->f_bsize = info.f_frsize;
484
492
        return result;
485
493
}
486
494
 
487
 
INT64_T chirp_local_access( const char *path, INT64_T mode )
 
495
INT64_T chirp_local_access(const char *path, INT64_T mode)
488
496
{
489
 
        return access(path,mode);
 
497
        return access(path, mode);
490
498
}
491
499
 
492
 
INT64_T chirp_local_chmod( const char *path, INT64_T mode )
 
500
INT64_T chirp_local_chmod(const char *path, INT64_T mode)
493
501
{
494
502
        struct chirp_stat info;
495
503
 
496
 
        int result = chirp_local_stat(path,&info);
497
 
        if(result<0) return result;
 
504
        int result = chirp_local_stat(path, &info);
 
505
        if(result < 0)
 
506
                return result;
498
507
 
499
508
        // A remote user can change some of the permissions bits,
500
509
        // which only affect local users, but we don't let them
502
511
 
503
512
        if(S_ISDIR(info.cst_mode)) {
504
513
                // On a directory, the user cannot set the execute bit.
505
 
                mode = 0700 | (mode&0077);
 
514
                mode = 0700 | (mode & 0077);
506
515
        } else {
507
516
                // On a file, the user can set the execute bit.
508
 
                mode = 0600 | (mode&0177);
 
517
                mode = 0600 | (mode & 0177);
509
518
        }
510
519
 
511
 
        return chmod(path,mode);
512
 
}
513
 
 
514
 
INT64_T chirp_local_chown( const char *path, INT64_T uid, INT64_T gid )
515
 
{
516
 
        // Changing file ownership is silently ignored,
517
 
        // because permissions are handled through the ACL model.
518
 
        return 0;
519
 
}
520
 
 
521
 
INT64_T chirp_local_lchown( const char *path, INT64_T uid, INT64_T gid )
522
 
{
523
 
        // Changing file ownership is silently ignored,
524
 
        // because permissions are handled through the ACL model.
525
 
        return 0;
526
 
}
527
 
 
528
 
INT64_T chirp_local_truncate( const char *path, INT64_T length )
529
 
{
530
 
        return truncate64(path,length);
531
 
}
532
 
 
533
 
INT64_T chirp_local_utime( const char *path, time_t actime, time_t modtime )
 
520
        return chmod(path, mode);
 
521
}
 
522
 
 
523
INT64_T chirp_local_chown(const char *path, INT64_T uid, INT64_T gid)
 
524
{
 
525
        // Changing file ownership is silently ignored,
 
526
        // because permissions are handled through the ACL model.
 
527
        return 0;
 
528
}
 
529
 
 
530
INT64_T chirp_local_lchown(const char *path, INT64_T uid, INT64_T gid)
 
531
{
 
532
        // Changing file ownership is silently ignored,
 
533
        // because permissions are handled through the ACL model.
 
534
        return 0;
 
535
}
 
536
 
 
537
INT64_T chirp_local_truncate(const char *path, INT64_T length)
 
538
{
 
539
        return truncate64(path, length);
 
540
}
 
541
 
 
542
INT64_T chirp_local_utime(const char *path, time_t actime, time_t modtime)
534
543
{
535
544
        struct utimbuf ut;
536
545
        ut.actime = actime;
537
546
        ut.modtime = modtime;
538
 
        return utime(path,&ut);
539
 
}
540
 
 
541
 
INT64_T chirp_local_md5( const char *path, unsigned char digest[16] )
542
 
{
543
 
        return md5_file(path,digest);
544
 
}
545
 
 
546
 
INT64_T chirp_local_init (const char *path)
547
 
{
548
 
  return 0;
549
 
}
550
 
 
551
 
INT64_T chirp_local_destroy (void)
552
 
{
553
 
  return 0;
 
547
        return utime(path, &ut);
 
548
}
 
549
 
 
550
INT64_T chirp_local_md5(const char *path, unsigned char digest[16])
 
551
{
 
552
        return md5_file(path, digest);
 
553
}
 
554
 
 
555
INT64_T chirp_local_init(const char *path)
 
556
{
 
557
        return 0;
 
558
}
 
559
 
 
560
INT64_T chirp_local_destroy(void)
 
561
{
 
562
        return 0;
554
563
}
555
564
 
556
565
struct chirp_filesystem chirp_local_fs = {
557
566
        chirp_local_init,
558
 
    chirp_local_destroy,
 
567
        chirp_local_destroy,
559
568
 
560
569
        chirp_local_open,
561
570
        chirp_local_close,