/#ssh: and /#rsh: aliases, ERRNOR() macro
Этот коммит содержится в:
родитель
f931d6b5d4
Коммит
ee12728d7d
@ -1,3 +1,10 @@
|
||||
Wed Sep 18 12:51:51 1998 Pavel Machek <pavel@ucw.cz>
|
||||
|
||||
* fish.c, vfs.c: created aliases /#ssh: and /#rsh:
|
||||
|
||||
* vfs.h: created ERRNOR() macro which sets my_errno and returns,
|
||||
which makes vfs's _much_ more readable
|
||||
|
||||
Fri Sep 18 10:37:28 1998 Pavel Roskin <pavel_roskin@geocities.com)
|
||||
|
||||
* extfs.c: free() was called twice for the some place in memory
|
||||
|
22
vfs/extfs.c
22
vfs/extfs.c
@ -424,10 +424,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir
|
||||
}
|
||||
|
||||
result = do_not_open ? -1 : read_archive (fstype, archive_name, &parc);
|
||||
if (result == -1) {
|
||||
my_errno = EIO;
|
||||
return NULL;
|
||||
}
|
||||
if (result == -1) ERRNOR (EIO, NULL);
|
||||
|
||||
if (archive_name){
|
||||
v = vfs_type (archive_name);
|
||||
@ -596,10 +593,7 @@ static void *extfs_open (char *file, int flags, int mode)
|
||||
return NULL;
|
||||
if ((entry = my_resolve_symlinks (entry)) == NULL)
|
||||
return NULL;
|
||||
if (S_ISDIR (entry->inode->mode)) {
|
||||
my_errno = EISDIR;
|
||||
return NULL;
|
||||
}
|
||||
if (S_ISDIR (entry->inode->mode)) ERRNOR (EISDIR, NULL);
|
||||
if (entry->inode->local_filename == NULL) {
|
||||
char *cmd, *archive_name, *p;
|
||||
|
||||
@ -628,10 +622,7 @@ static void *extfs_open (char *file, int flags, int mode)
|
||||
}
|
||||
|
||||
local_handle = open (entry->inode->local_filename, flags, mode);
|
||||
if (local_handle == -1) {
|
||||
my_errno = EIO;
|
||||
return NULL;
|
||||
}
|
||||
if (local_handle == -1) ERRNOR (EIO, NULL);
|
||||
|
||||
extfs_info = (struct pseudofile *) xmalloc (sizeof (struct pseudofile), "Extfs: extfs_open");
|
||||
extfs_info->archive = archive;
|
||||
@ -714,11 +705,8 @@ static int extfs_close (void *data)
|
||||
}
|
||||
|
||||
free (data);
|
||||
if (errno_code){
|
||||
my_errno = EIO; /* Non standard, but who cares? */
|
||||
return -1;
|
||||
} else
|
||||
return 0;
|
||||
if (errno_code) ERRNOR (EIO, -1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define RECORDSIZE 512
|
||||
|
54
vfs/fish.c
54
vfs/fish.c
@ -107,6 +107,7 @@ static void free_bucket (void *data);
|
||||
static void connection_destructor(void *data);
|
||||
static void flush_all_directory(struct connection *bucket);
|
||||
static int get_line (int sock, char *buf, int buf_len, char term);
|
||||
static char *get_path (struct connection **bucket, char *path);
|
||||
|
||||
static char *my_get_host_and_username (char *path, char **host, char **user, int *flags, char **pass)
|
||||
{
|
||||
@ -239,10 +240,7 @@ open_command_connection (char *host, char *user, int flags, char *netrcpass)
|
||||
bucket = xmalloc(sizeof(struct connection),
|
||||
"struct connection");
|
||||
|
||||
if (bucket == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
if (bucket == NULL) ERRNOR (ENOMEM, NULL);
|
||||
|
||||
qhost(bucket) = strdup (host);
|
||||
quser(bucket) = strdup (user);
|
||||
@ -353,9 +351,8 @@ open_link (char *host, char *user, int flags, char *netrcpass)
|
||||
if (bucket == NULL)
|
||||
return NULL;
|
||||
if (!linklist_insert(connections_list, bucket)) {
|
||||
my_errno = ENOMEM;
|
||||
connection_destructor(bucket);
|
||||
return NULL;
|
||||
ERRNOR (ENOMEM, NULL);
|
||||
}
|
||||
return bucket;
|
||||
}
|
||||
@ -365,8 +362,7 @@ static char *fish_get_current_directory(struct connection *bucket)
|
||||
{
|
||||
if (command(bucket, WANT_STRING, "#PWD\npwd; echo '### 200'\n") == COMPLETE)
|
||||
return copy_strings(reply_str, "/", NULL);
|
||||
my_errno = EIO;
|
||||
return NULL;
|
||||
ERRNOR (EIO, NULL);
|
||||
}
|
||||
|
||||
#define X "fish"
|
||||
@ -378,6 +374,20 @@ static char *fish_get_current_directory(struct connection *bucket)
|
||||
#define X_done fish_done
|
||||
#include "shared_ftp_fish.c"
|
||||
|
||||
static char*
|
||||
get_path (struct connection **bucket, char *path)
|
||||
{
|
||||
char *res;
|
||||
if (res = s_get_path (bucket, path, "/#sh:"))
|
||||
return res;
|
||||
if (res = s_get_path (bucket, path, "/#ssh:"))
|
||||
return res;
|
||||
if (res = s_get_path (bucket, path, "/#rsh:")) {
|
||||
qflags((*bucket)) |= FISH_FLAG_RSH;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the 'new' code
|
||||
*/
|
||||
@ -612,10 +622,8 @@ store_file(struct direntry *fe)
|
||||
}
|
||||
disable_interrupt_key();
|
||||
close(local_handle);
|
||||
if (get_reply (qsockr(fe->bucket), NULL, 0) != COMPLETE) {
|
||||
my_errno = EIO;
|
||||
return 0;
|
||||
}
|
||||
if (get_reply (qsockr(fe->bucket), NULL, 0) != COMPLETE)
|
||||
ERRNOR (EIO, 0);
|
||||
return (!was_error);
|
||||
error_return:
|
||||
disable_interrupt_key();
|
||||
@ -650,17 +658,12 @@ fish_abort (struct connection *bucket)
|
||||
|
||||
static int retrieve_file_start(struct direntry *fe)
|
||||
{
|
||||
if (fe->local_filename == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
if (fe->local_filename == NULL)
|
||||
ERRNOR (ENOMEM, 0);
|
||||
if (command(fe->bucket, WANT_STRING,
|
||||
"#RETR %s\nls -l %s | ( read var1 var2 var3 var4 var5 var6; echo $var5 ); echo '### 100'; cat %s; echo '### 200'\n",
|
||||
fe->remote_filename, fe->remote_filename, fe->remote_filename )
|
||||
!= PRELIM) {
|
||||
my_errno = EPERM;
|
||||
return 0;
|
||||
}
|
||||
!= PRELIM) ERRNOR (EPERM, 0);
|
||||
|
||||
remotestat_size = atoi(reply_str);
|
||||
|
||||
@ -675,12 +678,11 @@ static int retrieve_file_start2(struct direntry *fe)
|
||||
remotelocal_handle = open(fe->local_filename, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600);
|
||||
if (remotelocal_handle == -1) {
|
||||
fish_abort(remoteent->bucket);
|
||||
my_errno = EIO;
|
||||
free(remotebuffer);
|
||||
free(fe->local_filename);
|
||||
fe->local_filename = NULL;
|
||||
fe->local_is_temp = 1;
|
||||
return 0;
|
||||
ERRNOR (EIO, 0);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -756,7 +758,6 @@ int fish_ctl (void *data, int ctlop, int arg)
|
||||
transfer_started = 0;
|
||||
fish_abort (remoteent->bucket);
|
||||
my_errno = EINTR;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -825,10 +826,7 @@ send_fish_command(struct connection *bucket, char *cmd, int flags)
|
||||
|
||||
r = command (bucket, WAIT_REPLY, cmd);
|
||||
vfs_add_noncurrent_stamps (&fish_vfs_ops, (vfsid) bucket, NULL);
|
||||
if (r != COMPLETE) {
|
||||
my_errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
if (r != COMPLETE) ERRNOR (EPERM, -1);
|
||||
if (flush_directory_cache)
|
||||
flush_all_directory(bucket);
|
||||
return 0;
|
||||
@ -879,7 +877,7 @@ int fish_##name (char *path1, char *path2) \
|
||||
return send_fish_command(bucket2, buf, OPT_FLUSH); \
|
||||
}
|
||||
|
||||
#define XTEST if (bucket1 != bucket2) { free(remote_path1); free(remote_path2); my_errno = EXDEV; return -1; }
|
||||
#define XTEST if (bucket1 != bucket2) { free(remote_path1); free(remote_path2); ERRNOR (EXDEV, -1); }
|
||||
FISH_OP(rename, XTEST, "#RENAME %s %s\nmv %s %s; echo '*** 000'" );
|
||||
FISH_OP(link, XTEST, "#LINK %s %s\nln %s %s; echo '*** 000'" );
|
||||
FISH_OP(symlink, , "#SYMLINK %s %s\nln -s %s %s; echo '*** 000'" );
|
||||
|
77
vfs/ftpfs.c
77
vfs/ftpfs.c
@ -149,6 +149,7 @@ static void free_bucket (void *data);
|
||||
static void connection_destructor(void *data);
|
||||
static void flush_all_directory(struct connection *bucket);
|
||||
static int get_line (int sock, char *buf, int buf_len, char term);
|
||||
static char *get_path (struct connection **bucket, char *path);
|
||||
|
||||
/* Extract the hostname and username from the path */
|
||||
/* path is in the form: [user@]hostname:port/remote-dir, e.g.:
|
||||
@ -276,10 +277,7 @@ static int
|
||||
changetype (struct connection *bucket, int binary)
|
||||
{
|
||||
if (binary != bucket->isbinary) {
|
||||
if (command (bucket, WAIT_REPLY, "TYPE %c", binary ? 'I' : 'A') != COMPLETE) {
|
||||
my_errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
if (command (bucket, WAIT_REPLY, "TYPE %c", binary ? 'I' : 'A') != COMPLETE) ERRNOR (EIO, -1);
|
||||
bucket->isbinary = binary;
|
||||
}
|
||||
return binary;
|
||||
@ -313,10 +311,7 @@ login_server (struct connection *bucket, char *netrcpass)
|
||||
" ", NULL);
|
||||
op = vfs_get_password (p);
|
||||
free (p);
|
||||
if (op == NULL) {
|
||||
my_errno = EPERM;
|
||||
return 0;
|
||||
}
|
||||
if (op == NULL) ERRNOR (EPERM, 0);
|
||||
bucket->password = strdup (op);
|
||||
} else
|
||||
op = strdup (bucket->password);
|
||||
@ -348,10 +343,9 @@ login_server (struct connection *bucket, char *netrcpass)
|
||||
proxypass = vfs_get_password (p);
|
||||
free(p);
|
||||
if (proxypass == NULL) {
|
||||
my_errno = EPERM;
|
||||
wipe_password (pass);
|
||||
free (proxyname);
|
||||
return 0;
|
||||
ERRNOR (EPERM, 0);
|
||||
}
|
||||
name = strdup(quser (bucket));
|
||||
#else
|
||||
@ -681,10 +675,7 @@ open_command_connection (char *host, char *user, int port, char *netrcpass)
|
||||
bucket = xmalloc(sizeof(struct connection),
|
||||
"struct connection");
|
||||
|
||||
if (bucket == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
if (bucket == NULL) ERRNOR (ENOMEM, NULL);
|
||||
#ifdef HAVE_MAD
|
||||
{
|
||||
extern void *watch_free_pointer;
|
||||
@ -864,10 +855,7 @@ static char *ftpfs_get_current_directory(struct connection *bucket)
|
||||
*bufq = 0;
|
||||
}
|
||||
return strdup (bufp);
|
||||
} else {
|
||||
my_errno = EIO;
|
||||
return NULL;
|
||||
}
|
||||
} else ERRNOR (EIO, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -922,15 +910,9 @@ initconn (struct connection *bucket)
|
||||
data_addr.sin_port = 0;
|
||||
|
||||
pe = getprotobyname("tcp");
|
||||
if (pe == NULL) {
|
||||
my_errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
if (pe == NULL) ERRNOR (EIO, -1);
|
||||
data = socket (AF_INET, SOCK_STREAM, pe->p_proto);
|
||||
if (data < 0) {
|
||||
my_errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
if (data < 0) ERRNOR (EIO, -1);
|
||||
|
||||
#ifdef ORIGINAL_CONNECT_CODE
|
||||
if (bucket->use_source_route){
|
||||
@ -994,10 +976,7 @@ open_data_connection (struct connection *bucket, char *cmd, char *remote,
|
||||
j = command (bucket, WAIT_REPLY, "%s %s", cmd, remote);
|
||||
else
|
||||
j = command (bucket, WAIT_REPLY, "%s", cmd);
|
||||
if (j != PRELIM) {
|
||||
my_errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
if (j != PRELIM) ERRNOR (EPERM, -1);
|
||||
enable_interrupt_key();
|
||||
if (bucket->use_passive_connection)
|
||||
data = s;
|
||||
@ -1112,6 +1091,13 @@ resolve_symlink(struct connection *bucket, struct dir *dir)
|
||||
#define X_done ftpfs_done
|
||||
#include "shared_ftp_fish.c"
|
||||
|
||||
static char*
|
||||
get_path (struct connection **bucket, char *path)
|
||||
{
|
||||
return s_get_path (bucket, path, "/#ftp:");
|
||||
}
|
||||
|
||||
|
||||
static struct dir *
|
||||
retrieve_dir(struct connection *bucket, char *remote_path, int resolve_symlinks)
|
||||
{
|
||||
@ -1162,11 +1148,7 @@ retrieve_dir(struct connection *bucket, char *remote_path, int resolve_symlinks)
|
||||
}
|
||||
|
||||
file_list = linklist_init();
|
||||
if (file_list == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
print_vfs_message("ftpfs: couldn't get a file listing");
|
||||
return NULL;
|
||||
}
|
||||
if (file_list == NULL) ERRNOR (ENOMEM, NULL);
|
||||
dcache = xmalloc(sizeof(struct dir),
|
||||
"struct dir");
|
||||
if (dcache == NULL) {
|
||||
@ -1326,10 +1308,7 @@ store_file(struct direntry *fe)
|
||||
|
||||
local_handle = open(fe->local_filename, O_RDONLY);
|
||||
unlink (fe->local_filename);
|
||||
if (local_handle == -1) {
|
||||
my_errno = EIO;
|
||||
return 0;
|
||||
}
|
||||
if (local_handle == -1) ERRNOR (EIO, 0);
|
||||
fstat(local_handle, &s);
|
||||
sock = open_data_connection(fe->bucket, "STOR", fe->remote_filename, TYPE_BINARY);
|
||||
if (sock < 0) {
|
||||
@ -1380,10 +1359,7 @@ store_file(struct direntry *fe)
|
||||
disable_interrupt_key();
|
||||
close(sock);
|
||||
close(local_handle);
|
||||
if (get_reply (qsock (fe->bucket), NULL, 0) != COMPLETE) {
|
||||
my_errno = EIO;
|
||||
return 0;
|
||||
}
|
||||
if (get_reply (qsock (fe->bucket), NULL, 0) != COMPLETE) ERRNOR (EIO, 0);
|
||||
return 1;
|
||||
error_return:
|
||||
disable_interrupt_key();
|
||||
@ -1398,10 +1374,7 @@ static int remotelocal_handle, remotesock, remoten, remotestat_size;
|
||||
|
||||
static int retrieve_file_start(struct direntry *fe)
|
||||
{
|
||||
if (fe->local_filename == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
if (fe->local_filename == NULL) ERRNOR (ENOMEM, 0);
|
||||
remotesock = open_data_connection(fe->bucket, "RETR", fe->remote_filename, TYPE_BINARY);
|
||||
if (remotesock == -1) {
|
||||
my_errno = EACCES;
|
||||
@ -1515,10 +1488,7 @@ static int retrieve_file(struct direntry *fe)
|
||||
fe->local_stat.st_mtime = 0;
|
||||
fe->local_filename = tempnam (NULL, "ftpfs");
|
||||
fe->local_is_temp = 1;
|
||||
if (fe->local_filename == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
if (fe->local_filename == NULL) ERRNOR (ENOMEM, 0);
|
||||
local_handle = open(fe->local_filename, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600);
|
||||
if (local_handle == -1) {
|
||||
my_errno = EIO;
|
||||
@ -1622,10 +1592,7 @@ send_ftp_command(char *filename, char *cmd, int flags)
|
||||
vfs_add_noncurrent_stamps (&ftpfs_vfs_ops, (vfsid) bucket, NULL);
|
||||
if (flags & OPT_IGNORE_ERROR)
|
||||
r = COMPLETE;
|
||||
if (r != COMPLETE) {
|
||||
my_errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
if (r != COMPLETE) ERRNOR (EPERM, -1);
|
||||
if (flush_directory_cache)
|
||||
flush_all_directory(bucket);
|
||||
return 0;
|
||||
|
@ -192,21 +192,23 @@ void X_fill_names (void (*func)(char *))
|
||||
/* get_path:
|
||||
* makes BUCKET point to the connection bucket descriptor for PATH
|
||||
* returns a malloced string with the pathname relative to BUCKET.
|
||||
*
|
||||
* path must _not_ contain initial /bla/#ftp:
|
||||
*/
|
||||
static char*
|
||||
get_path (struct connection **bucket, char *path)
|
||||
s_get_path (struct connection **bucket, char *path, char *name)
|
||||
{
|
||||
char *user, *host, *remote_path, *pass;
|
||||
int port;
|
||||
|
||||
#ifndef BROKEN_PATHS
|
||||
if (strncmp (path, X_myname, strlen (X_myname)))
|
||||
if (strncmp (path, name, strlen (name)))
|
||||
return NULL; /* Normal: consider cd /bla/#ftp */
|
||||
#else
|
||||
if (!(path = strstr (path, X_myname)))
|
||||
if (!(path = strstr (path, name)))
|
||||
return NULL;
|
||||
#endif
|
||||
path += strlen (X_myname);
|
||||
path += strlen (name);
|
||||
|
||||
if (!(remote_path = my_get_host_and_username (path, &host, &user, &port, &pass)))
|
||||
my_errno = ENOENT;
|
||||
@ -296,14 +298,8 @@ _get_file_entry(struct connection *bucket, char *file_name,
|
||||
ent = lptr->data;
|
||||
if (strcmp(p, ent->name) == 0) {
|
||||
if (S_ISLNK(ent->s.st_mode) && (op & DO_RESOLVE_SYMLINK)) {
|
||||
if (ent->l_stat == NULL) {
|
||||
my_errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
if (S_ISLNK(ent->l_stat->st_mode)) {
|
||||
my_errno = ELOOP;
|
||||
return NULL;
|
||||
}
|
||||
if (ent->l_stat == NULL) ERRNOR (ENOENT, NULL);
|
||||
if (S_ISLNK(ent->l_stat->st_mode)) ERRNOR (ELOOP, NULL);
|
||||
}
|
||||
if (ent && (op & DO_OPEN)) {
|
||||
mode_t fmode;
|
||||
@ -311,24 +307,12 @@ _get_file_entry(struct connection *bucket, char *file_name,
|
||||
fmode = S_ISLNK(ent->s.st_mode)
|
||||
? ent->l_stat->st_mode
|
||||
: ent->s.st_mode;
|
||||
if (S_ISDIR(fmode)) {
|
||||
my_errno = EISDIR;
|
||||
return NULL;
|
||||
}
|
||||
if (!S_ISREG(fmode)) {
|
||||
my_errno = EPERM;
|
||||
return NULL;
|
||||
}
|
||||
if ((flags & O_EXCL) && (flags & O_CREAT)) {
|
||||
my_errno = EEXIST;
|
||||
return NULL;
|
||||
}
|
||||
if (S_ISDIR(fmode)) ERRNOR (EISDIR, NULL);
|
||||
if (!S_ISREG(fmode)) ERRNOR (EPERM, NULL);
|
||||
if ((flags & O_EXCL) && (flags & O_CREAT)) ERRNOR (EEXIST, NULL);
|
||||
if (ent->remote_filename == NULL) {
|
||||
ent->remote_filename = strdup(file_name);
|
||||
if (ent->remote_filename == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
if (ent->remote_filename == NULL) ERRNOR (ENOMEM, NULL);
|
||||
}
|
||||
if (ent->local_filename == NULL ||
|
||||
!ent->local_stat.st_mtime ||
|
||||
@ -342,15 +326,9 @@ _get_file_entry(struct connection *bucket, char *file_name,
|
||||
}
|
||||
if (flags & O_TRUNC) {
|
||||
ent->local_filename = tempnam (NULL, X "fs");
|
||||
if (ent->local_filename == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
if (ent->local_filename == NULL) ERRNOR (ENOMEM, NULL);
|
||||
handle = open(ent->local_filename, O_CREAT | O_TRUNC | O_RDWR | O_EXCL, 0600);
|
||||
if (handle < 0) {
|
||||
my_errno = EIO;
|
||||
return NULL;
|
||||
}
|
||||
if (handle < 0) ERRNOR (EIO, NULL);
|
||||
close(handle);
|
||||
if (stat (ent->local_filename, &ent->local_stat) < 0)
|
||||
ent->local_stat.st_mtime = 0;
|
||||
@ -384,10 +362,7 @@ _get_file_entry(struct connection *bucket, char *file_name,
|
||||
ent = xmalloc(sizeof(struct direntry), "struct direntry");
|
||||
ent->freshly_created = 0;
|
||||
ent->tmp_reget = 0;
|
||||
if (ent == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
if (ent == NULL) ERRNOR (ENOMEM, NULL);
|
||||
ent->count = 1;
|
||||
ent->linkname = NULL;
|
||||
ent->l_stat = NULL;
|
||||
@ -397,14 +372,12 @@ _get_file_entry(struct connection *bucket, char *file_name,
|
||||
ent->local_filename = tempnam (NULL, X "fs");
|
||||
if (!ent->name && !ent->remote_filename && !ent->local_filename) {
|
||||
direntry_destructor(ent);
|
||||
my_errno = ENOMEM;
|
||||
return NULL;
|
||||
ERRNOR (ENOMEM, NULL);
|
||||
}
|
||||
handle = creat(ent->local_filename, 0700);
|
||||
if (handle == -1) {
|
||||
my_errno = EIO;
|
||||
direntry_destructor(ent);
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
fstat(handle, &ent->s);
|
||||
close(handle);
|
||||
@ -412,24 +385,20 @@ _get_file_entry(struct connection *bucket, char *file_name,
|
||||
/* This is very wrong - like this a zero length file will be always created
|
||||
and usually preclude uploading anything more desirable */
|
||||
#if defined(UPLOAD_ZERO_LENGTH_FILE)
|
||||
if (!store_file(ent)) {
|
||||
direntry_destructor(ent);
|
||||
return NULL;
|
||||
}
|
||||
if (!store_file(ent)) goto error;
|
||||
#endif
|
||||
#endif
|
||||
if (!linklist_insert(file_list, ent)) {
|
||||
my_errno = ENOMEM;
|
||||
direntry_destructor(ent);
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
ent->freshly_created = 1;
|
||||
return ent;
|
||||
}
|
||||
else {
|
||||
my_errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
else ERRNOR (ENOENT, NULL);
|
||||
error:
|
||||
direntry_destructor(ent);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -519,10 +488,7 @@ static void *s_open (char *file, int flags, int mode)
|
||||
struct direntry *fe;
|
||||
|
||||
fp = xmalloc(sizeof(struct filp), "struct filp");
|
||||
if (fp == NULL) {
|
||||
my_errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
if (fp == NULL) ERRNOR (ENOMEM, NULL);
|
||||
fe = get_file_entry(file, DO_OPEN | DO_RESOLVE_SYMLINK, flags);
|
||||
if (fe == NULL) {
|
||||
free(fp);
|
||||
@ -739,18 +705,9 @@ static int s_readlink (char *path, char *buf, int size)
|
||||
fe = get_file_entry(path, DO_FREE_RESOURCE, 0);
|
||||
if (!fe)
|
||||
return -1;
|
||||
if (!S_ISLNK(fe->s.st_mode)) {
|
||||
my_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (fe->linkname == NULL) {
|
||||
my_errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
if (strlen(fe->linkname) >= size) {
|
||||
my_errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
if (!S_ISLNK(fe->s.st_mode)) ERRNOR (EINVAL, -1);
|
||||
if (fe->linkname == NULL) ERRNOR (EACCES, -1);
|
||||
if (strlen(fe->linkname) >= size) ERRNOR (ERANGE, -1);
|
||||
strncpy(buf, fe->linkname, size);
|
||||
return strlen(fe->linkname);
|
||||
}
|
||||
|
@ -127,10 +127,7 @@ static void * s_opendir (char *dirname)
|
||||
return NULL;
|
||||
if ((entry = my_resolve_symlinks (entry)) == NULL)
|
||||
return NULL;
|
||||
if (!S_ISDIR (entry->inode->mode)) {
|
||||
my_errno = ENOTDIR;
|
||||
return NULL;
|
||||
}
|
||||
if (!S_ISDIR (entry->inode->mode)) ERRNOR (ENOTDIR, NULL);
|
||||
|
||||
info = (struct entry **) xmalloc (2*sizeof (struct entry *), "shared opendir");
|
||||
info[0] = entry->inode->first_in_subdir;
|
||||
@ -270,10 +267,7 @@ static int s_readlink (char *path, char *buf, int size)
|
||||
entry = find_entry (archive->root_entry, q, 0, 0);
|
||||
if (entry == NULL)
|
||||
return -1;
|
||||
if (!S_ISLNK (entry->inode->mode)) {
|
||||
my_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (!S_ISLNK (entry->inode->mode)) ERRNOR (EINVAL, -1);
|
||||
if (size > (i = strlen (entry->inode->linkname))) {
|
||||
size = i;
|
||||
}
|
||||
|
26
vfs/tar.c
26
vfs/tar.c
@ -811,10 +811,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir
|
||||
result = -1;
|
||||
else
|
||||
result = read_tar_archive (archive_name, &parc);
|
||||
if (result == -1) {
|
||||
my_errno = EIO;
|
||||
return NULL;
|
||||
}
|
||||
if (result == -1) ERRNOR (EIO, NULL);
|
||||
v = vfs_type (archive_name);
|
||||
if (v == &local_vfs_ops) {
|
||||
parent = NULL;
|
||||
@ -908,14 +905,8 @@ static void *tar_open (char *file, int flags, int mode)
|
||||
return NULL;
|
||||
if ((entry = my_resolve_symlinks (entry)) == NULL)
|
||||
return NULL;
|
||||
if (S_ISDIR (entry->inode->mode)) {
|
||||
my_errno = EISDIR;
|
||||
return NULL;
|
||||
}
|
||||
if ((flags & O_ACCMODE) != O_RDONLY) {
|
||||
my_errno = EROFS; /* At the moment we are RO */
|
||||
return NULL;
|
||||
}
|
||||
if (S_ISDIR (entry->inode->mode)) ERRNOR (EISDIR, NULL);
|
||||
if ((flags & O_ACCMODE) != O_RDONLY) ERRNOR (EROFS, NULL);
|
||||
|
||||
tar_info = (struct pseudofile *) xmalloc (sizeof (struct pseudofile), "Tar: tar_open");
|
||||
tar_info->archive = archive;
|
||||
@ -937,10 +928,8 @@ static int tar_read (void *data, char *buffer, int count)
|
||||
|
||||
if (file->archive->is_gzipped != targz_growing &&
|
||||
mc_lseek (file->archive->fd, file->begin + file->pos, SEEK_SET) !=
|
||||
file->begin + file->pos) {
|
||||
my_errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
file->begin + file->pos) ERRNOR (EIO, -1);
|
||||
|
||||
|
||||
if (count > file->end - file->begin - file->pos)
|
||||
count = file->end - file->begin - file->pos;
|
||||
@ -971,10 +960,7 @@ static int tar_read (void *data, char *buffer, int count)
|
||||
cnt -= j;
|
||||
}
|
||||
}
|
||||
else if ((count = mc_read (file->archive->fd, buffer, count)) == -1) {
|
||||
my_errno = errno;
|
||||
return -1;
|
||||
}
|
||||
else if ((count = mc_read (file->archive->fd, buffer, count)) == -1) ERRNOR (errno, -1);
|
||||
file->pos += count;
|
||||
return count;
|
||||
}
|
||||
|
@ -116,6 +116,10 @@ vfs *vfs_type_from_op (char *path)
|
||||
#endif
|
||||
if (!(vfs_flags & FL_NO_FISH) && !strncmp (path, "sh:", 3))
|
||||
return &fish_vfs_ops;
|
||||
if (!(vfs_flags & FL_NO_FISH) && !strncmp (path, "ssh:", 4))
|
||||
return &fish_vfs_ops;
|
||||
if (!(vfs_flags & FL_NO_FISH) && !strncmp (path, "rsh:", 4))
|
||||
return &fish_vfs_ops;
|
||||
if (!(vfs_flags & FL_NO_TARFS) && !strcmp (path, "utar"))
|
||||
return &tarfs_vfs_ops;
|
||||
if (!(vfs_flags & FL_NO_EXTFS) && extfs_which (path) != -1)
|
||||
|
36
vfs/vfs.h
36
vfs/vfs.h
@ -298,21 +298,17 @@ extern char *vfs_get_password (char *msg);
|
||||
#define MCCTL_ISREMOTECOPY 1
|
||||
#define MCCTL_REMOTECOPYCHUNK 2
|
||||
#define MCCTL_FINISHREMOTE 3
|
||||
#define MCCTL_FLUSHDIR 4
|
||||
#define MCCTL_FLUSHDIR 4 /* Unreferenced */
|
||||
#define MCCTL_REMOVELOCALCOPY 5
|
||||
#define MCCTL_IS_NOTREADY 6
|
||||
|
||||
/* Return codes from the ${fs}_ctl routine */
|
||||
|
||||
#define MCERR_TARGETOPEN -1
|
||||
/* Can't open target file */
|
||||
#define MCERR_READ -2
|
||||
/* Read error on source file */
|
||||
#define MCERR_WRITE -3
|
||||
/* Write error on target file */
|
||||
#define MCERR_FINISH -4
|
||||
/* Finished transfer */
|
||||
#define MCERR_DATA_ON_STDIN -5
|
||||
/* Data waiting on stdin to be processed */
|
||||
#define MCERR_TARGETOPEN -1 /* Can't open target file */
|
||||
#define MCERR_READ -2 /* Read error on source file */
|
||||
#define MCERR_WRITE -3 /* Write error on target file */
|
||||
#define MCERR_FINISH -4 /* Finished transfer */
|
||||
#define MCERR_DATA_ON_STDIN -5 /* Data waiting on stdin to be processed */
|
||||
|
||||
extern int vfs_flags;
|
||||
extern uid_t vfs_uid;
|
||||
@ -334,5 +330,21 @@ extern void mc_vfs_init( void );
|
||||
extern void mc_vfs_done( void );
|
||||
#endif
|
||||
|
||||
#endif /* __VFS_H */
|
||||
#define ERRNOR(x,y) do { my_errno = x; return y; } while(0)
|
||||
|
||||
#define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
|
||||
/* Midnight commander code should _not_ use other flags than those
|
||||
listed above and O_APPEND */
|
||||
|
||||
#if (O_ALL & O_APPEND)
|
||||
#warning Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz
|
||||
#define O_LINEAR 0
|
||||
#define IS_LINEAR(a) 0
|
||||
#define NO_LINEAR(a) a
|
||||
#else
|
||||
#define O_LINEAR O_APPEND
|
||||
#define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR))
|
||||
#define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
|
||||
#endif
|
||||
|
||||
#endif /* __VFS_H */
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user