81
81
(b).cst_ctime = (a).st_ctime;
84
INT64_T chirp_local_file_size( const char *path )
86
struct chirp_stat info;
87
if(chirp_local_stat(path,&info)==0) {
94
INT64_T chirp_local_fd_size( int fd )
96
struct chirp_stat info;
97
if(chirp_local_fstat(fd,&info)==0) {
104
INT64_T chirp_local_open( const char *path, INT64_T flags, INT64_T mode )
106
mode = 0600 | (mode&0100);
107
return open64(path,flags,(int)mode);
110
INT64_T chirp_local_close( int fd )
84
INT64_T chirp_local_file_size(const char *path)
86
struct chirp_stat info;
87
if(chirp_local_stat(path, &info) == 0) {
94
INT64_T chirp_local_fd_size(int fd)
96
struct chirp_stat info;
97
if(chirp_local_fstat(fd, &info) == 0) {
104
INT64_T chirp_local_open(const char *path, INT64_T flags, INT64_T mode)
106
mode = 0600 | (mode & 0100);
107
return open64(path, flags, (int) mode);
110
INT64_T chirp_local_close(int fd)
112
112
return close(fd);
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)
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);
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)
128
128
INT64_T total = 0;
129
129
INT64_T actual = 0;
130
130
char *buffer = vbuffer;
132
if(stride_length<0 || stride_skip<0 || offset<0) {
132
if(stride_length < 0 || stride_skip < 0 || offset < 0) {
137
while(length>=stride_length) {
138
actual = chirp_local_pread(fd,&buffer[total],stride_length,offset);
137
while(length >= stride_length) {
138
actual = chirp_local_pread(fd, &buffer[total], stride_length, offset);
140
140
length -= actual;
142
142
offset += stride_skip;
143
if(actual==stride_length) {
143
if(actual == stride_length) {
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)
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);
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)
177
177
INT64_T total = 0;
178
178
INT64_T actual = 0;
179
179
const char *buffer = vbuffer;
181
if(stride_length<0 || stride_skip<0 || offset<0) {
181
if(stride_length < 0 || stride_skip < 0 || offset < 0) {
186
while(length>=stride_length) {
187
actual = chirp_local_pwrite(fd,&buffer[total],stride_length,offset);
186
while(length >= stride_length) {
187
actual = chirp_local_pwrite(fd, &buffer[total], stride_length, offset);
189
189
length -= actual;
191
191
offset += stride_skip;
192
if(actual==stride_length) {
192
if(actual == stride_length) {
213
INT64_T chirp_local_fstat( int fd, struct chirp_stat *buf )
213
INT64_T chirp_local_fstat(int fd, struct chirp_stat * buf)
215
215
struct stat64 info;
217
result = fstat64(fd,&info);
218
if(result==0) COPY_CSTAT(info,*buf);
217
result = fstat64(fd, &info);
219
COPY_CSTAT(info, *buf);
219
220
buf->cst_mode = buf->cst_mode & (~0077);
223
INT64_T chirp_local_fstatfs( int fd, struct chirp_statfs *buf )
224
INT64_T chirp_local_fstatfs(int fd, struct chirp_statfs * buf)
225
226
struct statfs64 info;
227
result = fstatfs64(fd,&info);
229
memset(buf,0,sizeof(*buf));
228
result = fstatfs64(fd, &info);
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;
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)
248
249
// Changing file ownership is silently ignored,
249
250
// because permissions are handled through the ACL model.
253
INT64_T chirp_local_fchmod( int fd, INT64_T mode )
254
INT64_T chirp_local_fchmod(int fd, INT64_T mode)
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);
262
INT64_T chirp_local_ftruncate( int fd, INT64_T length )
263
INT64_T chirp_local_ftruncate(int fd, INT64_T length)
264
return ftruncate64(fd,length);
265
return ftruncate64(fd, length);
267
INT64_T chirp_local_fsync( int fd )
268
INT64_T chirp_local_fsync(int fd)
269
270
return fsync(fd);
272
void * chirp_local_opendir( const char *path )
273
void *chirp_local_opendir(const char *path)
274
275
return opendir(path);
277
char * chirp_local_readdir( void *dir )
278
char *chirp_local_readdir(void *dir)
279
280
struct dirent *d;
280
281
d = readdir(dir);
288
void chirp_local_closedir( void *dir )
289
void chirp_local_closedir(void *dir)
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)
297
298
struct chirp_stat info;
299
result = chirp_local_stat(path,&info);
300
if(result<0) return result;
300
result = chirp_local_stat(path, &info);
302
304
if(S_ISDIR(info.cst_mode)) {
312
fd = chirp_local_open(path,O_RDONLY,0);
314
fd = chirp_local_open(path, O_RDONLY, 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);
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)
330
mode = 0600 | (mode&0100);
332
mode = 0600 | (mode & 0100);
332
fd = chirp_local_open(path,O_WRONLY|O_CREAT|O_TRUNC,(int)mode);
334
link_putliteral(link,"0\n",stoptime);
335
result = link_stream_to_fd(link,fd,length,stoptime);
337
if(result>=0) link_soak(link,length-result,stoptime);
334
fd = chirp_local_open(path, O_WRONLY | O_CREAT | O_TRUNC, (int) mode);
336
link_putliteral(link, "0\n", stoptime);
337
result = link_stream_to_fd(link, fd, length, stoptime);
338
if(result != length) {
340
link_soak(link, length - result, stoptime);
340
343
chirp_local_close(fd);
347
INT64_T chirp_local_mkfifo( const char *path )
350
INT64_T chirp_local_mkfifo(const char *path)
349
return mknod(path,0700|S_IFIFO,0);
352
return mknod(path, 0700 | S_IFIFO, 0);
352
INT64_T chirp_local_unlink( const char *path )
355
INT64_T chirp_local_unlink(const char *path)
354
357
int result = unlink(path);
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
On Solaris, an unlink on a directory
361
returns EPERM when it should return EISDIR.
362
Check for this cast, and then fix it.
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)) {
377
INT64_T chirp_local_rename( const char *path, const char *newpath )
379
return rename(path,newpath);
382
INT64_T chirp_local_link( const char *path, const char *newpath )
384
return link(path,newpath);
387
INT64_T chirp_local_symlink( const char *path, const char *newpath )
389
return symlink(path,newpath);
392
INT64_T chirp_local_readlink( const char *path, char *buf, INT64_T length )
394
return readlink(path,buf,length);
397
INT64_T chirp_local_chdir( const char *path)
402
INT64_T chirp_local_mkdir( const char *path, INT64_T mode )
404
return mkdir(path,0700);
380
INT64_T chirp_local_rename(const char *path, const char *newpath)
382
return rename(path, newpath);
385
INT64_T chirp_local_link(const char *path, const char *newpath)
387
return link(path, newpath);
390
INT64_T chirp_local_symlink(const char *path, const char *newpath)
392
return symlink(path, newpath);
395
INT64_T chirp_local_readlink(const char *path, char *buf, INT64_T length)
397
return readlink(path, buf, length);
400
INT64_T chirp_local_chdir(const char *path)
405
INT64_T chirp_local_mkdir(const char *path, INT64_T mode)
407
return mkdir(path, 0700);
420
423
dir = chirp_local_opendir(path);
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))) {
430
if(!strncmp(d, ".__", 3))
438
444
errno = ENOTEMPTY;
446
INT64_T chirp_local_stat( const char *path, struct chirp_stat *buf )
450
result = stat64(path,&info);
451
if(result==0) COPY_CSTAT(info,*buf);
455
INT64_T chirp_local_lstat( const char *path, struct chirp_stat *buf )
459
result = lstat64(path,&info);
460
if(result==0) COPY_CSTAT(info,*buf);
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)
456
result = stat64(path, &info);
458
COPY_CSTAT(info, *buf);
462
INT64_T chirp_local_lstat(const char *path, struct chirp_stat * buf)
466
result = lstat64(path, &info);
468
COPY_CSTAT(info, *buf);
472
INT64_T chirp_local_statfs(const char *path, struct chirp_statfs * buf)
466
474
struct statfs64 info;
468
result = statfs64(path,&info);
470
memset(buf,0,sizeof(*buf));
476
result = statfs64(path, &info);
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;
487
INT64_T chirp_local_access( const char *path, INT64_T mode )
495
INT64_T chirp_local_access(const char *path, INT64_T mode)
489
return access(path,mode);
497
return access(path, mode);
492
INT64_T chirp_local_chmod( const char *path, INT64_T mode )
500
INT64_T chirp_local_chmod(const char *path, INT64_T mode)
494
502
struct chirp_stat info;
496
int result = chirp_local_stat(path,&info);
497
if(result<0) return result;
504
int result = chirp_local_stat(path, &info);
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
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);
507
516
// On a file, the user can set the execute bit.
508
mode = 0600 | (mode&0177);
517
mode = 0600 | (mode & 0177);
511
return chmod(path,mode);
514
INT64_T chirp_local_chown( const char *path, INT64_T uid, INT64_T gid )
516
// Changing file ownership is silently ignored,
517
// because permissions are handled through the ACL model.
521
INT64_T chirp_local_lchown( const char *path, INT64_T uid, INT64_T gid )
523
// Changing file ownership is silently ignored,
524
// because permissions are handled through the ACL model.
528
INT64_T chirp_local_truncate( const char *path, INT64_T length )
530
return truncate64(path,length);
533
INT64_T chirp_local_utime( const char *path, time_t actime, time_t modtime )
520
return chmod(path, mode);
523
INT64_T chirp_local_chown(const char *path, INT64_T uid, INT64_T gid)
525
// Changing file ownership is silently ignored,
526
// because permissions are handled through the ACL model.
530
INT64_T chirp_local_lchown(const char *path, INT64_T uid, INT64_T gid)
532
// Changing file ownership is silently ignored,
533
// because permissions are handled through the ACL model.
537
INT64_T chirp_local_truncate(const char *path, INT64_T length)
539
return truncate64(path, length);
542
INT64_T chirp_local_utime(const char *path, time_t actime, time_t modtime)
535
544
struct utimbuf ut;
536
545
ut.actime = actime;
537
546
ut.modtime = modtime;
538
return utime(path,&ut);
541
INT64_T chirp_local_md5( const char *path, unsigned char digest[16] )
543
return md5_file(path,digest);
546
INT64_T chirp_local_init (const char *path)
551
INT64_T chirp_local_destroy (void)
547
return utime(path, &ut);
550
INT64_T chirp_local_md5(const char *path, unsigned char digest[16])
552
return md5_file(path, digest);
555
INT64_T chirp_local_init(const char *path)
560
INT64_T chirp_local_destroy(void)
556
565
struct chirp_filesystem chirp_local_fs = {
557
566
chirp_local_init,
560
569
chirp_local_open,
561
570
chirp_local_close,