[syslinux:lwip] pxe: push the open flags down into individual methods

syslinux-bot for H. Peter Anvin hpa at zytor.com
Sun May 1 18:33:26 PDT 2011


Commit-ID:  275abcfb66c764bbc7b0d07ec9b63e6fda63ec3a
Gitweb:     http://syslinux.zytor.com/commit/275abcfb66c764bbc7b0d07ec9b63e6fda63ec3a
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Sun, 1 May 2011 18:30:01 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Sun, 1 May 2011 18:30:01 -0700

pxe: push the open flags down into individual methods

Push the open flags down to the individual system methods.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 core/fs/pxe/ftp.c  |    5 ++++-
 core/fs/pxe/http.c |    5 ++++-
 core/fs/pxe/pxe.c  |   18 ++++++++++--------
 core/fs/pxe/pxe.h  |    9 ++++++---
 core/fs/pxe/tftp.c |    4 +++-
 5 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/core/fs/pxe/ftp.c b/core/fs/pxe/ftp.c
index 4efcedb..93255a1 100644
--- a/core/fs/pxe/ftp.c
+++ b/core/fs/pxe/ftp.c
@@ -168,7 +168,8 @@ static void ftp_close_file(struct inode *inode)
     ftp_free(inode);
 }
 
-void ftp_open(struct url_info *url, struct inode *inode, const char **redir)
+void ftp_open(struct url_info *url, int flags, struct inode *inode,
+	      const char **redir)
 {
     struct pxe_pvt_inode *socket = PVT(inode);
     struct pxe_pvt_inode *ctlsock;
@@ -179,6 +180,8 @@ void ftp_open(struct url_info *url, struct inode *inode, const char **redir)
     err_t err;
 
     (void)redir;		/* FTP does not redirect */
+    (void)flags;
+
     inode->size = 0;
 
     if (!url->port)
diff --git a/core/fs/pxe/http.c b/core/fs/pxe/http.c
index fef87b0..6f159f6 100644
--- a/core/fs/pxe/http.c
+++ b/core/fs/pxe/http.c
@@ -145,7 +145,8 @@ void http_bake_cookies(void)
     http_do_bake_cookies(cookie_buf);
 }
 
-void http_open(struct url_info *url, struct inode *inode, const char **redir)
+void http_open(struct url_info *url, int flags, struct inode *inode,
+	       const char **redir)
 {
     struct pxe_pvt_inode *socket = PVT(inode);
     int header_bytes;
@@ -172,6 +173,8 @@ void http_open(struct url_info *url, struct inode *inode, const char **redir)
     int status;
     int pos;
 
+    (void)flags;
+
     if (!header_buf)
 	return;			/* http is broken... */
 
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index b7ec050..60f5d58 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -4,6 +4,7 @@
 #include <core.h>
 #include <fs.h>
 #include <minmax.h>
+#include <fcntl.h>
 #include <sys/cpu.h>
 #include <lwip/api.h>
 #include <lwip/dns.h>
@@ -32,13 +33,15 @@ __lowmem char packet_buf[PKTBUF_SIZE] __aligned(16);
 
 static struct url_scheme {
     const char *name;
-    void (*open)(struct url_info *url, struct inode *inode, const char **redir);
+    void (*open)(struct url_info *, int, struct inode *, const char **);
+    int ok_flags;
 } url_schemes[] = {
-    { "tftp", tftp_open },
-    { "http", http_open },
-    { "ftp",  ftp_open },
-    { NULL, NULL },
+    { "tftp", tftp_open, 0 },
+    { "http", http_open, O_DIRECTORY },
+    { "ftp",  ftp_open,  0 },
+    { NULL, NULL, 0 },
 };
+#define OK_FLAGS_MASK	(O_DIRECTORY|O_WRONLY)
 
 /*
  * Allocate a local UDP port structure and assign it a local port number.
@@ -321,8 +324,6 @@ static void __pxe_searchdir(const char *filename, int flags, struct file *file)
     int redirect_count = 0;
     bool found_scheme = false;
 
-    (void)flags;
-
     inode = file->inode = NULL;
 
     while (filename) {
@@ -352,7 +353,8 @@ static void __pxe_searchdir(const char *filename, int flags, struct file *file)
 	found_scheme = false;
 	for (us = url_schemes; us->name; us++) {
 	    if (!strcmp(us->name, url.scheme)) {
-		us->open(&url, inode, &filename);
+		if (((flags ^ us->ok_flags) & OK_FLAGS_MASK) == 0)
+		    us->open(&url, flags, inode, &filename);
 		found_scheme = true;
 		break;
 	    }
diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h
index c8d35d0..c084790 100644
--- a/core/fs/pxe/pxe.h
+++ b/core/fs/pxe/pxe.h
@@ -219,18 +219,21 @@ void pxe_idle_init(void);
 void pxe_idle_cleanup(void);
 
 /* tftp.c */
-void tftp_open(struct url_info *url, struct inode *inode, const char **redir);
+void tftp_open(struct url_info *url, int flags, struct inode *inode,
+	       const char **redir);
 
 /* gpxeurl.c */
 void gpxe_open(struct inode *inode, const char *url);
 #define GPXE 0
 
 /* http.c */
-void http_open(struct url_info *url, struct inode *inode, const char **redir);
+void http_open(struct url_info *url, int flags, struct inode *inode,
+	       const char **redir);
 void http_bake_cookies(void);
 
 /* ftp.c */
-void ftp_open(struct url_info *url, struct inode *inode, const char **redir);
+void ftp_open(struct url_info *url, int flags, struct inode *inode,
+	      const char **redir);
 
 /* tcp.c */
 void tcp_close_file(struct inode *inode);
diff --git a/core/fs/pxe/tftp.c b/core/fs/pxe/tftp.c
index 5aafd8e..b203a8f 100644
--- a/core/fs/pxe/tftp.c
+++ b/core/fs/pxe/tftp.c
@@ -209,7 +209,8 @@ static void tftp_get_packet(struct inode *inode)
  * @out: the lenght of this file, stores in file->file_len
  *
  */
-void tftp_open(struct url_info *url, struct inode *inode, const char **redir)
+void tftp_open(struct url_info *url, int flags, struct inode *inode,
+	       const char **redir)
 {
     struct pxe_pvt_inode *socket = PVT(inode);
     char *buf;
@@ -234,6 +235,7 @@ void tftp_open(struct url_info *url, struct inode *inode, const char **redir)
     struct ip_addr addr;
 
     (void)redir;		/* TFTP does not redirect */
+    (void)flags;
 
     if (url->type != URL_OLD_TFTP) {
 	/*



More information about the Syslinux-commits mailing list