* vfs.h: Constify some arguments for many functions.

* xdirentry.h: Likewise.  Adjust all dependencies.
This commit is contained in:
Pavel Roskin 2003-10-28 02:10:33 +00:00
parent 5bc20fd294
commit 7d16d65e35
15 changed files with 245 additions and 189 deletions

View File

@ -1,5 +1,8 @@
2003-10-27 Pavel Roskin <proski@gnu.org> 2003-10-27 Pavel Roskin <proski@gnu.org>
* vfs.h: Constify some arguments for many functions.
* xdirentry.h: Likewise. Adjust all dependencies.
* *.c: Rename functions that don't have an a prefix indicating * *.c: Rename functions that don't have an a prefix indicating
what file they are defined in. This simplifies debugging. what file they are defined in. This simplifies debugging.

View File

@ -129,42 +129,44 @@ static void cpio_free_archive(struct vfs_class *me, struct vfs_s_super *super)
mc_close(super->u.arch.fd); mc_close(super->u.arch.fd);
} }
static int cpio_open_cpio_file(struct vfs_class *me, struct vfs_s_super *super, char *name) static int
cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super,
const char *name)
{ {
int fd, type; int fd, type;
mode_t mode; mode_t mode;
struct vfs_s_inode *root; struct vfs_s_inode *root;
if((fd = mc_open(name, O_RDONLY)) == -1) { if ((fd = mc_open (name, O_RDONLY)) == -1) {
message (1, MSG_ERROR, _("Cannot open cpio archive\n%s"), name); message (1, MSG_ERROR, _("Cannot open cpio archive\n%s"), name);
return -1; return -1;
} }
super->name = g_strdup(name); super->name = g_strdup (name);
super->u.arch.fd = -1; /* for now */ super->u.arch.fd = -1; /* for now */
mc_stat(name, &(super->u.arch.st)); mc_stat (name, &(super->u.arch.st));
super->u.arch.type = CPIO_UNKNOWN; super->u.arch.type = CPIO_UNKNOWN;
type = get_compression_type(fd); type = get_compression_type (fd);
if (type != COMPRESSION_NONE) { if (type != COMPRESSION_NONE) {
char *s; char *s;
mc_close(fd); mc_close (fd);
s = g_strconcat(name, decompress_extension(type), NULL); s = g_strconcat (name, decompress_extension (type), NULL);
if((fd = mc_open(s, O_RDONLY)) == -1) { if ((fd = mc_open (s, O_RDONLY)) == -1) {
message (1, MSG_ERROR, _("Cannot open cpio archive\n%s"), s); message (1, MSG_ERROR, _("Cannot open cpio archive\n%s"), s);
g_free(s); g_free (s);
return -1; return -1;
} }
g_free(s); g_free (s);
} }
super->u.arch.fd = fd; super->u.arch.fd = fd;
mode = super->u.arch.st.st_mode & 07777; mode = super->u.arch.st.st_mode & 07777;
mode |= (mode & 0444) >> 2; /* set eXec where Read is */ mode |= (mode & 0444) >> 2; /* set eXec where Read is */
mode |= S_IFDIR; mode |= S_IFDIR;
root = vfs_s_new_inode(me, super, &(super->u.arch.st)); root = vfs_s_new_inode (me, super, &(super->u.arch.st));
root->st.st_mode = mode; root->st.st_mode = mode;
root->data_offset = -1; root->data_offset = -1;
root->st.st_nlink++; root->st.st_nlink++;
@ -172,7 +174,7 @@ static int cpio_open_cpio_file(struct vfs_class *me, struct vfs_s_super *super,
super->root = root; super->root = root;
CPIO_SEEK_SET(super, 0); CPIO_SEEK_SET (super, 0);
return fd; return fd;
} }
@ -505,17 +507,19 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
/* Need to CPIO_SEEK_CUR to skip the file at the end of add entry!!!! */ /* Need to CPIO_SEEK_CUR to skip the file at the end of add entry!!!! */
static int cpio_open_archive(struct vfs_class *me, struct vfs_s_super *super, char *name, char *op) static int
cpio_open_archive (struct vfs_class *me, struct vfs_s_super *super,
const char *name, char *op)
{ {
int status = STATUS_START; int status = STATUS_START;
if(cpio_open_cpio_file(me, super, name) == -1) if (cpio_open_cpio_file (me, super, name) == -1)
return -1; return -1;
for(;;) { for (;;) {
status = cpio_read_head(me, super); status = cpio_read_head (me, super);
switch(status) { switch (status) {
case STATUS_EOF: case STATUS_EOF:
message (1, MSG_ERROR, _("Unexpected end of file\n%s"), name); message (1, MSG_ERROR, _("Unexpected end of file\n%s"), name);
return 0; return 0;
@ -531,17 +535,18 @@ static int cpio_open_archive(struct vfs_class *me, struct vfs_s_super *super, ch
} }
/* Remaining functions are exactly same as for tarfs (and were in fact just copied) */ /* Remaining functions are exactly same as for tarfs (and were in fact just copied) */
static void *cpio_super_check(struct vfs_class *me, char *archive_name, char *op) static void *
cpio_super_check (struct vfs_class *me, const char *archive_name, char *op)
{ {
static struct stat sb; static struct stat sb;
if(mc_stat(archive_name, &sb)) if (mc_stat (archive_name, &sb))
return NULL; return NULL;
return &sb; return &sb;
} }
static int static int
cpio_super_same (struct vfs_class *me, struct vfs_s_super *parc, char *archive_name, cpio_super_same (struct vfs_class *me, struct vfs_s_super *parc,
char *op, void *cookie) const char *archive_name, char *op, void *cookie)
{ {
struct stat *archive_stat = cookie; /* stat of main archive */ struct stat *archive_stat = cookie; /* stat of main archive */

View File

@ -420,13 +420,14 @@ vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super)
/* ------------------------------------------------------------------------= */ /* ------------------------------------------------------------------------= */
static void static void
vfs_s_stamp_me (struct vfs_class *me, struct vfs_s_super *psup, char *fs_name) vfs_s_stamp_me (struct vfs_class *me, struct vfs_s_super *psup,
const char *fs_name)
{ {
struct vfs_stamping *parent; struct vfs_stamping *parent;
struct vfs_class *v; struct vfs_class *v;
v = vfs_get_class (fs_name); v = vfs_get_class (fs_name);
if (v->flags & VFSF_LOCAL){ if (v->flags & VFSF_LOCAL) {
parent = NULL; parent = NULL;
} else { } else {
parent = g_new (struct vfs_stamping, 1); parent = g_new (struct vfs_stamping, 1);
@ -438,27 +439,33 @@ vfs_s_stamp_me (struct vfs_class *me, struct vfs_s_super *psup, char *fs_name)
} }
char * char *
vfs_s_get_path_mangle (struct vfs_class *me, char *inname, struct vfs_s_super **archive, int flags) vfs_s_get_path_mangle (struct vfs_class *me, const char *inname,
struct vfs_s_super **archive, int flags)
{ {
char *local, *op, *archive_name; char *local, *op;
const char *archive_name;
int result = -1; int result = -1;
struct vfs_s_super *super; struct vfs_s_super *super;
void *cookie = NULL; void *cookie = NULL;
archive_name = inname; archive_name = inname;
vfs_split (inname, &local, &op); vfs_split (inname, &local, &op);
if (!local) if (!local)
local = ""; local = "";
if (MEDATA->archive_check) if (MEDATA->archive_check)
if (! (cookie = MEDATA->archive_check (me, archive_name, op))) if (!(cookie = MEDATA->archive_check (me, archive_name, op)))
return NULL; return NULL;
for (super = MEDATA->supers; super != NULL; super = super->next){ for (super = MEDATA->supers; super != NULL; super = super->next) {
int i; /* 0 == other, 1 == same, return it, 2 == other but stop scanning */ /* 0 == other, 1 == same, return it, 2 == other but stop scanning */
if ((i = MEDATA->archive_same (me, super, archive_name, op, cookie))){ int i;
if (i==1) goto return_success; if ((i =
else break; MEDATA->archive_same (me, super, archive_name, op, cookie))) {
if (i == 1)
goto return_success;
else
break;
} }
} }
@ -467,7 +474,7 @@ vfs_s_get_path_mangle (struct vfs_class *me, char *inname, struct vfs_s_super **
super = vfs_s_new_super (me); super = vfs_s_new_super (me);
result = MEDATA->open_archive (me, super, archive_name, op); result = MEDATA->open_archive (me, super, archive_name, op);
if (result == -1){ if (result == -1) {
vfs_s_free_super (me, super); vfs_s_free_super (me, super);
ERRNOR (EIO, NULL); ERRNOR (EIO, NULL);
} }
@ -479,7 +486,7 @@ vfs_s_get_path_mangle (struct vfs_class *me, char *inname, struct vfs_s_super **
vfs_s_insert_super (me, super); vfs_s_insert_super (me, super);
vfs_s_stamp_me (me, super, archive_name); vfs_s_stamp_me (me, super, archive_name);
return_success: return_success:
*archive = super; *archive = super;
return local; return local;
} }
@ -536,7 +543,7 @@ vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino)
/* ------------------------ readdir & friends ----------------------------- */ /* ------------------------ readdir & friends ----------------------------- */
static struct vfs_s_inode * static struct vfs_s_inode *
vfs_s_inode_from_path (struct vfs_class *me, char *name, int flags) vfs_s_inode_from_path (struct vfs_class *me, const char *name, int flags)
{ {
struct vfs_s_super *super; struct vfs_s_super *super;
struct vfs_s_inode *ino; struct vfs_s_inode *ino;
@ -684,7 +691,7 @@ vfs_s_readlink (struct vfs_class *me, char *path, char *buf, int size)
} }
static void * static void *
vfs_s_open (struct vfs_class *me, char *file, int flags, int mode) vfs_s_open (struct vfs_class *me, const char *file, int flags, int mode)
{ {
int was_changed = 0; int was_changed = 0;
struct vfs_s_fh *fh; struct vfs_s_fh *fh;
@ -697,7 +704,7 @@ vfs_s_open (struct vfs_class *me, char *file, int flags, int mode)
ino = vfs_s_find_inode (me, super, q, LINK_FOLLOW, FL_NONE); ino = vfs_s_find_inode (me, super, q, LINK_FOLLOW, FL_NONE);
if (ino && ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))) if (ino && ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)))
ERRNOR (EEXIST, NULL); ERRNOR (EEXIST, NULL);
if (!ino){ if (!ino) {
char *dirname, *name, *save; char *dirname, *name, *save;
struct vfs_s_entry *ent; struct vfs_s_entry *ent;
struct vfs_s_inode *dir; struct vfs_s_inode *dir;
@ -724,7 +731,7 @@ vfs_s_open (struct vfs_class *me, char *file, int flags, int mode)
if (S_ISDIR (ino->st.st_mode)) if (S_ISDIR (ino->st.st_mode))
ERRNOR (EISDIR, NULL); ERRNOR (EISDIR, NULL);
fh = g_new (struct vfs_s_fh, 1); fh = g_new (struct vfs_s_fh, 1);
fh->pos = 0; fh->pos = 0;
fh->ino = ino; fh->ino = ino;
@ -732,28 +739,29 @@ vfs_s_open (struct vfs_class *me, char *file, int flags, int mode)
fh->changed = was_changed; fh->changed = was_changed;
fh->linear = 0; fh->linear = 0;
if (IS_LINEAR(flags)) { if (IS_LINEAR (flags)) {
if (MEDATA->linear_start) { if (MEDATA->linear_start) {
print_vfs_message (_("Starting linear transfer...")); print_vfs_message (_("Starting linear transfer..."));
if (!MEDATA->linear_start (me, fh, 0)){ if (!MEDATA->linear_start (me, fh, 0)) {
g_free(fh); g_free (fh);
return NULL; return NULL;
} }
} }
} else if ((MEDATA->fh_open) && (MEDATA->fh_open (me, fh, flags, mode))){ } else if ((MEDATA->fh_open)
g_free(fh); && (MEDATA->fh_open (me, fh, flags, mode))) {
return NULL; g_free (fh);
} return NULL;
}
if (fh->ino->localname){ if (fh->ino->localname) {
fh->handle = open (fh->ino->localname, NO_LINEAR(flags), mode); fh->handle = open (fh->ino->localname, NO_LINEAR (flags), mode);
if (fh->handle == -1){ if (fh->handle == -1) {
g_free(fh); g_free (fh);
ERRNOR (errno, NULL); ERRNOR (errno, NULL);
} }
} }
/* i.e. we had no open files and now we have one */ /* i.e. we had no open files and now we have one */
vfs_rmstamp (me, (vfsid) super, 1); vfs_rmstamp (me, (vfsid) super, 1);
super->fd_usage++; super->fd_usage++;
fh->ino->st.st_nlink++; fh->ino->st.st_nlink++;
@ -959,16 +967,13 @@ vfs_s_ferrno (struct vfs_class *me)
} }
static char * static char *
vfs_s_getlocalcopy (struct vfs_class *me, char *path) vfs_s_getlocalcopy (struct vfs_class *me, const char *path)
{ {
struct vfs_s_inode *ino; struct vfs_s_inode *ino;
char buf[MC_MAXPATHLEN];
strncpy (buf, path, MC_MAXPATHLEN);
ino = vfs_s_inode_from_path (me, path, FL_FOLLOW | FL_NONE); ino = vfs_s_inode_from_path (me, path, FL_FOLLOW | FL_NONE);
if (!ino->localname) if (!ino->localname)
ino->localname = mc_def_getlocalcopy (me, buf); ino->localname = mc_def_getlocalcopy (me, path);
/* FIXME: fd_usage++ missing */ /* FIXME: fd_usage++ missing */
return g_strdup (ino->localname); return g_strdup (ino->localname);
} }

View File

@ -199,7 +199,7 @@ static void extfs_free_archive (struct archive *archive)
} }
static FILE * static FILE *
extfs_open_archive (int fstype, char *name, struct archive **pparc) extfs_open_archive (int fstype, const char *name, struct archive **pparc)
{ {
static dev_t __extfs_no = 0; static dev_t __extfs_no = 0;
FILE *result; FILE *result;
@ -242,7 +242,7 @@ extfs_open_archive (int fstype, char *name, struct archive **pparc)
current_archive = g_new (struct archive, 1); current_archive = g_new (struct archive, 1);
current_archive->fstype = fstype; current_archive->fstype = fstype;
current_archive->name = name ? g_strdup (name) : name; current_archive->name = name ? g_strdup (name) : NULL;
current_archive->local_name = local_name; current_archive->local_name = local_name;
if (local_name != NULL) if (local_name != NULL)
@ -279,16 +279,17 @@ extfs_open_archive (int fstype, char *name, struct archive **pparc)
* Return 0 on success, -1 on error. * Return 0 on success, -1 on error.
*/ */
static int static int
extfs_read_archive (int fstype, char *name, struct archive **pparc) extfs_read_archive (int fstype, const char *name, struct archive **pparc)
{ {
FILE *extfsd; FILE *extfsd;
char *buffer; char *buffer;
struct archive *current_archive; struct archive *current_archive;
char *current_file_name, *current_link_name; char *current_file_name, *current_link_name;
if ((extfsd = extfs_open_archive (fstype, name, &current_archive)) == NULL) { if ((extfsd =
extfs_open_archive (fstype, name, &current_archive)) == NULL) {
message (1, MSG_ERROR, _("Cannot open %s archive\n%s"), message (1, MSG_ERROR, _("Cannot open %s archive\n%s"),
extfs_prefixes[fstype], name); extfs_prefixes[fstype], name);
return -1; return -1;
} }
@ -320,7 +321,9 @@ extfs_read_archive (int fstype, char *name, struct archive **pparc)
if (S_ISDIR (hstat.st_mode) if (S_ISDIR (hstat.st_mode)
&& (!strcmp (p, ".") || !strcmp (p, ".."))) && (!strcmp (p, ".") || !strcmp (p, "..")))
goto read_extfs_continue; goto read_extfs_continue;
pent = extfs_find_entry (current_archive->root_entry, q, 1, 0); pent =
extfs_find_entry (current_archive->root_entry, q, 1,
0);
if (pent == NULL) { if (pent == NULL) {
/* FIXME: Should clean everything one day */ /* FIXME: Should clean everything one day */
g_free (buffer); g_free (buffer);
@ -341,7 +344,7 @@ extfs_read_archive (int fstype, char *name, struct archive **pparc)
if (!S_ISLNK (hstat.st_mode) && current_link_name != NULL) { if (!S_ISLNK (hstat.st_mode) && current_link_name != NULL) {
pent = pent =
extfs_find_entry (current_archive->root_entry, extfs_find_entry (current_archive->root_entry,
current_link_name, 0, 0); current_link_name, 0, 0);
if (pent == NULL) { if (pent == NULL) {
/* FIXME: Should clean everything one day */ /* FIXME: Should clean everything one day */
g_free (buffer); g_free (buffer);
@ -412,10 +415,11 @@ extfs_read_archive (int fstype, char *name, struct archive **pparc)
* mangled by this operation (so you must not free its return value). * mangled by this operation (so you must not free its return value).
*/ */
static char * static char *
extfs_get_path_mangle (char *inname, struct archive **archive, int is_dir, extfs_get_path_mangle (const char *inname, struct archive **archive,
int do_not_open) int is_dir, int do_not_open)
{ {
char *local, *archive_name, *op; char *local, *op;
const char *archive_name;
int result = -1; int result = -1;
struct archive *parc; struct archive *parc;
struct vfs_stamping *parent; struct vfs_stamping *parent;
@ -448,7 +452,9 @@ extfs_get_path_mangle (char *inname, struct archive **archive, int is_dir,
} }
} }
result = do_not_open ? -1 : extfs_read_archive (fstype, archive_name, &parc); result =
do_not_open ? -1 : extfs_read_archive (fstype, archive_name,
&parc);
if (result == -1) if (result == -1)
ERRNOR (EIO, NULL); ERRNOR (EIO, NULL);
@ -642,7 +648,7 @@ extfs_run (char *file)
} }
static void * static void *
extfs_open (struct vfs_class *me, char *file, int flags, int mode) extfs_open (struct vfs_class *me, const char *file, int flags, int mode)
{ {
struct pseudofile *extfs_info; struct pseudofile *extfs_info;
struct archive *archive; struct archive *archive;
@ -1228,17 +1234,18 @@ static void extfs_free (vfsid id)
extfs_free_archive (archive); extfs_free_archive (archive);
} }
static char *extfs_getlocalcopy (struct vfs_class *me, char *path) static char *
extfs_getlocalcopy (struct vfs_class *me, const char *path)
{ {
struct pseudofile *fp = struct pseudofile *fp =
(struct pseudofile *) extfs_open (me, path, O_RDONLY, 0); (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
char *p; char *p;
if (fp == NULL) if (fp == NULL)
return NULL; return NULL;
if (fp->entry->inode->local_filename == NULL) { if (fp->entry->inode->local_filename == NULL) {
extfs_close ((void *) fp); extfs_close ((void *) fp);
return NULL; return NULL;
} }
p = g_strdup (fp->entry->inode->local_filename); p = g_strdup (fp->entry->inode->local_filename);
fp->archive->fd_usage++; fp->archive->fd_usage++;
@ -1246,22 +1253,24 @@ static char *extfs_getlocalcopy (struct vfs_class *me, char *path)
return p; return p;
} }
static int extfs_ungetlocalcopy (struct vfs_class *me, char *path, char *local, int has_changed) static int
extfs_ungetlocalcopy (struct vfs_class *me, const char *path, char *local,
int has_changed)
{ {
struct pseudofile *fp = struct pseudofile *fp =
(struct pseudofile *) extfs_open (me, path, O_RDONLY, 0); (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
if (fp == NULL) if (fp == NULL)
return 0; return 0;
if (!strcmp (fp->entry->inode->local_filename, local)) { if (!strcmp (fp->entry->inode->local_filename, local)) {
fp->archive->fd_usage--; fp->archive->fd_usage--;
fp->has_changed |= has_changed; fp->has_changed |= has_changed;
extfs_close ((void *) fp); extfs_close ((void *) fp);
return 0; return 0;
} else { } else {
/* Should not happen */ /* Should not happen */
extfs_close ((void *) fp); extfs_close ((void *) fp);
return mc_def_ungetlocalcopy (me, path, local, has_changed); return mc_def_ungetlocalcopy (me, path, local, has_changed);
} }
} }

View File

@ -306,12 +306,14 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
} }
static int static int
fish_open_archive (struct vfs_class *me, struct vfs_s_super *super, char *archive_name, char *op) fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
const char *archive_name, char *op)
{ {
char *host, *user, *password, *p; char *host, *user, *password, *p;
int flags; int flags;
p = vfs_split_url (strchr(op, ':')+1, &host, &user, &flags, &password, 0, URL_NOSLASH); p = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags,
&password, 0, URL_NOSLASH);
if (p) if (p)
g_free (p); g_free (p);
@ -319,7 +321,7 @@ fish_open_archive (struct vfs_class *me, struct vfs_s_super *super, char *archiv
SUP.host = host; SUP.host = host;
SUP.user = user; SUP.user = user;
SUP.flags = flags; SUP.flags = flags;
if (!strncmp( op, "rsh:", 4 )) if (!strncmp (op, "rsh:", 4))
SUP.flags |= FISH_FLAG_RSH; SUP.flags |= FISH_FLAG_RSH;
SUP.cwdir = NULL; SUP.cwdir = NULL;
if (password) if (password)
@ -328,19 +330,20 @@ fish_open_archive (struct vfs_class *me, struct vfs_s_super *super, char *archiv
} }
static int static int
fish_archive_same(struct vfs_class *me, struct vfs_s_super *super, char *archive_name, char *op, void *cookie) fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
{ const char *archive_name, char *op, void *cookie)
{
char *host, *user; char *host, *user;
int flags; int flags;
op = vfs_split_url (strchr(op, ':')+1, &host, &user, &flags, 0, 0, URL_NOSLASH); op = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, 0, 0,
URL_NOSLASH);
if (op) if (op)
g_free (op); g_free (op);
flags = ((strcmp (host, SUP.host) == 0) && flags = ((strcmp (host, SUP.host) == 0)
(strcmp (user, SUP.user) == 0) && && (strcmp (user, SUP.user) == 0) && (flags == SUP.flags));
(flags == SUP.flags));
g_free (host); g_free (host);
g_free (user); g_free (user);

View File

@ -741,7 +741,8 @@ ftpfs_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
} }
static int static int
ftpfs_open_archive (struct vfs_class *me, struct vfs_s_super *super, char *archive_name, char *op) ftpfs_open_archive (struct vfs_class *me, struct vfs_s_super *super,
const char *archive_name, char *op)
{ {
char *host, *user, *password; char *host, *user, *password;
int port; int port;
@ -760,15 +761,17 @@ ftpfs_open_archive (struct vfs_class *me, struct vfs_s_super *super, char *archi
SUP.strict = ftpfs_use_unix_list_options ? RFC_AUTODETECT : RFC_STRICT; SUP.strict = ftpfs_use_unix_list_options ? RFC_AUTODETECT : RFC_STRICT;
SUP.isbinary = TYPE_UNKNOWN; SUP.isbinary = TYPE_UNKNOWN;
SUP.remote_is_amiga = 0; SUP.remote_is_amiga = 0;
super->name = g_strdup("/"); super->name = g_strdup ("/");
super->root = vfs_s_new_inode (me, super, vfs_s_default_stat(me, S_IFDIR | 0755)); super->root =
vfs_s_new_inode (me, super,
vfs_s_default_stat (me, S_IFDIR | 0755));
return ftpfs_open_archive_int (me, super); return ftpfs_open_archive_int (me, super);
} }
static int static int
ftpfs_archive_same (struct vfs_class *me, struct vfs_s_super *super, ftpfs_archive_same (struct vfs_class *me, struct vfs_s_super *super,
char *archive_name, char *op, void *cookie) const char *archive_name, char *op, void *cookie)
{ {
char *host, *user; char *host, *user;
int port; int port;

View File

@ -19,18 +19,18 @@
static struct vfs_class vfs_local_ops; static struct vfs_class vfs_local_ops;
static void * static void *
local_open (struct vfs_class *me, char *file, int flags, int mode) local_open (struct vfs_class *me, const char *file, int flags, int mode)
{ {
int *local_info; int *local_info;
int fd; int fd;
fd = open (file, NO_LINEAR(flags), mode); fd = open (file, NO_LINEAR (flags), mode);
if (fd == -1) if (fd == -1)
return 0; return 0;
local_info = g_new (int, 1); local_info = g_new (int, 1);
*local_info = fd; *local_info = fd;
return local_info; return local_info;
} }
@ -249,13 +249,14 @@ local_free (vfsid id)
} }
static char * static char *
local_getlocalcopy (struct vfs_class *me, char *path) local_getlocalcopy (struct vfs_class *me, const char *path)
{ {
return g_strdup (path); return g_strdup (path);
} }
static int static int
local_ungetlocalcopy (struct vfs_class *me, char *path, char *local, int has_changed) local_ungetlocalcopy (struct vfs_class *me, const char *path, char *local,
int has_changed)
{ {
return 0; return 0;
} }

View File

@ -83,7 +83,7 @@ static struct vfs_class vfs_mcfs_ops;
/* Extract the hostname and username from the path */ /* Extract the hostname and username from the path */
/* path is in the form: hostname:user/remote-dir */ /* path is in the form: hostname:user/remote-dir */
static char * static char *
mcfs_get_host_and_username (char *path, char **host, char **user, mcfs_get_host_and_username (const char *path, char **host, char **user,
int *port, char **pass) int *port, char **pass)
{ {
return vfs_split_url (path, host, user, port, pass, 0, 0); return vfs_split_url (path, host, user, port, pass, 0, 0);
@ -361,7 +361,7 @@ mcfs_set_error (int result, int errno_num)
} }
static char * static char *
mcfs_get_path (mcfs_connection **mc, char *path) mcfs_get_path (mcfs_connection **mc, const char *path)
{ {
char *user, *host, *remote_path; char *user, *host, *remote_path;
char *pass; char *pass;
@ -510,7 +510,7 @@ mcfs_gethome (mcfs_connection *mc)
/* The callbacks */ /* The callbacks */
static void * static void *
mcfs_open (struct vfs_class *me, char *file, int flags, int mode) mcfs_open (struct vfs_class *me, const char *file, int flags, int mode)
{ {
char *remote_file; char *remote_file;
mcfs_connection *mc; mcfs_connection *mc;
@ -520,8 +520,8 @@ mcfs_open (struct vfs_class *me, char *file, int flags, int mode)
if (!(remote_file = mcfs_get_path (&mc, file))) if (!(remote_file = mcfs_get_path (&mc, file)))
return 0; return 0;
rpc_send (mc->sock, RPC_INT, MC_OPEN, RPC_STRING, remote_file, rpc_send (mc->sock, RPC_INT, MC_OPEN, RPC_STRING, remote_file, RPC_INT,
RPC_INT, flags, RPC_INT, mode, RPC_END); flags, RPC_INT, mode, RPC_END);
g_free (remote_file); g_free (remote_file);
if (0 == if (0 ==

View File

@ -43,46 +43,58 @@ static int sfs_flags[ MAXFS ];
#define F_NOLOCALCOPY 4 #define F_NOLOCALCOPY 4
#define F_FULLMATCH 8 #define F_FULLMATCH 8
static int sfs_uptodate (char *name, char *cache) static int
sfs_uptodate (char *name, char *cache)
{ {
return 1; return 1;
} }
static int sfs_vfmake (struct vfs_class *me, char *name, char *cache) static int
sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
{ {
char *inpath, *op; char *inpath, *op;
int w; int w;
char pad [10240]; char pad[10240];
char *s, *t = pad; char *s, *t = pad;
int was_percent = 0; int was_percent = 0;
vfs_split (name, &inpath, &op); vfs_split (name, &inpath, &op);
if ((w = (*me->which) (me, op)) == -1) if ((w = (*me->which) (me, op)) == -1)
vfs_die ("This cannot happen... Hopefully.\n"); vfs_die ("This cannot happen... Hopefully.\n");
if ((sfs_flags[w] & F_1) || (!strcmp (name, "/"))) ; else return -1; if ((sfs_flags[w] & F_1) || (!strcmp (name, "/")));
else
return -1;
/* if ((sfs_flags[w] & F_2) || (!inpath) || (!*inpath)); else return -1; */ /* if ((sfs_flags[w] & F_2) || (!inpath) || (!*inpath)); else return -1; */
if (!(sfs_flags[w] & F_NOLOCALCOPY)) { if (!(sfs_flags[w] & F_NOLOCALCOPY)) {
s = mc_getlocalcopy (name); s = mc_getlocalcopy (name);
if (!s) if (!s)
return -1; return -1;
name = name_quote (s, 0); name = name_quote (s, 0);
g_free (s); g_free (s);
} else } else
name = name_quote (name, 0); name = name_quote (name, 0);
#define COPY_CHAR if (t-pad>sizeof(pad)) { g_free (name); return -1; } else *t++ = *s; #define COPY_CHAR if (t-pad>sizeof(pad)) { return -1; } else *t++ = *s;
#define COPY_STRING(a) if ((t-pad)+strlen(a)>sizeof(pad)) { g_free (name); return -1; } else { strcpy (t, a); t+= strlen(a); } #define COPY_STRING(a) if ((t-pad)+strlen(a)>sizeof(pad)) { return -1; } else { strcpy (t, a); t+= strlen(a); }
for (s = sfs_command[w]; *s; s++) { for (s = sfs_command[w]; *s; s++) {
if (was_percent) { if (was_percent) {
char *ptr = NULL; const char *ptr = NULL;
was_percent = 0; was_percent = 0;
switch (*s) { switch (*s) {
case '1': ptr = name; break; case '1':
case '2': ptr = op + strlen (sfs_prefix[w]); break; ptr = name;
case '3': ptr = cache; break; break;
case '%': COPY_CHAR; continue; case '2':
ptr = op + strlen (sfs_prefix[w]);
break;
case '3':
ptr = cache;
break;
case '%':
COPY_CHAR;
continue;
} }
COPY_STRING (ptr); COPY_STRING (ptr);
} else { } else {
@ -92,7 +104,6 @@ static int sfs_vfmake (struct vfs_class *me, char *name, char *cache)
COPY_CHAR; COPY_CHAR;
} }
} }
g_free (name);
open_error_pipe (); open_error_pipe ();
if (my_system (EXECUTE_AS_SHELL, "/bin/sh", pad)) { if (my_system (EXECUTE_AS_SHELL, "/bin/sh", pad)) {
@ -101,11 +112,11 @@ static int sfs_vfmake (struct vfs_class *me, char *name, char *cache)
} }
close_error_pipe (0, NULL); close_error_pipe (0, NULL);
return 0; /* OK */ return 0; /* OK */
} }
static char * static char *
sfs_redirect (struct vfs_class *me, char *name) sfs_redirect (struct vfs_class *me, const char *name)
{ {
struct cachedfile *cur = head; struct cachedfile *cur = head;
char *cache; char *cache;
@ -146,19 +157,19 @@ sfs_redirect (struct vfs_class *me, char *name)
} }
static void * static void *
sfs_open (struct vfs_class *me, char *path, int flags, int mode) sfs_open (struct vfs_class *me, const char *path, int flags, int mode)
{ {
int *sfs_info; int *sfs_info;
int fd; int fd;
path = sfs_redirect (me, path); path = sfs_redirect (me, path);
fd = open (path, NO_LINEAR(flags), mode); fd = open (path, NO_LINEAR (flags), mode);
if (fd == -1) if (fd == -1)
return 0; return 0;
sfs_info = g_new (int, 1); sfs_info = g_new (int, 1);
*sfs_info = fd; *sfs_info = fd;
return sfs_info; return sfs_info;
} }
@ -282,15 +293,18 @@ static int sfs_nothingisopen (vfsid id)
return 1; return 1;
} }
static char *sfs_getlocalcopy (struct vfs_class *me, char *path) static char *
sfs_getlocalcopy (struct vfs_class *me, const char *path)
{ {
path = sfs_redirect (me, path); path = sfs_redirect (me, path);
return g_strdup (path); return g_strdup (path);
} }
static int sfs_ungetlocalcopy (struct vfs_class *me, char *path, char *local, int has_changed) static int
sfs_ungetlocalcopy (struct vfs_class *me, const char *path, char *local,
int has_changed)
{ {
g_free(local); g_free (local);
return 0; return 0;
} }

View File

@ -1791,7 +1791,7 @@ smbfs_open_readwrite (smbfs_handle *remote_handle, char *rname, int flags, int m
} }
static void * static void *
smbfs_open (struct vfs_class *me, char *file, int flags, int mode) smbfs_open (struct vfs_class *me, const char *file, int flags, int mode)
{ {
char *remote_file, *p; char *remote_file, *p;
void *ret; void *ret;

View File

@ -198,18 +198,20 @@ static void tar_free_archive (struct vfs_class *me, struct vfs_s_super *archive)
static int current_tar_position = 0; static int current_tar_position = 0;
/* Returns fd of the open tar file */ /* Returns fd of the open tar file */
static int tar_tar_open_archive (struct vfs_class *me, char *name, struct vfs_s_super *archive) static int
tar_open_archive_int (struct vfs_class *me, const char *name,
struct vfs_s_super *archive)
{ {
int result, type; int result, type;
mode_t mode; mode_t mode;
struct vfs_s_inode *root; struct vfs_s_inode *root;
result = mc_open (name, O_RDONLY); result = mc_open (name, O_RDONLY);
if (result == -1) { if (result == -1) {
message (1, MSG_ERROR, _("Cannot open tar archive\n%s"), name); message (1, MSG_ERROR, _("Cannot open tar archive\n%s"), name);
ERRNOR (ENOENT, -1); ERRNOR (ENOENT, -1);
} }
archive->name = g_strdup (name); archive->name = g_strdup (name);
mc_stat (name, &(archive->u.arch.st)); mc_stat (name, &(archive->u.arch.st));
archive->u.arch.fd = -1; archive->u.arch.fd = -1;
@ -219,21 +221,24 @@ static int tar_tar_open_archive (struct vfs_class *me, char *name, struct vfs_s_
mc_lseek (result, 0, SEEK_SET); mc_lseek (result, 0, SEEK_SET);
if (type != COMPRESSION_NONE) { if (type != COMPRESSION_NONE) {
char *s; char *s;
mc_close( result ); mc_close (result);
s = g_strconcat ( archive->name, decompress_extension (type), NULL ); s = g_strconcat (archive->name, decompress_extension (type), NULL);
result = mc_open (s, O_RDONLY); result = mc_open (s, O_RDONLY);
if (result == -1) if (result == -1)
message (1, MSG_ERROR, _("Cannot open tar archive\n%s"), s); message (1, MSG_ERROR, _("Cannot open tar archive\n%s"), s);
g_free(s); g_free (s);
if (result == -1) if (result == -1)
ERRNOR (ENOENT, -1); ERRNOR (ENOENT, -1);
} }
archive->u.arch.fd = result; archive->u.arch.fd = result;
mode = archive->u.arch.st.st_mode & 07777; mode = archive->u.arch.st.st_mode & 07777;
if (mode & 0400) mode |= 0100; if (mode & 0400)
if (mode & 0040) mode |= 0010; mode |= 0100;
if (mode & 0004) mode |= 0001; if (mode & 0040)
mode |= 0010;
if (mode & 0004)
mode |= 0001;
mode |= S_IFDIR; mode |= S_IFDIR;
root = vfs_s_new_inode (me, archive, &archive->u.arch.st); root = vfs_s_new_inode (me, archive, &archive->u.arch.st);
@ -514,7 +519,7 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive, int tard)
*/ */
static int static int
tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive, tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive,
char *name, char *op) const char *name, char *op)
{ {
/* Initial status at start of archive */ /* Initial status at start of archive */
ReadStatus status = STATUS_EOFMARK; ReadStatus status = STATUS_EOFMARK;
@ -523,7 +528,7 @@ tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive,
current_tar_position = 0; current_tar_position = 0;
/* Open for reading */ /* Open for reading */
if ((tard = tar_tar_open_archive (me, name, archive)) == -1) if ((tard = tar_open_archive_int (me, name, archive)) == -1)
return -1; return -1;
for (;;) { for (;;) {
@ -580,7 +585,8 @@ tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive,
return 0; return 0;
} }
static void *tar_super_check(struct vfs_class *me, char *archive_name, char *op) static void *
tar_super_check (struct vfs_class *me, const char *archive_name, char *op)
{ {
static struct stat stat_buf; static struct stat stat_buf;
if (mc_stat (archive_name, &stat_buf)) if (mc_stat (archive_name, &stat_buf))
@ -589,8 +595,8 @@ static void *tar_super_check(struct vfs_class *me, char *archive_name, char *op)
} }
static int static int
tar_super_same (struct vfs_class *me, struct vfs_s_super *parc, char *archive_name, tar_super_same (struct vfs_class *me, struct vfs_s_super *parc,
char *op, void *cookie) const char *archive_name, char *op, void *cookie)
{ {
struct stat *archive_stat = cookie; /* stat of main archive */ struct stat *archive_stat = cookie; /* stat of main archive */

View File

@ -380,19 +380,20 @@ typedef struct {
/* We do not support lseek */ /* We do not support lseek */
static void * static void *
undelfs_open (struct vfs_class *me, char *fname, int flags, int mode) undelfs_open (struct vfs_class *me, const char *fname, int flags, int mode)
{ {
char *file, *f; char *file, *f;
ext2_ino_t inode, i; ext2_ino_t inode, i;
undelfs_file *p = NULL; undelfs_file *p = NULL;
/* Only allow reads on this file system */ /* Only allow reads on this file system */
undelfs_get_path (fname, &file, &f); undelfs_get_path (fname, &file, &f);
if (!file) if (!file)
return 0; return 0;
if (!ext2_fname || strcmp (ext2_fname, file)){ if (!ext2_fname || strcmp (ext2_fname, file)) {
message (1, undelfserr, _(" You have to chdir to extract files first ")); message (1, undelfserr,
_(" You have to chdir to extract files first "));
g_free (file); g_free (file);
g_free (f); g_free (f);
return 0; return 0;
@ -400,19 +401,19 @@ undelfs_open (struct vfs_class *me, char *fname, int flags, int mode)
inode = atol (f); inode = atol (f);
/* Search the file into delarray */ /* Search the file into delarray */
for (i = 0; i < num_delarray; i++){ for (i = 0; i < num_delarray; i++) {
if (inode != delarray [i].ino) if (inode != delarray[i].ino)
continue; continue;
/* Found: setup all the structures needed by read */ /* Found: setup all the structures needed by read */
p = g_new (undelfs_file, 1); p = g_new (undelfs_file, 1);
if (!p){ if (!p) {
g_free (file); g_free (file);
g_free (f); g_free (f);
return 0; return 0;
} }
p->buf = g_malloc (fs->blocksize); p->buf = g_malloc (fs->blocksize);
if (!p->buf){ if (!p->buf) {
g_free (p); g_free (p);
g_free (file); g_free (file);
g_free (f); g_free (f);
@ -423,7 +424,7 @@ undelfs_open (struct vfs_class *me, char *fname, int flags, int mode)
p->f_index = i; p->f_index = i;
p->error_code = 0; p->error_code = 0;
p->pos = 0; p->pos = 0;
p->size = delarray [i].size; p->size = delarray[i].size;
} }
g_free (file); g_free (file);
g_free (f); g_free (f);

View File

@ -1008,9 +1008,10 @@ mc_munmap (caddr_t addr, size_t len)
#endif #endif
char * char *
mc_def_getlocalcopy (struct vfs_class *vfs, char *filename) mc_def_getlocalcopy (struct vfs_class *vfs, const char *filename)
{ {
char *tmp, *suffix, *basename; char *tmp, *suffix;
const char *basename;
int fdin, fdout, i; int fdin, fdout, i;
char buffer[8192]; char buffer[8192];
struct stat mystat; struct stat mystat;
@ -1079,8 +1080,8 @@ mc_getlocalcopy (const char *pathname)
} }
int int
mc_def_ungetlocalcopy (struct vfs_class *vfs, char *filename, char *local, mc_def_ungetlocalcopy (struct vfs_class *vfs, const char *filename,
int has_changed) char *local, int has_changed)
{ {
int fdin = -1, fdout = -1, i; int fdin = -1, fdout = -1, i;
if (has_changed) { if (has_changed) {

View File

@ -34,7 +34,8 @@ struct vfs_class {
int (*which) (struct vfs_class *me, char *path); int (*which) (struct vfs_class *me, char *path);
void *(*open) (struct vfs_class *me, char *fname, int flags, int mode); void *(*open) (struct vfs_class *me, const char *fname, int flags,
int mode);
int (*close) (void *vfs_info); int (*close) (void *vfs_info);
int (*read) (void *vfs_info, char *buffer, int count); int (*read) (void *vfs_info, char *buffer, int count);
int (*write) (void *vfs_info, char *buf, int count); int (*write) (void *vfs_info, char *buf, int count);
@ -49,9 +50,11 @@ struct vfs_class {
int (*chmod) (struct vfs_class *me, char *path, int mode); int (*chmod) (struct vfs_class *me, char *path, int mode);
int (*chown) (struct vfs_class *me, char *path, int owner, int group); int (*chown) (struct vfs_class *me, char *path, int owner, int group);
int (*utime) (struct vfs_class *me, char *path, struct utimbuf * times); int (*utime) (struct vfs_class *me, char *path,
struct utimbuf * times);
int (*readlink) (struct vfs_class *me, char *path, char *buf, int size); int (*readlink) (struct vfs_class *me, char *path, char *buf,
int size);
int (*symlink) (struct vfs_class *me, char *n1, char *n2); int (*symlink) (struct vfs_class *me, char *n1, char *n2);
int (*link) (struct vfs_class *me, char *p1, char *p2); int (*link) (struct vfs_class *me, char *p1, char *p2);
int (*unlink) (struct vfs_class *me, char *path); int (*unlink) (struct vfs_class *me, char *path);
@ -67,19 +70,21 @@ struct vfs_class {
int (*nothingisopen) (vfsid id); int (*nothingisopen) (vfsid id);
void (*free) (vfsid id); void (*free) (vfsid id);
char *(*getlocalcopy) (struct vfs_class *me, char *filename); char *(*getlocalcopy) (struct vfs_class *me, const char *filename);
int (*ungetlocalcopy) (struct vfs_class *me, char *filename, char *local, int (*ungetlocalcopy) (struct vfs_class *me, const char *filename,
int has_changed); char *local, int has_changed);
int (*mkdir) (struct vfs_class *me, char *path, mode_t mode); int (*mkdir) (struct vfs_class *me, char *path, mode_t mode);
int (*rmdir) (struct vfs_class *me, char *path); int (*rmdir) (struct vfs_class *me, char *path);
int (*ctl) (void *vfs_info, int ctlop, void *arg); int (*ctl) (void *vfs_info, int ctlop, void *arg);
int (*setctl) (struct vfs_class *me, char *path, int ctlop, void *arg); int (*setctl) (struct vfs_class *me, char *path, int ctlop,
void *arg);
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
caddr_t (*mmap) (struct vfs_class *me, caddr_t addr, size_t len, int prot, caddr_t (*mmap) (struct vfs_class *me, caddr_t addr, size_t len,
int flags, void *vfs_info, off_t offset); int prot, int flags, void *vfs_info, off_t offset);
int (*munmap) (struct vfs_class *me, caddr_t addr, size_t len, void *vfs_info); int (*munmap) (struct vfs_class *me, caddr_t addr, size_t len,
void *vfs_info);
#endif #endif
}; };
@ -175,9 +180,9 @@ int mc_mkdir (char *path, mode_t mode);
char *mc_getlocalcopy (const char *pathname); char *mc_getlocalcopy (const char *pathname);
int mc_ungetlocalcopy (const char *pathname, char *local, int has_changed); int mc_ungetlocalcopy (const char *pathname, char *local, int has_changed);
char *mc_def_getlocalcopy (struct vfs_class *vfs, char *filename); char *mc_def_getlocalcopy (struct vfs_class *vfs, const char *filename);
int mc_def_ungetlocalcopy (struct vfs_class *vfs, char *filename, char *local, int mc_def_ungetlocalcopy (struct vfs_class *vfs, const char *filename,
int has_changed); char *local, int has_changed);
int mc_ctl (int fd, int ctlop, void *arg); int mc_ctl (int fd, int ctlop, void *arg);
int mc_setctl (char *path, int ctlop, void *arg); int mc_setctl (char *path, int ctlop, void *arg);
#ifdef HAVE_MMAP #ifdef HAVE_MMAP

View File

@ -121,11 +121,11 @@ struct vfs_s_subclass {
void (*free_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */ void (*free_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */
int (*init_entry) (struct vfs_class *me, struct vfs_s_entry *entry); /* optional */ int (*init_entry) (struct vfs_class *me, struct vfs_s_entry *entry); /* optional */
void *(*archive_check) (struct vfs_class *me, char *name, char *op); /* optional */ void *(*archive_check) (struct vfs_class *me, const char *name, char *op); /* optional */
int (*archive_same) (struct vfs_class *me, struct vfs_s_super *psup, int (*archive_same) (struct vfs_class *me, struct vfs_s_super *psup,
char *archive_name, char *op, void *cookie); const char *archive_name, char *op, void *cookie);
int (*open_archive) (struct vfs_class *me, struct vfs_s_super *psup, int (*open_archive) (struct vfs_class *me, struct vfs_s_super *psup,
char *archive_name, char *op); const char *archive_name, char *op);
void (*free_archive) (struct vfs_class *me, void (*free_archive) (struct vfs_class *me,
struct vfs_s_super *psup); struct vfs_s_super *psup);
@ -180,7 +180,7 @@ struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me,
/* outside interface */ /* outside interface */
void vfs_s_init_class (struct vfs_class *vclass); void vfs_s_init_class (struct vfs_class *vclass);
char *vfs_s_get_path_mangle (struct vfs_class *me, char *inname, char *vfs_s_get_path_mangle (struct vfs_class *me, const char *inname,
struct vfs_s_super **archive, int flags); struct vfs_s_super **archive, int flags);
void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super); void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino); char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);